Skip to content

fix(runtime): kill the in-container process group when a CLI exec client dies (RIG-4181) - #1791

Merged
trunk-io[bot] merged 2 commits into
mainfrom
compass-agent/rig-4181-cli-stop-kills-agent
Oct 7, 2026
Merged

trunk-io[bot] merged 2 commits into
mainfrom
compass-agent/rig-4181-cli-stop-kills-agent

Conversation

@rigel-mintaka

@rigel-mintaka rigel-mintaka commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

This PR is part of a stack containing 2 PRs:

  1. main
  2. "fix(runtime): kill the in-container process group when a CLI exec client dies (RIG-4181)" (this PR)
  3. fix(runner): sweep detached exec sessions when an agent stops (RIG-4708) #1805

Summary

  • On the podman and apple container backends, Stop SIGKILLed only the host-side exec -i client, so the agent inside the container kept running.
  • The streaming exec command now runs under a small sh wrapper (stopWithClientScript in go/internal/runtime/clispawn.go). A watcher in the same process group relays stdin. When the client dies, stdin hits EOF and the watcher SIGKILLs the whole exec process group.
  • On a natural exit the wrapper kills the watcher and returns the command's own exit status.
  • Processes that call setsid leave the group and still survive. That is not a regression, and the scope decision is filed separately.

Verification

  • go test -tags podman -run 'TestExecStreaming(StopKills|NaturalExit)' ./e2e/ against compass-agent:latest: pass. With the wrapper removed, the Stop test fails with sleep 3000/sleep 3001 still live.
  • Wrapper probe on alpine, debian (dash) and the agent image: client kill clears the group; natural exit 5 → 5; missing command → 127; stdin/stderr pass through; SIGPIPE-ignored environment exits promptly.
  • go test ./internal/runtime/... ./internal/runner/...: ok. go vet -tags podman ./internal/runtime/ ./e2e/: clean. golangci-lint reports nothing new in changed files.
  • Independent review-correctness pass: 0 high; its 3 mediums were fixed in this head (KILL instead of PIPE, test moved into the CI e2e lane, doc claim narrowed).
  • The e2e test reads /proc via podman exec because podman top exits 125 inside the CI e2e container (first CI run).

Risks

  • An agent now dies when the Runner dies, because the Runner holds its stdin. A restarted Runner holds no stream for the old agent anyway.
  • Stop still returns before the in-container group is dead; the window is the time the engine takes to close the exec's stdin.
  • Rollback: revert this commit.

Compatibility

No API or config change. The exec argv gains an sh -c prefix; the agent image and apple container guests ship a POSIX sh, cat and kill.

Documentation

None: runtime-internal behavior; the doc comments on spawnStreaming and stopWithClient describe it.

Refs RIG-4181

…ent dies (RIG-4181)

On podman and apple container, killing the `exec -i` client left the
in-container agent running. Wrap the streaming exec command in a watcher
that relays stdin and SIGKILLs the exec's process group on EOF. A natural
exit kills the watcher and keeps the command's exit status.

Descendants that call setsid leave the group and still survive a Stop.

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@trunk-io

trunk-io Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

@linear-code

linear-code Bot commented Oct 6, 2026

Copy link
Copy Markdown

RIG-4181

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Compass engineering docs preview: https://compass-agent-rig-4181-cli-s.compass-eng-docs.pages.dev

Deployed from compass-agent/rig-4181-cli-stop-kills-agent at d9ad86d.

…(RIG-4181)

`podman top` exits 125 inside the CI e2e container, so read /proc through
`podman exec`, which that lane already runs.

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@rigel-mintaka
rigel-mintaka marked this pull request as ready for review October 6, 2026 16:17
@mattwilkinsonn
mattwilkinsonn added this pull request to stack #1819 October 7, 2026 00:17
@trunk-io

trunk-io Bot commented Oct 7, 2026

Copy link
Copy Markdown

This pull request is queued for merge as part of 1805, which will merge 1791, 1805.

@trunk-io
trunk-io Bot merged commit 9b77e93 into main Oct 7, 2026
17 checks passed
@trunk-io
trunk-io Bot deleted the compass-agent/rig-4181-cli-stop-kills-agent branch October 7, 2026 02:01
@trunk-io

trunk-io Bot commented Oct 7, 2026

Copy link
Copy Markdown

This pull request was merged into main as part of stacked PR 1805.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants