Repository navigation
fix: propagate uncertain extension command cleanup - #169629
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR makes extension command execution reject with the existing cleanup error when owned processes cannot be confirmed stopped. Example: A canceled Linux command exits with code 0, but its SIGTERM-resistant descendant survives because group SIGKILL fails with EPERM.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: current main still discards uncertain extension-command cleanup, and this PR repairs that gap without an identified correctness defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherSession extensions call ExtensionAPI.exec; the session adapter delegates spawning and termination to shared process owners and returns captured output or a cleanup error. flowchart TD
A[Session extension] --> B[ExtensionAPI exec]
B --> C[Session execCommand]
C --> D[Shared spawn owner]
D --> E[Root and descendant processes]
C --> F[Termination controller]
F --> E
F --> G[Cleanup verdict]
G --> C
C --> H[Result or cleanup error]
Technical reviewBest possible solution: Preserve the shared termination owner and propagate its uncertain verdict with the captured command result attached. Do we have a high-confidence way to reproduce the issue? Current-main source demonstrably ignores the cleanup verdict; the inspected native regression reports baseline failure and repaired success, but this read-only review did not execute it. Is this the best way to solve the issue? The patch fixes the result adapter using the existing cleanup classification, preserves successful results, and introduces no competing termination policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9ea2d5edd52a. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -2, Tests +144. Total +142 across 2 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes: No label 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 HistoryReview history (1 earlier review cycle)
Reviewed October 12, 2026, 2:54 AM ET / 06:54 UTC (Revision 2). |
|
Merged via squash.
|
What Problem This Solves
Fixes: extension commands report a normal result after cancellation even when forced cleanup fails and a descendant remains alive.
User Impact
Extension callers now receive the existing
CommandProcessCleanupErrorwhen command cleanup is uncertain. Captured output and the root command's exit result remain available in the error's cause. Successful cleanup, cancellation, output limits, and bounded startup behavior keep their existing results.Why This Change Was Made
The termination owner already records whether cleanup succeeded, but extension exec discarded that verdict. Await the owner's settlement directly and propagate its canonical cleanup error. The async completion path replaces the nested completion promise and callback chain, reducing production code by two lines without adding a result schema, configuration, or retry policy.
Evidence
The Linux regression invokes real
ExtensionAPI.execthrough the extension factory/runtime. A real root command spawns a real descendant; the test denies only the exact owned group's forced stop, then verifies actual descendant and group liveness. The baseline returned a normal result while that group remained alive. The repaired path rejects with the canonical cleanup error and preserves captured output in its cause. A positive control verifies successful forced cleanup. Each case independently restores signalling and cleans its own process group before completing.The baseline failed as expected before the production edit: one failed case, 404 ms test time, 62.03 s command wall time. The repaired focused command passed all 19 cases across the native API test and existing exec-command controls:
pnpm test src/agents/sessions/extensions/loader.exec-cleanup.real.test.ts src/agents/sessions/exec.test.ts --maxWorkers=1Measured command wall time was 52.86 s; the native healthy and denied-stop cases took 170 ms and 185 ms. Most command time was compiled-subprocess preparation (41.08 s). The tests use a Date-only fake clock to cross the existing cleanup budget while native timers, signals, exits, and liveness checks remain real. Native proof is Linux-specific.
Fresh full independent P2 review passed with no findings on the final staged candidate. Targeted typed lint passed in 5.62 s after correcting a redundant boolean comparison in the test. Formatting, conflict markers, staged line-cap/max-lines/environment/assertion/database/test-fixture ratchets, import-cycle checks, and diff checks passed. Hosted CI seconds remain pending.