Repository navigation
fix: recover stuck Control UI chat runs - #42258
siewcapital wants to merge 1 commit into
Conversation
Greptile SummaryThis PR introduces a client-side watchdog in the Control UI chat to detect and recover stuck chat runs when the terminal gateway event is missed. After 15 seconds of inactivity on an active run, the watchdog probes Key observations:
Confidence Score: 4/5
Last reviewed commit: 3fe0756 |
| } catch (err) { | ||
| host.lastError = String(err); | ||
| } finally { |
There was a problem hiding this comment.
Background probe failures bleed into lastError
When agent.wait throws a network exception, host.lastError = String(err) will surface that as a visible error banner to the user. Because this probe fires silently in the background (after 15 s of inactivity), a transient connection blip will show the user an unexpected error even when the primary run was not actually affected. The error persists until loadChatHistory clears it on the next successful probe cycle.
Consider suppressing this assignment (or routing it to a dedicated, non-visible field) and only escalating to lastError after a configurable number of consecutive failures:
| } catch (err) { | |
| host.lastError = String(err); | |
| } finally { | |
| } catch { | |
| // Swallow transient probe failures; the watchdog will retry automatically. | |
| } finally { |
Prompt To Fix With AI
This is a comment left during a code review.
Path: ui/src/ui/app-chat.ts
Line: 97-99
Comment:
**Background probe failures bleed into `lastError`**
When `agent.wait` throws a network exception, `host.lastError = String(err)` will surface that as a visible error banner to the user. Because this probe fires silently in the background (after 15 s of inactivity), a transient connection blip will show the user an unexpected error even when the primary run was not actually affected. The error persists until `loadChatHistory` clears it on the next successful probe cycle.
Consider suppressing this assignment (or routing it to a dedicated, non-visible field) and only escalating to `lastError` after a configurable number of consecutive failures:
```suggestion
} catch {
// Swallow transient probe failures; the watchdog will retry automatically.
} finally {
```
How can I resolve this? If you propose a fix, please make it concise.| if (changed.has("chatRunId")) { | ||
| if (host.chatRunId) { | ||
| scheduleChatRunWatchdog(host as unknown as Parameters<typeof scheduleChatRunWatchdog>[0]); | ||
| } else { | ||
| resetChatRunWatchdog(host as unknown as Parameters<typeof resetChatRunWatchdog>[0]); | ||
| } | ||
| } |
There was a problem hiding this comment.
Watchdog double-scheduled on every LitElement update cycle
handleUpdated calls scheduleChatRunWatchdog / resetChatRunWatchdog whenever chatRunId changes in the reactive property system. handleChatGatewayEvent in app-gateway.ts independently calls the same helpers for every incoming chat event. While scheduleChatRunWatchdog is idempotent (it cancels the previous timer before scheduling a new one), these two code paths both fire when a run starts or ends and the order depends on the LitElement microtask flush, which can make the effective idle timer slightly shorter than CHAT_RUN_WATCHDOG_IDLE_MS.
Specifically, when the first delta event arrives, noteChatRunActivity reschedules the timer and then — after the next LitElement flush — handleUpdated might reschedule it again from a slightly different Date.now(). This is harmless in practice but makes the scheduling logic harder to reason about. Adding a comment here explaining that this is the "start the watchdog for new sends initiated outside the gateway event path" case would help future readers distinguish the two scheduling sites.
Prompt To Fix With AI
This is a comment left during a code review.
Path: ui/src/ui/app-lifecycle.ts
Line: 94-100
Comment:
**Watchdog double-scheduled on every LitElement update cycle**
`handleUpdated` calls `scheduleChatRunWatchdog` / `resetChatRunWatchdog` whenever `chatRunId` changes in the reactive property system. `handleChatGatewayEvent` in `app-gateway.ts` independently calls the same helpers for every incoming chat event. While `scheduleChatRunWatchdog` is idempotent (it cancels the previous timer before scheduling a new one), these two code paths both fire when a run starts or ends and the order depends on the LitElement microtask flush, which can make the effective idle timer slightly shorter than `CHAT_RUN_WATCHDOG_IDLE_MS`.
Specifically, when the first `delta` event arrives, `noteChatRunActivity` reschedules the timer and then — after the next LitElement flush — `handleUpdated` might reschedule it again from a slightly different `Date.now()`. This is harmless in practice but makes the scheduling logic harder to reason about. Adding a comment here explaining that this is the "start the watchdog for new sends initiated outside the gateway event path" case would help future readers distinguish the two scheduling sites.
How can I resolve this? If you propose a fix, please make it concise.| if (payload.runId && state.chatRunId && payload.runId === state.chatRunId) { | ||
| state.chatRunLastActivityAt = Date.now(); | ||
| } |
There was a problem hiding this comment.
Redundant chatRunLastActivityAt write for delta events
handleChatEvent stamps state.chatRunLastActivityAt = Date.now() here for every matching event. For delta events the caller (handleChatGatewayEvent) then immediately calls noteChatRunActivity, which writes host.chatRunLastActivityAt a second time and reschedules the watchdog timer. The first write is harmless but creates noise when tracing state mutations.
For terminal events (final, aborted, error) handleChatEvent already clears chatRunId before returning, so handleChatGatewayEvent will call resetChatRunWatchdog which nulls out chatRunLastActivityAt anyway, making this write a no-op for those paths too.
Moving the activity stamp solely into noteChatRunActivity / the gateway layer (or keeping it here but removing the redundant call from handleChatGatewayEvent) would eliminate the duplication.
Prompt To Fix With AI
This is a comment left during a code review.
Path: ui/src/ui/controllers/chat.ts
Line: 286-288
Comment:
**Redundant `chatRunLastActivityAt` write for delta events**
`handleChatEvent` stamps `state.chatRunLastActivityAt = Date.now()` here for every matching event. For `delta` events the caller (`handleChatGatewayEvent`) then immediately calls `noteChatRunActivity`, which writes `host.chatRunLastActivityAt` a second time and reschedules the watchdog timer. The first write is harmless but creates noise when tracing state mutations.
For terminal events (`final`, `aborted`, `error`) `handleChatEvent` already clears `chatRunId` before returning, so `handleChatGatewayEvent` will call `resetChatRunWatchdog` which nulls out `chatRunLastActivityAt` anyway, making this write a no-op for those paths too.
Moving the activity stamp solely into `noteChatRunActivity` / the gateway layer (or keeping it here but removing the redundant call from `handleChatGatewayEvent`) would eliminate the duplication.
How can I resolve this? If you propose a fix, please make it concise.|
This pull request has been automatically marked as stale due to inactivity. |
|
Codex review: needs real behavior proof before merge. Workflow note: Future ClawSweeper reviews update this same comment in place. How this review workflow works
Summary Reproducibility: yes. at source level. Leave PR rating Rank-up moves:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. Real behavior proof Mantis proof suggestion Risk before merge
Maintainer options:
Next step before merge Security Review findings
Review detailsBest possible solution: Land a rebased Control UI recovery path that preserves current session reconciliation, uses the full Do we have a high-confidence way to reproduce the issue? Yes, at source level. Leave Is this the best way to solve the issue? No, not as currently patched. A UI-side Label justifications:
Full review comments:
Overall correctness: patch is incorrect Acceptance criteria:
What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against b8e9ab9385c0. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
|
This pull request has been automatically marked as stale due to inactivity. |
|
ClawSweeper 🐠 reef update Thanks for the work on this. ClawSweeper did not have permission to update this branch directly, so it opened a narrow replacement PR instead. that's a branch access thing, not a knock on the contribution. Why replacement: ClawSweeper could not update the source PR branch directly; GitHub did not grant sufficient push rights to the bot for that branch.
fish notes: model gpt-5.5, reasoning high; reviewed against ae868b7. |
Summary
agent.waitafter chat inactivity and recovers the UI when the gateway already considers the run finished.Change Type
Scope
Linked Issue/PR
User-visible / Behavior Changes
agent.waitstill reports the run as active, the UI keeps waiting and does not flush the queue early.Security Impact
NoNoNoNoNoYes, explain risk + mitigation:Repro + Verification
Environment
Steps
chatRunIdactive.Expected
agent.waitafter inactivity.Actual
Evidence
Human Verification
What you personally verified (not just CI), and how:
pnpm vitest run ui/src/ui/controllers/chat.test.ts,pnpm exec oxlint ui/src/ui/app-chat.ts ui/src/ui/app-lifecycle.ts ui/src/ui/app-gateway.ts ui/src/ui/app.ts ui/src/ui/controllers/chat.ts ui/src/ui/controllers/chat.test.ts,pnpm buildReview Conversations
Compatibility / Migration
YesNoNoFailure Recovery (if this breaks)
ui/src/ui/app-chat.tsui/src/ui/app-chat.ts,ui/src/ui/app-gateway.ts,ui/src/ui/app-lifecycle.ts,ui/src/ui/controllers/chat.tsRisks and Mitigations
agent.waitafter inactivity and could recover too aggressively if the inactivity threshold is wrongagent.waitreports terminal status, and keeps waiting when the run still reportstimeout