Skip to content
This repository was archived by the owner on Nov 7, 2026. It is now read-only.

Commit 5d878c1

Browse files
brentyates-swxFinn763rekram1-node
authored
fix(core): backport transport and process-exit cleanup (#410)
* docs: plan transport and lifecycle backport Implement the assigned transport and lifecycle behavior in existing fork owners. - Pick each donor in its own -x commit; omit shell-failure UI and absent CLI/MCP payload. - Disable Bun’s independent fetch deadline only for long network clients and native provider requests; preserve caller signals, domain deadlines, and the #303 watchdog. - Track detached POSIX groups only while cleanup is owed, preserving #380 escalation and release of intentional descendants; route terminal SIGHUP through the TUI lifecycle. - Add real-server and child-process regressions with removal proofs, then record donor coverage and focused checks in CHANGESET.md. * fix(tui): keep long-pending requests past Bun's fetch deadline (anomalyco#55149) Give the TUI client timeout: false, share the no-timeout fetch helper across run, mini and the TUI via @opencode/util/no-timeout-fetch, and surface existing-session shell failures with a toast and composer restore. Closes anomalyco#54974 Co-authored-by: Finn763 <[email protected]> (cherry picked from commit 52a10f5) * fix(core): disable Bun's fetch idle timeout for provider requests (anomalyco#55007) (cherry picked from commit 460c626) * fix(util): kill spawned process groups when opencode exits (anomalyco#59411) (cherry picked from commit e2bc79d) * fix(core): type Bun fetch timeout overrides * test(opencode): verify mini attach timeout wiring Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * test(core): verify abrupt owner process-group cleanup Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * test(tui): verify SDK long-call fetch policy Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * fix(tui): preserve nohup SIGHUP behavior Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * test(core): verify native fetch timeout override Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * test(core): prove native requests outlive default idle timeout Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * test(opencode): verify attached runs survive Bun idle timeout Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * docs: record transport and lifecycle backport Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * docs: clarify backport regression ownership Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * test(opencode): allow Bun 1.4.4 server startup window Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * test: shorten idle-timeout acceptance tests Run the native and attached held-response witnesses in bounded Bun 1.4.4 child processes with BUN_CONFIG_HTTP_IDLE_TIMEOUT=2 so they stay out of the multi-minute range. Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * test(tui): prove SDK long calls survive Bun idle expiry Exercise SDKProvider's external SDK and SSE paths with a held event stream, a real timeout control, and a completed event after the injected short idle expiry. Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * test(opencode): prove mini attach survives Bun idle expiry Hold the real mini attach session response in a Bun 1.4.4 child process, observe an unmodified control fetch time out first, then release the expected 404 response. Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * test(tui): make SIGHUP fixture reports truthful Keep the nohup fixture scoped to listener policy and process survival, and add a non-TTY non-nohup default-disposition witness while retaining lifecycle assertions only from the real TUI producer. Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * fix(tui): clean Worker-owned process groups on exit Acknowledge Worker group ownership and release events, kill and await remaining groups before the shutdown reply, and use the recorded PGID ledger as the bounded TUI-owner backstop when shutdown is unconfirmed. Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * docs: finalize transport exit review coverage Record the acknowledged TUI Worker group lifecycle, truthful SIGHUP behavior, and short Bun 1.4.4 behavioral witnesses in the backport ledger. Claude-Session: c368ed23-1e31-4f2c-b305-b84f21d79cc5 * fix(tui): centralize Worker process-group ownership * docs: plan transport exit review fixes 1. Make worker and parent ownership ledgers converge on each local acquire, release, and cleanup decision even when acknowledgement is rejected or delayed; validate recorded identities before parent-side signalling. 2. Add rejected/delayed acknowledgement regressions for acquire, release, cleanup announcement, and release/reacquire identity fallback. 3. Harden fixture cleanup and deadlines; add Linux-only guards; correct CHANGESET ownership and SIGHUP claims; remove only test hooks no longer needed. 4. Verify focused changed cases and then each importing test file once under checksum-verified Bun 1.4.4; commit without pushing. * fix(core): reconcile process-group acknowledgement failures Reconcile Worker and parent ownership ledgers on local acquire, release, and cleanup facts, independent of rejected or delayed acknowledgements. Validate recorded member identities before signalling and preserve released member identities across reacquisition. Bound identity-owned process fixture cleanup, gate procfs child fixtures to Linux, retain portable SDK cancellation coverage, and correct the #410 SIGHUP and ownership ledger. Claude-Session: unknown * test(opencode): gate shell output on spawn readiness Wait for the process spawn acknowledgement before the ShellTool first-output deadline and reap the child on readiness failure. Tighten process-group fixture types for package typecheck. Claude-Session: unknown * fix(core): restore cross-platform process group cleanup Claude-Session: unavailable (OpenCode session) * fix(core): unify process-group ownership decisions Claude-Session: unavailable (OpenCode session) * fix(core): publish process-group ownership updates Claude-Session: unavailable (OpenCode session) * test(opencode): cover cancellation-overlap ownership Claude-Session: unavailable (OpenCode session) * test(core): wait for process-group cleanup Claude-Session: unavailable (OpenCode session) * test(opencode): harden process-group test results Claude-Session: unavailable (OpenCode session) * test(opencode): validate cancellation result shape Claude-Session: unavailable (OpenCode session) * test(opencode): type fixture results as unknown Claude-Session: unavailable (OpenCode session) --------- Co-authored-by: Finn763 <[email protected]> Co-authored-by: Finn763 <[email protected]> Co-authored-by: Aiden Cline <[email protected]>
1 parent e8113c4 commit 5d878c1

28 files changed

Lines changed: 5292 additions & 215 deletions

‎CHANGESET.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ Newest first. Each entry names the upstream range brought in.
140140

141141
### Runtime fixes
142142

143+
- **#410** Backport `anomalyco/opencode#55149` (`52a10f573f1da5103c85990da9341e3645a39365`), `#55007` (`460c626acd9e3de8fdffc27bde99bb5f070bb70f`), and `#59411` (`e2bc79dc0bae112b79ab780f7c1a63db8a7f7dae`) in separate `git cherry-pick -x` commits, retaining each donor trailer. Assigned behavior is complete; #55149's payload is partial because its existing-session shell-failure UI recovery is unassigned, #55007's payload is complete, and #59411's payload is partial because its upstream CLI shutdown-deadline module is absent here and was not imported. _Partly upstream._
144+
- `packages/core/src/no-timeout-fetch.ts` is wired to `packages/tui/src/context/sdk.tsx` and `packages/opencode/src/cli/cmd/run.ts` for long TUI/run/mini requests; `packages/core/src/effect/app-node-platform.ts` applies the donor-faithful replace-not-merge of `FetchHttpClient.RequestInit` (`{ timeout: false }`) at native `RequestExecutor` composition, while the high-level fetch wrapper preserves caller request options and abort signals. Provider caller deadlines and fork #303's generation-progress watchdog remain independent of Bun's idle timeout.
145+
- `packages/core/src/cross-spawn-spawner.ts` captures each detached leader's process identity in its ownership events; detached Worker spawn waits for the parent acquire acknowledgement and fails/reaps if `ProcessGroup.makeWorkerTracker` does not receive it within its configured five-second timeout. Failed and late acknowledgements do not reverse local release or cleanup facts, and release events retain the original identity after the leader exits. Cleanup-owed groups retain an asynchronous member snapshot so Worker exit hooks can revalidate surviving descendants. Worker `killGroups`, shutdown and spawn-ack failure use the shared `decideGroupOwnership` table with explicit gone → refuted → confirmed → pending/unavailable precedence.
146+
- `packages/opencode/src/cli/tui/process-group.ts` is the shared parent owner used by `TuiThreadCommand`; its Worker tracker publishes each newest PGID fact immediately, tags snapshots with ownership sequences, and rejects stale results. Failed discovery resolves to unavailable rather than leaving a group pending; released-member entries are retained only for live groups and expire. The tracker, parent owner, and Core signal paths use `decideGroupOwnership`; refuted/gone groups are pruned immediately.
147+
- Preserve fork #380 cancellation escalation. A generic detached spawn without `forceKillAfter` whose leader exits abnormally is deliberately released from exit-hook ownership; its later scope finalizer may still send TERM. The non-renderer `run`/`serve` SIGHUP/SIGTERM gap is tracked by swxtchio/swx-opencode#417.
148+
- `packages/tui/src/app.tsx` creates the OpenTUI renderer without overriding its `exitSignals`, so the renderer's own SIGHUP handler destroys it regardless of TTY state; `TuiThreadCommand` then reaches its stop/finally owner cleanup. Established OpenTUI non-TTY/nohup SIGHUP behavior is retained unchanged; the new terminal gate only prevents a redundant app-level listener on top of the renderer's existing handler.
149+
- `packages/core/test/fixture/process-group.ts` is the shared identity and membership fixture used by Core, OpenCode and TUI tests. `packages/core/test/effect/cross-spawn-spawner.test.ts` covers refuted-leader precedence, rejected/delayed acquire acknowledgements, cleanup-owed failure, identity-stable release and the identity-unavailable signal fallback. `packages/opencode/test/cli/tui/worker-process-group.test.ts` drives the owner through the real Core Worker, including delayed initial acknowledgements with held discovery, repeated completed Core spawns, discovery failure and cancellation. Its cancellation-overlap case acknowledges spawn, starts cancellation while the leader is live, holds Worker-side discovery, exits the leader, and triggers the owner Worker-error hook before checking the resistant descendant is reaped. The action matrix runs serially with comma-separated `SWX_TUI_GROUP_CASE` selection.
150+
- `packages/opencode/test/tool/shell.test.ts` retains its abort/interruption regressions asserting that a TERM-resistant command's output-write refusal still ends with both its process and recorded group gone; its output deadline starts after the explicit spawn acknowledgement.
151+
- `packages/opencode/test/cli/tui/hangup-process-group.test.ts` sends terminal SIGHUP to a PTY-backed TUI and confirms the stop/finally path removes a live Worker group before the owner exits. `packages/tui/test/cli/tui/sdk-transport.test.tsx` proves the held SDK request survives the shortened idle window, preserves portable caller-cancellation coverage, and bounds a held-pipe child cleanup; `packages/opencode/test/cli/run/mini-attach.test.ts` and `packages/opencode/test/cli/run/mini-attach-interactive-worker.test.ts` exercise successful and cancellable `runMini` SDK calls through production `RunCommand` and record both the PTY launcher and command identities.
152+
- `packages/core/test/no-timeout-fetch.test.ts` proves request-init preservation and caller-signal cancellation; `packages/core/test/effect/app-node-platform.test.ts` proves native provider requests replace configured timeout with `false` at `RequestExecutor`, survive a short-idle control, and abort on caller deadline; `packages/opencode/test/cli/run/run-process.test.ts` holds an attached provider response past a short injected idle timeout; and `packages/opencode/test/session/llm.test.ts` preserves the #303 keepalive-only stall watchdog while valid reasoning and structured progress keep attempts live.
153+
- `packages/tui/test/app-lifecycle.test.tsx` exercises the real `runSighupFixture` drain call site with an outliving inherited writer and fails within the configured bound; held-request witnesses use child Bun 1.4.4 processes with `BUN_CONFIG_HTTP_IDLE_TIMEOUT=2`. The prior unmodified-default Bun 1.4.4 run remains historical acceptance evidence, not a test timing requirement. Removing `timeout: false` from `noTimeoutFetch` made the held ordinary TUI SDK witness fail with `TimeoutError`.
154+
- Round-2 through round-5 review fixes use focused tests under checksum-verified Bun 1.4.4; the full suite and typecheck remain firstmate's leased build-box gate under the no-heavy-builds ruling.
143155
- **#406** Backport `anomalyco/opencode#54023` (`94353780cf289dcecee2866322dbbe1f34d51641`) to coordinate provider OAuth refresh across concurrent callers. The required provider-refresh behavior is complete; donor payload is partial.
144156
- Adapt `packages/core/src/credential.ts` to add `Credential.lock` to the fork's global service and use its existing `EffectFlock`; keep `packages/core/src/integration.ts`'s `Integration.connection.resolve` Location-owned, re-read stored state inside the lock, and preserve key, environment, missing-credential, fresh-token and no-refresh behavior. MCP SDK refresh and provider-401 recovery remain out of scope.
145157
- Omit the donor's upstream-only `CredentialLegacy`, Bus and ErrorSummary plumbing and interface-only updates to upstream config/MCP OAuth test doubles; do not restore the deleted MCP OAuth suite or config fixture.

0 commit comments

Comments
 (0)