Skip to content

[fix] Fetch remote-run records immediately and once more when the run ends [#5624] - #5629

Open
mmabrouk wants to merge 1 commit into
mainfrom
fix/5624-remote-run-stopgaps
Open

[fix] Fetch remote-run records immediately and once more when the run ends [#5624]#5629
mmabrouk wants to merge 1 commit into
mainfrom
fix/5624-remote-run-stopgaps

Conversation

@mmabrouk

@mmabrouk mmabrouk commented Aug 1, 2026

Copy link
Copy Markdown
Member

Stopgap for #5624, per the triage decision: close the reported reproduction now with the two smallest possible changes; the real fix (a records-count endpoint, option A on the issue) is scheduled separately and retires both this patch's polling cost and #5609.

Context

Open the same session in two tabs, send a message in tab 1, switch to tab 2: tab 2 shows neither the message nor the answer, indefinitely. Archiving and unarchiving was the only workaround, because it remounts the conversation.

The watermark adoption guard from #5589 is correct. The gap is the triggers around the remote-run poll in useSessionHydration.ts:

  • The poll's first fetch was armed with setTimeout(poll, delay) at 15 seconds. Most turns finish sooner.
  • The effect cleanup cancels the pending timer the moment runningElsewhere flips false. A run ending between ticks discards the pending fetch.

Together: short runs were often fetched zero times. Full analysis and the backend fix ladder are on #5624.

Changes

Two changes in one file, both feeding the existing guarded adoption:

  1. The first poll tick fires immediately instead of after 15 seconds. The chained-timeout shape and backoff are unchanged; only the initial arm becomes a direct call.
  2. A new falling-edge effect runs one final guarded fetch when runningElsewhere flips from true to false, so records written between the last tick and the run's end still land. The previous-state ref also tracks sessionId, so switching sessions cannot fire a spurious edge for the wrong session; and since adoption is guarded by the record watermark, an extra read is harmless by construction.

Before: tab notices run at t=0, first fetch scheduled t=15s, run ends t=8s, fetch cancelled, transcript stale until remount.
After: fetch at t=0 (user message appears), ticks while running, one final fetch at t=8s (answer appears).

Tests

What to QA

  • Two tabs, same session: send a short message in tab 1, switch to tab 2 within a few seconds. Tab 2 shows the user message near-instantly and the answer within moments of the run finishing, with no archive tricks.
  • Regression: a long run (>30s) still shows the "running elsewhere" strip in tab 2 and keeps catching up while it runs; when it ends, the tail is present.
  • Regression: switching tab 2 to a different agent's session mid-run does not fetch the old session (the falling-edge guard is per-session).

Closes nothing; #5624 stays open for the scheduled records-count endpoint.

https://claude.ai/code/session_01R1ExBrpDc3rFVeuwKw4ucs

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Aug 1, 2026
@vercel

vercel Bot commented Aug 1, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview Aug 1, 2026 2:57pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Remote-run status updates now appear immediately without waiting for the first polling interval.
    • The final transcript is fetched when a remote run finishes, ensuring the latest messages are displayed.
    • Improved transcript updates avoid unnecessary scroll jumps.

Walkthrough

The session hydration hook now fetches remote-run data immediately. When runningElsewhere changes from true to false, it performs one guarded final transcript fetch without re-arming scroll jumps.

Changes

Remote transcript hydration

Layer / File(s) Summary
Polling and final transcript adoption
web/oss/src/components/AgentChatSlice/hooks/useSessionHydration.ts
Remote-run polling invokes its first fetch immediately. A falling edge of runningElsewhere triggers one guarded final transcript fetch, suppresses scroll jumps, and cancels adoption during cleanup.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • Agenta-AI/agenta#5589: Extends the same remote-run polling and transcript-adoption logic in useSessionHydration.ts.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the immediate and end-of-run fetching changes for remote-run records.
Description check ✅ Passed The description directly explains the stale transcript issue, implemented changes, testing limits, and QA coverage.
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 fix/5624-remote-run-stopgaps

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

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
web/oss/src/components/AgentChatSlice/hooks/useSessionHydration.ts (1)

237-240: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Add regression coverage for the new timing and cancellation paths.

Cover these cases:

  • runningElsewhere starts as true: the first fetch starts without a 15-second delay.
  • runningElsewhere changes from true to false: one final fetch adopts with {armJump: false}.
  • sessionId changes: the falling-edge effect does not fetch the previous session.
  • Cleanup runs before loadSessionMessages resolves: neither callback adopts a transcript.

Also verify that the poll timer is canceled and that a new session starts its own polling cycle.

Also applies to: 249-268


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e7b23556-6eba-4eec-86cb-cee3de010296

📥 Commits

Reviewing files that changed from the base of the PR and between 7c395db and 4fa13d5.

📒 Files selected for processing (1)
  • web/oss/src/components/AgentChatSlice/hooks/useSessionHydration.ts

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Railway Preview Environment

Preview URL https://gateway-production-83d7.up.railway.app/w
Project agenta-oss-pr-5629
Image tag pr-5629-d3330fb
Status Deployed
Railway logs Open logs
Workflow logs View workflow run
Updated at 2026-08-01T15:09:23.314Z

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

Labels

Bug Report Something isn't working Frontend size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant