Skip to content

Commit 7bd4035

Browse files
sahrizviclaude
andcommitted
fix: [AI-7519] transition idle on bootstrap failure
Kilo caught a follow-on issue from the busy-before-bootstrap change in 6b41623: if any bootstrap traceSpan throws (Session.get / Config.get / Fingerprint.detect / Telemetry.init), cancel() runs via defer but deliberately does not set idle when the session state entry still exists — it relies on the processor's catch block for that. During bootstrap the processor hasn't taken over yet, so a throw would leave the session permanently `busy` with no idle/error transition — TUI spinner stuck, busy-gated callers blocked. Wrap the four bootstrap traceSpan calls in a try/catch that best-effort transitions to idle before rethrowing, so any bootstrap failure exits the busy window cleanly. Co-Authored-By: Claude Opus 4.7 <[email protected]> Claude-Session: https://claude.ai/code/session_01Q8FGy89Qpr39k8nCSpCcK2
1 parent 6b41623 commit 7bd4035

1 file changed

Lines changed: 37 additions & 18 deletions

File tree

‎packages/opencode/src/session/prompt.ts‎

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -418,27 +418,46 @@ export namespace SessionPrompt {
418418
// loop from elsewhere.
419419
await SessionStatus.set(sessionID, { type: "busy" })
420420
// altimate_change end
421-
const session = await traceSpan(
422-
"bootstrap.session-get",
423-
() => Session.get(sessionID),
424-
{ sessionID },
425-
sessionID,
426-
)
427-
// altimate_change start - detect environment fingerprint at session start
428-
const altCfg = await traceSpan("bootstrap.config-get", () => Config.get(), undefined, sessionID)
429-
if (altCfg.experimental?.env_fingerprint_skill_selection === true) {
430-
await traceSpan(
431-
"bootstrap.fingerprint-detect",
432-
() => Fingerprint.detect(Instance.directory, Instance.worktree),
433-
undefined,
421+
// altimate_change start (AI-7519) — discharge the busy status if a bootstrap
422+
// await throws. cancel() (prompt.ts:364) deliberately does NOT set idle
423+
// when the state entry still exists — it relies on the processor's catch
424+
// block for that. But during bootstrap the processor hasn't taken over
425+
// yet, so a throw here (Session.get / Config.get / Fingerprint.detect /
426+
// Telemetry.init) would leave the session permanently `busy` with no
427+
// idle/error transition. Reset to idle on any bootstrap failure and
428+
// re-throw so callers still see the error.
429+
let session: Awaited<ReturnType<typeof Session.get>>
430+
let altCfg: Awaited<ReturnType<typeof Config.get>>
431+
try {
432+
session = await traceSpan(
433+
"bootstrap.session-get",
434+
() => Session.get(sessionID),
435+
{ sessionID },
434436
sessionID,
435-
).catch((e) => {
436-
log.warn("fingerprint detection failed", { error: e })
437-
})
437+
)
438+
// altimate_change start - detect environment fingerprint at session start
439+
altCfg = await traceSpan("bootstrap.config-get", () => Config.get(), undefined, sessionID)
440+
if (altCfg.experimental?.env_fingerprint_skill_selection === true) {
441+
await traceSpan(
442+
"bootstrap.fingerprint-detect",
443+
() => Fingerprint.detect(Instance.directory, Instance.worktree),
444+
undefined,
445+
sessionID,
446+
).catch((e) => {
447+
log.warn("fingerprint detection failed", { error: e })
448+
})
449+
}
450+
// altimate_change end
451+
// altimate_change start — session telemetry tracking
452+
await traceSpan("bootstrap.telemetry-init", () => Telemetry.init(), undefined, sessionID)
453+
} catch (e) {
454+
// Best-effort transition to idle so the TUI spinner + any busy-gated
455+
// callers don't stay stuck. Swallow inner failure so the original
456+
// bootstrap error is what bubbles out.
457+
await SessionStatus.set(sessionID, { type: "idle" }).catch(() => {})
458+
throw e
438459
}
439460
// altimate_change end
440-
// altimate_change start — session telemetry tracking
441-
await traceSpan("bootstrap.telemetry-init", () => Telemetry.init(), undefined, sessionID)
442461
Telemetry.setContext({ sessionId: sessionID, projectId: Instance.project?.id ?? "" })
443462
const sessionStartTime = Date.now()
444463
let sessionTotalCost = 0

0 commit comments

Comments
 (0)