Repository navigation
fix(process): avoid Gateway fork stalls in detached commands - #198478
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@clawsweeper re-review The branch and evidence are complete at df3ac4a. Please review the Gateway lifetime broker lookup, explicit native-only scope precedence, and close cleanup. The PR body includes red-on-parent regressions, final Linux measurements at 9.11 GiB RSS, A/A controls, CPU profiles, and the guarded-path allocation tradeoff. |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR makes detached Gateway commands use the existing spawn broker while preserving scoped overrides and explicit native-only execution. Example: A detached callback runs Git from a Linux Node Gateway with 9.11 GiB RSS.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: current main still loses the broker outside request context, and this focused, maintainer-directed repair addresses that gap without an identified correctness regression. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway startup owns the broker; shared command adapters select it to launch child processes while existing supervisors retain output, cancellation, authority and cleanup. flowchart TD
A[Gateway startup] --> B[Ready broker lifetime]
C[Detached callback] --> D[Transport lookup]
E[Explicit scope] --> D
B --> D
D --> F[Broker or native launch]
F --> G[Existing process supervisor]
Technical reviewBest possible solution: Keep the focused lifetime registration in the existing broker owner, preserving explicit transport scopes and successful-cleanup invalidation. Do we have a high-confidence way to reproduce the issue? Current-main lookup and both shared launch adapters establish the native fallback after detachment; the author also reports regressions failing on the exact parent, which this read-only review did not execute. Is this the best way to solve the issue? The patch fixes transport discovery at its existing owner with a small lifecycle registration, and AsyncContext already preserves the removed redundant same-value fast path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b74fa8348ffc. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +14, Tests +76, Docs 0, Other +52. Total +142 across 6 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 13, 2026, 5:15 PM ET / 22:15 UTC. |
|
Merged via squash.
|
What Problem This Solves
Fixes Gateway pauses when detached callbacks start Git, exec-tool commands, or container helpers from a large Node process.
User Impact
Linux Gateway commands continue using the existing small spawn broker after their request async context has ended. Command output, exit codes, environment, working directory, cancellation, deadlines, and process-tree ownership keep their existing contracts.
Why This Change Was Made
The broker belongs to the Gateway lifetime, but its lookup only consulted request async context. Both shared spawn adapters therefore fell back to native spawn for detached work even when the broker was healthy. Register the ready broker at its existing owner and clear it after successful host cleanup. Explicit native-only scopes and scoped broker overrides retain precedence.
Production growth is 14 lines for the lifetime registration and cleanup hook. No configuration, cache, schema, or duplicate command implementation. Native transport remains for CLI/other runtimes, host-owned descriptors and explicit synchronous launch-authority boundaries.
Evidence
Both regressions fail on exact parent
649ca5f879f1e4349a2c5cf9872e30366962a595: detached commands have the main process as parent, and the real exec fixture completes without using its ready broker. Candidate owner, exec, transport and Gateway shutdown coverage passes; the lifecycle batch is 62 tests. The new owner test takes about 1.1 seconds of test time; compilation is excluded from that figure.Codex autoreview of the complete local candidate is scoped-clean through P2, with no accepted/actionable findings. Core test typechecks and scoped script checks pass after fixture corrections.
pnpm check:changedpasses every gate except unused exports; those failures reproduce unchanged on a clean exact-parent checkout:TELEPORT_PT,QA_UX_STREAM_END_MARKER: introduced in chore(ios): measure chat scroll and streaming stability on the simulator #198293 (858b5b01338e).adoptTelegramDmTopicMessage,TELEGRAM_DM_TOPIC_ADOPT_WINDOW_SEC: introduced in fix(telegram): first DM message lands in root chat when the client creates the topic separately #169444 (90c620b8e554).RELEASE_VALIDATION_WAIVERS: introduced in fix(release): move validation waivers into trusted tooling #173437 (2a1285197991); no external reader in its symbol history.These are recorded main regressions, not passing checks.
Linux proof uses the committed
scripts/perf/durable-spawn-measure.tsworkload, source-frozen parent/candidate bundles, a 9.11 GiB resident parent including 4 GiB V8 heap, five alternating pairs and identical-source A/A controls (250 commands per source per owner). All 750 native host spawns become zero.Median allocation per command: Git 514,667 → 342,058 bytes; guarded exec 120,356 → 187,833 bytes; container 747,066 → 360,073 bytes. The guarded path adds about 66 KiB (+56%) through existing broker admission/IPC while reducing main-thread CPU by 96.8%. A/A wall medians were 42.324/42.856 → 2.318/2.429 ms for Git, 32.461/32.416 → 2.394/2.336 for guarded exec, and 46.009/46.917 → 14.059/13.976 for container helpers.
Separate CPU profiles (50 commands/source/owner) attribute 1,396 ms of Git and 1,503 ms of guarded-exec samples to native
spawnbefore, with no native-spawn samples after. Timing acceptance uses unprofiled runs.This is transport-owner proof in an isolated local Linux VM (ARM64, Node 26.12.1, overlayfs), not complete Gateway throughput or btrfs coverage. The commands do not read the database or workspace; the synthetic fixture matches resident heap and mapping cost without copying production data. The broker remains about 80–84 MiB RSS.