Skip to content

Commit 4554ecc

Browse files
committed
fix(session): render fail-fast and stuck-compaction errors in the transcript
The start-of-iteration stop paths only published a session error event, which the desktop app surfaces as a notification badge at best — the turn ended silently with no visible error. Persist an assistant message carrying the error (rendered inline as a TimelineRow.Error) for both the window-too-small fail-fast and the loop-guard stop, alongside the existing event. Refs anomalyco#48847
1 parent 294ae02 commit 4554ecc

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,37 @@ const layer = Layer.effect(
232232
return size
233233
})
234234

235+
// Ends the turn with a visible error: persists an assistant message
236+
// carrying the error (so it renders inline in the timeline) and publishes
237+
// the session error event, without spending an LLM request.
238+
const failTurn = Effect.fn("SessionPrompt.failTurn")(function* (input: {
239+
sessionID: SessionID
240+
lastUser: SessionV1.User
241+
model: Provider.Model
242+
error: InstanceType<typeof SessionV1.ContextOverflowError>
243+
}) {
244+
const ctx = yield* InstanceState.context
245+
const msg: SessionV1.Assistant = {
246+
id: MessageID.ascending(),
247+
parentID: input.lastUser.id,
248+
role: "assistant",
249+
mode: input.lastUser.agent,
250+
agent: input.lastUser.agent,
251+
variant: input.lastUser.model.variant,
252+
path: { cwd: ctx.directory, root: ctx.worktree },
253+
cost: 0,
254+
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
255+
modelID: input.model.id,
256+
providerID: input.model.providerID,
257+
time: { created: Date.now() },
258+
sessionID: input.sessionID,
259+
error: input.error.toObject(),
260+
finish: "error",
261+
}
262+
yield* sessions.updateMessage(msg)
263+
yield* events.publish(Session.Event.Error, { sessionID: input.sessionID, error: input.error.toObject() })
264+
})
265+
235266
const title = Effect.fn("SessionPrompt.ensureTitle")(function* (input: {
236267
session: Session.Info
237268
history: SessionV1.WithParts[]
@@ -1220,7 +1251,7 @@ const layer = Layer.effect(
12201251
floor,
12211252
usable: budget,
12221253
})
1223-
yield* events.publish(Session.Event.Error, { sessionID, error: error.toObject() })
1254+
yield* failTurn({ sessionID, lastUser, model, error })
12241255
break
12251256
}
12261257
}
@@ -1231,7 +1262,7 @@ const layer = Layer.effect(
12311262
"session.id": sessionID,
12321263
streak,
12331264
})
1234-
yield* events.publish(Session.Event.Error, { sessionID, error: error.toObject() })
1265+
yield* failTurn({ sessionID, lastUser, model, error })
12351266
break
12361267
}
12371268
yield* compaction.create({ sessionID, agent: lastUser.agent, model: lastUser.model, auto: true })

0 commit comments

Comments
 (0)