fix(desktop): reduce idle polling and checkpoint turns - #9731
Open
wqshan-cn wants to merge 5 commits into
Open
Conversation
wqshan-cn
force-pushed
the
fix/idle-background-runtime-poll
branch
2 times, most recently
from
September 4, 2026 10:56
7e96905 to
52ac7c9
Compare
Emit(TurnDone) returned as soon as the final snapshot was scheduled, so a process exit immediately after a completed turn could lose the last transcript: the autosave loop and the display-only write retry goroutine were still running in the background. - add waitForTabSnapshot: TurnDone waits until the autosave loop drains its current write and any queued saveAgain pass - add waitForPendingDisplayWrites: TurnDone also waits for the flushed display-only text to finish its current persist attempt (bounded retries); mid-turn checkpoint events stay asynchronous - compare background runtime lists order-insensitively by tabId; the backend iterates a map, so identical runtimes in a different order must not trigger React state updates - regression tests: session content readable immediately after Emit(TurnDone) returns; reordered identical runtime lists compare equal
wqshan-cn
force-pushed
the
fix/idle-background-runtime-poll
branch
from
September 5, 2026 01:47
52ac7c9 to
6a2d086
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Improve two desktop reliability paths:
TurnStartedas an unsafe proxy, and makeTurnDonea real persistence barrier.BackgroundRuntimesbridge polling and prevent overlapping requests. The session-catalog repair-loop CPU root cause is handled separately by merged PR fix(sessioncatalog): stop idle CPU repair loops / 根治空闲历史修复满核 #9697; this PR does not claim to fix that loop itself.Changes
TurnStartedas a lifecycle signal, then emitturn_phase=workingonly after the user message is in the session; desktop autosave checkpoints that post-append boundary.TurnDone.Emit(TurnDone)now waits until (a) the autosave loop drains its current write plus any queuedsaveAgainpass (waitForTabSnapshot), and (b) the flushed display-only text finishes its current persist attempt including bounded retries (waitForPendingDisplayWrites). A process exit immediately after a completed turn can no longer lose the final transcript. Mid-turn checkpoint events stay asynchronous — no per-token disk writes.BackgroundRuntimesfrom Go maps whose iteration order is unstable, sosameBackgroundRuntimeListsnow compares bytabIdinstead of by array position; identical runtimes no longer trigger redundant React state updates.WorkspaceConflictForTabrequests and lower its fallback cadence to 1.5 seconds.Emit(TurnDone)returns (TestTurnDoneWaitBlocksUntilSnapshotWritten), and reordered identical runtime lists compare equal.Verification
go test ./internal/agent ./internal/control -count=1passed (after rebase ontoupstream/main-v2@c01ec347b).TestScheduleSnapshotCoalesces,TestCloseTabNoResurrectionFromAutosave, and the cannot-persist guard tests.background-runtime-refresh.test.tspassed (including the new order-insensitivity assertion).tsc --noEmitpassed after regenerating the local (gitignored) Wails bindings for this branch — earlier failures came from stale generated bindings left behind by the feat(subagents): allow per-profile max-steps cap #9659 work, not from PR code.git diff --checkpassed.Documentation-impact: none - this change affects internal desktop polling and persistence behavior; existing user-facing documentation does not describe these implementation details.
Cache-impact: none - no provider prompt, tool schema, or cache-prefix behavior changes.
Cache-guard:
go test ./internal/agent ./internal/control -count=1, the focused desktop autosave tests (including the newTestTurnDoneWaitBlocksUntilSnapshotWrittenbarrier regression), andbackground-runtime-refresh.test.tscover checkpoint ordering, the TurnDone persistence barrier, order-insensitive runtime comparison, refresh coalescing, retry behavior, and disposal.System-prompt-review: no system-prompt or agent-instruction templates are touched; all changes are desktop event-sink persistence, autosave scheduling, and frontend refresh coordination.