Skip to content

fix(tui): clear stale streaming after orphaned finals#72389

Merged
vincentkoc merged 3 commits intomainfrom
clownfish/ghcrawl-199270-agentic-merge
Apr 28, 2026
Merged

fix(tui): clear stale streaming after orphaned finals#72389
vincentkoc merged 3 commits intomainfrom
clownfish/ghcrawl-199270-agentic-merge

Conversation

@vincentkoc
Copy link
Copy Markdown
Member

Summary

Review findings addressed

  • Greptile: add a regression test that actually reaches the orphan-clear branch.
  • Codex: avoid propagating inactive-run failures to the global status.
  • Codex: avoid forcing idle after unrelated inactive finals.
  • Codex: restore deferred history refresh for overlapping local runs.

Validation

  • pnpm -s vitest run src/tui/tui-event-handlers.test.ts
  • pnpm check:changed

Refs: #52745, cluster ghcrawl-199270-agentic-merge.

ProjectClownfish replacement details:

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 26, 2026

Greptile Summary

This PR repairs the TUI orphaned-streaming-state path: when an inactive final event arrives with no live tracked run in sessionRuns, it now clears the stale activeChatRunId and resets activityStatus to "idle" without surfacing the inactive run's error status or disturbing an overlapping concurrent run. Three regression tests cover the new branch.

One P2 to watch: flushPendingHistoryRefreshIfIdle is invoked earlier in finalizeRun/terminateRun while activeChatRunId is still non-null, so it bails early. After the stale clear nulls activeChatRunId, flushPendingHistoryRefreshIfIdle is never called again — meaning a pendingHistoryRefresh deferred from a prior concurrent local run would remain stuck until the next chat event.

Confidence Score: 4/5

Safe to merge; the orphan-clear logic is correct and well-tested — one P2 edge case around a deferred history refresh not being flushed after stale-clear.

Only P2 findings present. Core logic is sound with three targeted regression tests. The missed flushPendingHistoryRefreshIfIdle call is a niche edge case (orphan final + prior deferred local-run refresh) and doesn't cause data loss or UI corruption.

src/tui/tui-event-handlers.ts — specifically clearStaleStreamingRunIfNoTrackedRunRemains, lines 197–210.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/tui/tui-event-handlers.ts
Line: 197-210

Comment:
**Stale-clear doesn't flush pending history refresh**

`clearStaleStreamingRunIfNoTrackedRunRemains` sets `activeChatRunId = null` after `flushPendingHistoryRefreshIfIdle` has already been called (and bailed early because `activeChatRunId` was still non-null). If `pendingHistoryRefresh` is `true` from a prior deferred local run, the reload is stuck until the next chat event arrives — and never fires if no further events come in.

This arises when: a local run deferred its history refresh (because a concurrent active run was present), that concurrent run went stale without a tracked final, and then an orphan final triggers the stale-clear path.

Adding `flushPendingHistoryRefreshIfIdle()` after nulling `activeChatRunId` would drain the deferred refresh:

```ts
state.activeChatRunId = null;
setActivityStatus("idle");
clearStreamingWatchdog();
flushPendingHistoryRefreshIfIdle();
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(tui): clear stale streaming after or..." | Re-trigger Greptile

Comment thread src/tui/tui-event-handlers.ts
@vincentkoc vincentkoc added the clawsweeper Tracked by ClawSweeper automation label Apr 27, 2026
@vincentkoc vincentkoc force-pushed the clownfish/ghcrawl-199270-agentic-merge branch 2 times, most recently from 88c5422 to 7905560 Compare April 27, 2026 06:02
@vincentkoc
Copy link
Copy Markdown
Member Author

ProjectClownfish pushed a narrow repair to this branch so the original contributor path can stay canonical.

Source PR: #72389
Validation: pnpm -s vitest run src/tui/tui-event-handlers.test.ts; pnpm check:changed
Contributor credit is preserved in the branch history and PR context.

@vincentkoc vincentkoc force-pushed the clownfish/ghcrawl-199270-agentic-merge branch from 7905560 to eb72137 Compare April 27, 2026 22:46
@vincentkoc
Copy link
Copy Markdown
Member Author

ProjectClownfish pushed a narrow repair to this branch so the original contributor path can stay canonical.

Source PR: #72389
Validation: pnpm -s vitest run src/tui/tui-event-handlers.test.ts; pnpm check:changed
Contributor credit is preserved in the branch history and PR context.

@vincentkoc vincentkoc force-pushed the clownfish/ghcrawl-199270-agentic-merge branch from eb72137 to b182228 Compare April 28, 2026 05:22
@vincentkoc vincentkoc merged commit d7e67b4 into main Apr 28, 2026
57 checks passed
@vincentkoc vincentkoc deleted the clownfish/ghcrawl-199270-agentic-merge branch April 28, 2026 05:23
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
* fix(tui): clear stale streaming after orphaned finals

* fix(tui): clear stale streaming after orphaned finals

* fix(tui): clear stale streaming after orphaned finals
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
* fix(tui): clear stale streaming after orphaned finals

* fix(tui): clear stale streaming after orphaned finals

* fix(tui): clear stale streaming after orphaned finals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper Tracked by ClawSweeper automation maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant