Skip to content

Commit ba616e5

Browse files
authored
fix(cloud-agent-next): include step and error detail in session restore failure messages (#957)
## Summary When `kilo-restore-session.js` fails, the structured stdout (containing `step`, `error`, and `code` fields) was logged locally inside the Durable Object but lost by the time the error propagated through the tRPC chain to logpush. The error message only said `"Cold-start session restore failed: exit 1"`, making it impossible to diagnose failures from logpush alone. This change enriches the `SessionSnapshotRestoreError` message at the throw site to include `step` and `error` fields extracted from the restore script's JSON stdout. The richer message flows naturally through the existing error chain (`SessionSnapshotRestoreError` → `ExecutionError.workspaceSetupFailed` → `TRPCError`) without any downstream changes. **Before:** `"Failed to prepare workspace: Cold-start session restore failed: exit 1"` **After:** `"Failed to prepare workspace: Cold-start session restore failed: exit 1, step=import, error=kilo import failed exitCode=1"` ## Verification - [x] `pnpm run typecheck` — passed (tsgo + wrapper) - [x] `pnpm run test` — 642 tests passed, 25 test files - [x] Verified existing test assertions use substring matching (`toThrow('Cold-start session restore failed')`) and remain compatible with the enriched message ## Visual Changes N/A ## Reviewer Notes - Single file change: `cloud-agent-next/src/session-service.ts` — extends the existing stdout JSON parsing block (which already extracts `code`) to also extract `step` and `error`. - No new error class fields, no changes to orchestrator/CloudAgentSession/session-execution. - The `as Record<string, unknown>` cast on `JSON.parse` matches the existing pattern at this location.
2 parents 2fd19d7 + 4c16275 commit ba616e5

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

cloud-agent-next/src/session-service.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,8 @@ export class SessionService {
13171317

13181318
// Parse stdout JSON for structured error info
13191319
let code: number | undefined;
1320+
let step: string | undefined;
1321+
let restoreError: string | undefined;
13201322
try {
13211323
const parsed = JSON.parse(restoreResult.stdout?.trim() ?? '{}') as Record<
13221324
string,
@@ -1325,6 +1327,12 @@ export class SessionService {
13251327
if (typeof parsed.code === 'number') {
13261328
code = parsed.code;
13271329
}
1330+
if (typeof parsed.step === 'string') {
1331+
step = parsed.step;
1332+
}
1333+
if (typeof parsed.error === 'string') {
1334+
restoreError = parsed.error;
1335+
}
13281336
} catch {
13291337
// non-JSON stdout, ignore
13301338
}
@@ -1335,10 +1343,15 @@ export class SessionService {
13351343
404
13361344
);
13371345
}
1338-
throw new SessionSnapshotRestoreError(
1339-
`Cold-start session restore failed: exit ${restoreResult.exitCode}`,
1340-
code
1341-
);
1346+
1347+
const detail = [
1348+
`exit ${restoreResult.exitCode}`,
1349+
step && `step=${step}`,
1350+
restoreError && `error=${restoreError}`,
1351+
]
1352+
.filter(Boolean)
1353+
.join(', ');
1354+
throw new SessionSnapshotRestoreError(`Cold-start session restore failed: ${detail}`, code);
13421355
}
13431356

13441357
// Log structured summary from restore script

0 commit comments

Comments
 (0)