Repository navigation
Conversation
The memory journal under <home>/memory/journal.jsonl was append-only and never pruned: 300 remember+forget turns left 600 lines behind while MEMORY.md was back to its empty skeleton. It now keeps the newest 500 changes and at most 1 MiB, folding everything older into one `truncated` record and rewriting the file through a temp name. Fixes #2807 Docs-not-needed: the retention bound sits inside the core-host page's existing description of the memory journal (file checks, write path, side channel); it adds no folder, no API and no new reader.
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.
fix(memory): cap the memory journal so it keeps its newest changes
Fixes #2807
Owner: Dev
Reviewer: Birfy
Written-by: Dev
Bot: Dev
Risk tier: T2
Base: f42ad01
Claim-Id: 3f049f868ab3ff391e0301d6dc1aea19
What changed
<home>/memory/journal.jsonlwas append-only and never pruned: everyremember,replace,forgetand archive added a line, and nothing ever removed one. The memory itself is at a steady state, so only this side channel grew without bound.core/src/host/memory.jsnow keeps the newest changes under two caps,JOURNAL_KEPT(500 lines) andJOURNAL_MAX_BYTES(1 MiB), the same shape as the state journal'spruneEntries: past a cap the oldest lines are folded into one{"time":…,"op":"truncated","dropped":N}record, an earlier fold's count carries into the next one, and the whole file is rewritten through a temp name andrename(replacePrivateFile, the target's mode kept) so a reader never sees half a line. A trim keeps 90% of the cap, so the file is rewritten every few changes rather than on every one. The normal log lines andmode: PRIVATE_FILE_MODEare unchanged;journal.jsonlstill has no reader outside the tests.core/test/memory-journal-cap.test.jsis new: a realapply()host runs 300remember+forgetturns (600 writes,MEMORY.mdback to its 20-byte skeleton), then asserts the file is at most 1 MiB and 500 lines, that the oldest note is gone and onetruncatedrecord names the fold, and that a change made after the prune is still the newest line. The regeneratedpatches/ds-bot/mirrors are in this diff;changelog.d/2807.fixed.mdrecords the user-visible change.Red first
At base
f42ad016, with only the new test applied andmemory.jsas it was:600 lines is the defect: the 300 add+forget cycles left every line behind while the memory was empty again.
Ran at this tip
Not run
npm run verify; it needs the test bench with a harness checkout, and this change is covered by the core suite above.npm run pack, the typecheck and actionlint: the CIpackagejob runs them; they are not part ofnpm run verify.Docs-not-needed: the retention bound sits inside the core-host page's existing description of the memory journal (file checks, write path, side channel); it adds no folder, no API and no new reader.
Checkpoint
{ "pr": 2809, "claim": "Dev", "issue": 2807, "summary": "The memory journal was append-only: 300 remember+forget turns left 600 lines while MEMORY.md was back to 20 bytes. `memory.js` now keeps the newest 500 changes (1 MiB) and folds the rest into one `truncated` record, rewritten through a temp name like the state journal. A new real-host test reproduces the growth and pins the cap, the fold count and the newest-line rule; regenerated `patches/ds-bot/` mirrors and a changelog fragment ride along.", "files": [ "core/src/host/memory.js", "core/test/memory-journal-cap.test.js", "patches/ds-bot/0001-core-fixes.patch", "patches/ds-bot/files/test/memory-journal-cap.test.js", "changelog.d/2807.fixed.md" ], "checks": { "ran": "TZ=UTC node --import ./test/harness-resolve.mjs --test test/memory-journal-cap.test.js (1/1); test/memory*.test.js (134/134); TZ=UTC npm run verify (core 3197/3198, social 619, tree 145, timeline 161, workflow 528, scripts+policy 673, interop 37, live-e2e 34; arch-docs OK; canonical no-op)", "result": "green", "at": "bf6ccf943e3024c3b9e7adb89f72df2cc262a8f7" }, "next": "none — ready for review" }