Repository navigation
test(opencode): prove Windows owner-death job cleanup on real processes (Closes #442) - #709
Closed
agenteinstinct1-max wants to merge 3 commits into
Closed
agenteinstinct1-max wants to merge 3 commits into
agenteinstinct1-max wants to merge 3 commits into
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. |
…es (Refs #442) Co-authored-by: arena-agent <[email protected]>
Co-authored-by: arena-agent <[email protected]>
…proof" This reverts commit f47eaae.
agenteinstinct1-max
force-pushed
the
arena/a1ad830f-silvercode
branch
from
October 30, 2026 18:29
28966df to
bdb3b86
Compare
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #442
Summary
Real Windows owner-death proof for the subprocess TUI worker. Tests and fixtures only — no production code changed (net diff vs.
dev-vibecoded: 4 new files, 434 insertions).What #561 / #568 installed (verified on tip
ace9659)src/cli/tui/win-job.ts:34,56-61JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSEwritten intoJOBOBJECT_EXTENDED_LIMIT_INFORMATIONat byte 16src/cli/tui/win-job.ts:96-105createOwnerJob— create + configure, close the handle if configuring failssrc/cli/tui/win-job.ts:112-119addProcessToJob—OpenProcess(PROCESS_SET_QUOTA|PROCESS_TERMINATE), assign, release only the process handlesrc/cli/tui/win-job.ts:136-168windowsJobApi— the realbun:ffikernel32 bindingsrc/cli/tui/win-job.ts:190-231createOwnerJobAdopter— one job per owner, reused for restarts; #568's warn-once-per-episode at217-222with retry against the retained job and rearm on successsrc/cli/tui/worker-process.ts:2,126,226adoptWorker = options.adoptWorker ?? adoptWorkerProcess, called for every spawn including crash-restartsProvably covered by the merged tests: struct layout and offsets, kernel32 signature/return translation, job reuse across spawns, every failure branch (create refused,
OpenProcessrefused, assign refused, FFI throw), warn-once/retry/rearm, and the non-win32 no-op. All of it drives a fakeWindowsJobApi— plusworker-process.integration.test.ts:541, which spawns a real worker and watches only its PID viatasklist.Not covered by any of it: that Windows actually terminates the worker tree, and that a resource the worker holds is actually released. That is what this PR adds.
Test design
test/fixture/win-owner-death-owner.tscalls the same factory the TUI command uses (src/cli/cmd/tui.ts:243→createTuiWorker→createWorkerProcess→adoptWorkerProcess). The job binding is the realbun:ffi/kernel32 path; no adopter is injected and nothing is stubbed. It also guards the premise (process.execPathmust bebun, else the thread path would make the test vacuous).loghook receives over IPC; the test asserts that log contains no(#442)tag — the suffix the production adopter appends to every job creation/assignment/FFI failure (win-job.ts:207,219,228). A worker that merely happened to die cannot read as job coverage.OpenProcessandtasklist) and both ports must accept connections.TerminateProcesson the owner PID only — one process, no/Ttree walk, no console control event, no shutdown RPC. Nothing in that call can be what ends the worker tree.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION), where onlyERROR_INVALID_PARAMETERreads as "gone" (any other failure,ERROR_ACCESS_DENIEDincluded, means a process is there), cross-checked against the process list withtasklist.--timeout), 50ms polling, retries only for the OS-settling races (process teardown, port release).test.skipIf(process.platform !== "win32")so non-Windows runs report a visible skip instead of a silent pass.Windows CI evidence
test.ymlalready runsunit (windows)onwindows-latest, so no workflow was touched.unit (windows)unit (linux)8f6623c(test added)41089290484f47eaae(mutation control)4109408684528966df(control reverted, head)41100393537Head
28966df9b31829fe23a2dda1b1cc0b0ffe64184c:unit (linux)success,unit (windows)success,typechecksuccess,check-standardssuccess,check-compliancesuccess.Mutation control. The job log text is not reachable from the sandbox that prepared this branch (
gh run view --logresolves toresults-receiver.actions.githubusercontent.com, which is outside its allowlist), so "the job is green" was not accepted as proof that the win32 test ran. Commitf47eaaeadded one deliberately-false assertion inside the gated test —expect(pidExists(report.grandchildPid)).toBe(false), placed before the kill, where the grandchild is certainly alive. Onwindows-latestthesilvercode-ai#testtask exited 1 (annotation:command (D:\a\silvercode\silvercode\packages\opencode) C:\Users\runneradmin\.bun\bin\bun.exe run test exited (1)). That establishes three things at once: the gated body executes on the Windows runner, its liveOpenProcessinspection really queried the OS and returned "alive", and a false assertion really fails the job — so the green run on the identical tree means the real assertions held. The control is reverted in28966df;git diff 8f6623c 28966dfis empty.The
unit (linux)failure in the same run is unrelated: the mutated file reports0 pass / 1 skip / 0 failon Linux (verified locally), the identical tree was green on Linux 30 minutes earlier, and Linux is green again on28966df— a flake in the existing suite.Other verification
bun testoverwin-job.test.ts,worker-process.test.ts,worker-process.integration.test.tsand the new file: 45 pass / 1 skip (the win32 gate on Linux) / 0 fail, 170expect()calls. The fix(tui): kill the Windows subprocess worker with the owner's job object (#442) #561 and fix(tui): warn once per Windows job assignment failure episode #568 unit tests are untouched.tsc --noEmitover the four new files: clean.oxlint: 0 errors, 1 warning of the sameno-unsafe-type-assertionclass that productionwin-job.ts:147already carries for the samebun:ffisymbol binding.connectsucceeds,bindfails), and afterSIGKILL-ing the owner the worker and grandchild survive holding both ports. That is the control showing the Windows assertions are not vacuous — off Windows nothing takes the tree down.Residual (explicitly not proven)
bun run+ the full TUI + "the configured port". CI drives the production worker factory thatsrc/cli/cmd/tui.ts:243calls, with a worker that binds a real listening TCP port instead of booting the silvercode server (which would need a database, config and auth). Owner-death tree kill and port release are proven for the real dev-worker spawn path; they are not proven for a worker hosting the realServer.listenendpoint.win-job.ts:25-27documents that assignment happens afterBun.spawnreturns, so an owner killed inside that window can still orphan a worker. That is a production limitation, not something this test can close, and no test attempts to.OpenProcessdenied, persistent assignment failure: CI cannot force those OS conditions, so they stay covered by the fake-API unit tests from fix(tui): kill the Windows subprocess worker with the owner's job object (#442) #561/fix(tui): warn once per Windows job assignment failure episode #568. What CI adds is the assertion that on a healthywindows-latestrunner the adopter logs no such failure.Scope note (acceptance)
This PR is the real Windows owner-death proof (hard-killed owner -> worker tree terminated, ports released, on windows-latest CI, mutation-controlled). It does NOT exercise the full interactive TUI vehicle from the issue repro (no DB/config/auth, no real Server.listen endpoint hosted by the worker), the Bun.spawn -> AssignProcessToJobObject window (win-job.ts:25-27) remains uncoverable by construction, and job-degradation paths remain unit-only. #442 stays open for those residuals.