fix(look-at): use synchronous prompt to fix race condition (#1620 regression)

PR #1620 migrated all prompt calls from session.prompt (blocking) to
session.promptAsync (fire-and-forget HTTP 204). This broke look_at which
needs the multimodal-looker response to be available immediately after
the prompt call returns.

Fix: add promptSyncWithModelSuggestionRetry() that uses session.prompt
(blocking) with model suggestion retry support. look_at now uses this
sync variant while all other callers keep using promptAsync.

- Add promptSyncWithModelSuggestionRetry to model-suggestion-retry.ts
- Switch look_at from promptWithModelSuggestionRetry to sync variant
- Add comprehensive tests for the new sync function
- No changes to other callers (delegate-task, background-agent)
This commit is contained in:
YeonGyu-Kim
2026-02-08 02:36:27 +09:00
parent 8cbebfad04
commit 93f40c2d2f
3 changed files with 167 additions and 3 deletions
+39
View File
@@ -88,3 +88,42 @@ export async function promptWithModelSuggestionRetry(
// model errors happen asynchronously server-side and cannot be caught here
await client.session.promptAsync(args as Parameters<typeof client.session.promptAsync>[0])
}
/**
* Synchronous variant of promptWithModelSuggestionRetry.
*
* Uses `session.prompt` (blocking HTTP call that waits for the LLM response)
* instead of `promptAsync` (fire-and-forget HTTP 204).
*
* Required by callers that need the response to be available immediately after
* the call returns — e.g. look_at, which reads session messages right away.
*/
export async function promptSyncWithModelSuggestionRetry(
client: Client,
args: PromptArgs,
): Promise<void> {
try {
await client.session.prompt(args as Parameters<typeof client.session.prompt>[0])
} catch (error) {
const suggestion = parseModelSuggestion(error)
if (!suggestion || !args.body.model) {
throw error
}
log("[model-suggestion-retry] Model not found, retrying with suggestion", {
original: `${suggestion.providerID}/${suggestion.modelID}`,
suggested: suggestion.suggestion,
})
await client.session.prompt({
...args,
body: {
...args.body,
model: {
providerID: suggestion.providerID,
modelID: suggestion.suggestion,
},
},
} as Parameters<typeof client.session.prompt>[0])
}
}