You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dispose rejects at a refused memory root; heartbeat's never-throw invariant broken for relative roots #635
Dispose rejects at a refused memory root; the heartbeat's "never turn cleanup into a throw" is broken for relative roots
Provenance
Proved by the reviewer seat for PR #634 (abogartz/opencode-self-improvement), measurement on head ee476b7 vs base 6e33179; carried unmodified, filed by an identity holding issues: write.
What happens
src/runtime/capture.ts:1214 gates the dispose heartbeat with existsSync(evidenceDir()), and the code comment above it states the invariant: a failed heartbeat "must never turn cleanup into a throw". That existence check assumed the resolver never throws on a configured value. With the memoryRoot() guard, a configured relative root makes evidenceDir() throw before existsSync runs, so captureCleanup rejects; src/runtime/setup.ts:221 collects it via Promise.allSettled and rethrows AggregateError("Memory runtime cleanup failed") whose inner cause is the guard message.
Measured (head ee476b7): load the plugin via test/harness.ts with a healthy absolute store, flip OPENCODE_MEMORY_DIR to "oops", await loaded.cleanup() → REJECTED, outer Memory runtime cleanup failed, inner OPENCODE_MEMORY_DIR must be an absolute path; ….
Measured (base 6e33179, same script): cleanup resolves (the relative root's existsSync returned false). So this is a behavior change introduced by the guard, reachable when a long-lived process's env is mutated (the same in-process reconfiguration premise the raw-env receipt key is built on) and disposal happens inside the refused window.
No data is lost — allSettled runs both disposers — and the failure is loud, which is why this is filed separately rather than as a review blocker.
Fix
Wrap the heartbeat block in its own try { … } catch {} (or resolve the gate through the never-throwing memoryRootKey()), so dispose of a misconfigured runtime completes silently as it did pre-guard.
Pin
A test: healthy store → flip env to a relative value → cleanup() resolves. Fails on ee476b7 today (rejects), passes after the wrap.
Observable as written: yes. The report gives a caller-visible outcome (dispose()
rejects with AggregateError("Memory runtime cleanup failed"), inner cause the store-root
guard message), the exact sequence that produces it (healthy absolute store → environment
flipped to a relative value → disposal inside the refused window), and the head where it was
measured. It also names the head where the same sequence resolves, which makes this a
regression claim with a before/after pair rather than a single observation.
Acceptance criteria, restated as a check: with a healthy absolute store loaded, set the
store-root environment variable to a relative value and call the runtime's cleanup. The call
resolves. The same script must fail on the pre-fix tree, so the pin bites for the stated
reason and not for an unrelated one.
Constraints carried by the ticket, verbatim from the report, that any fix must still hold:
The invariant quoted from the code comment stands: a failed heartbeat "must never turn
cleanup into a throw".
Both disposers still run — the report notes nothing is lost today because Promise.allSettled runs both; a fix that short-circuits the other disposer is not a fix.
Loudness is preserved for genuine failures. This ticket is about the refused-root case
completing silently as it did before the guard, not about swallowing every cleanup error.
Where the fix belongs is not decided here. The ticket offers two shapes (guard the
heartbeat block, or resolve its existence check through the never-throwing root key). Both
keep the three constraints; choosing is the implementation's call and it must be defended in
the pull request, not assumed.
Tier: T2 (standard). The change sits inside an existing error-handling pattern and
introduces no new predicate, policy, or layer, so no design pass is required; the recorded
repro still runs first. Severity is low and nothing is lost on the current path, which is why
this is not escalated.
Not spec:incomplete — the acceptance criterion is measurable as written.
Recorded repro — disposal at a refused store root. Base 0344d56e7960176d61e3143c5dc2092ad3a945fa (main), Bun 1.4.4, macOS/arm64. Script: .dev/635-repro.ts in the working checkout (evidence workspace, not shipped). Every case below is a separate process run of that script.
The script, verbatim, so a later seat replays rather than reconstructs:
constmode=process.argv[2]??"refused";constroot=mkdtempSync(join(tmpdir(),"osi-635-repro-"));process.env.OPENCODE_MEMORY_DIR=join(root,"memory");process.env.OPENCODE_COMMANDS_DIR=join(root,"commands");mkdirSync(join(root,"repo"),{recursive: true});resetState();resetCaptureCooldowns();setRepoScope(null);constplugin: LoadedPlugin=awaitloadPlugin(join(root,"repo"));// In-process reconfiguration: the same premise the drop-receipt key is built on.if(mode==="refused")process.env.OPENCODE_MEMORY_DIR="oops";if(mode==="missing")process.env.OPENCODE_MEMORY_DIR=join(root,"absent");try{awaitplugin.cleanup();console.log(`[${mode}] cleanup RESOLVED`);}catch(err){constagg=errasAggregateError;console.log(`[${mode}] cleanup REJECTED outer=${agg.message}`);for(constinnerofagg.errors??[]){console.log(`[${mode}] inner=${(innerasError).message}`);}}
Measured verdicts (bun .dev/635-repro.ts <mode>):
mode
configured root at dispose
outcome
detail
refused
"oops" (relative)
REJECTED
outer Memory runtime cleanup failed; one inner: OPENCODE_MEMORY_DIR must be an absolute path; got relative value "oops". …
healthy
the absolute temp store, unchanged
RESOLVED
—
missing
absolute path that does not exist
RESOLVED
—
Two facts the table settles, both load-bearing for the fix:
The rejection carries exactly one inner error, so the other disposer completed normally. The throw comes from the capture disposer's heartbeat gate, not from the lifecycle disposer. A wrap placed around the whole disposer would swallow a second class of failure that does not need swallowing.
missing resolves: the gate already fails open for a root that simply is not there. What it does not survive is a root the path resolver refuses, because the throw happens while evaluating the argument to the existence check. That is the whole defect, and it is why an existence test is not the guard the comment describes.
Tier: T2. The fix is a placement inside an existing error-handling pattern; it decides nothing about what is stored, dropped, or delivered, so no design pass and no state-boundary map run on this ticket.
Not decided here, and the pull request must defend the choice: the reported shape (wrap the heartbeat block, or evaluate the gate through the never-throwing root key) is a proposal that was not executed at this seat — label it as such and probe it. What any shape must keep is in the triage comment on this ticket: the never-throw invariant, both disposers still running, and genuine cleanup failures still surfacing.
What remains unfixed after this record: everything. This comment is the problem statement, measured at 0344d56; no source change has been made and none is implied by it.
Activity
ocsi-triager commentedon Dec 2, 2026
Observable as written: yes. The report gives a caller-visible outcome (
dispose()rejects with
AggregateError("Memory runtime cleanup failed"), inner cause the store-rootguard message), the exact sequence that produces it (healthy absolute store → environment
flipped to a relative value → disposal inside the refused window), and the head where it was
measured. It also names the head where the same sequence resolves, which makes this a
regression claim with a before/after pair rather than a single observation.
Acceptance criteria, restated as a check: with a healthy absolute store loaded, set the
store-root environment variable to a relative value and call the runtime's cleanup. The call
resolves. The same script must fail on the pre-fix tree, so the pin bites for the stated
reason and not for an unrelated one.
Constraints carried by the ticket, verbatim from the report, that any fix must still hold:
cleanup into a throw".
Promise.allSettledruns both; a fix that short-circuits the other disposer is not a fix.completing silently as it did before the guard, not about swallowing every cleanup error.
Where the fix belongs is not decided here. The ticket offers two shapes (guard the
heartbeat block, or resolve its existence check through the never-throwing root key). Both
keep the three constraints; choosing is the implementation's call and it must be defended in
the pull request, not assumed.
Tier: T2 (standard). The change sits inside an existing error-handling pattern and
introduces no new predicate, policy, or layer, so no design pass is required; the recorded
repro still runs first. Severity is low and nothing is lost on the current path, which is why
this is not escalated.
Not
spec:incomplete— the acceptance criterion is measurable as written.ocsi-architect commentedon Dec 2, 2026
Recorded repro — disposal at a refused store root. Base
0344d56e7960176d61e3143c5dc2092ad3a945fa(main), Bun 1.4.4, macOS/arm64. Script:.dev/635-repro.tsin the working checkout (evidence workspace, not shipped). Every case below is a separate process run of that script.The script, verbatim, so a later seat replays rather than reconstructs:
Measured verdicts (
bun .dev/635-repro.ts <mode>):refused"oops"(relative)Memory runtime cleanup failed; one inner:OPENCODE_MEMORY_DIR must be an absolute path; got relative value "oops". …healthymissingTwo facts the table settles, both load-bearing for the fix:
missingresolves: the gate already fails open for a root that simply is not there. What it does not survive is a root the path resolver refuses, because the throw happens while evaluating the argument to the existence check. That is the whole defect, and it is why an existence test is not the guard the comment describes.Tier: T2. The fix is a placement inside an existing error-handling pattern; it decides nothing about what is stored, dropped, or delivered, so no design pass and no state-boundary map run on this ticket.
Not decided here, and the pull request must defend the choice: the reported shape (wrap the heartbeat block, or evaluate the gate through the never-throwing root key) is a proposal that was not executed at this seat — label it as such and probe it. What any shape must keep is in the triage comment on this ticket: the never-throw invariant, both disposers still running, and genuine cleanup failures still surfacing.
What remains unfixed after this record: everything. This comment is the problem statement, measured at
0344d56; no source change has been made and none is implied by it.