Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/core/src/session/runner/publish-llm-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const INPUT_FAILURES = {
export interface StepRecord {
/** The model produced visible output this attempt, which bars transparent retries and overflow recovery. */
readonly outputStarted: boolean
/** Reasoning alone is not a completed response; tool input has its own settlement path. */
readonly hasContent: boolean
readonly providerFailed: boolean
/** The step's recorded assistant failure, if any. */
readonly failure?: SessionError.Error
Expand Down Expand Up @@ -123,6 +125,7 @@ export const createLLMEventPublisher = (bus: Pick<Bus.Interface, "publish">, inp
let stepStarted = false
let providerFailed = false
let outputStarted = false
let hasText = false
let stepFailure: SessionError.Error | undefined
let stepSettlement: StepRecord["finish"]

Expand Down Expand Up @@ -240,6 +243,7 @@ export const createLLMEventPublisher = (bus: Pick<Bus.Interface, "publish">, inp
"text",
(_textID, value, ordinal, state) =>
Effect.gen(function* () {
if (value.trim()) hasText = true
yield* bus.publish(SessionEvent.Text.Ended, {
sessionID: input.sessionID,
assistantMessageID: yield* currentAssistantMessageID(),
Expand Down Expand Up @@ -652,6 +656,7 @@ export const createLLMEventPublisher = (bus: Pick<Bus.Interface, "publish">, inp
/** Immutable snapshot of everything recorded for this step so far. */
record: (): StepRecord => ({
outputStarted,
hasContent: hasText || tools.size > 0,
providerFailed,
failure: stepFailure,
finish: stepSettlement,
Expand Down
12 changes: 8 additions & 4 deletions packages/core/src/session/runner/step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,20 @@ export const make = Effect.gen(function* () {

if (overflowFailure) yield* publisher.publish(overflowFailure)
const recorded = publisher.record()
const unknownFinish =
Exit.isSuccess(stream) && recorded.finish?.finish === "unknown"
const invalidFinish =
Exit.isSuccess(stream) &&
(recorded.finish?.finish === "unknown" || (recorded.finish?.finish === "stop" && !recorded.hasContent))
? new AIError({
reason: new InvalidProviderOutputError({
message: "The provider response ended with an unknown finish reason.",
message:
recorded.finish?.finish === "unknown"
? "The provider response ended with an unknown finish reason."
: "The provider response ended without text or tool calls.",
classification: "incomplete-stream",
}),
})
: undefined
const llmFailure = streamFailure instanceof AIError ? streamFailure : unknownFinish
const llmFailure = streamFailure instanceof AIError ? streamFailure : invalidFinish
const llmError = llmFailure && !recorded.providerFailed ? toSessionError(llmFailure) : undefined
if (
input.recoverContinuation &&
Expand Down
Loading
Loading