Skip to content

fix(memory): the memory fences use the shared neutralization - #392

Merged
IvanJS17 merged 4 commits into
mainfrom
fix/memory-fences-use-the-shared-neutralization
Nov 28, 2026
Merged

IvanJS17 merged 4 commits into
mainfrom
fix/memory-fences-use-the-shared-neutralization

Conversation

@IvanJS17

@IvanJS17 IvanJS17 commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

The persisted-memory document and the memory curator's three evidence blocks now neutralize their text with the shared neutralizeFence, so text inside them cannot open or close the block, however the tag or the id is written. A guard test refuses new private copies.

What changed

  • lib/memory/prompt.ts fenceMemory: neutralizeFence(content, nonce, ["memory-document"]); the nonce is still derived from the original content.
  • modules/memory/memory.curator.ts fenced: neutralizeFence(content, nonce, [the three labels]); the <label-UUID> format and the system prompt are unchanged.
  • src/__tests__/promptFenceUse.test.ts: no hand-made neutralization outside lib/promptFence.ts; every file that writes a nonce tag for a prompt reaches the shared function.
  • Ledger row for the two shared files.

Why

One implementation of the neutralization for every fence. The chat engine, the training prompts and the playbook prompts already use the shared function; these two fences had their own.

Testing

New tests through buildMemoryTurn and runMemoryCuratorScope byte-for-byte equality with the old output for text without a token, cache stability of the memory document, cross-label checks for the curator, the guard with samples. Targeted suites, npm run build, npm run typecheck:test pass. Mutants (old split/join in either file, own label only, a private copy) are caught.

Deploy notes

No migration or configuration. Prompts for text without a reserved token are unchanged byte for byte, so provider prefix caches are not affected. Text that contains a reserved tag now shows &lt; in place of its <. Cost per call, measured on a shared, loaded host: tens of microseconds for a memory document of ordinary size and 0.2 to 2 ms at its largest size (16,384 units; about 5 ms for the slowest text built); 1 to 7 ms for a curator block at its largest size (48,000 units). A text that starts with a reserved name (for instance <existing-memory-notes>) is neutralized too.

The persisted memory document and the memory curator's evidence blocks
neutralize their text with the shared function, so the text cannot
carry the fence tag or the id in any written form. A text without a
token gives the same prompt as before. A test refuses a fence that
neutralizes by hand.
…-the-shared-neutralization

# Conflicts:
#	docs/UPSTREAM_COMPATIBILITY_LEDGER.md
…e a closing tag

A file that writes a fence tag must call the shared neutralization or
a builder that does; importing it is not enough. A tag with the id in
its name counts as a fence tag. Removing a closing tag with replace or
replaceAll is refused like split and join.
@IvanJS17
IvanJS17 merged commit 7dc1454 into main Nov 28, 2026
13 checks passed
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