Skip to content

Keep stored line breaks out of model-facing output - #369

Merged
abogartz merged 1 commit into
mainfrom
299-flatten-render
Nov 9, 2026
Merged

abogartz merged 1 commit into
mainfrom
299-flatten-render

Conversation

@abogartz

@abogartz abogartz commented Nov 9, 2026

Copy link
Copy Markdown
Owner

What this does

Memories can hold several lines of text, and the repo's rule is that they stay multiline in the store and get flattened to one line only when something shows them to a model. Two places showed row text without flattening it, so a control character stored earlier reappeared in a tool reply as a real line break:

  1. The refusal hint. When a write is blocked because the same content was rejected before, the reply quotes the reason a human typed at that earlier forget. That reason went in raw, so a reason containing a newline split the hint across lines.
  2. Consolidation proposals. The proposal list prints the text of the row it wants to keep and the rows it wants to absorb. Both were sliced straight from the store, so a multiline row took two output lines where every other row took one.

Both now flatten at the render seam, the same way memory_recall already does. Nothing else changes: the store keeps multiline prose, the rejection hash and the credential scrubbing in the hint behave exactly as before, and the proposal output is still one line per row.

Impact is formatting hygiene, not a security boundary — the store file was always one record per line and nothing here reaches the system prompt. It is worth fixing because both strings are model-facing, and a renderer that silently changes line structure is the kind of thing that makes a tool reply ambiguous.

Tests

RED first, on current main:

  • a forget reason of a\nb produced a hint containing a real line break;
  • a proposal whose survivor content contains \n produced two output lines for that one row.

GREEN: both render one line per record, and the hint still names the when/why/hash and the way to lift a rejection.

bun run gate green: 1104 unit tests + 30 terminal/BDD tests against a real host, 0 fail. bunx tsc --noEmit clean; lint and format identical to main's baseline.

Closes #299.

…dation output (#299)

Row prose is multiline in the store and flattened only at the render seam. Two
render sites missed it: the refusal hint spliced the tombstone reason raw, and
renderProposals sliced survivor/loser content raw, so a stored control character
reached tool output as a real line break.

RED first: a forget reason of "a\nb" produced a multi-line hint, and a
multi-line survivor produced two output lines for one row. GREEN: both render
one line per record; credential redaction in the hint is unchanged.
@abogartz

abogartz commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Adversarial self-review (author-side, not independent)

Tried to break the "only these two seams needed fixing" claim and the redaction order. Both hold.

Verified clean:

  • Completeness. Every other place row text reaches a model already flattens: inject/format.ts (the injected block), tools/decay.ts, tools/list.ts, capture/runtime.ts. A grep for .content interpolated into tool strings without flattenMemoryText comes back empty. The two seams this PR fixes were genuinely the last ones.
  • Redaction order in the refusal hint: redactSecrets runs on the raw reason before flattening, so a secret that was only visible across the line break is still scrubbed. Flattening after cannot reassemble one — it only collapses whitespace classes.
  • No write-back path: memory_merge_review resolves rows by ts id, not by the rendered text, so flattening the proposal display cannot leak into the store.
  • Side improvement in the hint: a whitespace-only reason now falls through to "no reason recorded" instead of quoting an empty gap.
  • git merge-tree against current main: clean. CI green on all four jobs.

Findings:

  1. 🔵 Cap semantics nit. flattenMemoryText(content.slice(0, 160)) caps the raw text, so a newline-heavy row renders shorter than 160 flattened chars while a single-line row uses the full budget. Only if you want the cap to mean "160 chars the model sees" would you flip it to flattenMemoryText(content).slice(0, 160). Cosmetic; fine as is.

Verdict: approve. Branch is 23 commits behind main; merge-tree is clean, so landing is a mechanical merge.

@abogartz
abogartz merged commit 78da1b0 into main Nov 9, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.22.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@abogartz

abogartz commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Merged into main at 78da1b0 with admin override (solo author). Landed in the order the self-review set: this PR before #368. The review's follow-ups are tracked separately (#375 for the re-tag scan; the optional nits were left as written).

@abogartz
abogartz deleted the 299-flatten-render branch November 19, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refusal hint and consolidation proposals render row-derived text unflattened

1 participant