GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(mothership): chat stream structuring + logs resource post fix by icecrasher321 · Pull Request #4189 · simstudioai/sim

Conversation

@icecrasher321

@icecrasher321 icecrasher321 commented Apr 15, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Summary

Clean up chat streaming order of ops to make react query client refetch redis first when conversation active. Also logs resource when open left chat hanging.

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

greptile-apps[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Vikhyath Mondreti added 2 commits April 15, 2026 16:08
Vikhyath Mondreti
fix(mothership): chat streaming structure
2640956
Vikhyath Mondreti
fix logs resource thinking bug"
3417332
@vercel

vercel Bot commented Apr 15, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 15, 2026 11:34pm

Request Review

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cursor

cursor Bot commented Apr 15, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches core chat streaming/stop behavior and client cache synchronization; regressions could surface as missing/duplicated messages or stuck queued sends. Changes are covered by new unit tests for transcript synthesis and stop-route behavior.

Overview
Chat fetch endpoints now return an effective transcript by normalizing persisted messages and synthesizing the in-flight assistant response from Redis stream snapshots (buildEffectiveChatTranscript), avoiding missing/duplicated tails while a conversation is active.

The home useChat streaming flow is refactored to write live SSE updates into the React Query chat detail cache (with a pendingMessages fallback) and introduces a sessionStorage-backed queued-send handoff so queued messages survive stop/reload/navigate scenarios without getting stuck.

Stopping a chat stream now always clears conversationId and can append a synthesized cancelled assistant message (with stable generateId IDs and stopped/complete:cancelled blocks), plus adds shared tooling for interpreting cancelled tool outcomes and expands allowed resource attachment types (incl. log/task/generic).

Reviewed by Cursor Bugbot for commit c956577. Configure here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@greptile-apps

greptile-apps Bot commented Apr 15, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two related chat streaming bugs: (1) when a chat is active, the API now returns an effective transcript that splices the live Redis-backed stream snapshot into the persisted message list via buildEffectiveChatTranscript, so the client always gets an up-to-date view on refetch; and (2) the stop route now unconditionally appends a cancelled assistant message (with a synthesized { type: 'stopped' } block) regardless of whether partial content was accumulated.

A significant client-side refactor moves streaming updates from a local setMessages state into the React Query cache via a new upsertTaskChatHistory helper, aligning the server and client views. handleTaskStatusEvent also drops the now-redundant detail-query invalidation on SSE completion, relying on the finalize path instead. Finally, task, log, and generic resource types are added to the chat-post schema, fixing the "log resource left chat hanging" regression.

Confidence Score: 5/5

Safe to merge — no P0/P1 issues found across any changed file.

All findings are P2 or lower. The core logic in buildEffectiveChatTranscript, the stop-route cancelled-block synthesis, and the React Query cache migration are all verifiably correct after tracing through normalizeMessage. New test files provide solid coverage for the new modules. The handleTaskStatusEvent narrowing (list-only, workspace-scoped) is safe because the workspaceId guard in useTaskEvents ensures the function is always called with a defined string.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/lib/copilot/chat/effective-transcript.ts New module that builds an effective chat transcript by replaying Redis stream events onto persisted messages; well-guarded (only appends live assistant if trailing message is the active user turn).
apps/sim/lib/copilot/chat/effective-transcript.test.ts New test file with six cases covering the key branches of buildEffectiveChatTranscript: already-persisted assistant, empty stream, text stream, thinking-only, tool cancellation, and cancelled tail.
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Major refactor: streaming flush now writes to the React Query cache via upsertTaskChatHistory instead of local state; messages is derived from chatHistory rather than a standalone useState; queued-send handoff mechanism added for cross-navigation recovery.
apps/sim/app/api/copilot/chat/stop/route.ts Stop route now always appends a cancelled assistant message (synthesizes { type: 'stopped' } block) instead of silently no-oping when content is empty; also replaces crypto.randomUUID() with generateId().
apps/sim/app/api/copilot/chat/stop/route.test.ts New test file covering auth, missing-chat, and empty-content stop scenarios; verifies the cancelled block shape stored in the DB.
apps/sim/app/api/copilot/chat/queries.ts GET handler now builds an effective transcript from the stream snapshot before returning, so refetches during an active stream include the live assistant tail.
apps/sim/app/api/mothership/chats/[chatId]/route.ts Same effective-transcript treatment applied to the mothership chat GET endpoint; replaces the raw messages array with the built transcript.
apps/sim/hooks/use-task-events.ts handleTaskStatusEvent now takes a workspaceId and invalidates only the workspace-specific list key; removes the previously redundant detail-query invalidation on completion.
apps/sim/lib/copilot/chat/post.ts Adds task, log, and generic to the ResourceAttachmentSchema enum; fixes the "log resource left chat hanging" validation rejection.
apps/sim/lib/copilot/chat/stream-tool-outcome.ts New utility that factors out the tool-outcome resolution logic (user_cancelled detection, success/error fallback) used in both effective-transcript.ts and use-chat.ts.

Sequence Diagram

sequenceDiagram
    participant C as Client (useChat)
    participant RQ as React Query Cache
    participant API as API Route
    participant Redis as Redis (stream snapshot)
    participant DB as Database

    C->>RQ: cancelQueries(detail)
    C->>RQ: upsertTaskChatHistory (optimistic user + assistant)
    C->>API: POST /api/mothership/chat (send message)
    API-->>C: SSE stream begins

    loop During streaming
        C->>RQ: upsertTaskChatHistory (flush: update assistant snapshot)
    end

    API->>Redis: write stream events
    API->>DB: persist final messages
    API-->>C: stream complete

    C->>C: finalize() → invalidateChatQueries
    C->>API: GET /api/mothership/chats/{chatId}
    API->>DB: fetch chat + conversationId
    API->>Redis: fetch streamSnapshot
    API->>API: buildEffectiveChatTranscript(messages, snapshot)
    API-->>C: effective transcript (persisted + live tail)
    C->>RQ: update cache with server response

    Note over C,RQ: SSE task_status → only list key invalidated (not detail)
Loading

Reviews (2): Last reviewed commit: "address comments" | Re-trigger Greptile

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

greptile-apps[bot]
greptile-apps Bot reviewed Apr 15, 2026
View reviewed changes
Comment thread apps/sim/app/api/copilot/chat/stop/route.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread apps/sim/lib/copilot/chat/effective-transcript.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread apps/sim/app/api/copilot/chat/stop/route.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Vikhyath Mondreti
address comments
7d4f7a0
cursor[bot]
cursor Bot reviewed Apr 15, 2026
View reviewed changes
Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Vikhyath Mondreti
address comments
c956577
@vercel
vercel Bot temporarily deployed to Preview April 15, 2026 23:34 Inactive
@icecrasher321

icecrasher321 commented Apr 15, 2026

Copy link
Copy Markdown
Contributor Author

bugbot run

cursor[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@icecrasher321

icecrasher321 commented Apr 15, 2026

Copy link
Copy Markdown
Contributor Author

@greptile

greptile-apps[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cursor[bot]
cursor Bot reviewed Apr 15, 2026
View reviewed changes

@cursor cursor Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c956577. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@icecrasher321
icecrasher321 merged commit 377712c into staging Apr 15, 2026
14 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@icecrasher321 icecrasher321 mentioned this pull request Apr 15, 2026
v0.6.46: mothership streaming fixes, brightdata integration #4190
Merged
@waleedlatif1
waleedlatif1 deleted the fix/chat-stream-bugs branch April 16, 2026 20:05

This branch was previously deployed

1 inactive deployment
Preview — c9565777 Deployed Apr 15, 2026 by vercel[bot]
View deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@greptile-apps greptile-apps[bot] greptile-apps[bot] left review comments
@cursor cursor[bot] cursor[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@icecrasher321
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.