Skip to content

fix(studio): Code Agent stream interruptions when navigating Studio - #552

Merged
htolentino-nvidia merged 3 commits into
mainfrom
studio-code-agent-fix-disconnections/htolentino
Jul 6, 2026
Merged

fix(studio): Code Agent stream interruptions when navigating Studio#552
htolentino-nvidia merged 3 commits into
mainfrom
studio-code-agent-fix-disconnections/htolentino

Conversation

@htolentino-nvidia

@htolentino-nvidia htolentino-nvidia commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes
    • Improved Claude Code chat stability by detecting premature/unexpected stream completion and showing a clearer “connection interrupted” message.
    • Added periodic server SSE keepalives when events are idle to prevent the stream from appearing stalled.
    • Reduced unnecessary rerenders during chat run handling by removing render-time path capture.
  • Tests
    • Updated Claude Code chat streaming tests to consistently signal completion with explicit stream-done handling.
  • Refactor
    • Simplified a chat runtime message conversion helper while keeping behavior unchanged.

@htolentino-nvidia
htolentino-nvidia requested review from a team as code owners July 2, 2026 19:31
@github-actions github-actions Bot added the fix label Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 852bcbe7-9555-4e6e-ac17-66dfdea36a7f

📥 Commits

Reviewing files that changed from the base of the PR and between 19e4366 and 9ace72f.

📒 Files selected for processing (4)
  • services/studio/src/nmp/studio/coding_agents.py
  • web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useClaudeCodeChatRuntime.test.ts
  • web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useClaudeCodeChatRuntime.ts
  • web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useCustomAssistantChatRuntime.ts
💤 Files with no reviewable changes (4)
  • web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useCustomAssistantChatRuntime.ts
  • web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useClaudeCodeChatRuntime.ts
  • services/studio/src/nmp/studio/coding_agents.py
  • web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useClaudeCodeChatRuntime.test.ts

📝 Walkthrough

Walkthrough

Claude Code streaming now tracks explicit stream completion, the backend emits SSE keepalives on idle queue waits, and the custom assistant runtime reuses a named convertMessage helper. Tests were updated to complete mocked streams with onDone().

Changes

Claude Code streaming onDone handling

Layer / File(s) Summary
Runtime: studioPathname ref and onDone completion check
web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useClaudeCodeChatRuntime.ts
Adds studioPathnameRef, passes it to streamClaudeCodeMessage, throws an interruption error when onDone was not received, and removes the direct studioPathname dependency from handleRun.
Tests: drive mock streams via handlers.onDone()
web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useClaudeCodeChatRuntime.test.ts
Adds onDone to test handler interfaces and updates permission, input, and AskUserQuestion stream mocks to complete via handlers.onDone().

MCP keepalive emission

Layer / File(s) Summary
Timed queue wait and keepalive emit
services/studio/src/nmp/studio/coding_agents.py
Changes _stream_claude to time out on queue.get() and emit ":\n\n" before continuing.

convertMessage extraction

Layer / File(s) Summary
Named convertMessage helper
web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useCustomAssistantChatRuntime.ts
Extracts the inline converter into a named convertMessage constant and reuses it in the runtime object.

Sequence Diagram(s)

sequenceDiagram
  participant UI
  participant handleRun
  participant streamClaudeCodeMessage

  UI->>handleRun: trigger run
  handleRun->>streamClaudeCodeMessage: stream(studioPathnameRef.current, handlers)
  streamClaudeCodeMessage-->>handleRun: onDone()
  alt onDone missing and not aborted
    handleRun->>UI: throw interruption Error
  end
Loading

Possibly related PRs

Suggested reviewers: dmariali

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: fixing Code Agent stream interruptions while navigating Studio.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch studio-code-agent-fix-disconnections/htolentino

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useClaudeCodeChatRuntime.test.ts (1)

247-251: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Repeated inline handler types instead of shared interfaces.

These tests redefine { onPermissionRequest/onInputRequest; onDone } inline, duplicating the already-defined PermissionRequestTestHandlers/InputRequestTestHandlers interfaces used elsewhere in this file.

Also applies to: 304-308, 417-421, 550-554, 654-658

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useClaudeCodeChatRuntime.test.ts`
around lines 247 - 251, The test callbacks in useClaudeCodeChatRuntime.test.ts
are repeating inline handler object types instead of reusing the existing shared
interfaces. Update the affected async handler signatures to use the
already-defined PermissionRequestTestHandlers and InputRequestTestHandlers types
(and their shared onDone shape where applicable) so the tests stay consistent
and avoid duplicated type definitions.
web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useClaudeCodeChatRuntime.ts (1)

393-396: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Ref sync during render — minor nit.

Assigning studioPathnameRef.current in the render body works but technically mutates outside the commit phase. Fine in practice for this "latest ref" pattern; consider moving to a layout effect if strict-mode purity ever becomes a concern.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useClaudeCodeChatRuntime.ts`
around lines 393 - 396, The latest-value ref sync for studioPathnameRef is being
done during render, which mutates state outside the commit phase. Update
useClaudeCodeChatRuntime to keep the ref in sync inside a layout effect instead
of assigning studioPathnameRef.current directly in the render body, and preserve
the existing onSessionIdChange/studioPathname handling around that ref.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useClaudeCodeChatRuntime.test.ts`:
- Around line 247-251: The test callbacks in useClaudeCodeChatRuntime.test.ts
are repeating inline handler object types instead of reusing the existing shared
interfaces. Update the affected async handler signatures to use the
already-defined PermissionRequestTestHandlers and InputRequestTestHandlers types
(and their shared onDone shape where applicable) so the tests stay consistent
and avoid duplicated type definitions.

In
`@web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useClaudeCodeChatRuntime.ts`:
- Around line 393-396: The latest-value ref sync for studioPathnameRef is being
done during render, which mutates state outside the commit phase. Update
useClaudeCodeChatRuntime to keep the ref in sync inside a layout effect instead
of assigning studioPathnameRef.current directly in the render body, and preserve
the existing onSessionIdChange/studioPathname handling around that ref.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e58ac827-acf1-4946-9afc-bae363cf4208

📥 Commits

Reviewing files that changed from the base of the PR and between bd70579 and 57c3b2f.

📒 Files selected for processing (3)
  • web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useClaudeCodeChatRuntime.test.ts
  • web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useClaudeCodeChatRuntime.ts
  • web/packages/studio/src/routes/agents/ClaudeCodeChatRoute/useCustomAssistantChatRuntime.ts

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 23089/30221 76.4% 61.3%
Integration Tests 13258/28901 45.9% 19.1%

@htolentino-nvidia
htolentino-nvidia force-pushed the studio-code-agent-fix-disconnections/htolentino branch from 57c3b2f to 19e4366 Compare July 2, 2026 20:56
htolentino-nvidia and others added 3 commits July 6, 2026 10:31
Signed-off-by: Henrique Tolentino <htolentino@nvidia.com>
Signed-off-by: Henrique Tolentino <htolentino@nvidia.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Henrique Tolentino <htolentino@nvidia.com>
@htolentino-nvidia
htolentino-nvidia force-pushed the studio-code-agent-fix-disconnections/htolentino branch from 19e4366 to 9ace72f Compare July 6, 2026 14:33
@htolentino-nvidia
htolentino-nvidia added this pull request to the merge queue Jul 6, 2026
Merged via the queue into main with commit 345f0e7 Jul 6, 2026
55 checks passed
@htolentino-nvidia
htolentino-nvidia deleted the studio-code-agent-fix-disconnections/htolentino branch July 6, 2026 20:03
arpitsardhana pushed a commit that referenced this pull request Jul 9, 2026
…552)

* Fix Code Agent stream interruptions when navigating Studio

Signed-off-by: Henrique Tolentino <htolentino@nvidia.com>

* Add keep alive

Signed-off-by: Henrique Tolentino <htolentino@nvidia.com>

* Fix lint formatting in coding_agents.py

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Henrique Tolentino <htolentino@nvidia.com>

---------

Signed-off-by: Henrique Tolentino <htolentino@nvidia.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants