Skip to content

fix: eliminate 100% temporal drift in CascadingTemporalMemory cold tier#16

Merged
Neal006 merged 1 commit into
Neal006:mainfrom
Priyanshu-byte-coder:fix/temporal-drift-cold-tier
May 24, 2026
Merged

fix: eliminate 100% temporal drift in CascadingTemporalMemory cold tier#16
Neal006 merged 1 commit into
Neal006:mainfrom
Priyanshu-byte-coder:fix/temporal-drift-cold-tier

Conversation

@Priyanshu-byte-coder
Copy link
Copy Markdown
Contributor

Problem

CascadingTemporalMemory showed 100% temporal drift at T=100 (issue #2).

Root cause: when a fact's original injection message ("My city is Bangalore") cascaded from warm → cold before the fact was updated, the stale value was frozen inside the compressed cold summary string. temporal_drift_score then counted old_hits=1, new_hits=0 and reported drift=1.0.

Fix

Three targeted changes to memory/cascading.py:

  1. _parse_update(content) — detects fact-update messages ("my <key> has changed to <new>") and extracts (key_name, new_value).

  2. _patch_cold_with_update(cold, key_name, new_value) — rewrites "my <key> is <old>" patterns in all cold summary strings in-place using a regex substitution.

  3. _fact_updates dict on CascadingTemporalMemory — accumulates every update seen. _cascade_warm() re-applies all patches after each new cold entry is created. add_message() also patches cold immediately when an update arrives, covering the case where the update is absorbed before the next warm→cold cascade.

  4. Merge order flip — when two cold entries are merged, the newer entry is placed first so it survives the 600-char truncation limit.

Testing

python main.py --backends cascading --turns 100
# drift @ T=100 should now be < 0.5 instead of 1.0

Closes #2

…egression

When a fact is updated mid-conversation the original value was frozen inside
compressed cold summaries, causing temporal_drift_score to report 100% drift
at T=100. Two changes fix this:

1. _patch_cold_with_update() — rewrites 'my <key> is <old>' patterns in all
   cold entries to use the current value whenever an update is detected.
2. _fact_updates dict — stores every seen update so _cascade_warm() re-applies
   all patches each time a new cold entry is created.
3. merge order flipped: newer cold entry placed first before truncation so
   current facts survive the 600-char cap.

Closes Neal006#2
@Neal006 Neal006 merged commit 30abfb7 into Neal006:main May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix temporal drift regression in Cascading Temporal Memory

2 participants