Skip to content

feat(memory): make memory opt-in and cap the note at 8 KB - #811

Merged
dean0x merged 28 commits into
mainfrom
feat/807-working-memory-small-note
Nov 23, 2026
Merged

dean0x merged 28 commits into
mainfrom
feat/807-working-memory-small-note

Conversation

@dean0x

@dean0x dean0x commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Memory is on by default, and the note has no size limit. Two sessions in one checkout write their turns to one note, so the turns mix. This change turns memory off for new installs, caps the note at 8,192 bytes, and keeps the turns of each session apart.

Changes

  • A new install has memory off. Run devflow memory --enable to turn it on. An install made before this change keeps its value.
  • The note has a limit of 8,192 bytes. Devflow refuses an update that would make the note larger than 8,192 bytes. SessionStart does not load a note larger than 8,192 bytes.
  • The note keeps only two sections: ## Now and ## Progress.
  • Each memory row carries its session id. An update pairs a prompt only with a reply from the same session.
  • When two sessions share one checkout, the note header states this. The header advises one git worktree for each parallel session.
  • The worker prompt keeps each data part separate.
  • When a queue trim finds that the queue is claimed, it prints no text to stderr. The worker claims the queue under the queue lock.

Incompatible Changes

  • New installs and init --reset set memory off. Run devflow memory --enable to turn it on.
  • The note keeps only the ## Now and ## Progress sections. The next update removes the other sections.
  • The Jira install-snapshot fixture records memory off. The GitHub install-snapshot fixture opts in to memory, so it still holds the memory hooks.

Known Limits

  • A note larger than 8 KB stays on disk until the next update rewrites it. SessionStart does not load that note.
  • New installs run one more parse process for each capture hook.
  • When the model writes too much, one batch uses at most two paid runs.
  • The multi-session header can show for up to 4 hours after the parallel session ends.
  • A handoff from one session to the next in the same checkout also sets the mark.
  • After /clear, Claude Code starts a new session. Its docs do not say whether the new session gets a new session id. If it does, the first update after /clear sets the mark.
  • A level-one title in the note passes the section check.
  • If the machine manifest is lost or unreadable, memory capture turns on again, also after an opt-out.

How the criteria are read

The AC numbers refer to the acceptance criteria for this change. The readings below restate four of them in plain words.

  • AC-1: A new install writes memory: false. A manifest from an earlier install that has no memory key sets memory to true one time. --reset sets memory to off.
  • AC-2: No devflow write leaves the note above 8,192 bytes. SessionStart never loads more than 8,192 bytes of note. A note that is on disk above the cap stays there until the first rewrite.
  • AC-3: The note update refuses any level-two title other than ## Now and ## Progress. Titles at level three and deeper pass.
  • AC-5: "More than one session" means that the note holds the turns of two valid session ids, in one batch or in separate batches. The note stamp keeps the id of the last session that wrote the note. The mark stays for 4 hours after the last batch that mixes sessions.

Tests

  • Run npm test to check the branch.
  • This branch changes 19 files in the test suite. They include the memory tests and the install snapshot fixtures.

Related Issues

Closes #807

Keep the stored choice on re-init. Record memory as on once for older
manifests that have no memory key. Start with memory off after a reset.

Refs #807
Task: feat/807-working-memory-small-note
Show the enable command in init. State the note limit and give advice
for parallel sessions. Keep memory hooks in the GitHub fixture setup.

Refs #807
Keep memory hooks in the GitHub snapshot and hook matrix. Record the
memory-off default in the Jira HIPAA snapshot.

Refs #807
Set shared note limits and keep the session stamp format in one place.
Add one extractor for the working directory, session ID and event value.

Refs #807
Task: feat/807-working-memory-small-note
Tag prompt and reply rows for memory. Keep curation rows byte for byte.
Leave no terminal error when a queue moves during a trim.

Refs #807 (feat/807-working-memory-small-note)
Keep session IDs on memory question rows. Pair prompts and replies only
when their session IDs match. Mark batches with interleaved sessions.

Refs #807 (feat/807-working-memory-small-note)
Keep only the Now and Progress sections within 8192 bytes. Set the
stamp from the checkout and keep the multi-session mark for four hours.

Keep the old note if a new note does not fit. Give the batch one retry
before the worker leaves a notice and drops it.

Task: feat/807-working-memory-small-note (P6)
Refs #807
Keep the queue for the next run if the worker cannot claim it.
Release the queue lock before the worker trims the claimed batch.

Refs: feat/807-working-memory-small-note (#807)
Skip notes above 8,192 bytes and keep the refresh banner. Show
worktree advice when the note covers more than one session.
Create new notes with two fixed sections at compaction.

Refs #807
Record the off default, the note limit, and the worktree advice.

Refs #807 (feat/807-working-memory-small-note)
Use the verified note outcome before the denial count. Restore the
worker's rules for task status without adding sections to the note.

Refs: feat/807-working-memory-small-note
Exit cleanly when prompt extraction fails. Keep the capture log when
the session ID is absent or invalid.

Refs: feat/807-working-memory-small-note
Test both memory toggle writes now that memory is off by default.
Keep the detached stamp and backup checks for the fixed first note.
Check the trim threshold and merge cap through the capture helper.
Update the line numbers for the three existing heredocs.

Refs feat/807-working-memory-small-note
Keep the HUD forecast and the working memory changes.
Keep their changelog entries under Unreleased.

Task: feat/807-working-memory-small-note
Refs #807
Use a byte budget for notes. Preserve turn order after an interrupted
merge. Clear temporary note output if the swap copy fails.

Task: resolve-C
Set a process limit for FIFO tests. Check refusal logs, swap modes,
malformed stamps, and denial markers.

Task: resolve-A
Use warm fakes and a test budget for worker runs. Check the memory
summary in the existing install test. Check the options that init
passes to the confirmation prompt.

Task: resolve-D
Discard the refused batch and leave a path notice when the worker
finds an occupied refusal marker path. Leave the entry in place.
Test paused notice cleanup and absent session IDs.

Task: resolve-D
Keep the live queue when a read-only batch prevents a merge.
Report each refused path once at session start.

Test blocked paths and failed moves separately. Match the current
notice text and update the existing heredoc exclusions.

Task: resolve-valfix-1
… knowledge base and split out the backup and JSON fallback
@dean0x

dean0x commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner Author

Test Plan Evidence — 75b99d7

Verified 50/50: VERIFIED-CI 47, ATTESTED-LOCAL 3, UNVERIFIED 0, STALE 0, FAILED 0, INDETERMINATE 0

  • TP-1 VERIFIED-CI sha:ab7609a7ae392f2f97f9c70b2eace7ffe895465a out:PASS run:45251891758/1 exit:0 h:0d50354a6f77
  • TP-2 VERIFIED-CI sha:ab7609a7ae392f2f97f9c70b2eace7ffe895465a out:PASS run:45251891758/1 exit:0 h:29c6f41a2773
  • TP-3 VERIFIED-CI sha:ab7609a7ae392f2f97f9c70b2eace7ffe895465a out:PASS run:45251891758/1 exit:0 h:0601b9e6d7a5
  • TP-4 VERIFIED-CI sha:c82598011cd789d64f6fd85b6a70c15455f3aafb out:PASS run:45275028784/2 exit:0 h:f5c7c770d7d0
  • TP-5 VERIFIED-CI sha:ab7609a7ae392f2f97f9c70b2eace7ffe895465a out:PASS run:45251891758/1 exit:0 h:19b3a987ba78
  • TP-6 VERIFIED-CI sha:c82598011cd789d64f6fd85b6a70c15455f3aafb out:PASS run:45275028784/2 exit:0 h:4aa969b4496c
  • TP-7 VERIFIED-CI sha:c82598011cd789d64f6fd85b6a70c15455f3aafb out:PASS run:45275028784/2 exit:0 h:0021797c40d6
  • TP-8 VERIFIED-CI sha:ab7609a7ae392f2f97f9c70b2eace7ffe895465a out:PASS run:45251891758/1 exit:0 h:fbb5b8146132
  • TP-9 VERIFIED-CI sha:d1a9a06fa57a474b23c1a814521b8e028ec92072 out:PASS run:45223737661/1 exit:0 h:fd5256558a94
  • TP-10 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:4081f453c9c0
  • TP-11 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:0dd14c4a80f0
  • TP-12 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:0eef60fdacd1
  • TP-13 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:faf4f1ef1481
  • TP-14 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:3e813a3793ac
  • TP-15 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:8fa3d15a49ca
  • TP-16 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:c08e8fac376b
  • TP-17 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:48deb2439d06
  • TP-18 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:d56392545b47
  • TP-19 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:337c2c6163df
  • TP-20 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:0afe80ccfb3f
  • TP-21 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:a5f15a3d1c08
  • TP-22 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:2df7acec1496
  • TP-23 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:423b647783a3
  • TP-24 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:3a4bc79dd4e2
  • TP-25 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:50086ffcc3aa
  • TP-26 VERIFIED-CI sha:c82598011cd789d64f6fd85b6a70c15455f3aafb out:PASS run:45275028784/2 exit:0 h:e88d81e9b578
  • TP-27 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:286dff9b7160
  • TP-28 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:4ddb437003d5
  • TP-29 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:688b1c147097
  • TP-30 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:86b486ab9fac
  • TP-31 VERIFIED-CI sha:c82598011cd789d64f6fd85b6a70c15455f3aafb out:PASS run:45275028784/2 exit:0 h:7c827470da1c
  • TP-32 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:2617aedb9af8
  • TP-33 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:c1e35ba9f061
  • TP-34 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:e6a37420850b
  • TP-35 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:60a01f3ed18a
  • TP-36 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:b68880c3c254
  • TP-37 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:8f5d3473f6d7
  • TP-38 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:5ef2ca66ea7a
  • TP-39 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:f08e394d797e
  • TP-40 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:5c4719be3895
  • TP-41 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:373640b224b6
  • TP-42 VERIFIED-CI sha:c82598011cd789d64f6fd85b6a70c15455f3aafb out:PASS run:45275028784/2 exit:0 h:1a559f004bf0
  • TP-43 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:e6aef037eeda
  • TP-44 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:24b12ae02454
  • TP-45 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:eb0ea65f806d
  • TP-46 ATTESTED-LOCAL sha:b613cf9d9f3e09b75dd8176a73ab3469625a952c out:PASS exit:0 h:02a029d5ce84
  • TP-47 ATTESTED-LOCAL sha:c82598011cd789d64f6fd85b6a70c15455f3aafb out:PASS h:70ae84f5edfb
  • TP-48 ATTESTED-LOCAL sha:b613cf9d9f3e09b75dd8176a73ab3469625a952c out:PASS exit:0 h:e2d335a4e4cd
  • TP-49 VERIFIED-CI sha:75b99d7fbd0f2ee9663c2e56e195ff76ad76890d out:PASS run:45275028784/2 exit:0 h:bf53c7df3daa
  • TP-50 VERIFIED-CI sha:b613cf9d9f3e09b75dd8176a73ab3469625a952c out:PASS run:45266127028/3 exit:0 h:78bf836256e4

Review Summary (cycle 1, at e0e2154)

Gate level: lean. Focus areas: security, testing, reliability.

  • Result: CHANGES REQUESTED. Blocking: 0 critical, 2 high, 8 medium, 2 low. Should fix: 0. Pre-existing: 0. Suggestions: 5.
  • The two high items: some test runners had no time bound, and some new process tests used the 5 s default time limit.
  • Checks that passed:
    • With working memory off, init installs no memory hook, the hooks write no file in the memory folder, and the curation rows have the same bytes as on main.
    • The paused-area gate and the notice-clear gate stop every notice write, notice clear and refusal count unless the memory folder is untracked.
    • Each worktree and each clone has its own note, queue and locks. Rows pair only on equal session IDs.
    • New files are owner-only and are created with an exclusive create. Each write, rename and delete checks for links first.

Resolution Summary

Outcome Count
Fixed 14
False positive 0
By design 2
Deferred (not filed) 3
Escalated 1

Fixed:

  • Test runners and process tests now have time bounds. The full init check moved into the existing install test.
  • New tests check the refusal Run: line and log words, the owner-only mode of a refused swap copy under a 022 umask, the worker prompt after a bad line 1, the paused-area notice clear, the swap-path checks before the model run, the denial count when a note is also refused, and shell characters in session IDs.
  • The prompt states the note target in bytes, with room for the first line, because the cap counts bytes.
  • A recovery merge that stopped part-way is finished before new rows are claimed, so it repeats no rows and sets no false multi-session mark.
  • The worker removes its staged output when it cannot write the swap copy.
  • When something that is not a regular file stands at the refusal marker, the worker drops the batch and leaves a one-time notice. So a batch uses at most two paid runs.

By design: the two allowed section lines must match exactly, and line 1 must carry the stamp prefix.

Deferred (not filed): a shared time budget for tests with several hook runs; a capture test on the plain default install path; a separate text for an unreadable note at session start.

Escalated, owner decision: a lost or unreadable machine manifest turns memory capture on again. This stays as a known limit and is in the PR body.

Verification at ab7609a

  • Build and typecheck: PASS. Lint: not configured.
  • Full test suite at 6a3e5dc: PASS (414 files, 19,897 tests). The later commit changes only knowledge files.
  • CI at ab7609a: PASS.
  • Test plan: 41 items were stale after the fixes. All 41 passed again at ab7609a.

Intent fix at 75b99d7

The note header now says "more than one session" when two sessions write one note. This is also true when they write in separate batches.

  • Change: line 1 of the note keeps the ID of the last session that wrote the note. A batch with two session IDs sets the mark. A batch with an ID that differs from the line 1 ID also sets the mark. The mark stays for 4 hours after the last such batch.
  • A handoff from one session to the next in the same checkout also sets the mark. This is in the Known Limits of the PR body.
  • The header advice fits a handoff and parallel sessions: "This note holds work from more than one session. Check that it fits your task. Parallel sessions: use one worktree for each."
  • After /clear, Claude Code starts a new session. Its docs do not say whether the new session gets a new session id. This is in the Known Limits of the PR body.
  • The PR body no longer lists the cross-batch limit.
  • Tests added first:
    • two sessions in one batch;
    • two sessions in separate batches;
    • one session only, with no mark;
    • a line 1 from before this change, with no session ID;
    • the new advice text.
  • Local tests:
    • The memory test files pass under bash 3.2. At 75b99d7, 9 files and 1,643 tests pass.
    • The full suite at f1fc307 had 2 failures in the heredoc guard, from moved line numbers. The fix is a346ad0, and that file passes.
  • CI at 75b99d7: build-and-test PASS, security/snyk PASS, macos-bash32-hooks PASS (run 45275028784, attempt 2; attempt 1 got no macOS runner).
  • Review: one regression review of the new commits. Result: approved with conditions, with 0 blocking items. Fixed: one stale knowledge line, one prompt check in a test. Not fixed (low): the session ID check is in two hook files.
  • Test plan: the items that the new commits made stale pass again at 75b99d7. The text of TP-36 and TP-40 now states the new rule.

The note stamp keeps the ID of the last session that wrote the note.
A batch with two session IDs, or with an ID that differs from the
stamp ID, marks the note. The mark ends four hours after the last
such batch. A note stamp without a session ID gets no mark.
@dean0x
dean0x merged commit 988a4b6 into main Nov 23, 2026
4 of 5 checks passed
@dean0x
dean0x deleted the feat/807-working-memory-small-note branch November 23, 2026 22:24
@dean0x dean0x mentioned this pull request Nov 24, 2026
dean0x added a commit that referenced this pull request Nov 24, 2026
## Summary

This PR sets the version to 3.21.0 and moves the `[Unreleased]` notes to
the 3.21.0 section. After the merge, a `v3.21.0` tag on the merge commit
starts the release workflow.

## Changes

- `package.json` and `package-lock.json`: version 3.20.0 to 3.21.0.
- `CHANGELOG.md`: new `## [3.21.0] - 2026-11-24` section, new empty
`[Unreleased]` section, and the 3.21.0 compare link.
- `CHANGELOG.md`: the `[Unreleased]` compare link now starts at
`v3.21.0`. It started at `v3.8.0` before.

## Shipped in 3.21.0

- #794: Code Mode flag (closes #792).
- #810: week forecast in the status line (closes #805).
- #811: working memory is opt-in, and the note has an 8 KB limit (closes
#807).
- #809: acceptance criteria under level 2 to 4 headings (closes #808).

## Breaking Changes

None. Working memory is off by default for new installs. Existing
installs keep their choice. `devflow memory --enable` turns it on.

## Testing

- `npm run build`: pass.
- `npm run test`: 417 files, 20084 passed, 8 skipped, 0 failed.
- `npm run test:integration`: 5 files, 55 passed.
- `npm run version:bump -- 3.21.0` a second time changes no file.
- The tests ran on the base commit c8282b1. This PR changes only the
version and the changelog.
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.

Working memory: a small note per session, off by default

1 participant