Skip to content

Write latency is model synopsis generation, not plugin (gate = 4ms); real costs: memory_init 25s critical path + graph built but never consumed #317

Open

Description

@abogartz

Problem

Measured from benchmark transcripts (state.time per tool call, both runs):

tool median p90 max
memory_remember 4.2–4.9s 8.5s 11.7s
memory_update 6.5s 10.8s 12.0s
memory_recall 0.56s 0.7s 1.4s
memory_read (status/list/evidence) <1s
memory_init 25s

Writes are ~10× reads, and the cost is roughly FLAT across store size (B1 22-row store and B4 41-row store both ~4.2–6.2s) — so it is a fixed per-write cost, not a scan. Dark run (zero contention) still shows ~4.2s, so it is not GPU queueing. This is a material part of the B1 cold-start tax (1.85× A billable) and adds seconds to every capture in production.

Suspects (unverified):

  • runWriteGate path: per-write snapshotFiles of the whole store; tree() scan for stale-ref checks; loadCanonical registry load; lock acquisition.
  • identity/repokey.ts runs git rev-parse / git remote get-url synchronously — if uncached per write that is process-spawn cost on every call.
  • No embeddings and no network in the write path by design ("zero-embedding" dedupe), so those are ruled out.
  • Graph is built but not wired: memory_init pays ~25s to index the codebase-memory graph, but the read/write paths do not appear to consume it — latency paid for no benefit. Verify whether gate1 ("canonical graph") actually queries the index or just the store.

Work

  1. Profile one memory_remember in-process (bun --cpu-prof or staged performance.now() around: identity bind, gate1, stale-ref scan, dupes, snapshot, append, evidence write). Produce a stage-cost table.
  2. Identify the dominant stage(s); fix or move off the critical path (candidate: append row first, run gates/snapshot async, surface blocks on next read).
  3. Decide the graph question explicitly: wire graph checks into the paths that should use them, or drop/defer memory_init indexing from the default flow. One or the other — not 25s for nothing.
  4. Re-measure in the benchmark (B1 pass) to confirm cold tax shrinks.

Acceptance

  • Stage-cost table in the issue.
  • memory_remember median < 1s locally (read parity class), or a written rationale for a floor.
  • memory_init off the first-write critical path or justified.
  • Benchmark B1 re-run shows reduced cold tax.

Activity

  1. added
    bench
    on Nov 6, 2026
  2. changed the title [-]memory_remember ~4.5s / memory_update ~6.5s vs reads ~0.5s — fixed per-write cost, graph built but unwired[/-] [+]Write latency is model synopsis generation, not plugin (gate = 4ms); real costs: memory_init 25s critical path + graph built but never consumed[/+] on Nov 6, 2026
  3. abogartz commented on Nov 6, 2026

    @abogartz
    OwnerAuthor

    Resolved by instrumentation (2026-11-06)

    Temp stage timers inside runWriteGate + a seeded 40-row store probe (opencode run, B profile):

    measurement value
    plugin internal: bind + gateContext + all 4 gates + append + evidence 4–7ms
    opencode-reported tool duration (state.time) for the same call 2,020ms
    benchmark-reported durations 4.2–6.5s

    The plugin write path is not slow. The gap between 4ms and 2,020ms is the model generating the tool-call arguments — the synopsis (~200–400 output tokens at local decode speed) — which opencode accounts inside the tool part's lifetime. That explains every pattern in the original data: writes (big args) 10× slower than reads (tiny args), memory_update > memory_remember (larger payload), flat vs store size (nothing scans), dark-run persistence (decode speed is contention-light but unchanged).

    So the synopsis cost is REAL but it is output tokens the model already pays — it is in the token accounting, not hidden wall-clock overhead. No async-gates fix needed; the gate is 4ms.

    Remaining genuine work, retitled:

    1. memory_init ~25s indexer spawn on the first-write critical path — background it or trust an existing stamp.
    2. Graph built, never consumed: codebase-memory is referenced only in src/init/* (+ tool descriptions). gate1 resolves refs against the live file tree, not the index. Either wire gate1/graph consumers to the index or stop paying 25s to build it in the default flow. Decision ticket.

    Instrumentation was temporary; plugin tree reverted clean.

  4. abogartz commented on Nov 6, 2026

    @abogartz
    OwnerAuthor

    Graph: disable-and-time proof (2026-11-06)

    Kill switch: OPENCODE_CBM_BIN=/nonexistent (graceful → action: unavailable).

    measurement graph ON graph OFF
    ensureGraph in-process (force, moderate) 11,532ms 1ms
    memory_init e2e tool duration (opencode run) 26,070ms 561ms
    whole probe run wall 37s 14s
    gate evidence (graph_current / ref_stale_scan) 3 / 3 3 / 3 — identical

    Three independent legs of the proof:

    1. Nothing consumes the graph. codebase-memory is referenced only in src/init/* and tool descriptions. gate1 resolves refs against the live file tree; evidence events are identical with the graph present or absent.
    2. The build usually fails anyway. Across the interactive benchmark stores: graph=unavailable ×29 vs graph=indexed ×3. The 25s was typically spent FAILING (manual spawn from a shell succeeds — the failure is host-environment-specific). The 3 successful builds were never read by anything.
    3. Cost when it works: 11.5–26s per init on the first-write critical path.

    DECISION PROPOSED: make graph indexing opt-in. Either default ensureGraph to skip (env OPENCODE_CBM_ENABLE=1 to opt in) or drop it from runInit until a consumer exists. Keeps the 25s out of memory_init, removes the flaky spawn, changes zero gate behavior (proven above). A future graph-consuming gate can flip the flag back on with its own ticket.

  5. abogartz commented on Nov 8, 2026

    @abogartz
    OwnerAuthor

    AC status: stage-cost table posted (2026-11-06 comment); rationale-for-floor satisfied by the same analysis (gate 4-7ms, the rest is model synopsis output tokens); memory_init off the critical path via #323 (graph indexing opt-in, default OFF). Remaining: the B1 re-run showing reduced cold tax — seat-serial bench queue behind results-f-main-x6 (#350) and #347.

  6. abogartz commented on Nov 9, 2026

    @abogartz
    OwnerAuthor

    Scope note from the 2026-11-09 backlog sweep, so the board shows only the one open item.

    Already satisfied, verified against main at f8f42fd today:

    Open item, one line: the B1 re-run showing the reduced cold tax. It is queued behind #347 on the same serial seat, and it is itself a run on merged main — so it can take #347's queue slot rather than holding a second ticket open. When #347 lands the B1 numbers, close this as completed with a pointer.

  7. abogartz commented on Nov 9, 2026

    @abogartz
    OwnerAuthor

    Correction to my 2026-11-09 scope note, one hour later: the graph is not opt-in, it is gone.

    PR #368 (231-remove-graph) merged 2026-11-09 into main @ f8f42fd. Verified on that tree: no file matching graph|cbm remains, and ensureGraph has zero occurrences under src/. The PR's own reason matches this ticket's finding — nothing ever read the index back, and the gate audit came out byte-identical with it present, so the ~25 s was pure cost.

    So of this ticket's three work items:

    1. Stage-cost table — done (2026-11-06 comment): plugin-internal write 4–7 ms, the 2.0 s+ figure is host-reported tool duration, i.e. model synopsis output.
    2. Dominant stage identified — same analysis; nothing on the plugin side to move off the critical path.
    3. Graph question — decided by removal, not by wiring. Supersedes Make codebase-memory graph indexing opt-in (default OFF): 25s/init for an artifact nothing reads #323, which only defaulted it OFF.

    Remaining, unchanged: the B1 re-run showing the reduced cold tax. That is now a run on a tree with the graph removed and the retrieval fixes (#364) and capture cost levers (#366) merged, so it measures something different from the 2026-11-06 numbers. It belongs in the benchmark queue with #347, which is the gate for it.

  8. added
    severity:medium
    enhancement
    tier:full
    tier:standard
    and removed
    tier:full
    on Nov 14, 2026
  9. ocsi-triager commented on Dec 1, 2026

    @ocsi-triager

    Triager

    Not actionable — no code change remains on this revision, and the one open acceptance item is a bench-queue measurement the owner reserved to themselves.

    Checked against 6e33179 (current main), read-only:

    1. The write-path mechanism is intact, and the ticket's own claim (latency is model synopsis, not plugin) is already owner-settled by instrumentation. Every suspect the ticket lists still exists and says what the ticket says — runWriteGate (src/gate/gate.ts:339), whole-store snapshotFiles inside the write (src/gate/gate.ts:1074), the stale-ref tree() scan (src/gate/gate.ts:290), loadCanonical (src/gate/gate.ts:230, called at :561), synchronous git rev-parse / git remote get-url (src/identity/repokey.ts:175-176) — and none of it is the cost: the owner's 2026-11-06 instrumentation comment shows the plugin-internal write (bind + all 4 gates + append + evidence) at 4–7 ms against 2,020 ms host-reported duration for the same call, and rules explicitly: "No async-gates fix needed; the gate is 4ms." AC1 (stage-cost table) and AC2 (median <1s or a written rationale for a floor) were satisfied by that comment and the floor rationale; the owner restated this in the 2026-11-08 and 2026-11-09 status notes. There is no code for a fixer to write against items 1–2 of the work list.

    2. The graph question is decided and shipped, not open. PR #368 (231-remove-graph) is merged — f8f42fd is an ancestor of 6e33179 (git merge-base --is-ancestor confirms). rg -in 'ensureGraph|codebase-memory|cbm' src/ matches only three explanatory comments (src/init/detect.ts:7, src/init/format.ts:3, src/init/run.ts:7); src/init/run.ts:1-9 documents memory_init as deterministic manifest parsing through the write gate with no indexer spawn. AC3 satisfied by removal.

    3. The only open AC is "Benchmark B1 re-run shows reduced cold tax" — a live-model measurement in the maintainer's serial bench queue, not a change on this tree. B1 is not defined anywhere in this repo (rg -n '\bB1\b|cold tax|billable' returns only unrelated fixture prose in bench/fixtures/availability-cases.ts); it is an interactive profile run of the external harness against a live local model, which no fixer change can produce or a reviewer check. And the owner ruled its ownership explicitly (2026-11-09 scope note): it "can take #347's queue slot rather than holding a second ticket open. When #347 lands the B1 numbers, close this as completed with a pointer." #347 has since closed (final comment 2026-11-10: t3 ×5 50/50, t7 ×3 29/30 on merged main) — that table is warm-vs-cold chain evidence, not the B1 cold-start tax figure, so the pointer this ticket awaits has still not landed. The pending move is the owner running the bench and closing; per the standing rule, a ticket whose remaining work lives in maintainer hands is a refusal, and dispatching a fixer here would spend a serial slot on a run only the owner performs.

    What would make this actionable: an owner-authored code request. As filed, the remaining item is a measurement. If any code work is wanted from this ticket, the owner would need to define it on the issue — e.g. a hermetic in-tree cold-tax regression runner (the bench/runners/ style, like write-latency.ts, which measures the gate path without a live model) that a fixer could implement and a reviewer could execute. Absent that, the correct disposition is the one the owner already prescribed: the B1 number comes off the serial bench queue and this issue closes completed with a pointer.

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

    benchenhancementseverity:mediumtier:standard

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions