Skip to content

Commit 4c1dc2e

Browse files
committed
Retain recovery profile ownership
1 parent 1f7cf36 commit 4c1dc2e

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎agents/adapters/supervisor.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const retainCleanupOwnership = (profile: ContainerProfile, detail: string, regis
7878
timer = undefined;
7979
complete = true;
8080
if (active.get(invocation.attemptId) === handle) active.delete(invocation.attemptId);
81+
activeProfiles.delete(profile);
8182
cleanupRecoveries.delete(handle);
8283
resolveSettled(Object.freeze({ attemptId: invocation.attemptId, context: invocation.context,
8384
exitCode: null, signal: null, stopReason: 'capture-failure', stdout: '',
@@ -91,6 +92,7 @@ const retainCleanupOwnership = (profile: ContainerProfile, detail: string, regis
9192
};
9293
handle = Object.freeze({ attemptId: invocation.attemptId, settled,
9394
cancel: () => { if (timer) clearTimeout(timer); timer = undefined; retry(); } });
95+
activeProfiles.add(profile);
9496
if (register) active.set(invocation.attemptId, handle);
9597
else cleanupRecoveries.add(handle);
9698
schedule();
@@ -399,8 +401,9 @@ export function startProfileInvocation(profile: ContainerProfile, options: Super
399401
decodedOutput = decoded;
400402
} catch (error) {
401403
const message = error instanceof Error ? error.message : String(error);
402-
const reason = error instanceof OutputLimitError || /exceeds its capture limit/i.test(message)
403-
? 'output-limit' : error instanceof CaptureDeadlineError ? 'timeout' : 'capture-failure';
404+
const reason: StopReason = stopReason ?? (performance.now() >= deadline ? 'timeout'
405+
: error instanceof OutputLimitError || /exceeds its capture limit/i.test(message)
406+
? 'output-limit' : error instanceof CaptureDeadlineError ? 'timeout' : 'capture-failure');
404407
failureDetail ??= message;
405408
if (closed) stopReason ??= reason;
406409
else stop(reason);

‎test/agent-supervisor.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ describe('container invocation supervisor', () => {
229229
expect(result.stdout).not.toContain('must-not-publish');
230230
}, 15_000);
231231

232+
it('classifies a decoder failure after the monotonic deadline as timeout', async () => {
233+
const result = await startProfileInvocation(profile(fixture(), 'finite-output', 'decode-fails-late', 30_000), {
234+
timeoutMs: 3_000,
235+
decode: (_current, _raw, _maximum, timeoutMs) => {
236+
const end = performance.now() + timeoutMs + 50;
237+
while (performance.now() < end) { /* deliberately block the timer queue */ }
238+
throw new Error('late decoder failure');
239+
},
240+
}).settled;
241+
expect(result.stopReason).toBe('timeout');
242+
}, 15_000);
243+
232244
it('validates and decodes provider output even when the process exits nonzero', async () => {
233245
const result = await startProfileInvocation(profile(fixture(), 'nonzero-output', 'nonzero-decode'), {
234246
decode: (_current, raw) => ({ text: `decoded:${raw.toString('utf8')}` }),

0 commit comments

Comments
 (0)