Skip to content

fix(tui): warn once per Windows job assignment failure episode - #568

Merged
agenteinstinct1-max merged 1 commit into
dev-vibecodedfrom
fix/win-job-assignment-warning-dedup
Oct 24, 2026
Merged

agenteinstinct1-max merged 1 commit into
dev-vibecodedfrom
fix/win-job-assignment-warning-dedup

Conversation

@agenteinstinct1-max

Copy link
Copy Markdown
Collaborator

Issue for this PR

Refs #442

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Post-merge follow-up to #561 (win-job.ts). The owner-side Job Object adopter warns when a worker cannot be put under the kill-on-close job so the watchdog fallback is known to be active. Job-creation and FFI-load failures were already logged once, but a failed OpenProcess/AssignProcessToJobObject logged on every adoption attempt: a worker respawning under a persistent assignment failure produced one warning per spawn (reproduced: one job creation, three adoptions, three identical warnings). Retrying is correct - a later spawn may assign fine - the defect was that warning deduplication was not independent of the retry.

Fix: the adopter now tracks the failure episode. The first failed assignment logs the warning; repeated failures stay quiet while every spawn is still attempted against the retained job; a successful assignment rearms the warning so a later failure episode is still reported. No other behavior changes: job creation, job retention, assignment retries, and the watchdog fallback are all unchanged.

How did you verify your code works?

New regression coverage in win-job.test.ts:

  • repeated AssignProcessToJobObject failure across three adoptions warns exactly once and still attempts every spawn against the same retained job (no job re-creation, no job handle close);
  • repeated OpenProcess failure warns exactly once;
  • failure-success-failure warns once per episode (success rearms the warning).

The existing failure-then-success retry test is unchanged and passing. bun test test/cli/tui/: 96 pass, 0 fail (bun 1.3.14, Linux). Windows runtime acceptance remains with #442, which stays open.

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The owner-side job adopter retried a failed OpenProcess or
AssignProcessToJobObject on every later spawn - correct - but also logged
the fallback warning on every attempt, so a worker respawning under a
persistent assignment failure spammed one warning per adoption. Track the
episode: log the first failure, stay quiet while failures repeat, keep
retrying against the retained job, and rearm the warning once an
assignment succeeds so a later episode is still reported.

Adds regression coverage for repeated assignment failure, repeated
OpenProcess failure, and the failure-success-failure sequence.
@github-actions

Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@kilo-code-bot

kilo-code-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/opencode/src/cli/tui/win-job.ts
  • packages/opencode/test/cli/tui/win-job.test.ts

Reviewed by free · Input: 19.8K · Output: 1.4K · Cached: 171.3K

@agenteinstinct1-max
agenteinstinct1-max merged commit d62d2c5 into dev-vibecoded Oct 24, 2026
7 checks passed
agenteinstinct1-max pushed a commit that referenced this pull request Oct 31, 2026
…next commit)

Temporary, deliberately broken commit. `adoptWorkerProcess` no longer calls
the adopter, so a spawned worker is never put into the owner's kill-on-close
Job Object - i.e. the state #561/#568 exist to prevent.

Expected: unit (windows) goes RED on the owner-death tests' survivor
assertion, because a force-killed owner no longer takes the worker tree
down. If those tests still passed with the binding disabled they would be
proving nothing.

win-job's own 21 unit tests still pass under this mutation because they
drive `createOwnerJobAdopter` directly rather than `adoptWorkerProcess`, so
the red signal is isolated to the integration coverage.

Reverted in the next commit.

Co-authored-by: arena-agent <[email protected]>
agenteinstinct1-max added a commit that referenced this pull request Oct 31, 2026
* test(opencode): prove Windows owner-death cleanup with real processes (#442)

win32-gated integration coverage that runs on the existing windows-latest
matrix leg and exercises the real spawn path bound to the Job Object: the
owner is force-killed with TerminateProcess and the worker tree is then
verified gone through real process inspection (OpenProcess + tasklist),
with both listening ports probed for release.

Two properties are covered:

- happy path: a force-killed owner takes the worker tree and its listening
  ports with it; incremental identity capture off the Bun.spawn handle
  (worker -> child -> child-port -> ready) means every PID is known as soon
  as it is created, so cleanup can reap a tree that never finished starting.
- stall path: the grandchild binds its port but never writes its ready line
  (SILVERCODE_TEST_GRANDCHILD_SILENT=1), so the bounded identity wait must
  fail at the deadline rather than hang, and the half-built tree must still
  leave nothing behind. Anti-vacuous-pass guards assert both PIDs were
  captured and grandchildPort stayed undefined, so a slow startup cannot
  masquerade as the stall.

All waits are hard-bounded (tasklist capped to the remaining budget, socket
probes 2s, cleanup raced against its own budget). The stall test sets its own
per-test timeout; the package default --timeout 30000 is unchanged.

Tests and fixtures only - no production or workflow changes. Existing #561
and #568 unit tests are untouched.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): give the stall test's post-bound phases fresh deadlines

unit (windows) failed at 366f0a9. The stall test's identity wait consumes
STALL_BUDGET_MS by design - `ready` is suppressed, so the bounded promise
never settles - which left the original `deadline` in the past for every
phase that followed:

  tasklistHasPid(pid, deadline)
    -> Math.max(1, Math.min(15000, negative)) = 1ms allowance
    -> exitedDueToTimeout, so it throws instead of reporting the pid
  bounded(owner.exited, ..., deadline)
    -> Math.max(0, negative) = 0ms allowance
    -> rejects with "the owner never exited after TerminateProcess"
       before the owner has had time to die

Reproduced directly: after the identity wait the remainder is -1ms, and a
0ms bounded rejects a promise that settles 30ms later, while the same
promise resolves against a fresh deadline.

The happy-path test was never affected because its bounded(treeReady)
resolves early and leaves most of the budget intact. Local verification
missed this because the Linux harness substitutes process.kill(pid, 0) for
tasklist and already used fresh deadlines.

Every phase after the identity wait now runs on its own fresh deadline:
STALL_PROBE_MS (15s) for pre-kill liveness and the owner's exit, and
STALL_VERIFY_MS (20s) for post-kill verification. STALL_BUDGET_MS is raised
15s -> 40s to match the budget already proven comfortable on windows-latest,
so a slow cold start cannot make the anti-vacuous-pass guards fire. The
per-test timeout follows the arithmetic: 40 + 15 + 20 + 5 cleanup = 80s,
so STALL_TEST_TIMEOUT_MS = 90_000. The package default --timeout 30000 is
still untouched. No assertion was weakened or reordered.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): make the stall test verify cleanup even when its first await throws

unit (windows) at 34d8f92 failed the stall test at
win-owner-death.integration.test.ts:507:102 - inside `.rejects.toThrow(` -
with `Received message: "The user aborted a request"`.

That line was the first statement of the `try`. Asserting the bounded
identity wait inline means ANY rejection there throws straight out of the
test, so every post-timeout assertion is skipped and the "leaves nothing
behind" property - the whole point of the test - is never verified.

Reproduced both halves locally:

- before: injecting that rejection makes the test bail immediately with
  zero assertions executed and no cleanup verification
- after: 7 cleanup/safety assertions run and pass (no survivors, both PIDs
  gone, both absent from the process list, worker port closed and
  rebindable), and only then does the diagnostic assertion report
  `Received: "The user aborted a request"`

Structure is now capture -> kill -> verify -> clean up -> assert. The
outcome of the identity wait is captured instead of asserted inline; probes
are wrapped so a wedged one yields its message (which then fails the
assertion consuming it) rather than either throwing early or being silently
read as "absent"; `settled()` is the non-throwing form of `until()`. Cleanup
runs before the assertions, so no failed assertion can leave a live process
on the runner.

The FETCH_ABORTED itself is not produced by this test. Verified: there is no
fetch, AbortController or abort signal anywhere in the four files;
make-fetch-happen, minipass-fetch and npm-registry-fetch are absent from the
entire repository; and bounded(treeReady, ...) can only ever reject with its
own message, because treeReady has no reject path. Locally the identity wait
rejects with exactly "the worker never reported its identity" and the
assertion passes. So this commit does not claim to fix the source of that
error - it makes the test survive it, verify what it exists to verify, and
report the unexpected message precisely.

No budget or timeout changed: STALL_BUDGET_MS stays 40_000,
STALL_TEST_TIMEOUT_MS stays 90_000, and the package default
(--timeout 30000) is untouched. No assertion was removed or weakened.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): return the stall test to the accepted budget envelope, harden deadlines

Applies the independent review verdict on 34d8f92.

Budget envelope. The 90s per-test timeout was a consequence of raising
STALL_BUDGET_MS from 15s to 40s, not of the negative-allowance fix. With a
fresh deadline per phase the fix stands on its own, so the raise is
reverted: STALL_BUDGET_MS 40_000 -> 15_000 and STALL_TEST_TIMEOUT_MS
90_000 -> 45_000, back inside the previously accepted 40/50 envelope. No
new deviation. Verified locally on a Linux-runnable copy of the real file:
the stall test now completes in 15.09s and both tests pass.

The timeout comment claimed 40+15+20+5=80s and omitted the `finally`
reapTree. It now gives the arithmetic by case instead of one sum: nominal
~21s, worst single-phase-failure 15+3+20+5=43s which fits, and the one
path that does not fit - probe AND verify phases both exhausting their
ceilings, 55s - where the timeout fires and the test fails loudly rather
than hanging.

Deadline guards. `bounded` and `tasklistHasPid` no longer clamp a spent
deadline to 0ms/1ms, which reported "the thing never happened" when the
real cause was "the caller's budget was already gone". Both now throw a
distinct "deadline already expired" error. Covered by a test that asserts
the exact messages, so the guard cannot rot silently.

PID-recycling guard. `reapTree` now takes the set of PIDs this test already
proved dead and skips them: a recycled PID would otherwise be signalled,
killing something the runner needs. The survivor check applies the same
guard, so a reused PID cannot be reported as a false survivor. Survivors
are also now computed BEFORE the manual reap, so the assertion proves the
job took the tree down rather than that our own cleanup did.

Positive log control. The adopter only logs on failure, so a clean run
produces no `log:` messages at all - which let the "(#442)"-free assertion
pass vacuously if IPC forwarding broke. The owner fixture now sends a
`log:owner-log-channel-ok` sentinel and both tests assert it arrived, so an
empty log is a failure rather than a pass.

No assertion removed or weakened; the package default --timeout 30000 is
untouched.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): MUTATION CONTROL - disable the job binding (reverted next commit)

Temporary, deliberately broken commit. `adoptWorkerProcess` no longer calls
the adopter, so a spawned worker is never put into the owner's kill-on-close
Job Object - i.e. the state #561/#568 exist to prevent.

Expected: unit (windows) goes RED on the owner-death tests' survivor
assertion, because a force-killed owner no longer takes the worker tree
down. If those tests still passed with the binding disabled they would be
proving nothing.

win-job's own 21 unit tests still pass under this mutation because they
drive `createOwnerJobAdopter` directly rather than `adoptWorkerProcess`, so
the red signal is isolated to the integration coverage.

Reverted in the next commit.

Co-authored-by: arena-agent <[email protected]>

* Revert "test(opencode): MUTATION CONTROL - disable the job binding (reverted next commit)"

This reverts commit 9bbe7bd.

* test(opencode): give the happy path fresh per-phase deadlines too

Review item (b) covered the happy path's `owner.exited` as well as the stall
test's, and only the stall test had been converted. The happy path still
passed its original `deadline` to ten calls - `tasklistHasPid` four times,
`bounded(owner.exited)`, `until` four times and `bounded(canBind)` twice.
Those were tolerable while a spent deadline merely clamped to a 1ms/0ms
allowance; once the distinct expiry guard landed, every one of them became a
hard throw as soon as the budget was spent.

Both tests now use `deadline` for exactly one thing - the identity wait - and
take a fresh `PROBE_BUDGET_MS` (15s) for the pre-kill liveness and owner exit
and a fresh `VERIFY_BUDGET_MS` (20s) for everything after the kill. The two
constants were renamed out of their stall-specific names because both tests
use them; their values are unchanged, so no budget was raised.

Verified on a Linux-runnable copy of the real file with the Job Object
contract emulated: both tests pass, the stall test completing in 15.10s, 33
expect() calls.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): preload config before permission waits (Refs #489, #732)

Co-authored-by: arena-agent <[email protected]>

* chore: align branch files with integration baseline

Co-authored-by: arena-agent <[email protected]>

---------

Co-authored-by: arena-agent <[email protected]>
Co-authored-by: arena-agent <[email protected]>
Co-authored-by: agenteinstinct1-max <[email protected]>
agenteinstinct1-max added a commit that referenced this pull request Nov 1, 2026
…on (Refs #736)

* test(opencode): prove Windows owner-death cleanup with real processes (#442)

win32-gated integration coverage that runs on the existing windows-latest
matrix leg and exercises the real spawn path bound to the Job Object: the
owner is force-killed with TerminateProcess and the worker tree is then
verified gone through real process inspection (OpenProcess + tasklist),
with both listening ports probed for release.

Two properties are covered:

- happy path: a force-killed owner takes the worker tree and its listening
  ports with it; incremental identity capture off the Bun.spawn handle
  (worker -> child -> child-port -> ready) means every PID is known as soon
  as it is created, so cleanup can reap a tree that never finished starting.
- stall path: the grandchild binds its port but never writes its ready line
  (SILVERCODE_TEST_GRANDCHILD_SILENT=1), so the bounded identity wait must
  fail at the deadline rather than hang, and the half-built tree must still
  leave nothing behind. Anti-vacuous-pass guards assert both PIDs were
  captured and grandchildPort stayed undefined, so a slow startup cannot
  masquerade as the stall.

All waits are hard-bounded (tasklist capped to the remaining budget, socket
probes 2s, cleanup raced against its own budget). The stall test sets its own
per-test timeout; the package default --timeout 30000 is unchanged.

Tests and fixtures only - no production or workflow changes. Existing #561
and #568 unit tests are untouched.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): give the stall test's post-bound phases fresh deadlines

unit (windows) failed at 366f0a9. The stall test's identity wait consumes
STALL_BUDGET_MS by design - `ready` is suppressed, so the bounded promise
never settles - which left the original `deadline` in the past for every
phase that followed:

  tasklistHasPid(pid, deadline)
    -> Math.max(1, Math.min(15000, negative)) = 1ms allowance
    -> exitedDueToTimeout, so it throws instead of reporting the pid
  bounded(owner.exited, ..., deadline)
    -> Math.max(0, negative) = 0ms allowance
    -> rejects with "the owner never exited after TerminateProcess"
       before the owner has had time to die

Reproduced directly: after the identity wait the remainder is -1ms, and a
0ms bounded rejects a promise that settles 30ms later, while the same
promise resolves against a fresh deadline.

The happy-path test was never affected because its bounded(treeReady)
resolves early and leaves most of the budget intact. Local verification
missed this because the Linux harness substitutes process.kill(pid, 0) for
tasklist and already used fresh deadlines.

Every phase after the identity wait now runs on its own fresh deadline:
STALL_PROBE_MS (15s) for pre-kill liveness and the owner's exit, and
STALL_VERIFY_MS (20s) for post-kill verification. STALL_BUDGET_MS is raised
15s -> 40s to match the budget already proven comfortable on windows-latest,
so a slow cold start cannot make the anti-vacuous-pass guards fire. The
per-test timeout follows the arithmetic: 40 + 15 + 20 + 5 cleanup = 80s,
so STALL_TEST_TIMEOUT_MS = 90_000. The package default --timeout 30000 is
still untouched. No assertion was weakened or reordered.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): make the stall test verify cleanup even when its first await throws

unit (windows) at 34d8f92 failed the stall test at
win-owner-death.integration.test.ts:507:102 - inside `.rejects.toThrow(` -
with `Received message: "The user aborted a request"`.

That line was the first statement of the `try`. Asserting the bounded
identity wait inline means ANY rejection there throws straight out of the
test, so every post-timeout assertion is skipped and the "leaves nothing
behind" property - the whole point of the test - is never verified.

Reproduced both halves locally:

- before: injecting that rejection makes the test bail immediately with
  zero assertions executed and no cleanup verification
- after: 7 cleanup/safety assertions run and pass (no survivors, both PIDs
  gone, both absent from the process list, worker port closed and
  rebindable), and only then does the diagnostic assertion report
  `Received: "The user aborted a request"`

Structure is now capture -> kill -> verify -> clean up -> assert. The
outcome of the identity wait is captured instead of asserted inline; probes
are wrapped so a wedged one yields its message (which then fails the
assertion consuming it) rather than either throwing early or being silently
read as "absent"; `settled()` is the non-throwing form of `until()`. Cleanup
runs before the assertions, so no failed assertion can leave a live process
on the runner.

The FETCH_ABORTED itself is not produced by this test. Verified: there is no
fetch, AbortController or abort signal anywhere in the four files;
make-fetch-happen, minipass-fetch and npm-registry-fetch are absent from the
entire repository; and bounded(treeReady, ...) can only ever reject with its
own message, because treeReady has no reject path. Locally the identity wait
rejects with exactly "the worker never reported its identity" and the
assertion passes. So this commit does not claim to fix the source of that
error - it makes the test survive it, verify what it exists to verify, and
report the unexpected message precisely.

No budget or timeout changed: STALL_BUDGET_MS stays 40_000,
STALL_TEST_TIMEOUT_MS stays 90_000, and the package default
(--timeout 30000) is untouched. No assertion was removed or weakened.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): return the stall test to the accepted budget envelope, harden deadlines

Applies the independent review verdict on 34d8f92.

Budget envelope. The 90s per-test timeout was a consequence of raising
STALL_BUDGET_MS from 15s to 40s, not of the negative-allowance fix. With a
fresh deadline per phase the fix stands on its own, so the raise is
reverted: STALL_BUDGET_MS 40_000 -> 15_000 and STALL_TEST_TIMEOUT_MS
90_000 -> 45_000, back inside the previously accepted 40/50 envelope. No
new deviation. Verified locally on a Linux-runnable copy of the real file:
the stall test now completes in 15.09s and both tests pass.

The timeout comment claimed 40+15+20+5=80s and omitted the `finally`
reapTree. It now gives the arithmetic by case instead of one sum: nominal
~21s, worst single-phase-failure 15+3+20+5=43s which fits, and the one
path that does not fit - probe AND verify phases both exhausting their
ceilings, 55s - where the timeout fires and the test fails loudly rather
than hanging.

Deadline guards. `bounded` and `tasklistHasPid` no longer clamp a spent
deadline to 0ms/1ms, which reported "the thing never happened" when the
real cause was "the caller's budget was already gone". Both now throw a
distinct "deadline already expired" error. Covered by a test that asserts
the exact messages, so the guard cannot rot silently.

PID-recycling guard. `reapTree` now takes the set of PIDs this test already
proved dead and skips them: a recycled PID would otherwise be signalled,
killing something the runner needs. The survivor check applies the same
guard, so a reused PID cannot be reported as a false survivor. Survivors
are also now computed BEFORE the manual reap, so the assertion proves the
job took the tree down rather than that our own cleanup did.

Positive log control. The adopter only logs on failure, so a clean run
produces no `log:` messages at all - which let the "(#442)"-free assertion
pass vacuously if IPC forwarding broke. The owner fixture now sends a
`log:owner-log-channel-ok` sentinel and both tests assert it arrived, so an
empty log is a failure rather than a pass.

No assertion removed or weakened; the package default --timeout 30000 is
untouched.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): MUTATION CONTROL - disable the job binding (reverted next commit)

Temporary, deliberately broken commit. `adoptWorkerProcess` no longer calls
the adopter, so a spawned worker is never put into the owner's kill-on-close
Job Object - i.e. the state #561/#568 exist to prevent.

Expected: unit (windows) goes RED on the owner-death tests' survivor
assertion, because a force-killed owner no longer takes the worker tree
down. If those tests still passed with the binding disabled they would be
proving nothing.

win-job's own 21 unit tests still pass under this mutation because they
drive `createOwnerJobAdopter` directly rather than `adoptWorkerProcess`, so
the red signal is isolated to the integration coverage.

Reverted in the next commit.

Co-authored-by: arena-agent <[email protected]>

* Revert "test(opencode): MUTATION CONTROL - disable the job binding (reverted next commit)"

This reverts commit 9bbe7bd.

* test(opencode): give the happy path fresh per-phase deadlines too

Review item (b) covered the happy path's `owner.exited` as well as the stall
test's, and only the stall test had been converted. The happy path still
passed its original `deadline` to ten calls - `tasklistHasPid` four times,
`bounded(owner.exited)`, `until` four times and `bounded(canBind)` twice.
Those were tolerable while a spent deadline merely clamped to a 1ms/0ms
allowance; once the distinct expiry guard landed, every one of them became a
hard throw as soon as the budget was spent.

Both tests now use `deadline` for exactly one thing - the identity wait - and
take a fresh `PROBE_BUDGET_MS` (15s) for the pre-kill liveness and owner exit
and a fresh `VERIFY_BUDGET_MS` (20s) for everything after the kill. The two
constants were renamed out of their stall-specific names because both tests
use them; their values are unchanged, so no budget was raised.

Verified on a Linux-runnable copy of the real file with the Job Object
contract emulated: both tests pass, the stall test completing in 15.10s, 33
expect() calls.

Co-authored-by: arena-agent <[email protected]>

* feat(opencode): recover truncated write calls into a guided continuation (Refs #736)

experimental_repairToolCall used to answer every unparseable tool call with the
`invalid` placeholder plus a generic retry-smaller nudge. For a `write` call cut
off mid-JSON that discarded the one fact the fragment still held: the target
path had usually already arrived complete.

The repair now salvages that path with a tolerant prefix parse and returns a
guided continuation. The salvage walks the raw fragment and decodes a top-level
string value only when its closing quote actually arrived, so a value that was
cut, an undecodable literal, or a `"filePath":` sequence that only appears
inside some other string yields nothing. No content is ever reconstructed and
the call is still routed to `invalid` - it never executes, so there is no
partial write to reconcile.

The message states what was recovered, states that this call did not execute and
therefore wrote nothing (scoped to this call only - earlier tool calls may have
had effects the repair cannot see), and asks for a chunked re-issue: write the
first chunk, then append the rest. The truncation cause stays qualified
("usually") because a fragment can also be genuinely malformed JSON.

Lowercase-name and deferred-tool-discovery repairs are untouched, and the hook
only attempts a recovery for tools present in the request.

Refs #736

Co-authored-by: arena-agent <[email protected]>

* fix(opencode): refuse ambiguous truncated-write targets and guide a safe append

Addresses three defects in the truncated-`write` recovery from #736 review.

1. The salvage returned the first `filePath` it saw. A fragment such as
   {"filePath":"first.md","filePath":"last.md","content":"..."} names last.md
   once completed (JSON keeps the last duplicate), so asserting first.md sent
   the model to the wrong file; the same scan also treated key-shaped text in
   a top-level array as a member. `salvageStringArgument` is now a structural
   prefix parse: the fragment must start an object, members are read as
   "key": value with real separators and validated scalar tokens, nested
   values are skipped with string-aware depth tracking, and a repeated target
   key is treated as ambiguous and yields nothing.

2. The recovery told the model to write the first chunk and then "append" the
   rest, without saying how - and `write` replaces the whole file, so a second
   write would discard the first chunk or content that earlier calls already
   produced. The guidance now inspects the path first, uses write only for the
   first chunk of a path that does not exist, and appends later chunks with
   edit (oldString = a unique tail, newString = tail + next chunk), explicitly
   warning that write replaces the entire file.

3. "No file content arrived before the cut" was false whenever content did
   arrive before the path. The message now says the content was not recovered
   and is unknown, and keeps the did-not-execute claim scoped to this one call,
   noting earlier calls may have had effects on the same path.

Tests: duplicate-key, array, structural and nested-member salvage cases; the
content-unknown wording; the existing-file continuation as an end-to-end run
where only edits execute and every pre-existing byte survives. Each fix is
killed by a mutant (first-match-wins, array-accepted, absence claim, unsafe
guidance).

Refs #736

Co-authored-by: arena-agent <[email protected]>

* fix(opencode): reject ambiguous and malformed truncated-write prefixes

Two holes in the truncated-write salvage let a malformed fragment name a
target it never really carried:

- A repeated `filePath` was only detected once its colon was read, so a
  fragment cut off right after the second key name
  (`{"filePath":"a","filePath"`) still reported the first value. The
  duplicate is now refused as soon as the name is read, before the
  end-of-fragment break.
- `skipValue` balanced nested values by counting brackets, so a mismatched
  pair such as `{"bad":{]` looked like a completed value. Opening brackets
  are now tracked, and a closing bracket only balances a value when it
  matches.

Tests cover both: the duplicate cut off before its colon and the malformed
nested value (directly and through `truncatedWriteRecovery`), plus the
companion case that a merely truncated later member still recovers the
path. Mutation checks (source patched, tests re-run, source restored) show
each new test fails when its fix is reverted.

Co-authored-by: arena-agent <[email protected]>

* chore(opencode): drop inherited Windows owner-death fixtures

The four Windows owner-death fixtures arrived with the seed branch's
unrelated owner-death work and are not part of the accepted #742 base.
Nothing references them, so they are removed on their own; no production
code is touched.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): restore accepted CLI retry coverage

Restore run-process.test.ts and run-retry-wait.test.ts byte-for-byte from current dev-vibecoded tip 2e94981. The inherited isModelAttempt/quota-response, retry-cap/count, and diagnostic assertion deletions are unrelated to the truncated-write recovery. No production code is reverted.

Refs #736

Co-authored-by: arena-agent <[email protected]>

* test(opencode): clarify doom-loop evidence

Co-authored-by: arena-agent <[email protected]>

---------

Co-authored-by: arena-agent <[email protected]>
Co-authored-by: arena-agent <[email protected]>
Co-authored-by: agenteinstinct1-max <[email protected]>
agenteinstinct1-max added a commit that referenced this pull request Nov 1, 2026
…716)

* test(opencode): prove Windows owner-death cleanup with real processes (#442)

win32-gated integration coverage that runs on the existing windows-latest
matrix leg and exercises the real spawn path bound to the Job Object: the
owner is force-killed with TerminateProcess and the worker tree is then
verified gone through real process inspection (OpenProcess + tasklist),
with both listening ports probed for release.

Two properties are covered:

- happy path: a force-killed owner takes the worker tree and its listening
  ports with it; incremental identity capture off the Bun.spawn handle
  (worker -> child -> child-port -> ready) means every PID is known as soon
  as it is created, so cleanup can reap a tree that never finished starting.
- stall path: the grandchild binds its port but never writes its ready line
  (SILVERCODE_TEST_GRANDCHILD_SILENT=1), so the bounded identity wait must
  fail at the deadline rather than hang, and the half-built tree must still
  leave nothing behind. Anti-vacuous-pass guards assert both PIDs were
  captured and grandchildPort stayed undefined, so a slow startup cannot
  masquerade as the stall.

All waits are hard-bounded (tasklist capped to the remaining budget, socket
probes 2s, cleanup raced against its own budget). The stall test sets its own
per-test timeout; the package default --timeout 30000 is unchanged.

Tests and fixtures only - no production or workflow changes. Existing #561
and #568 unit tests are untouched.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): give the stall test's post-bound phases fresh deadlines

unit (windows) failed at 366f0a9. The stall test's identity wait consumes
STALL_BUDGET_MS by design - `ready` is suppressed, so the bounded promise
never settles - which left the original `deadline` in the past for every
phase that followed:

  tasklistHasPid(pid, deadline)
    -> Math.max(1, Math.min(15000, negative)) = 1ms allowance
    -> exitedDueToTimeout, so it throws instead of reporting the pid
  bounded(owner.exited, ..., deadline)
    -> Math.max(0, negative) = 0ms allowance
    -> rejects with "the owner never exited after TerminateProcess"
       before the owner has had time to die

Reproduced directly: after the identity wait the remainder is -1ms, and a
0ms bounded rejects a promise that settles 30ms later, while the same
promise resolves against a fresh deadline.

The happy-path test was never affected because its bounded(treeReady)
resolves early and leaves most of the budget intact. Local verification
missed this because the Linux harness substitutes process.kill(pid, 0) for
tasklist and already used fresh deadlines.

Every phase after the identity wait now runs on its own fresh deadline:
STALL_PROBE_MS (15s) for pre-kill liveness and the owner's exit, and
STALL_VERIFY_MS (20s) for post-kill verification. STALL_BUDGET_MS is raised
15s -> 40s to match the budget already proven comfortable on windows-latest,
so a slow cold start cannot make the anti-vacuous-pass guards fire. The
per-test timeout follows the arithmetic: 40 + 15 + 20 + 5 cleanup = 80s,
so STALL_TEST_TIMEOUT_MS = 90_000. The package default --timeout 30000 is
still untouched. No assertion was weakened or reordered.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): make the stall test verify cleanup even when its first await throws

unit (windows) at 34d8f92 failed the stall test at
win-owner-death.integration.test.ts:507:102 - inside `.rejects.toThrow(` -
with `Received message: "The user aborted a request"`.

That line was the first statement of the `try`. Asserting the bounded
identity wait inline means ANY rejection there throws straight out of the
test, so every post-timeout assertion is skipped and the "leaves nothing
behind" property - the whole point of the test - is never verified.

Reproduced both halves locally:

- before: injecting that rejection makes the test bail immediately with
  zero assertions executed and no cleanup verification
- after: 7 cleanup/safety assertions run and pass (no survivors, both PIDs
  gone, both absent from the process list, worker port closed and
  rebindable), and only then does the diagnostic assertion report
  `Received: "The user aborted a request"`

Structure is now capture -> kill -> verify -> clean up -> assert. The
outcome of the identity wait is captured instead of asserted inline; probes
are wrapped so a wedged one yields its message (which then fails the
assertion consuming it) rather than either throwing early or being silently
read as "absent"; `settled()` is the non-throwing form of `until()`. Cleanup
runs before the assertions, so no failed assertion can leave a live process
on the runner.

The FETCH_ABORTED itself is not produced by this test. Verified: there is no
fetch, AbortController or abort signal anywhere in the four files;
make-fetch-happen, minipass-fetch and npm-registry-fetch are absent from the
entire repository; and bounded(treeReady, ...) can only ever reject with its
own message, because treeReady has no reject path. Locally the identity wait
rejects with exactly "the worker never reported its identity" and the
assertion passes. So this commit does not claim to fix the source of that
error - it makes the test survive it, verify what it exists to verify, and
report the unexpected message precisely.

No budget or timeout changed: STALL_BUDGET_MS stays 40_000,
STALL_TEST_TIMEOUT_MS stays 90_000, and the package default
(--timeout 30000) is untouched. No assertion was removed or weakened.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): return the stall test to the accepted budget envelope, harden deadlines

Applies the independent review verdict on 34d8f92.

Budget envelope. The 90s per-test timeout was a consequence of raising
STALL_BUDGET_MS from 15s to 40s, not of the negative-allowance fix. With a
fresh deadline per phase the fix stands on its own, so the raise is
reverted: STALL_BUDGET_MS 40_000 -> 15_000 and STALL_TEST_TIMEOUT_MS
90_000 -> 45_000, back inside the previously accepted 40/50 envelope. No
new deviation. Verified locally on a Linux-runnable copy of the real file:
the stall test now completes in 15.09s and both tests pass.

The timeout comment claimed 40+15+20+5=80s and omitted the `finally`
reapTree. It now gives the arithmetic by case instead of one sum: nominal
~21s, worst single-phase-failure 15+3+20+5=43s which fits, and the one
path that does not fit - probe AND verify phases both exhausting their
ceilings, 55s - where the timeout fires and the test fails loudly rather
than hanging.

Deadline guards. `bounded` and `tasklistHasPid` no longer clamp a spent
deadline to 0ms/1ms, which reported "the thing never happened" when the
real cause was "the caller's budget was already gone". Both now throw a
distinct "deadline already expired" error. Covered by a test that asserts
the exact messages, so the guard cannot rot silently.

PID-recycling guard. `reapTree` now takes the set of PIDs this test already
proved dead and skips them: a recycled PID would otherwise be signalled,
killing something the runner needs. The survivor check applies the same
guard, so a reused PID cannot be reported as a false survivor. Survivors
are also now computed BEFORE the manual reap, so the assertion proves the
job took the tree down rather than that our own cleanup did.

Positive log control. The adopter only logs on failure, so a clean run
produces no `log:` messages at all - which let the "(#442)"-free assertion
pass vacuously if IPC forwarding broke. The owner fixture now sends a
`log:owner-log-channel-ok` sentinel and both tests assert it arrived, so an
empty log is a failure rather than a pass.

No assertion removed or weakened; the package default --timeout 30000 is
untouched.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): MUTATION CONTROL - disable the job binding (reverted next commit)

Temporary, deliberately broken commit. `adoptWorkerProcess` no longer calls
the adopter, so a spawned worker is never put into the owner's kill-on-close
Job Object - i.e. the state #561/#568 exist to prevent.

Expected: unit (windows) goes RED on the owner-death tests' survivor
assertion, because a force-killed owner no longer takes the worker tree
down. If those tests still passed with the binding disabled they would be
proving nothing.

win-job's own 21 unit tests still pass under this mutation because they
drive `createOwnerJobAdopter` directly rather than `adoptWorkerProcess`, so
the red signal is isolated to the integration coverage.

Reverted in the next commit.

Co-authored-by: arena-agent <[email protected]>

* Revert "test(opencode): MUTATION CONTROL - disable the job binding (reverted next commit)"

This reverts commit 9bbe7bd.

* test(opencode): give the happy path fresh per-phase deadlines too

Review item (b) covered the happy path's `owner.exited` as well as the stall
test's, and only the stall test had been converted. The happy path still
passed its original `deadline` to ten calls - `tasklistHasPid` four times,
`bounded(owner.exited)`, `until` four times and `bounded(canBind)` twice.
Those were tolerable while a spent deadline merely clamped to a 1ms/0ms
allowance; once the distinct expiry guard landed, every one of them became a
hard throw as soon as the budget was spent.

Both tests now use `deadline` for exactly one thing - the identity wait - and
take a fresh `PROBE_BUDGET_MS` (15s) for the pre-kill liveness and owner exit
and a fresh `VERIFY_BUDGET_MS` (20s) for everything after the kill. The two
constants were renamed out of their stall-specific names because both tests
use them; their values are unchanged, so no budget was raised.

Verified on a Linux-runnable copy of the real file with the Job Object
contract emulated: both tests pass, the stall test completing in 15.10s, 33
expect() calls.

Co-authored-by: arena-agent <[email protected]>

* fix(tui): use purpose-led copy in the effort selector

Replace the mechanics-focused descriptions (review passes, review
ritual) with purpose-led one-liners for Fast, Medium and Thorough, and
drop the per-row backstage detail lines so each level shows a single
line. Update the selector test expectations to match.

Supersedes #717; refs #716.

Co-authored-by: arena-agent <[email protected]>

* test(tui): assert effort selector has three rows

Co-authored-by: arena-agent <[email protected]>

* chore(test): remove inherited unaccepted seed owner-death test files

Co-authored-by: arena-agent <[email protected]>

---------

Co-authored-by: arena-agent <[email protected]>
Co-authored-by: arena-agent <[email protected]>
Co-authored-by: agenteinstinct1-max <[email protected]>
agenteinstinct1-max added a commit that referenced this pull request Nov 1, 2026
* test(opencode): prove doom-loop runtime guard with write recovery

Co-authored-by: arena-agent <[email protected]>

* fix(tui): simplify agent effort selector copy (Supersedes #762, Refs #716)

* test(opencode): prove Windows owner-death cleanup with real processes (#442)

win32-gated integration coverage that runs on the existing windows-latest
matrix leg and exercises the real spawn path bound to the Job Object: the
owner is force-killed with TerminateProcess and the worker tree is then
verified gone through real process inspection (OpenProcess + tasklist),
with both listening ports probed for release.

Two properties are covered:

- happy path: a force-killed owner takes the worker tree and its listening
  ports with it; incremental identity capture off the Bun.spawn handle
  (worker -> child -> child-port -> ready) means every PID is known as soon
  as it is created, so cleanup can reap a tree that never finished starting.
- stall path: the grandchild binds its port but never writes its ready line
  (SILVERCODE_TEST_GRANDCHILD_SILENT=1), so the bounded identity wait must
  fail at the deadline rather than hang, and the half-built tree must still
  leave nothing behind. Anti-vacuous-pass guards assert both PIDs were
  captured and grandchildPort stayed undefined, so a slow startup cannot
  masquerade as the stall.

All waits are hard-bounded (tasklist capped to the remaining budget, socket
probes 2s, cleanup raced against its own budget). The stall test sets its own
per-test timeout; the package default --timeout 30000 is unchanged.

Tests and fixtures only - no production or workflow changes. Existing #561
and #568 unit tests are untouched.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): give the stall test's post-bound phases fresh deadlines

unit (windows) failed at 366f0a9. The stall test's identity wait consumes
STALL_BUDGET_MS by design - `ready` is suppressed, so the bounded promise
never settles - which left the original `deadline` in the past for every
phase that followed:

  tasklistHasPid(pid, deadline)
    -> Math.max(1, Math.min(15000, negative)) = 1ms allowance
    -> exitedDueToTimeout, so it throws instead of reporting the pid
  bounded(owner.exited, ..., deadline)
    -> Math.max(0, negative) = 0ms allowance
    -> rejects with "the owner never exited after TerminateProcess"
       before the owner has had time to die

Reproduced directly: after the identity wait the remainder is -1ms, and a
0ms bounded rejects a promise that settles 30ms later, while the same
promise resolves against a fresh deadline.

The happy-path test was never affected because its bounded(treeReady)
resolves early and leaves most of the budget intact. Local verification
missed this because the Linux harness substitutes process.kill(pid, 0) for
tasklist and already used fresh deadlines.

Every phase after the identity wait now runs on its own fresh deadline:
STALL_PROBE_MS (15s) for pre-kill liveness and the owner's exit, and
STALL_VERIFY_MS (20s) for post-kill verification. STALL_BUDGET_MS is raised
15s -> 40s to match the budget already proven comfortable on windows-latest,
so a slow cold start cannot make the anti-vacuous-pass guards fire. The
per-test timeout follows the arithmetic: 40 + 15 + 20 + 5 cleanup = 80s,
so STALL_TEST_TIMEOUT_MS = 90_000. The package default --timeout 30000 is
still untouched. No assertion was weakened or reordered.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): make the stall test verify cleanup even when its first await throws

unit (windows) at 34d8f92 failed the stall test at
win-owner-death.integration.test.ts:507:102 - inside `.rejects.toThrow(` -
with `Received message: "The user aborted a request"`.

That line was the first statement of the `try`. Asserting the bounded
identity wait inline means ANY rejection there throws straight out of the
test, so every post-timeout assertion is skipped and the "leaves nothing
behind" property - the whole point of the test - is never verified.

Reproduced both halves locally:

- before: injecting that rejection makes the test bail immediately with
  zero assertions executed and no cleanup verification
- after: 7 cleanup/safety assertions run and pass (no survivors, both PIDs
  gone, both absent from the process list, worker port closed and
  rebindable), and only then does the diagnostic assertion report
  `Received: "The user aborted a request"`

Structure is now capture -> kill -> verify -> clean up -> assert. The
outcome of the identity wait is captured instead of asserted inline; probes
are wrapped so a wedged one yields its message (which then fails the
assertion consuming it) rather than either throwing early or being silently
read as "absent"; `settled()` is the non-throwing form of `until()`. Cleanup
runs before the assertions, so no failed assertion can leave a live process
on the runner.

The FETCH_ABORTED itself is not produced by this test. Verified: there is no
fetch, AbortController or abort signal anywhere in the four files;
make-fetch-happen, minipass-fetch and npm-registry-fetch are absent from the
entire repository; and bounded(treeReady, ...) can only ever reject with its
own message, because treeReady has no reject path. Locally the identity wait
rejects with exactly "the worker never reported its identity" and the
assertion passes. So this commit does not claim to fix the source of that
error - it makes the test survive it, verify what it exists to verify, and
report the unexpected message precisely.

No budget or timeout changed: STALL_BUDGET_MS stays 40_000,
STALL_TEST_TIMEOUT_MS stays 90_000, and the package default
(--timeout 30000) is untouched. No assertion was removed or weakened.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): return the stall test to the accepted budget envelope, harden deadlines

Applies the independent review verdict on 34d8f92.

Budget envelope. The 90s per-test timeout was a consequence of raising
STALL_BUDGET_MS from 15s to 40s, not of the negative-allowance fix. With a
fresh deadline per phase the fix stands on its own, so the raise is
reverted: STALL_BUDGET_MS 40_000 -> 15_000 and STALL_TEST_TIMEOUT_MS
90_000 -> 45_000, back inside the previously accepted 40/50 envelope. No
new deviation. Verified locally on a Linux-runnable copy of the real file:
the stall test now completes in 15.09s and both tests pass.

The timeout comment claimed 40+15+20+5=80s and omitted the `finally`
reapTree. It now gives the arithmetic by case instead of one sum: nominal
~21s, worst single-phase-failure 15+3+20+5=43s which fits, and the one
path that does not fit - probe AND verify phases both exhausting their
ceilings, 55s - where the timeout fires and the test fails loudly rather
than hanging.

Deadline guards. `bounded` and `tasklistHasPid` no longer clamp a spent
deadline to 0ms/1ms, which reported "the thing never happened" when the
real cause was "the caller's budget was already gone". Both now throw a
distinct "deadline already expired" error. Covered by a test that asserts
the exact messages, so the guard cannot rot silently.

PID-recycling guard. `reapTree` now takes the set of PIDs this test already
proved dead and skips them: a recycled PID would otherwise be signalled,
killing something the runner needs. The survivor check applies the same
guard, so a reused PID cannot be reported as a false survivor. Survivors
are also now computed BEFORE the manual reap, so the assertion proves the
job took the tree down rather than that our own cleanup did.

Positive log control. The adopter only logs on failure, so a clean run
produces no `log:` messages at all - which let the "(#442)"-free assertion
pass vacuously if IPC forwarding broke. The owner fixture now sends a
`log:owner-log-channel-ok` sentinel and both tests assert it arrived, so an
empty log is a failure rather than a pass.

No assertion removed or weakened; the package default --timeout 30000 is
untouched.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): MUTATION CONTROL - disable the job binding (reverted next commit)

Temporary, deliberately broken commit. `adoptWorkerProcess` no longer calls
the adopter, so a spawned worker is never put into the owner's kill-on-close
Job Object - i.e. the state #561/#568 exist to prevent.

Expected: unit (windows) goes RED on the owner-death tests' survivor
assertion, because a force-killed owner no longer takes the worker tree
down. If those tests still passed with the binding disabled they would be
proving nothing.

win-job's own 21 unit tests still pass under this mutation because they
drive `createOwnerJobAdopter` directly rather than `adoptWorkerProcess`, so
the red signal is isolated to the integration coverage.

Reverted in the next commit.

Co-authored-by: arena-agent <[email protected]>

* Revert "test(opencode): MUTATION CONTROL - disable the job binding (reverted next commit)"

This reverts commit 9bbe7bd.

* test(opencode): give the happy path fresh per-phase deadlines too

Review item (b) covered the happy path's `owner.exited` as well as the stall
test's, and only the stall test had been converted. The happy path still
passed its original `deadline` to ten calls - `tasklistHasPid` four times,
`bounded(owner.exited)`, `until` four times and `bounded(canBind)` twice.
Those were tolerable while a spent deadline merely clamped to a 1ms/0ms
allowance; once the distinct expiry guard landed, every one of them became a
hard throw as soon as the budget was spent.

Both tests now use `deadline` for exactly one thing - the identity wait - and
take a fresh `PROBE_BUDGET_MS` (15s) for the pre-kill liveness and owner exit
and a fresh `VERIFY_BUDGET_MS` (20s) for everything after the kill. The two
constants were renamed out of their stall-specific names because both tests
use them; their values are unchanged, so no budget was raised.

Verified on a Linux-runnable copy of the real file with the Job Object
contract emulated: both tests pass, the stall test completing in 15.10s, 33
expect() calls.

Co-authored-by: arena-agent <[email protected]>

* fix(tui): use purpose-led copy in the effort selector

Replace the mechanics-focused descriptions (review passes, review
ritual) with purpose-led one-liners for Fast, Medium and Thorough, and
drop the per-row backstage detail lines so each level shows a single
line. Update the selector test expectations to match.

Supersedes #717; refs #716.

Co-authored-by: arena-agent <[email protected]>

* test(tui): assert effort selector has three rows

Co-authored-by: arena-agent <[email protected]>

* chore(test): remove inherited unaccepted seed owner-death test files

Co-authored-by: arena-agent <[email protected]>

---------

Co-authored-by: arena-agent <[email protected]>
Co-authored-by: arena-agent <[email protected]>
Co-authored-by: agenteinstinct1-max <[email protected]>

---------

Co-authored-by: agenteinstinct1-max <[email protected]>
Co-authored-by: arena-agent <[email protected]>
Co-authored-by: arena-agent <[email protected]>
agenteinstinct1-max added a commit that referenced this pull request Nov 9, 2026
* test(opencode): prove Windows owner-death cleanup with real processes (#442)

win32-gated integration coverage that runs on the existing windows-latest
matrix leg and exercises the real spawn path bound to the Job Object: the
owner is force-killed with TerminateProcess and the worker tree is then
verified gone through real process inspection (OpenProcess + tasklist),
with both listening ports probed for release.

Two properties are covered:

- happy path: a force-killed owner takes the worker tree and its listening
  ports with it; incremental identity capture off the Bun.spawn handle
  (worker -> child -> child-port -> ready) means every PID is known as soon
  as it is created, so cleanup can reap a tree that never finished starting.
- stall path: the grandchild binds its port but never writes its ready line
  (SILVERCODE_TEST_GRANDCHILD_SILENT=1), so the bounded identity wait must
  fail at the deadline rather than hang, and the half-built tree must still
  leave nothing behind. Anti-vacuous-pass guards assert both PIDs were
  captured and grandchildPort stayed undefined, so a slow startup cannot
  masquerade as the stall.

All waits are hard-bounded (tasklist capped to the remaining budget, socket
probes 2s, cleanup raced against its own budget). The stall test sets its own
per-test timeout; the package default --timeout 30000 is unchanged.

Tests and fixtures only - no production or workflow changes. Existing #561
and #568 unit tests are untouched.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): give the stall test's post-bound phases fresh deadlines

unit (windows) failed at 366f0a9. The stall test's identity wait consumes
STALL_BUDGET_MS by design - `ready` is suppressed, so the bounded promise
never settles - which left the original `deadline` in the past for every
phase that followed:

  tasklistHasPid(pid, deadline)
    -> Math.max(1, Math.min(15000, negative)) = 1ms allowance
    -> exitedDueToTimeout, so it throws instead of reporting the pid
  bounded(owner.exited, ..., deadline)
    -> Math.max(0, negative) = 0ms allowance
    -> rejects with "the owner never exited after TerminateProcess"
       before the owner has had time to die

Reproduced directly: after the identity wait the remainder is -1ms, and a
0ms bounded rejects a promise that settles 30ms later, while the same
promise resolves against a fresh deadline.

The happy-path test was never affected because its bounded(treeReady)
resolves early and leaves most of the budget intact. Local verification
missed this because the Linux harness substitutes process.kill(pid, 0) for
tasklist and already used fresh deadlines.

Every phase after the identity wait now runs on its own fresh deadline:
STALL_PROBE_MS (15s) for pre-kill liveness and the owner's exit, and
STALL_VERIFY_MS (20s) for post-kill verification. STALL_BUDGET_MS is raised
15s -> 40s to match the budget already proven comfortable on windows-latest,
so a slow cold start cannot make the anti-vacuous-pass guards fire. The
per-test timeout follows the arithmetic: 40 + 15 + 20 + 5 cleanup = 80s,
so STALL_TEST_TIMEOUT_MS = 90_000. The package default --timeout 30000 is
still untouched. No assertion was weakened or reordered.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): make the stall test verify cleanup even when its first await throws

unit (windows) at 34d8f92 failed the stall test at
win-owner-death.integration.test.ts:507:102 - inside `.rejects.toThrow(` -
with `Received message: "The user aborted a request"`.

That line was the first statement of the `try`. Asserting the bounded
identity wait inline means ANY rejection there throws straight out of the
test, so every post-timeout assertion is skipped and the "leaves nothing
behind" property - the whole point of the test - is never verified.

Reproduced both halves locally:

- before: injecting that rejection makes the test bail immediately with
  zero assertions executed and no cleanup verification
- after: 7 cleanup/safety assertions run and pass (no survivors, both PIDs
  gone, both absent from the process list, worker port closed and
  rebindable), and only then does the diagnostic assertion report
  `Received: "The user aborted a request"`

Structure is now capture -> kill -> verify -> clean up -> assert. The
outcome of the identity wait is captured instead of asserted inline; probes
are wrapped so a wedged one yields its message (which then fails the
assertion consuming it) rather than either throwing early or being silently
read as "absent"; `settled()` is the non-throwing form of `until()`. Cleanup
runs before the assertions, so no failed assertion can leave a live process
on the runner.

The FETCH_ABORTED itself is not produced by this test. Verified: there is no
fetch, AbortController or abort signal anywhere in the four files;
make-fetch-happen, minipass-fetch and npm-registry-fetch are absent from the
entire repository; and bounded(treeReady, ...) can only ever reject with its
own message, because treeReady has no reject path. Locally the identity wait
rejects with exactly "the worker never reported its identity" and the
assertion passes. So this commit does not claim to fix the source of that
error - it makes the test survive it, verify what it exists to verify, and
report the unexpected message precisely.

No budget or timeout changed: STALL_BUDGET_MS stays 40_000,
STALL_TEST_TIMEOUT_MS stays 90_000, and the package default
(--timeout 30000) is untouched. No assertion was removed or weakened.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): return the stall test to the accepted budget envelope, harden deadlines

Applies the independent review verdict on 34d8f92.

Budget envelope. The 90s per-test timeout was a consequence of raising
STALL_BUDGET_MS from 15s to 40s, not of the negative-allowance fix. With a
fresh deadline per phase the fix stands on its own, so the raise is
reverted: STALL_BUDGET_MS 40_000 -> 15_000 and STALL_TEST_TIMEOUT_MS
90_000 -> 45_000, back inside the previously accepted 40/50 envelope. No
new deviation. Verified locally on a Linux-runnable copy of the real file:
the stall test now completes in 15.09s and both tests pass.

The timeout comment claimed 40+15+20+5=80s and omitted the `finally`
reapTree. It now gives the arithmetic by case instead of one sum: nominal
~21s, worst single-phase-failure 15+3+20+5=43s which fits, and the one
path that does not fit - probe AND verify phases both exhausting their
ceilings, 55s - where the timeout fires and the test fails loudly rather
than hanging.

Deadline guards. `bounded` and `tasklistHasPid` no longer clamp a spent
deadline to 0ms/1ms, which reported "the thing never happened" when the
real cause was "the caller's budget was already gone". Both now throw a
distinct "deadline already expired" error. Covered by a test that asserts
the exact messages, so the guard cannot rot silently.

PID-recycling guard. `reapTree` now takes the set of PIDs this test already
proved dead and skips them: a recycled PID would otherwise be signalled,
killing something the runner needs. The survivor check applies the same
guard, so a reused PID cannot be reported as a false survivor. Survivors
are also now computed BEFORE the manual reap, so the assertion proves the
job took the tree down rather than that our own cleanup did.

Positive log control. The adopter only logs on failure, so a clean run
produces no `log:` messages at all - which let the "(#442)"-free assertion
pass vacuously if IPC forwarding broke. The owner fixture now sends a
`log:owner-log-channel-ok` sentinel and both tests assert it arrived, so an
empty log is a failure rather than a pass.

No assertion removed or weakened; the package default --timeout 30000 is
untouched.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): MUTATION CONTROL - disable the job binding (reverted next commit)

Temporary, deliberately broken commit. `adoptWorkerProcess` no longer calls
the adopter, so a spawned worker is never put into the owner's kill-on-close
Job Object - i.e. the state #561/#568 exist to prevent.

Expected: unit (windows) goes RED on the owner-death tests' survivor
assertion, because a force-killed owner no longer takes the worker tree
down. If those tests still passed with the binding disabled they would be
proving nothing.

win-job's own 21 unit tests still pass under this mutation because they
drive `createOwnerJobAdopter` directly rather than `adoptWorkerProcess`, so
the red signal is isolated to the integration coverage.

Reverted in the next commit.

Co-authored-by: arena-agent <[email protected]>

* Revert "test(opencode): MUTATION CONTROL - disable the job binding (reverted next commit)"

This reverts commit 9bbe7bd.

* test(opencode): give the happy path fresh per-phase deadlines too

Review item (b) covered the happy path's `owner.exited` as well as the stall
test's, and only the stall test had been converted. The happy path still
passed its original `deadline` to ten calls - `tasklistHasPid` four times,
`bounded(owner.exited)`, `until` four times and `bounded(canBind)` twice.
Those were tolerable while a spent deadline merely clamped to a 1ms/0ms
allowance; once the distinct expiry guard landed, every one of them became a
hard throw as soon as the budget was spent.

Both tests now use `deadline` for exactly one thing - the identity wait - and
take a fresh `PROBE_BUDGET_MS` (15s) for the pre-kill liveness and owner exit
and a fresh `VERIFY_BUDGET_MS` (20s) for everything after the kill. The two
constants were renamed out of their stall-specific names because both tests
use them; their values are unchanged, so no budget was raised.

Verified on a Linux-runnable copy of the real file with the Job Object
contract emulated: both tests pass, the stall test completing in 15.10s, 33
expect() calls.

Co-authored-by: arena-agent <[email protected]>

* fix(opencode): read agent effort per step inside an existing session

The selector persisted effort to the session row, and finish/task already
re-read that row, but the run loop resolved the prompt's effective level from
the Session.Info snapshot captured once before the loop. A level changed while
a run was in progress therefore kept feeding the old effort policy block to
every later generation step, even though the UI, finish and newly dispatched
children saw the new level.

Resolve the effective effort from the persisted session row at every
generation step, matching finish's own read. A change now applies to the next
step built after it; a request already in flight keeps the system prompt it was
sent with, and a missing row mid-run falls back to the snapshot instead of
dying. The run is not restarted, no tool effect is replayed, and earlier
transcript entries are untouched.

Tests drive the real prompt loop and finish tool over scripted provider
requests: they hold one request open, change the persisted level mid-run in
both directions, assert the in-flight request kept the old policy while the
next step and the following turn in the same session carry the new one, and
check the writes and finish labels from before/after the switch. Reverting the
fresh read makes the new-step assertion fail with the stale level.

Refs #748

Co-authored-by: arena-agent <[email protected]>

* test(opencode): remove the four unaccepted Windows owner-death test files

These four files were inherited on this branch lineage from the earlier
owner-death session and were not accepted; they are outside the effort scope
tracked by #748. Remove only those test/fixture files, in a normal commit, so
the branch's own change is limited to the effort fix.

The accepted base and the effort tests are untouched.

* test(opencode): cover the finish gate upgrade mid-turn (Refs #748)

The per-step prompt already asserts both downgrade and upgrade for the
next generation step, next turn and writes-once, and the finish checkpoint
already verified a downgrade (thorough -> fast) with an in-flight old
prompt. The upgrade direction (fast -> thorough) was untested: a fast
request already on the wire keeps its fast policy, but every finish the
model calls after the upgrade is judged thorough and must be declined
as review-required, never as the stale fast success.

Add a loop-driven upgrade case that holds step 2 open, flips the
persisted selection fast -> thorough mid-flight, asserts the in-flight
request kept fast while the next request carries thorough, and then
drives three finish attempts through the real loop. Each is declined
as thorough requiring review (not the stale fast fast-path), the loop
exits after its nudge limit, the persisted selection stays thorough,
and the two writes land exactly once. Reverting the per-step fresh
session read to the opening snapshot makes both downgrade and upgrade
fail on the stale level, while the finish gate upgrade fails open as
fast.

No production or workflow change; no assertion weakened or timeout
raised. The permission preload tip (4a08a04) and activity/ retry
fixtures (2e94981 / 3d4c83f) are preserved exactly; only the four
unaccepted Windows owner-death files remain removed via the inherited
d2cdf31 commit.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): align mid-turn effort upgrade tests with finish runtime and types (Refs #748)

Repair the untested upgrade case from a0d8d20 against the real finish.ts and MessageV2 contracts:

- Narrow SessionV1.WithParts.info to role === "assistant" before reading finish/error so tsc --noEmit passes cleanly (fixes TS2339 on lines 6513-6514).
- Match finish.ts's softened UNREVIEWED delivery for unreviewed file writes (blockingFindings === 0 && !reviewInProgress): an upgrade from fast to thorough delivers with UNREVIEWED: effort thorough, Review required: effort is "thorough", passes 0 until-clean, and validation full/incomplete rather than four errored finish nudges, while never reporting approved or the stale fast label.
- Add a second loop-driven upgrade test covering hard-declined finish enforcement when blocking findings exist on an already-in-flight fast generation (reason: "failure" delivers at fast, declines at thorough with Review required: effort is "thorough"), plus newly dispatched task children inheriting thorough while pre-switch children keep fast.

Co-authored-by: arena-agent <[email protected]>

---------

Co-authored-by: arena-agent <[email protected]>
Co-authored-by: arena-agent <[email protected]>
Co-authored-by: agenteinstinct1-max <[email protected]>
agenteinstinct1-max added a commit that referenced this pull request Nov 11, 2026
* test(opencode): prove Windows owner-death cleanup with real processes (#442)

win32-gated integration coverage that runs on the existing windows-latest
matrix leg and exercises the real spawn path bound to the Job Object: the
owner is force-killed with TerminateProcess and the worker tree is then
verified gone through real process inspection (OpenProcess + tasklist),
with both listening ports probed for release.

Two properties are covered:

- happy path: a force-killed owner takes the worker tree and its listening
  ports with it; incremental identity capture off the Bun.spawn handle
  (worker -> child -> child-port -> ready) means every PID is known as soon
  as it is created, so cleanup can reap a tree that never finished starting.
- stall path: the grandchild binds its port but never writes its ready line
  (SILVERCODE_TEST_GRANDCHILD_SILENT=1), so the bounded identity wait must
  fail at the deadline rather than hang, and the half-built tree must still
  leave nothing behind. Anti-vacuous-pass guards assert both PIDs were
  captured and grandchildPort stayed undefined, so a slow startup cannot
  masquerade as the stall.

All waits are hard-bounded (tasklist capped to the remaining budget, socket
probes 2s, cleanup raced against its own budget). The stall test sets its own
per-test timeout; the package default --timeout 30000 is unchanged.

Tests and fixtures only - no production or workflow changes. Existing #561
and #568 unit tests are untouched.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): give the stall test's post-bound phases fresh deadlines

unit (windows) failed at 366f0a9. The stall test's identity wait consumes
STALL_BUDGET_MS by design - `ready` is suppressed, so the bounded promise
never settles - which left the original `deadline` in the past for every
phase that followed:

  tasklistHasPid(pid, deadline)
    -> Math.max(1, Math.min(15000, negative)) = 1ms allowance
    -> exitedDueToTimeout, so it throws instead of reporting the pid
  bounded(owner.exited, ..., deadline)
    -> Math.max(0, negative) = 0ms allowance
    -> rejects with "the owner never exited after TerminateProcess"
       before the owner has had time to die

Reproduced directly: after the identity wait the remainder is -1ms, and a
0ms bounded rejects a promise that settles 30ms later, while the same
promise resolves against a fresh deadline.

The happy-path test was never affected because its bounded(treeReady)
resolves early and leaves most of the budget intact. Local verification
missed this because the Linux harness substitutes process.kill(pid, 0) for
tasklist and already used fresh deadlines.

Every phase after the identity wait now runs on its own fresh deadline:
STALL_PROBE_MS (15s) for pre-kill liveness and the owner's exit, and
STALL_VERIFY_MS (20s) for post-kill verification. STALL_BUDGET_MS is raised
15s -> 40s to match the budget already proven comfortable on windows-latest,
so a slow cold start cannot make the anti-vacuous-pass guards fire. The
per-test timeout follows the arithmetic: 40 + 15 + 20 + 5 cleanup = 80s,
so STALL_TEST_TIMEOUT_MS = 90_000. The package default --timeout 30000 is
still untouched. No assertion was weakened or reordered.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): make the stall test verify cleanup even when its first await throws

unit (windows) at 34d8f92 failed the stall test at
win-owner-death.integration.test.ts:507:102 - inside `.rejects.toThrow(` -
with `Received message: "The user aborted a request"`.

That line was the first statement of the `try`. Asserting the bounded
identity wait inline means ANY rejection there throws straight out of the
test, so every post-timeout assertion is skipped and the "leaves nothing
behind" property - the whole point of the test - is never verified.

Reproduced both halves locally:

- before: injecting that rejection makes the test bail immediately with
  zero assertions executed and no cleanup verification
- after: 7 cleanup/safety assertions run and pass (no survivors, both PIDs
  gone, both absent from the process list, worker port closed and
  rebindable), and only then does the diagnostic assertion report
  `Received: "The user aborted a request"`

Structure is now capture -> kill -> verify -> clean up -> assert. The
outcome of the identity wait is captured instead of asserted inline; probes
are wrapped so a wedged one yields its message (which then fails the
assertion consuming it) rather than either throwing early or being silently
read as "absent"; `settled()` is the non-throwing form of `until()`. Cleanup
runs before the assertions, so no failed assertion can leave a live process
on the runner.

The FETCH_ABORTED itself is not produced by this test. Verified: there is no
fetch, AbortController or abort signal anywhere in the four files;
make-fetch-happen, minipass-fetch and npm-registry-fetch are absent from the
entire repository; and bounded(treeReady, ...) can only ever reject with its
own message, because treeReady has no reject path. Locally the identity wait
rejects with exactly "the worker never reported its identity" and the
assertion passes. So this commit does not claim to fix the source of that
error - it makes the test survive it, verify what it exists to verify, and
report the unexpected message precisely.

No budget or timeout changed: STALL_BUDGET_MS stays 40_000,
STALL_TEST_TIMEOUT_MS stays 90_000, and the package default
(--timeout 30000) is untouched. No assertion was removed or weakened.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): return the stall test to the accepted budget envelope, harden deadlines

Applies the independent review verdict on 34d8f92.

Budget envelope. The 90s per-test timeout was a consequence of raising
STALL_BUDGET_MS from 15s to 40s, not of the negative-allowance fix. With a
fresh deadline per phase the fix stands on its own, so the raise is
reverted: STALL_BUDGET_MS 40_000 -> 15_000 and STALL_TEST_TIMEOUT_MS
90_000 -> 45_000, back inside the previously accepted 40/50 envelope. No
new deviation. Verified locally on a Linux-runnable copy of the real file:
the stall test now completes in 15.09s and both tests pass.

The timeout comment claimed 40+15+20+5=80s and omitted the `finally`
reapTree. It now gives the arithmetic by case instead of one sum: nominal
~21s, worst single-phase-failure 15+3+20+5=43s which fits, and the one
path that does not fit - probe AND verify phases both exhausting their
ceilings, 55s - where the timeout fires and the test fails loudly rather
than hanging.

Deadline guards. `bounded` and `tasklistHasPid` no longer clamp a spent
deadline to 0ms/1ms, which reported "the thing never happened" when the
real cause was "the caller's budget was already gone". Both now throw a
distinct "deadline already expired" error. Covered by a test that asserts
the exact messages, so the guard cannot rot silently.

PID-recycling guard. `reapTree` now takes the set of PIDs this test already
proved dead and skips them: a recycled PID would otherwise be signalled,
killing something the runner needs. The survivor check applies the same
guard, so a reused PID cannot be reported as a false survivor. Survivors
are also now computed BEFORE the manual reap, so the assertion proves the
job took the tree down rather than that our own cleanup did.

Positive log control. The adopter only logs on failure, so a clean run
produces no `log:` messages at all - which let the "(#442)"-free assertion
pass vacuously if IPC forwarding broke. The owner fixture now sends a
`log:owner-log-channel-ok` sentinel and both tests assert it arrived, so an
empty log is a failure rather than a pass.

No assertion removed or weakened; the package default --timeout 30000 is
untouched.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): MUTATION CONTROL - disable the job binding (reverted next commit)

Temporary, deliberately broken commit. `adoptWorkerProcess` no longer calls
the adopter, so a spawned worker is never put into the owner's kill-on-close
Job Object - i.e. the state #561/#568 exist to prevent.

Expected: unit (windows) goes RED on the owner-death tests' survivor
assertion, because a force-killed owner no longer takes the worker tree
down. If those tests still passed with the binding disabled they would be
proving nothing.

win-job's own 21 unit tests still pass under this mutation because they
drive `createOwnerJobAdopter` directly rather than `adoptWorkerProcess`, so
the red signal is isolated to the integration coverage.

Reverted in the next commit.

Co-authored-by: arena-agent <[email protected]>

* Revert "test(opencode): MUTATION CONTROL - disable the job binding (reverted next commit)"

This reverts commit 9bbe7bd.

* test(opencode): give the happy path fresh per-phase deadlines too

Review item (b) covered the happy path's `owner.exited` as well as the stall
test's, and only the stall test had been converted. The happy path still
passed its original `deadline` to ten calls - `tasklistHasPid` four times,
`bounded(owner.exited)`, `until` four times and `bounded(canBind)` twice.
Those were tolerable while a spent deadline merely clamped to a 1ms/0ms
allowance; once the distinct expiry guard landed, every one of them became a
hard throw as soon as the budget was spent.

Both tests now use `deadline` for exactly one thing - the identity wait - and
take a fresh `PROBE_BUDGET_MS` (15s) for the pre-kill liveness and owner exit
and a fresh `VERIFY_BUDGET_MS` (20s) for everything after the kill. The two
constants were renamed out of their stall-specific names because both tests
use them; their values are unchanged, so no budget was raised.

Verified on a Linux-runnable copy of the real file with the Job Object
contract emulated: both tests pass, the stall test completing in 15.10s, 33
expect() calls.

Co-authored-by: arena-agent <[email protected]>

* fix(opencode): count doom-loop failures per step

* test(opencode): prove a doom-loop streak needs identical input (Refs #725)

Independent review of the merged head killed 11 of 15 mutants and found no
logic defect, but the M14 mutant - deleting the input comparison from
`isRepeatedFailureStep` - survived all 42 tests. Every existing streak case
either varies the tool name (a different tool) or keeps `lookup`'s input
identical, so name-only matching was still consistent with all of them.

P4 probe: six consecutive steps whose single `lookup` call fails every time,
with inputs `same, same, different, same, same, same`. The one differing
input is inside the two-step window of every call up to the fifth send, so
nothing may ask; the sixth send is the first whose two predecessors are the
identical call. The test therefore fails if the guard compares names only
(it asks on the third send) and proves both the name and the input must match
for a step to count as a repetition.

Mutation control on this tree: with the input comparison deleted,
`bun test -t "doom loop"` goes red on exactly this test (3 unexpected asks,
`Expected length: 0` at the fifth-send assertion) while all 12 pre-existing
doom tests still pass; reverting restores 43/43.

Full file: 43 pass, 0 fail, 205 expect() calls.

Co-authored-by: arena-agent <[email protected]>

* test(opencode): isolate doom-loop identity and pagination probes (Refs #725)

Fresh mutation review on the merged tree found two coverage gaps beyond the retained six-step input probe: the different-tool reset also changed input, and the synthetic-nudge history fit inside one 20-message page. Keep the input identical in the different-tool case, and extend the existing nudge case with persisted tool-less messages so the guard must page backward. No assertion, timeout, or budget is changed: the full file remains 43 tests and 205 runtime expect() calls.

The fresh 15-mutant matrix kills 13, including independent M05 tool-name and M14 input controls. Only the two retry-reset deletions survive; both are equivalent because retries cannot follow tool activity, while the memo and asked-step set are populated only on the tool-call path. Production processor.ts remains byte-identical to exact reviewed head de90b09.

Co-authored-by: arena-agent <[email protected]>

* test(session): match doom-loop contract across failed steps

---------

Co-authored-by: arena-agent <[email protected]>
Co-authored-by: arena-agent <[email protected]>
Co-authored-by: agenteinstinct1-max <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant