-
Notifications
You must be signed in to change notification settings - Fork 141
fix: bound Windows ACP shutdown and retain failed cleanup #430
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
Closed
slashdevcorpse
wants to merge
4
commits into
LodyAI:main
from
slashdevcorpse:fix/windows-process-tree-cleanup
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5536eaa
fix: await bounded Windows ACP process tree cleanup
slashdevcorpse 506095b
fix: preserve graceful termination failure cause
slashdevcorpse 8f71ec1
fix: retain failed shutdown ownership and await terminal exits
slashdevcorpse 26b6ad7
fix: reserve forced shutdown and coalesce session cleanup
slashdevcorpse 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
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,81 @@ | ||
| import { afterEach, expect, it, vi } from 'vitest'; | ||
| import type { ChildProcess } from 'child_process'; | ||
| import { EventEmitter } from 'events'; | ||
| import type { SessionId, WorkspaceId } from '@lody/shared'; | ||
| import { Session } from '../session/session'; | ||
| import { createStartShutdownController } from './start-shutdown'; | ||
| import type { Logger } from '../utils/logger'; | ||
| import type { SessionProcessHandle } from '../session/session-sandbox'; | ||
|
|
||
| afterEach(() => vi.useRealTimers()); | ||
|
|
||
| it('runs the Session process phase before outer exit when terminal disposal hangs', async () => { | ||
| vi.useFakeTimers(); | ||
| const logger: Logger = { | ||
| info: vi.fn(), | ||
| warn: vi.fn(), | ||
| error: vi.fn(), | ||
| debug: vi.fn(), | ||
| success: vi.fn(), | ||
| setLevel: vi.fn(), | ||
| child: () => logger, | ||
| close: async () => {}, | ||
| }; | ||
| const session = new Session( | ||
| { | ||
| workspaceId: 'workspace' as WorkspaceId, | ||
| sessionId: 'session' as SessionId, | ||
| userId: 'user', | ||
| machineId: 'machine', | ||
| agentCliType: 'builtin', | ||
| agentType: 'codex', | ||
| userName: 'test', | ||
| userEmail: 'test@example.com', | ||
| }, | ||
| logger, | ||
| process.cwd() | ||
| ); | ||
| session.acpSessionId = 'acp' as never; | ||
| const dispose = vi | ||
| .spyOn(session.terminalManager, 'disposeAll') | ||
| .mockImplementation(() => new Promise(() => {})); | ||
| const child = new EventEmitter() as ChildProcess; | ||
| child.exitCode = null; | ||
| child.signalCode = null; | ||
| const terminate = vi.fn(async () => { | ||
| child.signalCode = 'SIGKILL'; | ||
| }); | ||
| const handle: SessionProcessHandle = { | ||
| child, | ||
| terminate, | ||
| inspectExit: async () => null, | ||
| onExit: () => () => {}, | ||
| onClose: () => () => {}, | ||
| onError: () => () => {}, | ||
| }; | ||
| // @ts-expect-error - synthetic owned process fixture | ||
| session.agentProcess = handle; | ||
| const exit = vi.fn(); | ||
| const controller = createStartShutdownController({ | ||
| signals: [], | ||
| logger, | ||
| shutdown: () => session.terminate(false), | ||
| forceShutdown: () => session.terminate(true), | ||
| flushTelemetry: async () => {}, | ||
| exit, | ||
| }); | ||
| const result = controller.shutdown('SIGTERM'); | ||
| await vi.advanceTimersByTimeAsync(14_999); | ||
| expect(terminate).not.toHaveBeenCalled(); | ||
| expect(exit).not.toHaveBeenCalled(); | ||
| await vi.advanceTimersByTimeAsync(1); | ||
| expect(terminate).toHaveBeenCalledWith(true); | ||
| expect(exit).not.toHaveBeenCalled(); | ||
| await vi.advanceTimersByTimeAsync(5_000); | ||
| await result; | ||
| expect(dispose).toHaveBeenCalledTimes(1); | ||
| expect(exit).toHaveBeenCalledWith(143); | ||
| // Failed terminal cleanup remains truthfully retryable despite root termination. | ||
| // @ts-expect-error - retained cleanup state | ||
| expect(session.status).toBe('stopping'); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.