perf: debounce the @memory narrative read-rewrite (#445)#460
Merged
Conversation
Addresses #445 item 2 (the @memory narrative is fully rewritten on every fresh render just to bump `updated`). Feat #2 — reading a *non-stale* narrative resets its staleness clock — rewrote the entire narrative file (`_save_narrative`) on EVERY render. Under bursty rendering (e.g. an agent loop) that's a file write per render. Debounce it: reuse the age already computed by the staleness check and only re-stamp `updated` when the recorded value is older than a window (default 60s, `memory.narrative_touch_debounce_s`) or unparseable. Staleness is measured in hours (ttl), so collapsing sub-window touches costs no meaningful precision while removing the repeated write. Contract preserved: both existing Feat #2 tests still pass unchanged — test_feat2_touch_updated_on_fresh_render uses a 30-min-old timestamp (>> the 60s window, so it still re-stamps), and test_feat2_no_touch_when_stale is unaffected (stale → never touched). Tests: + test_feat2_touch_is_debounced_within_window (a render with `updated` 10s ago and a 5-min window does NOT rewrite the file). 46 passed across the memory-feature + agora suites. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Addresses #445 item 2 (the
@memorynarrative is fully rewritten on every fresh render just to bumpupdated). Owner-approved approach: debounce.Problem
Feat #2 — reading a non-stale narrative resets its staleness clock — rewrote the entire narrative file (
_save_narrative) on every render. Under bursty rendering (e.g. an agent loop) that's a file write per render.Fix
Reuse the age already computed by the staleness check and only re-stamp
updatedwhen the recorded value is older than a window (default 60s,memory.narrative_touch_debounce_s) or unparseable. Staleness is measured in hours (ttl), so collapsing sub-window touches costs no meaningful precision while removing the repeated write.Contract preserved
Both existing Feat #2 tests pass unchanged:
test_feat2_touch_updated_on_fresh_renderuses a 30-min-old timestamp (≫ the 60s window) → still re-stamps.test_feat2_no_touch_when_stale→ stale narratives are never touched (unaffected).Tests
test_feat2_touch_is_debounced_within_window— a render withupdated10s ago and a 5-min window does not rewrite the file.🤖 Generated with Claude Code