mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-16 19:29:33 +01:00
fix(agent): COD-549 preserve spawned ID on readiness transport errors
This commit is contained in:
1 parent
3e06f3c141
commit
af4b65697a
3 files changed
+53
-15
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'aicodeman': patch
|
||||
---
|
||||
|
||||
Preserve the created session ID in agent spawn output when the readiness request fails with a transport error.
|
||||
+19
-15
@@ -555,21 +555,25 @@ export async function agentSpawn(deps: AgentDeps, options: SpawnOptions): Promis
|
||||
let dead = false;
|
||||
const mark = composerReadyMark(options.mode);
|
||||
if (options.ready && mark) {
|
||||
const wait = await deps.request(deps.ctx, {
|
||||
method: 'GET',
|
||||
path: `/api/v1/sessions/${encodeURIComponent(sid)}/wait-output`,
|
||||
query: { match: mark, from: 'buffer', timeout: options.timeoutMs },
|
||||
timeoutMs: options.timeoutMs + 10_000,
|
||||
});
|
||||
// A failed readiness call (waiter cap, 400, network) is its own error, not "the
|
||||
// composer never showed up": report the real reason instead of the trust-dialog hint.
|
||||
if (!wait.json?.success) readinessError = describeFailure(wait);
|
||||
else {
|
||||
const result = (wait.json.data as { wait?: WaitResult } | undefined)?.wait;
|
||||
// A worker that died while we waited is exit 3 like every other wait, not a
|
||||
// "composer not seen" timeout that sends the caller looking for a dialog.
|
||||
dead = waitExitCode(result) === EXIT.dead;
|
||||
ready = !dead && Boolean(result?.matched);
|
||||
try {
|
||||
const wait = await deps.request(deps.ctx, {
|
||||
method: 'GET',
|
||||
path: `/api/v1/sessions/${encodeURIComponent(sid)}/wait-output`,
|
||||
query: { match: mark, from: 'buffer', timeout: options.timeoutMs },
|
||||
timeoutMs: options.timeoutMs + 10_000,
|
||||
});
|
||||
// A failed readiness call (waiter cap, 400, network) is its own error, not "the
|
||||
// composer never showed up": report the real reason instead of the trust-dialog hint.
|
||||
if (!wait.json?.success) readinessError = describeFailure(wait);
|
||||
else {
|
||||
const result = (wait.json.data as { wait?: WaitResult } | undefined)?.wait;
|
||||
// A worker that died while we waited is exit 3 like every other wait, not a
|
||||
// "composer not seen" timeout that sends the caller looking for a dialog.
|
||||
dead = waitExitCode(result) === EXIT.dead;
|
||||
ready = !dead && Boolean(result?.matched);
|
||||
}
|
||||
} catch (error) {
|
||||
readinessError = getErrorMessage(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -548,6 +548,35 @@ describe('agent spawn', () => {
|
||||
expect(deps.calls).toHaveLength(1);
|
||||
expect(deps.err.join('')).toMatch(/SESSION_BUSY/);
|
||||
});
|
||||
|
||||
it.each([false, true])('preserves the created id when readiness throws (json=%s)', async (json) => {
|
||||
const deps = fakeDeps((options) => {
|
||||
if (options.path === '/api/v1/quick-start') return ok({ sessionId: OTHER, caseName: 'c' });
|
||||
throw new Error('readiness connection reset');
|
||||
}, json);
|
||||
const exit = await agentSpawn(deps, { caseName: 'c', mode: 'claude', ready: true, timeoutMs: 1000 }).catch(
|
||||
() => undefined
|
||||
);
|
||||
|
||||
if (json) {
|
||||
expect(deps.out).toHaveLength(1);
|
||||
expect(JSON.parse(deps.out[0])).toEqual({
|
||||
sessionId: OTHER,
|
||||
caseName: 'c',
|
||||
readinessError: 'readiness connection reset',
|
||||
});
|
||||
expect(deps.err).toEqual([]);
|
||||
} else {
|
||||
expect(deps.out).toEqual([OTHER]);
|
||||
expect(deps.err.join('')).toContain('readiness check failed: readiness connection reset');
|
||||
expect(deps.err.join('')).not.toMatch(/composer not seen|startup dialog/);
|
||||
}
|
||||
expect(exit).toBe(EXIT.error);
|
||||
expect(deps.calls.map(({ method, path }) => ({ method, path }))).toEqual([
|
||||
{ method: 'POST', path: '/api/v1/quick-start' },
|
||||
{ method: 'GET', path: `/api/v1/sessions/${OTHER}/wait-output` },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('session id prefixes', () => {
|
||||
|
||||
Reference in new issue
Block a user