Skip to content

fix: stop working timer when turn completes despite stale session status#1348

Closed
rdoupe wants to merge 4 commits intopingdotgg:mainfrom
rdoupe:fix/working-timer-pending-user-input
Closed

fix: stop working timer when turn completes despite stale session status#1348
rdoupe wants to merge 4 commits intopingdotgg:mainfrom
rdoupe:fix/working-timer-pending-user-input

Conversation

@rdoupe
Copy link

@rdoupe rdoupe commented Mar 24, 2026

What Changed

Two locations showed a stale "Working" state after the agent finished responding:

  1. ChatView.tsx — "Working for Xm Xs" timer in the main chat area
  2. Sidebar.logic.ts — "Working" pill on thread list items

Root Cause

The server's shouldApplyThreadLifecycle guard in ProviderRuntimeIngestion.ts can reject turn.completed events when turn IDs don't match. When this happens:

  • session.status stays stuck on "running" indefinitely
  • session.activeTurnId becomes permanently stale

However, latestTurn.completedAt is set through a separate, independent path (thread.turn.diff.complete) that bypasses this guard — so the frontend has a reliable signal that the turn is done.

Fix

Use completedAt on the latest turn as the reliable completion signal, rather than depending solely on session.status:

// ChatView.tsx
const turnDone = !!activeLatestTurn?.completedAt;
const isActivelyRunning =
  phase === "running" && pendingUserInputs.length === 0 && !turnDone;
const isWorking = isActivelyRunning || isSendBusy || isConnecting || isRevertingCheckpoint;

// Sidebar.logic.ts
const sidebarTurnDone = !!thread.latestTurn?.completedAt;
if (thread.session?.status === "running" && !sidebarTurnDone) { ... }

This also correctly suppresses the working indicator when the agent is blocked waiting for user input (pendingUserInputs.length > 0), since that check was already present.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes

Fixes #1069, closes #1335

The isWorking flag was computed before pendingUserInputs, so it never
accounted for the agent being in a paused state waiting for user input.
This caused the "Working for Xm Xs" timer to keep counting indefinitely
even after the agent had asked a question and was no longer actively running.

Fixes pingdotgg#1069, closes pingdotgg#1335

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a91c5dde-af0a-4b9b-b76e-6655817aa2ca

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@github-actions github-actions bot added size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Mar 24, 2026
@rdoupe rdoupe marked this pull request as draft March 24, 2026 03:41
Two locations showed stale "Working" state after the agent finished:

1. ChatView.tsx - "Working for Xm Xs" timer in the main chat
2. Sidebar.logic.ts - "Working" pill on thread list items

Root cause: both checked only session.status === "running", but the
server can lag in transitioning that status even after the latest turn
has a completedAt timestamp. Also, neither checked for pending user
inputs, so the timer kept running when the agent was blocked waiting
for the user to answer a question.

Fix: suppress "working" state when latestTurn.completedAt is set
(turn is done regardless of server status lag), or when there are
pending user inputs (agent is waiting, not working).

Fixes pingdotgg#1069, closes pingdotgg#1335

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added size:S 10-29 changed lines (additions + deletions). and removed size:XS 0-9 changed lines (additions + deletions). labels Mar 24, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added size:XS 0-9 changed lines (additions + deletions). and removed size:S 10-29 changed lines (additions + deletions). labels Mar 24, 2026
The server lifecycle guard (shouldApplyThreadLifecycle) can reject
turn.completed events, leaving session.status stuck on "running" and
activeTurnId permanently stale. Since completedAt is set through an
independent path (thread.turn.diff.complete), it reliably indicates
turn completion regardless of session status lag.

Extract turnDone variable and add comments explaining the root cause.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rdoupe rdoupe changed the title fix: stop working timer when agent is awaiting user input fix: stop working timer when turn completes despite stale session status Mar 24, 2026
@github-actions github-actions bot added size:S 10-29 changed lines (additions + deletions). and removed size:XS 0-9 changed lines (additions + deletions). labels Mar 24, 2026
@sfncore
Copy link

sfncore commented Mar 24, 2026

Just made a PR related to this as well. Below is message from Claude:

Interesting — PR #1348 is a different
fix for the same root cause we
identified. They took the frontend
approach: use latestTurn.completedAt as
the reliable completion signal instead
of trusting session.status.

Their fix is a workaround (frontend
compensates for the stale session
status). Our fix (#1364) addresses the
root cause (server-side: always apply
turn.completed so session status
actually transitions to "ready").

Both fixes are complementary — theirs
makes the UI resilient even if the
server state is stale, ours prevents the
server state from getting stale in the
first place. Together they'd provide
defense in depth.

@rdoupe
Copy link
Author

rdoupe commented Mar 24, 2026

Just made a PR related to this as well. Below is message from Claude:

Interesting — PR #1348 is a different fix for the same root cause we identified. They took the frontend approach: use latestTurn.completedAt as the reliable completion signal instead of trusting session.status.

Their fix is a workaround (frontend compensates for the stale session status). Our fix (#1364) addresses the root cause (server-side: always apply turn.completed so session status actually transitions to "ready").

Both fixes are complementary — theirs makes the UI resilient even if the server state is stale, ours prevents the server state from getting stale in the first place. Together they'd provide defense in depth.

@sfncore

feel free to snag all or part of this if you want. found out this version doesn't actually start the Working text correctly in the chat or the sidebar. working on it again, lets see what else I find.

@rdoupe
Copy link
Author

rdoupe commented Mar 24, 2026

I've confirmed through human testing the backend only fix in #1364 is working correctly to my taste.

I'm going to close this issue.

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

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Working timer continues when the agent asks a question [Bug]: Main timeline keeps counting "Working for X" while thread is awaiting user input

2 participants