fix(core): restore LocalStorageBackend auto-wire in TdaiCore constructor (CR-2)#209
Open
ferminquant wants to merge 2 commits into
Open
fix(core): restore LocalStorageBackend auto-wire in TdaiCore constructor (CR-2)#209ferminquant wants to merge 2 commits into
ferminquant wants to merge 2 commits into
Conversation
…tor (CR-2)
The l1-writer CR-2 guard (l1-writer.ts:202-217) expects every writeMemory
call to be backed by a StorageAdapter. Its own comment says standalone
mode is supposed to auto-wire a LocalStorageBackend at startup, but the
auto-wire is missing for the OpenClaw host-adapter entry: server.ts:261
and the bundled dist/index.mjs:21372 both construct TdaiCore without
passing storage, leaving this.storage undefined.
Effect in standalone mode: every L1 write emits the CR-2 guard warning
4 times per extraction (once per memory), even though the data lands at
the correct JSONL path. Effect in service mode: callers that forget to
pass storage get a real data-loss path because writes fall back to
ephemeral pod fs.
Restore the auto-wire in TdaiCore.constructor: default this.storage to
new LocalStorageBackend({ rootDir: dataDir, logger }) when opts.storage
is undefined. Service-mode callers that pass a custom storage (e.g.
CosStorageBackend) still win because the fallback only fires when
opts.storage is undefined.
Closes TencentCloud#208
Collaborator
|
Thanks for your attention. We will review it and get back to you soon. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Restore the
LocalStorageBackendauto-wire inTdaiCore.constructorthat thel1-writerCR-2 guard comment refers to but is missing in this build. The auto-wire was documented (l1-writer.ts:202-217says "the gateway auto-wires aLocalStorageBackendat startup (server.ts:199-203)") but neitherserver.ts:261nor the OpenClaw host-adapter entry actually constructs one before constructingTdaiCore, sothis.storageisundefinedin standalone installs.This makes the CR-2 guard fire on every L1 write in standalone mode (no real data loss, but the warning is misleading) and leaves the original data-loss path open in service mode for any caller that forgets to pass
storageexplicitly.Changes
src/core/tdai-core.ts— in the constructor, defaultthis.storagetonew LocalStorageBackend({ rootDir: this.dataDir, logger: this.logger })whenopts.storageis undefined. One import line, one logic line, plus a comment explaining the intent.Why this shape
server.ts:134,server.ts:261, the bundled OpenClaw host-adapter) and the gateway may add more. Putting the fallback in one place is harder to forget than a chain of call-site changes.??and not a config flag: the documented intent is that this is always safe in standalone mode (theLocalStorageBackendwrites to the samedataDirthe existing fs fallback would write to, with the same JSONL format). Adding a flag would imply a case where the operator wants the warning to keep firing, which is the opposite of what the guard comment says.storage. Lowering the warning would hide a real data-loss path. The constructor auto-wire makes the warning fire only when the operator actually has a problem.Testing
I have this running on my local OpenClaw install (
@tencentdb-agent-memory/memory-tencentdbv1.0.0 + OpenClaw v2026.5.20, single host, WSL2). The CR-2 warnings stop appearing injournalctl --user -u openclaw-gateway.serviceafter restart with the patch. L1 records continue to land at~/.openclaw/memory-tdai/records/<date>.jsonlwith the same on-disk format (theLocalStorageBackendusesO_APPENDatomic appends, which is the same primitive the previousfs.appendFilepath used).I have not run the upstream test suite — my fork is a clean checkout. If maintainers want CI green before merge, I can rebase and run it locally if there's a Makefile or test script I should use.
Risk
opts.storage ?? LocalStorageBackendonly falls back whenopts.storageis undefined. Callers that pass aCosStorageBackend(or any other custom storage) keep using it.fs.appendFile" to "write to local fs viaLocalStorageBackend." The on-disk format is identical (both usefs.appendFileunder the hood, the storage wrapper just adds theO_APPENDflag which is the default forappendFile). Records already on disk from the old path remain readable.LocalStorageBackendis already used inserver.ts:362, 558, 1443, so the import is already in the dep graph at the package level.Out of scope
PipelineFactoryOptions/createPipelineinterface also lacks astorage?field, which is a related but distinct issue. I left it alone in this PR to keep the diff small. Happy to send a follow-up PR if the maintainers want the data flow to be explicit at every layer.seed-runtimepath also callscreatePipelineand may have the same issue. Same — follow-up PR if needed.Linked
Closes #208