Repository navigation
fix(claude): run structured Claude under the POSIX provider supervisor #23476
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f17bf18
fix(codex): the provider supervisor outlives its provider group when …
brennanb2025 75a7e73
fix(codex): a closed owner pipe no longer ends the supervisor before …
brennanb2025 401380b
fix(codex): bound the supervisor grace so recovery's SIGTERM stage al…
brennanb2025 e18fdb4
Merge remote-tracking branch 'origin/brennanb2025/harden-provider-sup…
brennanb2025 3b37405
fix(codex): every supervisor stop asks the provider with SIGTERM first
brennanb2025 d146ae8
fix(claude): run the structured Claude child under the POSIX provider…
brennanb2025 2fbd0ca
test(claude): pin the supervised stop against a real Claude CLI, opt-in
brennanb2025 7d1c0f9
test(claude): a requested stop reads interrupted through the frames t…
brennanb2025 84934e4
test(claude): show what the real CLI did when it never ran the tool
brennanb2025 5bd82b7
Merge remote-tracking branch 'origin/brennanb2025/harden-provider-sup…
brennanb2025 297ea48
test(claude): Orca's death now reaps Claude's own tool through its SI…
brennanb2025 a6a1605
refactor(claude): take supervision from the spawn spec so the close l…
brennanb2025 05728a1
Merge remote-tracking branch 'origin/main' into brennanb2025/claude-u…
brennanb2025 07d6876
fix(native-chat): derive quit's chat-eviction bound from the longest …
brennanb2025 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
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
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,72 @@ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { PROVIDER_SUPERVISOR_MAX_STOP_MS } from '../codex/codex-app-server-posix-supervisor' | ||
| import type { ClaudeChildTreeReaper } from './claude-agent-sdk-exit-proof' | ||
| import { proveClaudeChildExitWithReaper } from './claude-child-exit-proof-ladder' | ||
|
|
||
| function fakeTree(): ClaudeChildTreeReaper & { reap: ReturnType<typeof vi.fn> } { | ||
| return { | ||
| capture: vi.fn(async () => {}), | ||
| refresh: vi.fn(async () => {}), | ||
| reap: vi.fn(async () => 'exited' as const), | ||
| treeVerdict: 'exited' | ||
| } | ||
| } | ||
|
|
||
| /** A root that leaves only once a SIGTERM has had `stopMs` to act, the way a supervisor does. */ | ||
| function rootStoppedBySigterm(stopMs: number) { | ||
| let exited = false | ||
| let settle = (): void => {} | ||
| const exitPromise = new Promise<void>((resolve) => { | ||
| settle = resolve | ||
| }) | ||
| const kill = vi.fn((signal?: NodeJS.Signals | number) => { | ||
| if (signal === 'SIGTERM') { | ||
| setTimeout(() => { | ||
| exited = true | ||
| settle() | ||
| }, stopMs) | ||
| } | ||
| return true | ||
| }) | ||
| const stdin = { end: vi.fn() } | ||
| return { | ||
| // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: The ladder reads only pid, kill and stdin.end from its child. | ||
| child: { pid: 4321, kill, stdin } as unknown as Parameters< | ||
| typeof proveClaudeChildExitWithReaper | ||
| >[0]['child'], | ||
| kill, | ||
| stdin, | ||
| exitPromise, | ||
| exited: () => exited | ||
| } | ||
| } | ||
|
|
||
| describe('Claude child exit proof ladder', () => { | ||
| it('stops a supervised child with SIGTERM and waits out the supervisor stop before forcing', async () => { | ||
| // Slower than the unsupervised 1.5 s grace, still inside the supervisor's own bound. | ||
| const root = rootStoppedBySigterm(PROVIDER_SUPERVISOR_MAX_STOP_MS - 500) | ||
| const tree = fakeTree() | ||
|
|
||
| await expect( | ||
| proveClaudeChildExitWithReaper({ ...root, supervised: true, tree }, () => tree) | ||
| ).resolves.toBe(true) | ||
|
|
||
| expect(root.stdin.end).toHaveBeenCalled() | ||
| expect(root.kill).toHaveBeenCalledWith('SIGTERM') | ||
| // Forcing here would SIGKILL the supervisor mid-stop and orphan Claude in its own group. | ||
| expect(root.kill).not.toHaveBeenCalledWith('SIGKILL') | ||
| expect(tree.reap).not.toHaveBeenCalled() | ||
| }, 10_000) | ||
|
|
||
| it('never signals an unsupervised child for the graceful stop', async () => { | ||
| const root = rootStoppedBySigterm(0) | ||
| const tree = fakeTree() | ||
|
|
||
| await proveClaudeChildExitWithReaper({ ...root, tree }, () => tree) | ||
|
|
||
| // On Windows a direct SIGTERM is TerminateProcess: stdin end stays the only graceful rung. | ||
| expect(root.stdin.end).toHaveBeenCalled() | ||
| expect(root.kill).not.toHaveBeenCalledWith('SIGTERM') | ||
| expect(tree.reap).toHaveBeenCalled() | ||
| }, 10_000) | ||
| }) |
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
Oops, something went wrong.
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.