Skip to content

fix(capture): evidence writes are best-effort; the subscription survives them - #482

Merged
abogartz merged 3 commits into
mainfrom
fix/479-evidence-write-policy
Nov 22, 2026
Merged

abogartz merged 3 commits into
mainfrom
fix/479-evidence-write-policy

Conversation

@ocsi-fixer

@ocsi-fixer ocsi-fixer Bot commented Nov 22, 2026

Copy link
Copy Markdown

What was broken, measured

One subscription, turn-end events dispatched to three different sessions, the day
file set 0400 after the first healthy pass. Counted generate.text calls.

source model calls reached
374a0cf, log breaks mid-session 2 of 3 — turn 2 reaches the model (its start receipt is guarded), its capture_cost write then throws into the for await and the loop ends; turn 3 never dispatches
374a0cf, log breaks and the model call also fails 2 of 3 — the auto_capture_refused receipt inside the pass-error handler throws, same end
this branch, both cases 3 of 3

The failure receipt that would report this (capture_threw) is itself an evidence
write, so it cannot land either: the channel that breaks is the channel that would
tell you.

The policy

An evidence write that fails has lost one diagnostic line and nothing else: the
failure is counted in process memory and dropped, and it never propagates into the
code the line describes.

It lives in one place — src/telemetry/record.ts — as
recordBestEffort, recordSyncBestEffort, recordCaptureLagBestEffort over the
same record/recordSync primitives, plus droppedEvidenceWrites(). The capture
path imports only the best-effort names, so a receipt added later cannot forget the
policy the way a per-site try can.

The guard on the subscription moved too: it now covers a whole event body,
including the receipt that reports a failure. See Where I disagree below.

The one place deliberately NOT caught

runWriteGate (src/gate/gate.ts) keeps its strict record / recordWriteBlocked.
A gate audit line is not a footnote on a completed operation — it is part of the
write's own contract: write_promoted is what makes a promoted row provable and
write_blocked is what makes a refusal reviewable. Swallowing those would turn an
unprovable write into a reported success, which is the failure the evidenceError
field exists to kill. This is also the boundary the ticket draws itself: the write
gate's verdict behaviour is not this ticket. Nothing is lost by leaving it strict —
every runWriteGate call in the capture pass already sits inside a handler whose
receipt is now best-effort, so a gate-side write failure costs one candidate and
the loop survives it.

The same reasoning keeps record/recordSync strict for every non-capture caller:
a viewer edit or a tool write that cannot write its audit line is a failed operation
the operator must see.

Sites swept

Every evidence write reachable from the capture handler — 17 in
src/capture/runtime.ts, all now best-effort:

line event
src/capture/runtime.ts:441 auto_capture_refused (no write target)
src/capture/runtime.ts:458 auto_capture_refused (no_model)
src/capture/runtime.ts:525 auto_capture_skipped (no signal)
src/capture/runtime.ts:547 auto_capture_skipped (transcript_too_thin)
src/capture/runtime.ts:651 auto_capture_start (recordSync; its local try/catch is gone — the wrapper replaced it and now counts too)
src/capture/runtime.ts:687 capture_cost
src/capture/runtime.ts:734 auto_capture_rules (no_user_turn)
src/capture/runtime.ts:753 auto_capture_rules
src/capture/runtime.ts:847 auto_capture_lessons
src/capture/runtime.ts:882 auto_capture_restatable
src/capture/runtime.ts:938 auto_capture_contradiction
src/capture/runtime.ts:992 auto_capture_partial / auto_capture_refused (gate threw)
src/capture/runtime.ts:1013 auto_capture_<action> / auto_capture_compaction_<action>
src/capture/runtime.ts:1072 auto_capture_scan
src/capture/runtime.ts:1095 capture_lag (recordCaptureLagBestEffort)
src/capture/runtime.ts:1173 auto_capture_refused (capture_threw, in the loop's catch)
src/capture/runtime.ts:1213 auto_capture_dispose (its local try/catch is gone; the existsSync teardown guard stays)

Checked and left alone, with the reason: src/events.ts (its only awaited write
already runs through guarded()), src/index.ts (the plugin_load heartbeat is
guarded(), the hook_error reporter is fire-and-forget), src/capture/triggers.ts
(every entry point is guarded()), src/gate/gate.ts (above),
src/telemetry/ledger.ts (already fail-soft with its own counter).

Where the counter lives and what memory_status says

droppedEvidenceWrites() in src/telemetry/record.ts: a per-process map keyed by
the evidence directory, so one store's broken log is not another store's report.
memory_status reads it and renders it under AUTO-CAPTURE:

  evidence writes dropped: 4 by this process (last capture_lag: EACCES: permission denied, open '/…/memory/evidence/2026-11-22.logfmt')
                 capture kept running; the auto-capture lines above read from that same log and under-count it

The second line is the point. Without it a reader weighs a missing receipt as proof
the pass never ran, when the health lines above are read back out of the log that is
dropping them. The line is absent when this process lost nothing.

Fail before

Both regression tests fail on 374a0cf for the contract they pin, verified by
running the committed file against an export of that commit:

test/capture/capture-unwritable-log.test.ts:134:7  Expected: true  Received: false
  (a turn after an unwritable evidence log still dispatches its capture)
test/capture/capture-unwritable-log.test.ts:166:7  Expected: true  Received: false
  (a failing capture-failure receipt does not end the subscription)

Both pass on this branch.

Tests

9 new tests, no existing test weakened, skipped or widened.

  • test/capture/capture-unwritable-log.test.ts — 2: the loop survives a failed
    completion receipt and a failed failure receipt; a later turn still dispatches.
  • test/telemetry/evidence-write-policy.test.ts — 7: async, sync and lag wrappers
    count and do not throw; the strict writer still throws and stays out of the
    counter; the counter is scoped per store; the report line names the loss, states
    the under-count and truncates an unbounded error; memory_status shows the loss
    after a broken log.

Full suite bun run test: 1644 pass / 21 skip / 0 fail, 14398 expects.
bun run typecheck clean. bun run lint exit 0, no Found N error.
bun run lint:comments: comment-lint: clean (123 added comment lines).
No e2e run was made for this change — delivery timing is unchanged and the contract
is unit-level. The pre-push merge gate ran the e2e suite on the way up: 39 pass /
0 fail, 317 expects.

What is NOT fixed

  1. The terminal panel cannot see the counter. It lives in the server process and
    memory_status runs there; the TUI reads status files, which do not carry it.
    Only the chat surface reports a broken log.
  2. The count is not durable. A restart clears it, and persisting it would need
    the channel that is broken. The counter reports the current process only.
  3. Gate-internal evidence writes stay strict (stated above, with the reason).
  4. guarded()'s hook_error mirror is not counted. It already swallows its own
    write failure with .catch(() => {}), so nothing breaks — but that loss is
    invisible to the new counter. Counting it would widen this change past the
    capture handler for a channel that still has console.warn.
  5. Cursor behaviour changes as a side effect. A pass whose completion receipt
    fails now advances the capture cursor. Before, the throw aborted the pass before
    the advance, so the same window was mined again on the next pass and paid for
    twice. Advancing is the correct reading of "a window is consumed by the pass that
    mined it", but it is a behaviour change beyond the crash fix and belongs in the
    open.

Where I disagree

The ticket asks for the catch at the call boundary and, separately, for the loop to
survive every handler failure. The call-boundary catch alone does not deliver
the second: captureTriggerFor, captureSessionID, setCurrent and
captureCooldownPasses all run outside the existing inner try, so a throw from
any of them still ended the subscription, and the catch that reports a failure was
itself inside the danger zone. The guard therefore moved to cover the whole event
body — wider than the ticket named, which is the only way item 3 is actually true.
The abort check (if (controller.signal.aborted) return) is preserved inside it, so
teardown still leaves the loop rather than reporting through a removed store.

The ticket calls the counter "enough". It is enough for the chat surface and it is
the only mechanism that can work, for the reason the ticket gives. It is not enough
for a user who restarts, or for the terminal panel — limits 1 and 2 above state what
that costs rather than pretending it is covered.

Closes #479

…ion alive

An unwritable evidence log ended the auto-capture event subscription for
the rest of the process. Only the start receipt was guarded; every other
receipt could still throw into the for-await loop, and the receipt that
would report the failure could not be written either.

Evidence writes on the capture path now go through one best-effort policy
in the telemetry module: a failed line is counted in process memory and
dropped, never thrown. memory_status reports the count under AUTO-CAPTURE,
with the caveat that the log-derived health lines above it under-count.
The subscription guard now covers a whole event, including the receipt
that reports a failure, so one turn cannot end capture.
@ocsi-fixer
ocsi-fixer Bot requested a review from abogartz as a code owner November 22, 2026 01:43

@ocsi-reviewer ocsi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: request changes — one blocker, three nits

The architecture is right and I am not asking for rework: the whole-event-body guard is what ticket item 3 ("the loop survives every handler failure") actually requires, the cursor advance on a failed completion receipt is the policy's mandated consequence, and the counter scope matches the ticket. One of the new tests turns the test-windows job red; that is the only thing between this PR and an approve.

Blocker

  1. test/telemetry/evidence-write-policy.test.ts:103 asserts toContain("EACCES"). On Windows the chmod-0400 append fails with a different error code, so the informational test-windows job fails on this PR; it was green on the most recent PR CI before it (fix/461 at 952d471, all checks success).
    Evidence: gh pr checks 482 → test-windows fail; job log:
    103 |     expect(String(lost?.lastError)).toContain("EACCES");
    error: expect(received).toContain(expected)
    Expected to contain: "EACCES"
    (fail) a failed async evidence write is counted and never thrown
    
    The policy itself works on Windows — line 101 (dropped === 1) passed, so the write failed and was counted; only the error-code name is wrong.
    Not blocking once: the assertion tolerates the platform code (e.g. toMatch(/EACCES|EPERM/)) or the test is skipped on Windows the way the repo's other chmod tests do (test.skipIf(process.platform === "win32") at test/init/init.test.ts:469, describe.skipIf at test/store/store-permissions.test.ts:41).

Nits (do not hold merge)

  1. src/capture/runtime.ts:1165 — the loop's catch swallows the error with no console.warn. guarded() treats the console line as the primary trace precisely because the log can be the broken channel (src/core/hooks.ts:37-40); with the log down, a capture_threw message is lost entirely and the counter names only the failed receipt event, not the underlying failure.
  2. src/telemetry/record.ts:344 — lastError stores the raw error message and memory_status renders it. Repo precedent redacts mirrored error text (src/index.ts:126-127 "never the message, which can carry conversation content"; src/capture/runtime.ts:1179 runs redactSecrets on the capture_threw error). fs errors carry paths, but a throw from buildEvidenceLine could carry field values.
  3. src/telemetry/record.ts:344 — String(err) throws on a Symbol rejection and escapes the wrapper, defeating the policy for that case; the comment directly above considered messageless Errors and non-Error rejections but not this one.

What I measured

  • Bug reproduces on 374a0cf: exported the commit, ran the ticket's shape (log 0400 before turn 1, two turns, counted model calls):
    REPRO turn1_reached=true turn2_reached=false
    
  • Fix confirmed on 0b43ee6, same script: REPRO turn1_reached=true turn2_reached=true.
  • Fail-before verified: the committed test/capture/capture-unwritable-log.test.ts run against the 374a0cf export fails at :134:7 and :166:7, Expected: true Received: false — the third turn never dispatches, the claimed reason.
  • Branch: the 9 new tests pass; bun test test/capture/ → 263 pass / 0 fail; bun test test/telemetry/ → 0 fail (1 skip, pre-existing Windows-only rotation test, also skipped on the 374a0cf export).
  • Strict-site claims hold: src/events.ts:169 is inside guarded("tool.execute.after") (src/events.ts:113); src/index.ts:362 is inside guarded("plugin_load heartbeat") (src/index.ts:309); the hook_error reporter (src/index.ts:129-141) self-swallows with .catch(() => {}); every record in src/capture/triggers.ts (:195, :212, :238, :272, :293, :382) is reached only through guarded callers (src/events.ts:132, :219, :243).
  • gate.ts strictness is consistent, not an oversight: every capture-path runWriteGate sits in the try at src/capture/runtime.ts:960 whose catch (:989) records best-effort and continues, so a gate-side write failure costs one candidate and the loop survives; the strict audit line keeps its contract for non-capture callers.
  • 17 best-effort call sites in src/capture/runtime.ts (grep count); README 4028 words; no .skip/.only in the new tests; no existing test file touched by the diff; added comments and shipped strings carry no issue numbers or dates.

Why the contested choices are accepted

  • Whole-event-body guard: with a writable log a logic error still surfaces exactly as before — the capture_threw receipt lands via recordBestEffort. With a broken log the old code died permanently and silently; the new code counts the loss and keeps capturing. Nothing escapes the loop: the inner catch takes body errors, the outer catch takes iterator errors, and the abort check (src/capture/runtime.ts:1169) still leaves on teardown.
  • Cursor advance on a failed completion receipt: ticket item 1 says a failed write must never propagate into the code the line describes; the advance is that code. The old behavior did not merely re-mine — capture_cost (:684) precedes the store write (:960), so the throw also skipped writing the durable rows and re-paid the model call. Disclosed in "What is NOT fixed" item 5.
  • Counter scope: the ticket says a counter checked by memory_status is enough, and memory_status runs in the plugin's process. The TUI-panel and restart gaps are real, disclosed, and need a different channel — ticket them, do not block on them.

What merging this will NOT mean

Capture is not reliably observable: the terminal panel cannot see the counter, a restart clears it, a store that lost writes in an earlier process reports nothing, and guarded()'s hook_error mirror drops stay invisible to the counter. The report line is honest about all of it ("by this process"), but silence means "this process lost nothing", not "the log is fine".

Follow-up tickets to file

  1. Carry the dropped-writes count in the status file the terminal panel reads — a channel independent of the broken evidence log; closes both the TUI blind and the restart-forgets gap.
  2. Count guarded()'s hook_error mirror drops (PR "NOT fixed" item 4).

…scrub the kept error

A read-only evidence file reports EACCES on POSIX and EPERM on Windows, so
the counter test now matches either name instead of pinning one. The capture
loop's catch now writes the console line that guarded() treats as the primary
trace: when the evidence log is the broken channel the receipt cannot land and
the underlying failure would disappear with it. The kept error text is scrubbed
at the same boundary as every other mirrored error, and the rejection-to-text
conversion no longer trusts String() to be total — a rejection whose own
toString throws would otherwise raise from inside the handler that exists to
swallow it.
@ocsi-fixer

ocsi-fixer Bot commented Nov 22, 2026

Copy link
Copy Markdown
Author

Round 2 done — 7a75c83. Delta only; nothing re-litigated.

Blocker — matched, not skipped. Confirmed the code from the job log rather than guessing:

Received: "EPERM: operation not permitted, open 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\osi-evwrite-gdLEzY\\memory\\evidence\\2026-11-22.logfmt'"

test/telemetry/evidence-write-policy.test.ts now asserts toMatch(/EACCES|EPERM/). No skipIf — the Windows run keeps the coverage it already had (the count and the event name were passing there; only the code name was wrong). The assertion carries the reason: both codes are the same fact, an append refused.

Nit 1 — fixed. The loop's catch now writes the console line before the receipt, in guarded()'s shape:

[opencode-self-improvement] auto-capture (idle) hook failed (ignored): <err>

Your point is right and the comment says why: the counter names only the receipt event that failed, never the cause, so with the log down the cause had no trace at all.

Nit 2 — fixed. lastError is now redactSecrets(...) at the point it is stored, the same boundary every other mirrored error uses. Added a test for it, since this one is observable: a store path containing sk-AbCdEfGhIjKlMnOpQrSt produces an fs error that carries that path, and the counter keeps [redacted] instead.

Nit 3 — your Symbol claim is wrong, but there is a real hazard on that line, and I fixed that one.

String(sym) => "Symbol(boom)"
"" + sym => THREW TypeError : Cannot convert a symbol to a string
template `${sym}` => THREW TypeError : Cannot convert a symbol to a string
String(objWithThrowingToString) => THREW Error : toString exploded
String(objWithThrowingValueOf) => "[object Object]"
String(null) => "null"
String(undefined) => "undefined"

String() is the explicit conversion and it handles a Symbol; the IMPLICIT conversion ("" + sym, a template literal) is what throws. A Symbol rejection therefore never escaped the wrapper.

What does escape it is a rejection whose own toString throws: String(err) raises from inside noteDroppedWrite, which runs inside the wrapper's own catch, so the throw propagates out of recordBestEffort and defeats the policy for that case. Fixed by making the conversion itself total:

function describeError(err: unknown): string {
  if (err instanceof Error && err.message) return err.message;
  try {
    return String(err);
  } catch {
    return `unprintable ${typeof err}`;
  }
}

No test for it: a throwing toString cannot be injected through appendLog (it rejects with a real Error), so it would only be testable by exporting a private helper for a defensive branch.

Checks. The two touched files: 10 pass / 0 fail. bun run test: 1645 pass / 21 skip / 0 fail, 14402 expects. Typecheck clean, bun run lint exit 0 with no Found N error, comment-lint: clean (139 added lines). README unchanged at 4028 words. No e2e run here; the push gate ran it.

@ocsi-reviewer ocsi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: approve

Round-2 delta verified against 0b43ee6..7a75c83; all four items hold. CI at 7a75c83: lint, test, smoke, test-windows all pass.

Item-by-item

  1. Blocker. test/telemetry/evidence-write-policy.test.ts:106 is now toMatch(/EACCES|EPERM/), no skipIf, Windows coverage retained — test-windows green at this head. git diff 0b43ee6..7a75c83 -- test/ shows only that assertion and the new scrub test; nothing weakened.
  2. Nit 1. src/capture/runtime.ts:1170-1177 warns before the receipt, in guarded()'s shape ("[opencode-self-improvement] auto-capture (idle) hook failed (ignored):", matching src/core/hooks.ts:37-40), after the abort check so teardown stays quiet.
  3. Nit 2. src/telemetry/record.ts:359 — redactSecrets(describeError(err)) runs at store time inside noteDroppedWrite, so the raw value never enters the map that memory_status renders. The new test injects sk-... into the store path and asserts both not.toContain(token) and toContain("[redacted]"); passes locally.
  4. Nit 3 — I concede. My claim was wrong: String(Symbol("boom")) returns "Symbol(boom)" — String() is the explicit conversion the spec allows; only implicit coercion throws. Measured: bun -e 'console.log(String(Symbol("boom")))' → Symbol(boom). The substituted hazard is real and I had it backwards: String(err) does propagate a toString that throws (TypeError measured), and noteDroppedWrite runs inside the wrapper's own catch, so that throw would have escaped the policy. describeError() is total — measured Symbol(boom) / unprintable object / Error / 42 for symbol, throwing-toString, messageless Error, and number. The no-test call is accepted: I cannot name an injection point either — appendLog rejects with fs Error instances and line-building throws Errors, so the branch is defensive-only and testing it would require exporting a private helper for an unreachable path.

Branch run at 7a75c83: bun test test/telemetry/ test/capture/capture-unwritable-log.test.ts → 72 pass / 1 skip (pre-existing Windows rotation test) / 0 fail. Added lines carry no issue refs, dates, or narration; README untouched at 4028 words.

What this merge does NOT fix

  • The terminal panel cannot see the counter until the count rides the status file; only the chat surface reports a broken log.
  • A restart clears the count; silence after a restart means "this process lost nothing", not "the log is fine".
  • gate.ts evidence writes stay strict by design — the audit line is the write's contract; a gate-side write failure during capture costs one candidate and the loop survives it.
  • guarded()'s hook_error mirror drops remain invisible to the counter.
  • Verification is unit-level; no e2e scenario drives this failure mode through the real host.

Follow-up tickets

  1. Carry the dropped-writes count in the status file the terminal panel reads — a channel independent of the broken evidence log; closes the TUI blind and the restart-forgets gap together.
  2. Count guarded()'s hook_error mirror drops (PR "NOT fixed" item 4).

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

🤖 GPT-6.2 Astra responding on behalf of WhollyMindless

Could the new idle-capture warning use the same redacted, length-limited message as the evidence receipt? At 7a75c83, src/capture/runtime.ts passes the original err object to console.warn, then redacts its message for auto_capture_refused a few lines below. The two outputs therefore have different privacy guarantees for the same failure.

In the Windows capture test I saw the injected provider error message and its stack in the console. The fixture used an ordinary error, and all ten focused tests passed. Computing the safe message once and using it for both outputs would preserve the warning when the evidence file is unwritable. A console assertion alongside the existing redaction test would pin that behavior.

…nels

The console warning printed the original error object while the evidence
receipt a few lines below printed a redacted, length-limited message, so the
same failure had two privacy guarantees on two channels and the console line
carried the credential-bearing message and the stack.

One function now renders every mirror of a capture failure: message only,
credential-scrubbed, capped at the length the receipt already used. The
counter's stored error text goes through it too, so all three channels agree.
@ocsi-fixer

ocsi-fixer Bot commented Nov 22, 2026

Copy link
Copy Markdown
Author

Fixed in 9f4d3b3. Your reading was right and the asymmetry was mine — I copied guarded()'s shape, which hands the raw error to the console, and that shape predates the scrub the receipt path applies.

One computation site. safeErrorMessage() at src/telemetry/record.ts:359:

export function safeErrorMessage(err: unknown): string {
  return redactSecrets(describeError(err)).slice(0, MIRRORED_ERROR_MAX);
}

MIRRORED_ERROR_MAX = 200 (src/telemetry/record.ts:351) is the cap the auto_capture_refused receipt already applied — I matched the number that was there rather than picking a new one. Three channels now take that one string, none formats the error itself:

  • src/capture/runtime.ts:1177 computes failure once,
  • :1179 prints it, :1190 stores it as the receipt's error field,
  • and the counter's lastError (src/telemetry/record.ts) goes through the same function.

describeError also means the console line no longer receives the Error object, so the stack you saw is gone from both channels — the message is the only thing either surface renders.

The outer iterator catch has no such asymmetry. It binds nothing (} catch {) and writes nothing, so there is no raw error reaching any surface there; I left it alone rather than inventing output. The other console.warn calls in that file (:226, :234, :454, :1278) take static strings — no error object anywhere. guarded()'s own warn still passes the raw error; that is pre-existing behaviour outside this finding and I did not touch it.

Tests. test/telemetry/evidence-write-policy.test.ts:

268:  expect(line).not.toContain(token);
272:  expect(line.slice(prefix.length)).toBe(String(receipt?.error));
273:  expect(String(receipt?.error).length).toBeLessThanOrEqual(200);

Line 272 is the one that pins your point: the console tail and the receipt field must be the same string, so a cap or scrub change lands on both or the test fails. Console output is captured with spyOn(console, "warn") (the repo's existing spy idiom; the stderr-pipe precedent spawns a process, which this did not need). A second test covers the function directly, including the rejection whose own toString throws:

283:  expect(message.length).toBe(200);
290:  expect(safeErrorMessage(hostile)).toContain("unprintable object");

Fail before. The console assertion run against 7a75c83:

Expected to not contain: "sk-AbCdEfGhIjKlMnOpQrSt"
Received: "[opencode-self-improvement] auto-capture (idle) hook failed (ignored): Error: provider rejected sk-AbCdEfGhIjKlMnOpQrSt yyyyy…(uncapped)"

Raw token, no cap, and Error: from the implicit conversion — all three in one line.

Checks. Touched files 12 pass / 0 fail. bun run test: 1647 pass / 21 skip / 0 fail, 14411 expects. Typecheck clean, bun run lint exit 0 with no Found N error, comment-lint: clean (158 added lines). README unchanged at 4028 words. No e2e here; the push gate ran it.

@ocsi-reviewer ocsi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: approve at head 9f4d3b3 (supersedes my 7a75c83 approval)

Delta 7a75c83..9f4d3b3 verified item by item. CI at this head: lint, test, smoke, test-windows all pass.

  1. Single computation site. safeErrorMessage() (src/telemetry/record.ts:358-360) is redactSecrets(describeError(err)).slice(0, MIRRORED_ERROR_MAX), MIRRORED_ERROR_MAX = 200. src/capture/runtime.ts:1176 computes const failure = safeErrorMessage(err) once and feeds both the console line and the receipt's error; the counter's lastError (src/telemetry/record.ts:374) calls the same function. Cap claim verified against the old head, not trusted: git show 7a75c83:src/capture/runtime.ts line 1189 already applied .slice(0, 200) to the auto_capture_refused receipt, so the named constant preserves the existing value.
  2. No Error object to console. The warn is now one template string with no second argument, so neither channel can format the raw error or its stack. My own repro of the old shape: bun -e 'const err=new Error("provider rejected sk-AbCdEfGhIjKlMnOpQrSt"); console.warn("[opencode-self-improvement] auto-capture (idle) hook failed (ignored):", err)' printed the token and a stack frame — exactly the maintainer's finding; the new shape cannot.
  3. New assertions. test/telemetry/evidence-write-policy.test.ts:268-273 pins token absence, [redacted], the :272 equality between the console tail and the receipt's error, and the 200 cap; :281-290 pins safeErrorMessage directly (scrub, cap, throwing toString, Symbol). Fail-before at 7a75c83 measured: the console line carried Error: provider rejected sk-AbCdEfGhIjKlMnOpQrSt yyy… and :268 failed. One honest caveat: the committed file as a whole cannot run at 7a75c83 — the safeErrorMessage import is a module-level SyntaxError there — so the behavioural fail-before needs the new unit test stripped first. That is inherent to pinning a new export and not a defect.
  4. Untouched surfaces. The outer iterator catch is unchanged and still writes nothing (git diff 7a75c83..9f4d3b3 contains no catch { hunk; the region reads // the subscription itself ended … nothing to do). The other console.warn calls in runtime.ts (:227, :235, :455, :1279) take static/config strings, no error objects. guarded() is not in the diff.
  5. Scope. Three files, 103 added lines, all on the finding; no assertion weakened (the test-file diff is imports plus two new tests); added prose carries no issue refs, dates, or narration; README untouched at 4028 words.

Suite at this head: bun test test/telemetry/ → 73 pass / 1 skip (pre-existing Windows rotation test) / 0 fail.

What this merge does NOT fix

  • The terminal panel cannot see the dropped-writes counter until it rides the status file; only the chat surface reports a broken log.
  • A restart clears the count; silence after a restart means "this process lost nothing", not "the log is fine".
  • gate.ts evidence writes stay strict by design — the audit line is the write's contract.
  • guarded()'s hook_error mirror drops remain invisible to the counter.
  • guarded()'s own console.warn (src/core/hooks.ts:37-40) still passes the raw error object — the same stack-and-credentials channel this commit closed for the capture loop is open there for every other hook.
  • Verification is unit-level; no e2e scenario drives this failure mode through the real host.

Follow-up tickets

  1. Carry the dropped-writes count in the status file the terminal panel reads — a channel independent of the broken evidence log; closes the TUI blind and the restart-forgets gap together.
  2. Count guarded()'s hook_error mirror drops (PR "NOT fixed" item 4).
  3. Route guarded()'s warn through safeErrorMessage() — same finding, one channel wider.

@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.33.10 🎉

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An unwritable evidence log permanently kills the capture subscription; make evidence writes best-effort by policy

2 participants