Fix competitor-analysis live browser preview never appearing - #247
Open
Hotragn wants to merge 1 commit into
Open
Fix competitor-analysis live browser preview never appearing#247Hotragn wants to merge 1 commit into
Hotragn wants to merge 1 commit into
Conversation
The scrape-pricing route cast each agent event to any and then read camelCase fields the stream does not publish. event.streamingUrl is always undefined -- the SDK sends streaming_url -- so the capture guard never fired, competitor_streaming was never sent, and the preview iframe stayed empty for every competitor. The client was fine; it never got the event. Two more stale reads in the same loop: - event.type === 'STEP' is not an event type the stream sends. Step forwarding only worked because the condition fell through to event.purpose. - event.resultJson does not exist either; completion only worked via the event.result fallback beside it. Dropped the any cast and switched the loop to the SDK's own EventType and RunStatus constants, matching how the migrated recipes already read the stream. Per @tiny-fish/sdk/dist/agent/types.d.ts the events are STREAMING_URL/streaming_url, PROGRESS/purpose and COMPLETE/status+result, and there is no ERROR event -- a failed run is COMPLETE with a non-COMPLETED status and an error.message -- so error handling moved inside the COMPLETE branch. No change to the recipe's own SSE vocabulary, so the client is untouched. Verified with tsc --noEmit and npm run lint, both clean. Found by the check in tinyfish-io#244; refs tinyfish-io#86.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Aug 4, 2026
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.
Refs #86. Found by the conformance check in #244.
The bug
app/api/scrape-pricing/route.tscast every agent event toanyand then read camelCase fields the stream doesn't publish:The SDK sends
streaming_url. So the guard never fired,competitor_streamingwas never sent, and the live preview iframe stayed empty for every competitor. The client side was correct the whole time — it just never received the event.Two more stale reads in the same loop, both masked by a fallback:
:382event.type === 'STEP'|| event.purpose.:395event.resultJson ?? event.resultresultJsondoesn't exist; completion worked via theevent.resultfallback beside it.The
anycast is what let all three through — with the real event union, each would have been a type error.The fix
Dropped the cast and switched the loop to the SDK's own constants, matching how the already-migrated recipes read the stream. From
@tiny-fish/sdk/dist/agent/types.d.ts:STREAMING_URL→streaming_url(:212)PROGRESS→purpose(:218-220)COMPLETE→status,result,error(:236-253)EventTypeisSTARTED | STREAMING_URL | PROGRESS | HEARTBEAT | COMPLETE(:186) — there is noERROReventThat last point matters: the old code had
if (event.type === 'ERROR' || event.status === 'FAILED'). A failed run actually arrives asCOMPLETEwith a non-COMPLETEDstatus and anerror.message, so error handling now lives inside theCOMPLETEbranch and readsevent.error?.message— the sameerror?.messageidiom already used infareguardandfounder-mode.Net −21/+15, and one
eslint-disable-next-line @typescript-eslint/no-explicit-anygoes away.Scope
The recipe's own SSE vocabulary is unchanged — the route still emits
competitor_streamingwith astreamingUrlkey andcompetitor_stepwith astepkey, which is exactly whatapp/analysis/page.tsxandapp/dashboard/page.tsxalready read. No client changes needed; fixing the route restores the chain end to end.Behaviour is otherwise identical. The old step-forwarding condition never fired for
STARTED,HEARTBEATorSTREAMING_URLeither, since none of them carry apurpose.Verification