fix(runner): verified exit must confirm stop despite unrelated protected wrapper (#2346)

* fix(runner): let verified exit confirm stop when only unrelated wrappers are protected

* test(runner): verified exit confirms stop despite unrelated protected wrapper
This commit is contained in:
SSU-WEI HUANG
2026-11-13 18:48:00 +08:00
committed by GitHub
parent 0684c77866
commit bb97a6512f
2 changed files with 15 additions and 2 deletions
+11 -1
View File
@@ -1,4 +1,4 @@
import { mkdtempSync, rmSync } from 'node:fs'
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
@@ -50,6 +50,7 @@ import { startRunner } from './run'
describe('runner stop confirmation after shared Codex tracking loss', () => {
let stopSession: Parameters<typeof startRunnerControlServer>[0]['stopSession']
let reportSession: Parameters<typeof startRunnerControlServer>[0]['onHappySessionWebhook']
let record: CodexRuntimeRecord
let home: string
@@ -59,6 +60,7 @@ describe('runner stop confirmation after shared Codex tracking loss', () => {
const captured = new Error('control handlers captured before runner networking')
mocks.controlServer.mockImplementation(async handlers => {
stopSession = handlers.stopSession
reportSession = handlers.onHappySessionWebhook
throw captured
})
// Stop startup at control-server registration. Exercise its real closure
@@ -67,6 +69,7 @@ describe('runner stop confirmation after shared Codex tracking loss', () => {
vi.spyOn(process, 'exit').mockImplementation(() => { throw captured })
vi.stubEnv('HAPI_RUNNER_HANDOFF_FROM_PID', '')
Object.defineProperty(configuration, 'runnerStateFile', { value: join(home, 'runner.json'), configurable: true })
writeFileSync(join(home, 'runner.json.verified-exits.json'), JSON.stringify(['exited']))
try {
await expect(startRunner()).rejects.toBe(captured)
expect(stopSession!).toBeTypeOf('function')
@@ -115,6 +118,13 @@ describe('runner stop confirmation after shared Codex tracking loss', () => {
await expect(stopSession('target')).resolves.toBe('unknown')
})
it('lets verified exit confirm stop despite an unrelated protected wrapper', async () => {
record.sessions = {}
reportSession('other', { hostPid: 4242, startedBy: 'terminal', capabilities: { concurrentClients: true } } as Parameters<typeof reportSession>[1])
await expect(stopSession('exited')).resolves.toBe('already_gone')
await expect(stopSession('target')).resolves.toBe('unknown')
})
it('still refuses when the orphan sweep cannot establish exit', async () => {
mocks.reapOrphans.mockResolvedValue('still_alive')
await expect(stopSession('target')).resolves.toBe('still_alive')
+4 -1
View File
@@ -1709,7 +1709,10 @@ export async function startRunner(options: { workspaceRoots?: string[] } = {}):
// whose wrapper may still be finishing cleanup after tracking loss.
// Sibling protection alone remains insufficient proof of archival.
const binding = sessionRegistryBindingState(liveRuntimes, sessionId);
if (binding !== 'absent' || sessionRuntimeHasActiveSiblings(liveRuntimes, sessionId) || protectedTrackedPids.size > 0) {
// Protected wrappers hosting only other sessions must not mask this
// session's verified exit, or reconcileCodexResume stays pending forever.
if (binding !== 'absent' || sessionRuntimeHasActiveSiblings(liveRuntimes, sessionId)
|| (protectedTrackedPids.size > 0 && !hasVerifiedExit(sessionId))) {
const decision = decideKeepWrapperArchive(binding);
logger.debug(
`[RUNNER RUN] Session ${sessionId}; shared binding=${binding}; archive=${decision}`