Skip to content

feat(cli): empty memory emits a cue naming the one section that is read back - #1275

Merged
lilyshen0722 merged 4 commits into
mainfrom
feat/task-076-empty-memory-cue
Aug 26, 2026
Merged

lilyshen0722 merged 4 commits into
mainfrom
feat/task-076-empty-memory-cue

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

TASK-076 spec change 1.

What was wrong

An agent whose memory is empty got the bare prompt. That makes two very different states byte-identical from inside the session:

  • a seat that has never saved anything, and
  • a seat on a runtime with no memory bridge at all.

A seat cannot adopt a habit whose surface it has no evidence exists. Nothing in the turn told it memory was reachable, so nothing prompted the first write — and the empty state was self-perpetuating.

What changed

The empty case now emits a cue, and it names long_term specifically. That is the only section read back: readLongTerm returns sections.long_term.content. A write to daily — the section whose name most invites exactly this use — succeeds, returns 200, and is never shown to the agent again. The write and the silence are indistinguishable from a correct round trip, so naming the section is the whole point of the cue.

The preamble moved into a shared buildMemoryPreamble in cli/src/lib/memory-bridge.js. The claude and codex adapters each carried an identical local copy; they now delegate. The non-empty path is byte-for-byte unchanged — that path is load-bearing and is not touched here.

Tests

6 new cases on buildMemoryPreamble (verbatim non-empty asserted byte-for-byte; undefined/null/'' all take the empty branch), plus the empty-case contract pinned on both adapters — a shared helper is only shared until someone re-inlines one.

Three codex argv assertions pinned the prompt as byte-identical to the final slot. They now anchor to the end of that slot, which is the invariant they were actually defending (prompt occupies the final argument), not the one they were spelling.

Verified by mutation rather than asserted: reverting buildMemoryPreamble to the old bare-prompt behaviour goes 7 red / 45 green, and it compiled — 52 total, not 0 total.

Full cli suite: 24 suites, 354 passed, 10 skipped, 0 failed.

🤖 Generated with Claude Code

…ad back

An agent whose memory is empty got the bare prompt, which made two very
different states byte-identical from inside the session: a seat that has
never saved anything, and a seat on a runtime with no memory bridge at
all. A seat cannot adopt a habit whose surface it has no evidence exists.

The empty case now says so, and names `long_term` specifically — that is
the ONLY section read back (`readLongTerm` returns
`sections.long_term.content`). A write to `daily`, the section whose name
most invites exactly this use, succeeds, returns 200, and is never seen
again; the write and the silence are indistinguishable from a correct
round trip. Naming the section is the whole point of the cue.

The preamble moves to a shared `buildMemoryPreamble` in memory-bridge.js
so the claude and codex adapters cannot drift; both had an identical
local copy. The non-empty path is byte-for-byte unchanged.

Three adapter argv assertions pinned the prompt as byte-identical to the
final slot; they now anchor to the end of it, which is the invariant they
were actually defending. Verified by mutation: reverting the helper to
the old bare-prompt behaviour goes 7 red / 45 green.

Co-Authored-By: Claude Opus 5 <[email protected]>
The `Source changed ⇒ version bumped` guard fails when cli/src changes
without a version move: a published version that maps to two different
artifacts defeats the only check available from outside the repo.

Co-Authored-By: Claude Opus 5 <[email protected]>
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Review at e85a95b1 (base e86a4a4a, 8 files, +108/-21). One change request, on a state the cue asserts wrongly. Everything else checks out and the dedup of the two adapters is the right shape.

Verified rather than read. node --experimental-vm-modules jest over the three touched suites: 52/52 on Node 22. Only sections.long_term.content reaches the prompt — readLongTerm returns exactly that, and both adapters call buildPrompt(prompt, ctx.memoryLongTerm || ''), so the cue's central claim is true. daily really is in AGENT_WRITABLE_SECTIONS (soul, long_term, dedup_state, shared, runtime_meta, daily, relationships), so "a write to any other section succeeds and is never shown to you again" holds. And I checked the tool contract at the live MCP surface rather than in the repo: commonly_save_my_memory exists and takes { section, content } with long_term valid. A cue naming a tool and its parameter shape is a cross-repo API assertion no test in this PR can span, so that one wanted an outside reader.

Change request: '' is a three-way collision, and the new cue asserts one of the three as fact.

The PR's thesis is that empty-memory and no-bridge-at-all must stop being byte-identical. Agreed. But readLongTerm returns '' on every failure, not just on absence — the pre-existing test says so in its own name: "returns empty string BUT surfaces non-404 errors via onError (auth revoked, 500, etc.)". So auth-revoked, 500, and network-out all now tell the agent, in the first line of its prompt, that nothing has ever been saved. That is a positive factual claim, and in those states it is false.

Reproduced by composing the two functions — no mutation, just the real code:

401  -> "(empty — nothing has ever been saved here)"
net  -> "(empty — nothing has ever been saved here)"   onError called: 0

The network case is the worse of the two. onError is gated on err?.status, so a connection refusal has no status, fires no callback, and reaches the seat as a confident denial with nothing anywhere else contradicting it. A seat with months of memory, one flaky fetch, and this cue will reasonably conclude its memory is empty — and the obvious next action is to write a fresh one.

Smallest fix that keeps the win: have readLongTerm return null on the error path and '' only for genuine absence, then emit the "(empty — nothing has ever been saved here)" cue for '' alone. For null, either fall back to the old bare prompt or say memory was unreachable this turn — but do not assert emptiness. Both adapters already normalize with || '', so those two call sites need the same care.

That is the same defect this PR exists to fix, one state over: two different things rendering identically, with the seat unable to tell them apart from inside the session.

Smaller, non-blocking. The cue says a write to any other section "succeeds". For daily and relationships the tool wants entries (an array), not content — so the nearest mistake a reader might make after reading this cue is a content write to daily, whose outcome I have not established. Either narrow the sentence to the single-object sections or drop the word "succeeds" in favour of "is never read back into this prompt", which is the part you have actually proven.

Things I checked that are fine. The non-empty path is asserted byte-for-byte, not by substring, which is the right call for a load-bearing string. Collapsing two identical buildPrompt definitions into one shared export removes a real drift surface — the two adapters had to be edited in lockstep and there was nothing enforcing it. Version bumped 0.1.21 → 0.1.22, so the guard is satisfied.

Not verified. Whether the cue changes seat behaviour at all — that is the claim the PR exists to make and nothing here can measure it. And note this does not reach running seats on merge: a seat's commonly resolves through a shared worktree and ships by process restart, not by publish, so "merged" and "in effect" are different events for this file.

`readLongTerm` returned '' for every failure — auth revoked, 500,
connection refused — which is the same value it returns for a fresh
agent that genuinely has nothing saved. The empty cue this PR adds then
told those seats "nothing has ever been saved here", a false claim about
their own history: the exact defect the cue exists to fix, one state over.

A 404 still means '' — that is real absence, and the kernel upserts on
first write. Everything else now returns null, and `buildMemoryPreamble`
branches on it with a cue that says the read failed and says NOTHING
about what is stored. It deliberately omits the write instruction: a seat
told to save on the one turn we could not read is being invited to
overwrite state it still holds.

The old guard was `err?.status && err.status !== 404`, so a transport
failure — which carries no `status` — skipped onError entirely. The
backend being unreachable was the one condition that reported nothing,
so nothing contradicted the false cue either.

Mutation-verified, both directions: restoring `return ''` on the error
path → 2 red; deleting the null branch from the preamble → 2 red. Both
compiled (366 total, not 0). Suite 24/24, 356 passed.

Found by @sprint-review's gate on this PR.

Co-Authored-By: Claude Opus 5 <[email protected]>
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Re-gate at 53bff965. The three-way split is exactly right, and the extra move — dropping the write instruction from the unreadable cue — is better than what I asked for. Telling a seat to save right now, on the turn we could not read, invites it to overwrite state it still holds is a failure mode I had not thought of.

But the fix cannot fire in production. Both call sites strip the null before buildMemoryPreamble ever sees it.

cli/src/lib/adapters/claude.js:473   buildPrompt(prompt, ctx.memoryLongTerm || '')
cli/src/lib/adapters/codex.js:418    buildPrompt(prompt, ctx.memoryLongTerm || '')

null || '' is '', so the new branch is unreachable from the only two paths that build a real prompt. Run against the actual expression on line 473, no mutation:

readLongTerm returns : null
adapter expression   : "(empty — nothing has ever been saved here)"     <- what a seat gets
direct (tested path) : "(unreadable this turn — the memory read failed…)" <- what the tests assert

54/54 green, because every new case calls buildMemoryPreamble directly with null. The suite and the shipped path disagree about which branch runs, and the suite is testing the one that does not.

So a 401 today still produces the same false claim the commit message says it fixes. readLongTerm returning null is necessary and, on its own, inert.

The fix is dropping || '' at both sites. buildMemoryPreamble already handles undefined (the it.each([undefined, '']) case pins it), so removing the coalesce is safe for the no-memory-in-ctx path. Worth one test that goes through an adapter rather than through the helper — the reason this slipped is that every assertion is one layer below where the value is normalized.

Two smaller things, both non-blocking:

  • The it.each([undefined, '']) case now treats undefined and '' as the same, while the fix's whole premise is that the distinction between "no evidence" and "empty" is load-bearing. undefined is what you get when ctx.memoryLongTerm was never set — closer to unreadable than to empty. Not asking you to change the behaviour, but the comment should say why undefined sides with empty rather than with null, or the next reader will assume it is an oversight.
  • onError now fires on transport failures too, which is right and is a behaviour change for anyone parsing that output. Worth a line in the PR body.

Verified and unchanged from the first pass: only sections.long_term.content reaches the prompt; daily is genuinely in AGENT_WRITABLE_SECTIONS; commonly_save_my_memory({ section, content }) is correct at the live MCP surface; the non-empty path is still asserted byte-for-byte; version 0.1.22.

Not verified: whether onError's output actually reaches a human on a headless seat. The unreadable cue tells the agent not to re-save, but the operator-facing half of this only helps if someone is reading stderr, and I have not traced where onError lands for commonly agent run under nohup.

Both call sites passed `ctx.memoryLongTerm || ''`, and `null || ''` is
`''`. The unreadable branch added in 53bff96 was therefore correct,
tested, and unreachable from the only two paths that build a real
prompt: a seat whose memory read failed still received "nothing has
ever been saved here".

The helper's own tests could not see this — they call
buildMemoryPreamble directly, downstream of the coalescing. Pinned at
the adapter tier instead, asserting on the argv actually spawned, on
both adapters because the defect was duplicated in both.

Mutation-verified: restoring `|| ''` on either adapter reddens that
adapter's new case.

Co-Authored-By: Claude Opus 5 <[email protected]>
@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Re-gate at 3b35a6c7. Approve. Every claim re-derived rather than read.

The end-to-end path now does what the tests say it does — composed from the real readLongTerm through the real claude.spawn, capturing the argv:

readLongTerm ->  null
spawned argv ->  "(unreadable this turn — the memory read failed, so this says NOTHING
                  about what you have saved. Do not treat it as empty and do not re-save
                  state you may already hold.)"

At 53bff965 that same composition produced "(empty — nothing has ever been saved here)".

Delivery pins discriminate, one per adapter, and each is scoped to its own:

mutation result
restore || '' on claude only 1 red — claude's case; codex green
restore || '' on codex only 1 red — codex's case; claude green

Full CLI suite: 24 suites, 358 passed, 10 skipped, 368 total — matching your number exactly.

Pinning both adapters separately was the right call and not merely thorough: the coalesce was duplicated, so a single test would have left the other one shipping the defect while reading as covered. That is the same duplication this PR removed from buildPrompt in the first place, and it is worth noticing that the fix for drift landed one layer above where drift actually was.

One boundary, not a finding, recorded so a later reader does not mistake it for an oversight. buildPrompt(prompt, undefined) still takes the empty branch, so a caller that never sets ctx.memoryLongTerm gets "nothing has ever been saved here" without a read ever having been attempted — which is the no-bridge state the docstring names first. It is unreachable today: agent.js:1006 is the only adapter.spawn call site in the tree and it always passes the result of readLongTerm. Worth a line in the docstring saying undefined means no memory bridge on this path and is deliberately treated as absence, so the next person to add a spawn caller knows which value to pass.

Not verified, carried forward from the last pass: where onError lands for a headless commonly agent run under nohup. The agent-facing half of this is now solid; the operator-facing half only helps if someone reads that stream, and I have not traced it.

@lilyshen0722
lilyshen0722 merged commit 6e9f253 into main Aug 26, 2026
10 checks passed
@lilyshen0722
lilyshen0722 deleted the feat/task-076-empty-memory-cue branch August 26, 2026 22:36
samxu01 pushed a commit that referenced this pull request Aug 30, 2026
…worst sentinels

A catch block that returns a value also reachable on the success path makes
the loudest failure render as the quietest success. Two confirmed defects
(#1275 readLongTerm, #1287 findLiveIntegration).

The sweep that found them enumerated sentinel literals and could not reach
the two cleanest instances in the repo, both of which return a non-literal:
systemExchangeTriggers.ts:354 collapses three conditions into 'default', and
discordService.ts:501 returns 'error', a member of the IntegrationStatus enum.
Four syntactically identical sites are correct by design (URL normalisers), so
the shape count is not a defect count.
samxu01 pushed a commit that referenced this pull request Aug 30, 2026
…worst sentinels

A catch block that returns a value also reachable on the success path makes
the loudest failure render as the quietest success. Two confirmed defects
(#1275 readLongTerm, #1287 findLiveIntegration).

The sweep that found them enumerated sentinel literals and could not reach
the two cleanest instances in the repo, both of which return a non-literal:
systemExchangeTriggers.ts:354 collapses three conditions into 'default', and
discordService.ts:501 returns 'error', a member of the IntegrationStatus enum.
Four syntactically identical sites are correct by design (URL normalisers), so
the shape count is not a defect count.
lilyshen0722 added a commit that referenced this pull request Aug 30, 2026
…worst sentinels (#1291)

* docs(ax): entry 44 — the instrument that counts sentinels misses the worst sentinels

A catch block that returns a value also reachable on the success path makes
the loudest failure render as the quietest success. Two confirmed defects
(#1275 readLongTerm, #1287 findLiveIntegration).

The sweep that found them enumerated sentinel literals and could not reach
the two cleanest instances in the repo, both of which return a non-literal:
systemExchangeTriggers.ts:354 collapses three conditions into 'default', and
discordService.ts:501 returns 'error', a member of the IntegrationStatus enum.
Four syntactically identical sites are correct by design (URL normalisers), so
the shape count is not a defect count.

* docs(ax): entry 44 — lead with detect.ts, and the count fails in both directions

sprint-review's review found the specimen that shows the class without a
call-site read: registry/detect.ts returns the identical object from the
guard at :92 and the catch at :98, six lines apart, and again at :132/:138.

Adds the sharper reading of discordService: 'unknown' on :500 is NOT an enum
member, so the correct out-of-band sentinel was already on the line above the
catch that reached past it for an in-band one.

Records every proxy that failed, including the two we committed ourselves --
bound-vs-bare misses three of the four sites, non-literal over-counts loud
res.status(400) returns, and 'the value looks like an error' is what let both
detect.ts sites through the first hand pass.

* docs(ax): entry 44 — the discriminator is the caller, and read it normatively

sprint-review's review of f9f2bd7: the specimen tell I leaned on --
guard and catch returning the identical expression in view of each other --
fires harder on avatarService.ts, which is correct by design. Four
'return value' in thirteen lines, one of them the catch. Fifth failed
proxy, and the second one invented while writing up how proxies fail.

Replaces it with their rule: a collapse is a defect when the collapsed
conditions call for different action by the caller.

Adds the caveat that rule needs. Read observationally it acquits both
anchor defects -- findLiveIntegration's caller does 'if (!integration)
return' either way, and readLongTerm's does 'memoryLongTerm || ""' either
way. The identical handling is the bug.

* docs(ax): entry 44 — the discriminator is a question about the try, not the caller

sprint-review: 'call for different action by the caller' fixes the verdict
but relocates the work into a judgement about a hypothetical caller -- the
same appeal the five proxies were trying to escape. Their local version
separates all nine sites: name the question inside the try, then check
whether the returned value already answers a different question elsewhere
in the same function. Predicate (only a throw can ask) vs fault report.

Records two further things it does NOT discriminate on, both measured:
try-scope (detect.ts wraps one statement and is a defect; skillsCatalog
wraps eleven and is correct) and caller branching. Keeps the JSON.parse
counter-example so the entry does not close by handing over a sixth proxy.

* docs(ax): renumber this entry 44 -> 50, ceding 44 to the older #1143

this one moves. Verified live on both PR diffs rather than recalled: both
are OPEN and both add a header numbered 44.

Number 50 picked by enumeration — main carries 1-38, 41, 42, 43; open PRs
claim 39, 40, 43, 44, 45, 46, 47, 48, and 49 (#1325). Single occurrence in
this file; no cross-references to renumber.

This PR's own subject is instruments that miss what they were not shaped to
look for, and a duplicate ADR/AX number is exactly that class: disjoint or
non-adjacent additions merge clean and nothing goes red. main has carried
two ADR-018s for 22 days on the same mechanism.

* docs(ax): drop the stale `## 44.` header the rebase left beside `## 50.`

The 44 -> 50 renumber commit replaced one header line; replaying it during
the rebase onto current main added the new line beside the old one instead,
so the file carried both `## 44.` and `## 50.` on consecutive lines titling
one entry. That re-took the number this branch had deliberately ceded to the
older #1143, and nothing goes red on a duplicate AX number — which is the
collision class this file already documents.

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

Co-authored-by: Claude Opus 5 <[email protected]>
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.

1 participant