Skip to content

write_promoted re-serializes the whole session call ledger — evidence lines grow to 22 KB (O(n^2) per session) #163

Closed

Description

@abogartz

Symptom

write_promoted evidence lines grow with session length and re-serialize the session's entire tool-call history on every promoted write. Measured on the dogfood host, 2026-10-28 (20 promoted writes):

Measurement Value
write_promoted line bytes min 564 · median 4,529 · max 21,785
Distinct call= ids inside one evidence_refs=[…] grew monotonically, ~570 ids by the last write of a long session
Evidence file for the day 0.45 MB, dominated by these lines

Not auto-capture

Worth stating explicitly because it was the initial guess: autoCapture is false in the live config, today's evidence contains zero capture events (capture_lag, auto_capture_refused, model-call lines), and all 20 promoted writes were manual memory_remember calls with grounded_by=engagement. The growth is in the write gate's grounding telemetry, so it happens on every ordinary session with capture off.

Root cause

evidenceCalls(sid) (src/triggers.ts:204-206) returns every call id recorded for the session:

export function evidenceCalls(sid: string): string[] {
  return session(sid).calls.map((c) => c.call);
}

src/gates.ts:675 writes that whole array into the line: evidence_refs: bracketList(ctx.evidenceCalls).

session(sid).calls is unbounded per session — SESSION_CAP = 64 (src/sessions.ts:8) caps the number of sessions held, not the number of calls inside one; the list is only dropped on LRU eviction or finalizeSession. So each promoted write costs O(calls so far) and a long session costs O(n²) bytes overall. Evidence day-files have no size cap or rotation (rotation exists only for the use ledger, src/hits.ts:65).

Impact

  • Disk growth in memory/evidence/, and slower reads for everything that parses those files (captureLag, blockedRecent, memory_status, the viewer).
  • A single 22 KB logfmt line is fragile for readers and for any future line-length limit.
  • No token cost — evidence is never injected into a prompt. This is a telemetry-hygiene and I/O bug, not a context-cost bug.

Proposed fix

Keep the audit signal, bound the line:

  1. Cap the refs that are rendered (e.g. the most recent N ≈ 10 engagement calls) and always include the calls GATE-4 actually reasons about: the gate-check call and the FAIL→PASS pair.
  2. Record evidence_refs_count alongside the truncated list so "how much engagement backed this write" survives as a number even when the ids do not.
  3. If full provenance must persist, write the complete chain once per session to its own file keyed by chain id and reference that key from the line, instead of repeating it per write.

Acceptance criteria

  • Test with a synthetic session of 1,000 recorded calls: a promoted write's evidence line stays under a pinned byte budget.
  • GATE-4 grounding behavior unchanged — existing engagement-grounding tests stay green, and a write grounded only by the FAIL→PASS pair still passes when the pair falls outside the rendered window.
  • memory_status, blockedRecent, and the viewer read the new shape without special-casing.
  • A backfill/compaction note in the docs for existing oversized day-files (or an explicit decision to leave them).

Out of scope

The prompt-cache invalidation issue (separate, higher priority). Auto-capture trigger economics (label capture).

Activity

  1. added
    bug
    on Oct 28, 2026
  2. WhollyMindless commented on Oct 29, 2026

    @WhollyMindless
    Contributor

    Intent to work this, unless it's already yours — you filed it two hours ago with the root cause mapped (evidenceCalls returns the unbounded per-session call list; SESSION_CAP caps sessions, not calls), and no one has claimed it.

    Plan, regression-first, matching the program's shape:

    1. Probe: a session with N recorded tool calls and a promoted write asserts (a) the write_promoted line's bytes do not grow with session length beyond a constant, and (b) one promoted write in a long session costs O(1) serialized bytes, not O(calls). Red on current main by construction.
    2. Fix shape (opening for argument before I build): evidence_refs exists to show WHICH behavior grounded the write — that argument does not need all ~570 ids, it needs the recent/relevant window. Leaning toward: keep the ids that actually ground the verdict (the engagement/gate_check window the gate consults) capped at the tail, with an evidence_total= field so the count stays honest and memory_evidence can say "12 of 570 shown". A cap alone (tail-N) would silently drop the earliest grounding evidence from a write that cites it — the count field is what keeps that from becoming a new truth problem, same family as P2: memory_update claims nothing was written after post-append audit failure; retry leaves two active rows #155's audit-line lessons.
    3. Full suite + typecheck, single PR referencing write_promoted re-serializes the whole session call ledger — evidence lines grow to 22 KB (O(n^2) per session) #163.

    One heads-up from the #158 fix round that just landed on that file: write_promoted's record now flows through the evidenceError wrap and auditCaveat, so whichever of our branches moves that line first, the other rebases over it cheaply.

    If you're already on it, say the word and I'll stand down.

  3. abogartz-opencode-self-improvement commented on Oct 29, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.14.19 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugreleased

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions