Skip to content

Commit c7b1d4e

Browse files
committed
reorder:
1 parent 49cf895 commit c7b1d4e

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

apps/sim/executor/handlers/pi/local-backend.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export const runLocalPi: PiBackendRun<PiLocalRunParams> = async (params, context
147147
context.signal?.addEventListener('abort', onAbort, { once: true })
148148
}
149149

150+
let runErrorMessage: string | undefined
150151
try {
151152
await agentSession.prompt(
152153
buildPiPrompt({
@@ -155,6 +156,9 @@ export const runLocalPi: PiBackendRun<PiLocalRunParams> = async (params, context
155156
task: params.task,
156157
})
157158
)
159+
// Pi has no error event; a failed run surfaces on the agent state. Capture
160+
// it before `dispose()` so the failure can't be missed by a later read.
161+
runErrorMessage = agentSession.agent.state.errorMessage
158162
} finally {
159163
unsubscribe()
160164
context.signal?.removeEventListener('abort', onAbort)
@@ -172,9 +176,8 @@ export const runLocalPi: PiBackendRun<PiLocalRunParams> = async (params, context
172176
throw new Error('Pi run aborted')
173177
}
174178

175-
// Pi has no error event; a failed run surfaces on the agent state.
176-
if (agentSession.agent.state.errorMessage) {
177-
totals.errorMessage = agentSession.agent.state.errorMessage
179+
if (runErrorMessage) {
180+
totals.errorMessage = runErrorMessage
178181
return { totals }
179182
}
180183

0 commit comments

Comments
 (0)