Skip to content

fix: propagate uncertain extension command cleanup - #169629

Merged
steipete merged 1 commit into
mainfrom
codex/extension-exec-cleanup-20261011
Oct 12, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/extension-exec-cleanup-20261011

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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 CommandProcessCleanupError when 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.exec through 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=1

Measured 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.

@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: ExtensionAPI.exec resolves with code 0 and killed true.
  • After: ExtensionAPI.exec rejects with ERR_COMMAND_PROCESS_CLEANUP_UNCERTAIN, retaining output and the command result in its cause.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A useful, focused repair with meaningful native boundary coverage and no identified defect; evidence remains harness-based.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply under the supplied maintainer-authored policy; inspected evidence covers real ExtensionAPI.exec processes with denied SIGKILL and healthy cleanup, through an in-process Linux regression.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Extension callers can receive an ordinary command result while canceled descendant work remains alive.
Reason: The owner-directed repair exposes an existing cleanup failure through the established error type without adding options or a new policy.

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
Reviewed head: 8eeb98c1c9c442a7b59a62d59712dc4f852e4e62

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied Linux extension regression exercises real processes in a test harness; no shipped CLI or Gateway scenario is demonstrated.
Agent review details

How this fits together

Session 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]
Loading

Technical review

Best 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

  • Awaited extension cancellation keeps the original intent (316c341: Join the shared termination owner before canceled commands complete.)
  • Callback completion and ordinary result resolution changes intended behavior with a stated reason (67cedc3: Support broker-backed spawning while retaining output, cancellation ownership, and bounded startup; later consolidation preserved ordinary result resolution.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 316c341 adds src/agents/sessions/exec.ts:96 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 316c341756d8; files: src/agents/sessions/exec.ts)
  • ooiuuii: Raw commit 53557f9 adds src/agents/sessions/exec.ts:85 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 53557f961869; files: src/agents/sessions/exec.ts)

PR surface

Source -2, Tests +144. Total +142 across 2 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 88 90 -2
Tests 1 144 0 +144
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 232 90 +142

Review metrics

Metric Value Why it matters
Production versus test LOC Production −2 net; tests +144 The adapter becomes smaller, while native regression coverage adds a real denied-stop scenario and a successful-cleanup control.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A bounded cancellation failure can report ordinary completion while descendant work remains alive.
  • merge-risk: 🚨 compatibility: ExtensionAPI.exec changes uncertain cleanup from resolution to rejection; the owner-directed repair explicitly accepts this behavior and retains diagnostics.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-12T05:26:47.038Z sha 8eeb98c :: needs maintainer review before merge. :: none

Reviewed October 12, 2026, 2:54 AM ET / 06:54 UTC (Revision 2).

@steipete
steipete marked this pull request as ready for review October 12, 2026 06:49
@steipete
steipete merged commit b82b033 into main Oct 12, 2026
190 checks passed
@steipete
steipete deleted the codex/extension-exec-cleanup-20261011 branch October 12, 2026 08:36
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant