fix(ai): keep OpenCode Ask AI subscribed before prompting - #1413
Open
danowicz wants to merge 3 commits into
Open
fix(ai): keep OpenCode Ask AI subscribed before prompting#1413danowicz wants to merge 3 commits into
danowicz wants to merge 3 commits into
Conversation
Ask AI hung with Failed to fetch against OpenCode 1.18 because the provider subscribed after promptAsync and ignored assistant text snapshots when deltas were missed.
AGENTS.md requires each test to name the failure it guards.
Extract consumeOpenCodeEvent so the query loop can be unit-tested. Ignore leftover idle from before promptAsync, skip user-prompt snapshots that have no time stamp, and fall back to the assistant text snapshot when deltas never arrive (backnotprop#514 / backnotprop#907).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the OpenCode half of #907 (source: #514). OpenCode Ask AI hung with Failed to fetch on 1.18.20:
/api/ai/sessionsucceeded,/api/ai/queryreturned SSE headers, then never emitted events.Related: #513 (port conflict when attaching to an existing
opencode serve).The failure
OpenCodeSession.querysubscribed to/eventafterpromptAsync. A short turn can finish before that subscriber is live, so the query loop never sees idle and the browser times out.Even when events arrive, 1.18 still streams
message.part.deltafor tokens but also lands a finalmessage.part.updatedtext snapshot. The mapper treated snapshots as no-ops, so a late subscriber with no deltas rendered an empty bubble (#514).The fix
Bun source of truth is
packages/ai/providers/opencode-sdk.ts. Pi picks it up throughvendor.sh(generated/ai/providers/opencode-sdk.ts); no hand-mirrored HTTP routes.promptAsync. That frame is only a liveness check — leftover idle from a previous turn is not consumed as this query's result.consumeOpenCodeEvent(unit-tested). Idle after the prompt completes the query even if OpenCode never emittedbusy.timestamp) before the result. User-prompt snapshots have notimeand are ignored, so the question is not echoed into the bubble.Two-runtime note
Ask AI lives in
@plannotator/ai. Both Bun (packages/server/ai-runtime.ts) and Pi (apps/pi-extension/server/ai-runtime.ts) load this provider.vendor.shalready copiesopencode-sdk.ts; no Pi server edit.Testing
bun test packages/ai/ai.test.ts: 121 pass. New cases cover snapshot-only idle (OpenCode AI tab: responses not rendering (empty bubbles) #514 empty bubble), no duplicate tokens when deltas already streamed, and ignoring the user-prompt snapshot.bun run typecheckwas not run in this checkout:tscis not on PATH and the isolated install has nobun-types. CItest.ymlshould cover it.Not done here: live Ask AI against a compiled
plannotatorbinary. That still needs a release after merge. #907's anchored plan Q&A / thinking-vs-answer UI criteria are out of scope.AI-assisted (Claude) under user direction.