Repository navigation
fix(tui): kill the Windows subprocess worker with the owner's job object (#442) - #561
Conversation
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (8 files)
Previous Review SummaryCurrent summary above is authoritative. Previous snapshots are kept for context only. Previous reviewThis review did not finish. The model reached its output limit before it Reviewed by free · Input: 31.5K · Output: 2.2K · Cached: 114.6K |
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
|
Reopened after the automated template-compliance closure. The description now includes the exact required Issue/Type/What/Verification/Checklist headings, with the original evidence and Windows limitations preserved. The code head is unchanged:4aeb13821f8a6d7cb9e58184c4e26d8e7a02d350. The needs:compliance label is absent. This metadata repair does not supply a clean independent review: the prior Kilo output-limit failure remains incomplete, and #442 remains open. |
…ect (#442) A hard-killed UI on Windows leaves the dev (uncompiled Bun) subprocess worker running: the owner-death watchdog is only installed off win32, and #480 showed that enabling it there does not help - neither the IPC `disconnect` nor the signal-0 probe observes a hard-killed owner on Windows. Make the guarantee parent-side and OS-enforced instead. On win32 the owner creates a Job Object with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE and assigns every spawned worker to it, crash-restart replacements included. The owner holds the only handle for its lifetime, so Windows terminates the worker (and anything it spawned) as soon as the owner dies, hard kill included. kernel32 is bound through bun:ffi, loaded lazily and only on win32, and every failure (nested jobs unavailable, FFI load failure, refused assignment) degrades to a single warning with the watchdog left as the fallback. The watchdog also stays on win32 as that fallback, using the ESRCH-only probe from the earlier attempt so a transient probe error cannot orphan a live owner's worker. Verification: win-job/owner-watch/worker-process unit suites and the worker integration suite pass (54 tests), typecheck clean. The win32 end-to-end test is gated to Windows and needs a real Windows desktop to run. Co-authored-by: arena-agent <[email protected]>
4aeb138 to
d9849b0
Compare
…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]>
* 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]>
…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]>
…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]>
* 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]>
* 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]>
* 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]>
Issue for this PR
Refs #442
Type of change
What does this PR do?
A hard-killed UI on Windows leaves the dev (uncompiled Bun) subprocess worker running:
worker.tsinstalls the IPC/PID owner watchdog only whenprocess.platform !== "win32", and #480 established that simply removing that gate does not fix it — on win32 the worker observes neither the IPCdisconnectnor a signal-0 probe failure when its owner is hard-killed (both attempts hung to the 30s timeout). The fix therefore has to be parent-side and enforced by the OS.Windows Job Object (new file
src/cli/tui/win-job.ts)JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE(CreateJobObjectW+SetInformationJobObject(JobObjectExtendedLimitInformation), a 144-byteJOBOBJECT_EXTENDED_LIMIT_INFORMATIONon x64 / 112 on x86) and assigns every spawned worker to it withAssignProcessToJobObject(OpenProcesswithPROCESS_SET_QUOTA | PROCESS_TERMINATE).worker-process.tscallsadoptWorkerProcess(child.pid, log)right after each spawn, so crash-restart replacements are adopted as well (a one-time adoption would leave the replacement unprotected).bun:ffiis loaded lazily viarequireinside the win32-only branch: nothing on POSIX touches FFI,dlopen, or kernel32.OpenProcessfailure, or a broken FFI load. A failed assignment keeps the job so the next restart can retry; a failed creation is remembered so restarts do not spam warnings.detached(unchanged): the job also gives Windows the process-tree cleanup that process groups provide on POSIX.Worker watchdog
probeOwnerAlivefrom the closedfix/442-win-worker-owner-watchbranch: onlyESRCHreads as owner death, soEPERMor a transient probe error can never orphan (and kill) a live owner's worker.Encoding, stdout and stderr handling are untouched.
How did you verify your code works?
From
packages/opencode:bun test --timeout 60000 test/cli/tui/owner-watch.test.ts test/cli/tui/win-job.test.ts test/cli/worker-process.test.ts test/cli/worker-process.integration.test.ts test/cli/tui-worker-defects.test.ts→ 54 pass / 0 fail.bun run typecheck(with a larger Node heap — the repo's tsc needs >2 GB) → clean.bunx oxlinton the touched files → 0 errors (1 pre-existing-style advisory on the opaque FFI handle cast).LimitFlagsat byte 16 with every other limit zero, job create/configure, assignment rights and handle release (the job handle is never closed), null-handle / refused-assignment / FFI-load-failure paths, single-warning degradation, job reuse across spawns, no-op off win32, and a full binding test of the kernel32 symbol signatures against a fakebun:ffi(symbol names,JobObjectExtendedLimitInformation = 9,ptrusage,i32→ boolean). TheprobeOwnerAlivetest fails under the old catch-all probe semantics.Windows-only integration test (gated with
if (process.platform !== "win32") return): spawns a stand-in owner that hosts a real TUI worker, hard-kills the owner with no shutdown RPC, and asserts viatasklistthat the worker PID disappears (tasklistrather than signal-0, which #480 showed is unreliable there). The worker script installs no watchdog, so only the job can end it.What stays unverified without a real Windows desktop
kernel32accepts these bindings at runtime: the FFI binding is unit-tested against a fake module only —dlopen("kernel32.dll")cannot be exercised on Linux/macOS CI.AssignProcessToJobObjectsucceeds in the environments people actually run in (Windows Terminal, VS Code terminal, CI runners already inside a job) and that the kill fires as promptly as expected. The gated integration test is the check for that and runs on the Windows CI leg, not locally in this session.TerminateProcess, so a Windows worker killed by its dead owner does not run the gracefulrpc.shutdown()path it would get from the watchdog on POSIX. That is the intended trade-off (an orphan holding a port is worse), but its user-visible effect (e.g. an interrupted transcript flush) is unmeasured.Bun.spawnoffers no suspended start, so an owner killed between spawn and assignment can still orphan the worker. Documented inwin-job.ts.Screenshots / recordings
No real Windows desktop or console recording is available. The unverified items above remain limitations; aggregate CI does not by itself establish a gated test executed.
Checklist
docs/tui/background.md— Windows owner-death contract)Current validation boundary
Current head d9849b0 has passing Linux/Windows unit, typecheck and current clean Kilo review. The original Windows-specific owner-death integration case uses a platform gate; aggregate success with only-failures output does not establish whether that specific case executed. Actual Windows owner-death behavior remains unverified here. This is partial implementation coverage, and #442 stays open for that acceptance check. Earlier thinking-body CI failures were not reproduced on the updated base; no root-cause claim follows from that pass.