-
Notifications
You must be signed in to change notification settings - Fork 0
fix(opencode): reap fatal provider process groups #821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
seonghobae
wants to merge
6
commits into
main
Choose a base branch
from
fix/opencode-fatal-process-groups-replacement
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+177
−18
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
178f969
fix(ci): terminate fatal OpenCode attempts by process group
seonghobae 5a099cd
Merge main and preserve process-group safety contract
seonghobae 5f250b0
Merge branch 'main' into fix/opencode-fatal-process-groups-replacement
opencode-agent[bot] 180bc31
Merge latest main into PR branch
seonghobae 7c60701
fix(opencode): reap fatal provider process groups
seonghobae e1eb679
Merge branch 'main' into fix/opencode-fatal-process-groups-replacement
opencode-agent[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
.github/workflows/fatal-provider-process-group-quality-ci.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| name: Fatal Provider Process Group Quality CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [main] | ||
| paths: | ||
| - ".github/workflows/fatal-provider-process-group-quality-ci.yml" | ||
| - "scripts/ci/run_opencode_review_model_pool.sh" | ||
| - "tests/test_opencode_model_pool_runner.py" | ||
| - "docs/doctoring/opencode-process-group-termination.md" | ||
| - "CHANGELOG.md" | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: fatal-provider-process-group-quality-${{ github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| exact-head-contract: | ||
| if: github.event_name != 'pull_request' || github.event.action != 'closed' | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - name: Checkout exact source revision | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.sha || github.sha }} | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 | ||
| with: | ||
| python-version: "3.14" | ||
|
|
||
| - name: Install exact hash-verified test runner dependencies | ||
| env: | ||
| PIP_DISABLE_PIP_VERSION_CHECK: "1" | ||
| PIP_NO_INPUT: "1" | ||
| shell: bash --noprofile --norc -e -o pipefail {0} | ||
| run: | | ||
| cat >"${RUNNER_TEMP}/fatal-provider-quality-requirements.txt" <<'EOF' | ||
| iniconfig==2.1.0 --hash=sha256:9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760 | ||
| packaging==26.2 --hash=sha256:5fc45236b9446107ff2415ce77c807cee2862cb6fac22b8a73826d0693b0980e | ||
| pluggy==1.6.0 --hash=sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746 | ||
| pygments==2.20.0 --hash=sha256:81a9e26dd42fd28a23a2d169d86d7ac03b46e2f8b59ed4698fb4785f946d0176 | ||
| pytest==9.1.1 --hash=sha256:37a86b45efb9a47a61a36449063e8e18d0cab3161329fc099eb21783169c4f0c | ||
| EOF | ||
| python -m pip install \ | ||
| --only-binary=:all: \ | ||
| --require-hashes \ | ||
| -r "${RUNNER_TEMP}/fatal-provider-quality-requirements.txt" | ||
|
|
||
| - name: Verify fail-first and exact-head contracts | ||
| shell: bash --noprofile --norc -e -o pipefail {0} | ||
| run: | | ||
| test "$(git rev-parse HEAD)" = "${{ github.event.pull_request.head.sha || github.sha }}" | ||
| python -m pytest -q tests/test_opencode_model_pool_runner.py \ | ||
| -k 'fatal_provider_error_kills_hung_opencode_run_early or delisted_openrouter_model_error_kills_hung_run_early' | ||
| python -m compileall -q tests/test_opencode_model_pool_runner.py | ||
| bash -n scripts/ci/run_opencode_review_model_pool.sh | ||
| git diff --exit-code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # OpenCode fatal-provider process-group termination | ||
|
|
||
| ## Incident | ||
|
|
||
| The exact-head coverage-evidence job for `.github` pull request #799 reached the repository test suite but did not complete inside its bounded measurement step. A focused reproduction identified `test_fatal_provider_error_kills_hung_opencode_run_early`: the launcher detected a fatal provider event and terminated the `timeout` wrapper, while a descendant fake `opencode` process could remain alive with inherited output pipes. The parent Python process then waited for end-of-file even though the launcher had returned. | ||
|
|
||
| ## Decision | ||
|
|
||
| Each bounded `opencode run` starts in a new session with `setsid` when that | ||
| tool is present (Linux CI / util-linux). On a structured fatal-provider | ||
| event, the launcher sends `SIGTERM` to the negative process-group | ||
| identifier, waits for bounded group disappearance, and then sends | ||
| `SIGKILL` to the same group if necessary. Darwin local runners without | ||
| `setsid` keep PID-directed `TERM`/`KILL` so the repository suite still | ||
| executes. The ordinary timeout contract remains | ||
| `timeout --kill-after=30s`; only the early-fatal cleanup boundary | ||
| changes. | ||
|
|
||
| The launcher explicitly disables Bash job control before it starts an | ||
| attempt. That preserves the POSIX identity relied on by the negative-PGID | ||
| signal: the background `setsid` process executes directly, and its PID becomes | ||
| the new session and process-group id. The implementation captures that id at | ||
| launch time instead of probing `PATH` again during cleanup. | ||
|
|
||
| The group signal is deliberately scoped to the session created for one model attempt. It does not target the workflow shell, unrelated model attempts, or the runner process. The production Ubuntu image already installs `util-linux`, which supplies `setsid`. | ||
|
|
||
| CWE-400 describes uncontrolled resource consumption when a child outlives the | ||
| intended bound (MITRE, 2026). NIST SP 800-53 Rev. 5 SI-4 requires monitoring | ||
| that detects and contains anomalous process behavior rather than treating a | ||
| returned parent as a complete cleanup (Joint Task Force, 2020). Killing only | ||
| the `timeout` wrapper therefore leaves a descendant that can stall coverage | ||
| evidence; the negative process-group identifier is the contained unit. | ||
|
|
||
| ## Verification | ||
|
|
||
| The existing behavioral regressions in | ||
| `tests/test_opencode_model_pool_runner.py` use fake providers that emit fatal | ||
| structured events and sleep for 120 seconds. Before the change, the tests | ||
| exceeded their subprocess boundary because a descendant retained the capture | ||
| pipes. With process-group termination, both the context/quota and delisted-model | ||
| cases complete in under 25 seconds. The focused workflow executes those real | ||
| process tests on Ubuntu, and shell syntax plus the repository-wide evidence | ||
| command remain required before merge. | ||
|
|
||
| ## Rollback | ||
|
|
||
| Rollback requires an independently reviewed change and a replacement mechanism that proves every descendant of a fatal model attempt is reaped without terminating unrelated runner work. Restoring PID-only termination is not acceptable because it reintroduces the pipe-retention failure mode. | ||
|
|
||
| ## APA 7th references | ||
|
|
||
| IEEE & The Open Group. (2024). *The Open Group base specifications issue 8: System interfaces, `kill()`*. https://pubs.opengroup.org/onlinepubs/9799919799/functions/kill.html | ||
|
|
||
| Joint Task Force. (2020). *Security and privacy controls for information systems | ||
| and organizations* (NIST SP 800-53 Rev. 5). National Institute of Standards and | ||
| Technology. https://doi.org/10.6028/NIST.SP.800-53r5 | ||
|
|
||
| MITRE. (2026). *CWE-400: Uncontrolled resource consumption*. | ||
| https://cwe.mitre.org/data/definitions/400.html | ||
|
|
||
| Free Software Foundation. (n.d.). *GNU Coreutils manual: `timeout`: Run a command with a time limit*. Retrieved August 7, 2026, from https://www.gnu.org/software/coreutils/manual/html_node/timeout-invocation.html | ||
|
|
||
| Linux man-pages project. (2026, February 8). *setsid(2) — Linux manual page* (Linux man-pages 6.18). https://man7.org/linux/man-pages/man2/setsid.2.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Info: Group kill covers only the fatal-provider path
The
setsidnegative-PGID kill applies only to the early fatal-provider abort. On an ordinarytimeoutexpiry,timeoutsignals only its direct child, so opencode descendants can still survive holding the capture pipes. This is pre-existing and unchanged; the PR scopes the fix to the fatal path only.(Refers to this code)
Was this helpful? React with 👍 or 👎 to provide feedback.