Skip to content

fix(sessions): preserve live transcript and settle reader activity - #6591

Open
mmabrouk wants to merge 3 commits into
release/v0.115.2from
fix/release-1152-session-reader
Open

fix(sessions): preserve live transcript and settle reader activity#6591
mmabrouk wants to merge 3 commits into
release/v0.115.2from
fix/release-1152-session-reader

Conversation

@mmabrouk

@mmabrouk mmabrouk commented Sep 5, 2026

Copy link
Copy Markdown
Member

Context

With shared session delivery enabled, the sending tab could show only activity dots while another tab displayed tool results. Streamed text could also disappear when a durable record arrived, and observers could remain busy after the run finished.

Changes

Allow the shared sender to adopt saved content while its accepted run is active. Keep temporary text visible until the corresponding saved output has been adopted, preserving unrelated streaming content and its frame cursor. Preserve the message identifier when the runner saves a completed streamed message.

Project the runner's existing done record into the terminal event the reader understands, and refresh stale running status after completion. Cancel obsolete reconnect timers when a fresh connection starts. Show normal activity during a reconnect while preserving the remote Stop action.

How to review

Start with the runner persistence identifier and API terminal projection, then the shared preview reducer and reader hook. The desktop hydration guard and desktop/mobile presentation consume those changes.

Tests

  • 48 focused API tests pass, covering terminal projection, publication after commit, durability, and relay behavior.
  • Focused frontend tests: 55 shared-reader, 41 desktop, and 14 mobile checks pass. Chat/mobile types and all 25 lint tasks pass. Runner persistence tests and types pass.
  • Independent review passed. Live two-client verification is pending; this is not yet a release-readiness claim.
  • This fix adds no migration beyond milestone 3 and changes no production flags.

What to QA

With shared delivery enabled, open the same session in two clients. Run a turn with streamed text and a failing tool: both clients should retain the text and display the tool error as saved records arrive. Both should stop showing activity when the turn completes.

Disconnect the reader, return to the tab, and wait beyond the previous five-second retry. The healthy connection should remain open. Then run another turn, approve a paused tool, and exercise Stop; content and controls should continue working without a reload.

@vercel

vercel Bot commented Sep 5, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
agenta-documentation Ready Ready Preview Sep 5, 2026 11:33pm UTC

Request Review

@mmabrouk

mmabrouk commented Sep 5, 2026

Copy link
Copy Markdown
Member Author

🤖 The AI agent says:

Independent review of this fix against the merged milestone-3 code found no blocking issue. Focused regression tests cover sender hydration, pending transcript adoption, reconnect snapshots, obsolete retry timers, natural terminal events, and same-session resume. Live sender/observer verification is still pending.

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 5, 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: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Team

Run ID: f56ff037-ba4b-4577-82dc-d667cceb432a

📥 Commits

Reviewing files that changed from the base of the PR and between fab59e4 and a6f2795.

📒 Files selected for processing (2)
  • web/mobile/src/features/chat/LiveConversation.tsx
  • web/packages/agenta-chat/tests/unit/hooks/useServerSessionInputs.test.ts
💤 Files with no reviewable changes (1)
  • web/packages/agenta-chat/tests/unit/hooks/useServerSessionInputs.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/mobile/src/features/chat/LiveConversation.tsx

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Summary

Summary by CodeRabbit

  • New Features

    • Completed and stopped executions now appear reliably in session activity, including their completion reason.
    • Remote runs now provide a clear Stop control instead of a “running elsewhere” banner.
    • Live conversation state refreshes when shared execution settles.
  • Bug Fixes

    • Improved live-preview reconciliation during reconnects, hydration, retries, and terminal events.
    • Preserved streamed content and message identifiers when adopting durable conversation history.
    • Prevented stale updates from overwriting newer conversation state.
    • Improved hydration while shared executions are accepted and local streaming is active.

Walkthrough

The change maps runner completion records to durable terminal events, preserves source message identifiers, and reworks live-preview retirement, hydration, liveness, and remote-stop presentation across web and mobile clients.

Changes

Session execution flow

Layer / File(s) Summary
Durable record event mapping
api/oss/src/core/sessions/*, services/runner/src/sessions/*
done records now emit execution.stopped events. Coalesced message and thought records preserve their source message_id.
Live-preview state and retirement
web/packages/agenta-entities/src/session/state/livePreview.ts, web/packages/agenta-chat/src/model/livePreview.ts, web/packages/agenta-chat/tests/unit/model/livePreview.test.ts
Live-preview state tracks complete, incomplete, retired, and terminal entities. Gap handling and durable reconciliation use selective retirement.
Hydration and reconnect orchestration
web/packages/agenta-chat/src/hooks/useSessionLivePreview.ts, web/packages/agenta-chat/tests/unit/hooks/useSessionLivePreview.test.tsx
Hydration preserves active preview content, tracks shared settlement, rejects stale reader generations, and reconciles bounded transcripts after reconnects.
Conversation liveness and remote stop presentation
web/packages/agenta-chat/src/hooks/useAgentConversation.ts, web/oss/src/components/AgentChatSlice/*, web/mobile/src/features/chat/LiveConversation.tsx, web/mobile/tests/unit/turnStatus.test.ts
Conversation state exposes settlement timestamps and refreshes liveness. Remote-stop presentation uses reader freshness, snapshot state, and owned continuations. The running-elsewhere strip is removed.

Estimated code review effort: 4 (Complex) | ~60 minutes

Merge Risk: ⚪ Minimal · up to a6f27

This change improves shared-session streaming handoff, completion status, reconnect behavior, and remote Stop presentation. Focused regression coverage is reported passing, with no current merge-blocking risk identified.

Sequence Diagram(s)

sequenceDiagram
  participant Reader
  participant useSessionLivePreview
  participant LivePreview
  participant DurableTranscript
  Reader->>useSessionLivePreview: Receive terminal event or reconnect
  useSessionLivePreview->>LivePreview: Mark execution terminal
  useSessionLivePreview->>DurableTranscript: Fetch bounded transcript
  DurableTranscript-->>useSessionLivePreview: Return transcript and covered entities
  useSessionLivePreview->>LivePreview: Retire covered entities
  useSessionLivePreview-->>Reader: Expose settled preview state
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 60.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 18 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: preserving live transcript content and correctly settling reader activity for shared sessions.
Description check ✅ Passed The description is directly related to the changeset. It explains the shared session delivery issues, implementation changes, tests, and remaining live verification.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/release-1152-session-reader

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.

❤️ Share

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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Team

Run ID: cd38c858-9f22-4b44-86ba-1e2da73300b2

📥 Commits

Reviewing files that changed from the base of the PR and between 78e5810 and 832a344.

📒 Files selected for processing (21)
  • api/oss/src/core/sessions/records/events.py
  • api/oss/tests/pytest/unit/sessions/test_durable_events.py
  • api/oss/tests/pytest/unit/sessions/test_records_worker_batching.py
  • services/runner/src/sessions/persist.ts
  • services/runner/tests/unit/session-persist.test.ts
  • web/mobile/src/features/chat/LiveConversation.tsx
  • web/mobile/tests/unit/turnStatus.test.ts
  • web/oss/src/components/AgentChatSlice/AgentConversation.tsx
  • web/oss/src/components/AgentChatSlice/components/AgentComposerDock.tsx
  • web/oss/src/components/AgentChatSlice/hooks/useAgentChatSession.test.ts
  • web/oss/src/components/AgentChatSlice/hooks/useAgentChatSession.ts
  • web/oss/src/components/AgentChatSlice/state/liveness.test.ts
  • web/oss/src/components/AgentChatSlice/state/liveness.ts
  • web/packages/agenta-chat/src/components/RunningElsewhereStrip.tsx
  • web/packages/agenta-chat/src/components/index.ts
  • web/packages/agenta-chat/src/hooks/useAgentConversation.ts
  • web/packages/agenta-chat/src/hooks/useSessionLivePreview.ts
  • web/packages/agenta-chat/src/model/livePreview.ts
  • web/packages/agenta-chat/tests/unit/hooks/useSessionLivePreview.test.tsx
  • web/packages/agenta-chat/tests/unit/model/livePreview.test.ts
  • web/packages/agenta-entities/src/session/state/livePreview.ts
💤 Files with no reviewable changes (3)
  • web/packages/agenta-chat/src/components/index.ts
  • web/packages/agenta-chat/src/components/RunningElsewhereStrip.tsx
  • web/oss/src/components/AgentChatSlice/components/AgentComposerDock.tsx

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Comment thread web/mobile/src/features/chat/LiveConversation.tsx Outdated
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

@mmabrouk I will review the changes in #6591. I will also check the shared-session behavior and the pending live sender/observer scenario.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Railway Preview Environment

Preview URL https://gateway-pr-6591.up.railway.app/w
Project agenta-oss-clone-spike
Image tag pr-6591-c18e624
Status Deployed
Railway logs Open logs
Workflow logs View workflow run
Updated at 2026-09-05T23:43:28.392Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant