Skip to content

feat: add detached turn streams, turn catch-up and plan step closing - #193

Merged
SummonShenron merged 1 commit into
mainfrom
sonic/working-changes-2026-11-25
Nov 25, 2026
Merged

SummonShenron merged 1 commit into
mainfrom
sonic/working-changes-2026-11-25

Conversation

@SummonShenron

Copy link
Copy Markdown
Owner

Adds backend/utils/detached_stream.py and local/src/turnCatchUp.ts so a chat turn can keep running and be picked up after a reconnect, with steering and plan-step closing updates in agent_workflow.py, code_plan.py, steering.py and Chat.tsx, plus new tests.

Opened with Sonic Assistant.

Adds backend/utils/detached_stream.py and local/src/turnCatchUp.ts so a chat turn can keep running and be picked up after a reconnect, with steering and plan-step closing updates in agent_workflow.py, code_plan.py, steering.py and Chat.tsx, plus new tests.

Co-authored-by: Sonic Assistant <sonic-assistant@users.noreply.github.com>
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
saapp Ready Ready Preview Nov 25, 2026 1:11pm UTC

@SummonShenron

Copy link
Copy Markdown
Owner Author

Sonic Assistant PR Overview

Summary

This PR introduces detached turn streams to ensure chat replies continue generating even if the browser connection drops, preventing premature "[Stopped by user]" records. It also adds a mechanism to close plan steps that require no edits, allowing Sonic to mark steps as done independently and resolve stalls in the planning workflow.

What changed

  • Detached Streams:
    • backend/utils/detached_stream.py: Added relay to run turn generation in a background task, decoupling it from the HTTP connection.
    • app.py: Updated secure_chat to stop relying on connection status for termination; it now uses steering.stop_requested and handles 409 status codes when a turn is already in progress.
    • local/src/turnCatchUp.ts & local/src/pages/Chat.tsx: Added logic to detect interrupted streams, poll /api/chat/turn-status, and reload conversations once the background task completes.
  • Plan Step Closing:
    • backend/utils/code_plan.py: Implemented close_step and record_close to allow closing steps without edits, provided the files were read. Updated mark_applied to track file application across multiple proposals.
    • backend/services/agent_workflow.py: Added the close_plan_step tool to the agent's menu and implemented its execution logic.
  • Steering:
    • backend/services/steering.py: Added request_stop and stop_requested to explicitly manage turn termination, replacing the previous reliance on connection drops.

Where to look

  • backend/utils/detached_stream.py: The core implementation of the background task relay.
  • backend/utils/code_plan.py: The logic for close_step and the updated mark_applied state machine.
  • local/src/pages/Chat.tsx: The catchUpRef and useEffect hooks that manage UI state during detached turn execution.

Risks and gaps

  • The close_step function relies on read_paths to verify files were inspected; if the agent's file-tracking cache is inconsistent, steps might be closed prematurely.
  • The Chat.tsx component now keeps the chat page mounted to prevent background streams from being discarded; this increases memory usage for long-lived sessions.

Not fully covered by this overview (diff cut short: backend/utils/code_plan.py, app.py, backend/services/native_tools.py; not read: local/src/components/__styles__/PlanCard.css, local/src/App.tsx, backend/utils/self_counters.py, local/src/components/stepKinds.ts, backend/auth/guest_policy.py, local/src/components/PlanCard.tsx, backend/tests/test_plan_steps_close.py, backend/tests/test_detached_turns.py, ...).

Updated for commit 87947c3

@SummonShenron
SummonShenron merged commit d2c1563 into main Nov 25, 2026
3 of 4 checks passed

This branch was successfully deployed

1 active deployment
Preview — 87947c31 Deployed Nov 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants