fix(agent): persist canonical todo state across tab switches and restarts#4159
Open
JesonChou wants to merge 1 commit into
Open
fix(agent): persist canonical todo state across tab switches and restarts#4159JesonChou wants to merge 1 commit into
JesonChou wants to merge 1 commit into
Conversation
…arts Builds on esengine#4132 (unique host-advance IDs) by fixing the remaining half of esengine#4105: host-advance events were emitted in real time but never persisted, so the TodoPanel reverted on tab switch or restart. Add HistoryWithCanonicalTodos that injects the canonical task list into the history response, and EmitCanonicalTodoState that pushes it via the live stream, covering both history-load and cached-tab-switch paths. Closes esengine#4105. Regression: internal/agent PASS internal/agent/testutil PASS internal/control PASS (1 pre-existing MCP env failure) internal/serve PASS (1 pre-existing HTML lang failure) internal/evidence PASS Full ./... PASS (9 pre-existing env failures unchanged)
320bad1 to
8a14c67
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.
Builds on #4132 · Closes #4105
Description
Relationship to #4132
#4132 fixed the host-advance ID collision (static
"host-advance"→ uniquehost-advance-{seq}-{idx}), ensuring multiplecomplete_stepcalls within a single turn correctly update the TodoPanel. This PR addresses the remaining half of #4105: the panel still reverted after tab switch or restart because the synthetic events were never persisted to the session file.Problem
Host-advance synthetic
todo_writeevents (emitTodoState) update the frontend TodoPanel in real time but are emitted to the event sink, not written asprovider.Messageto the session file. When the session is reloaded (restart, tab switch, reconnect) the frontend rebuilds its transcript from the session file and only sees the last explicit modeltodo_write, missing every intermediate host-advance.Reproduction (after #4132):
Fix
Two complementary mechanisms:
HistoryWithCanonicalTodos— appends a synthetic assistant message carrying the canonical todo state at the end of the history response. Called fromHistoryForTab(desktop) andGET /history(HTTP).EmitCanonicalTodoState— emits the canonical state as a live event through the sink, so the frontend receives it even when tab state is served from the in-memory cache without a full history reload.Preserved (unchanged)
verifyTodoCompletionTransitions(feat(agent): guard todo completion transitions #2576), final-answer gate (fix(agent): block final answers with incomplete todos #2920),advanceCanonicalTodo/recordTodoState(fix(agent): close complete_step cross-turn evidence + loop gaps #4014)Files changed
internal/agent/agent.goCanonicalTodoStategetter andEmitCanonicalTodoStatemethodinternal/control/controller.goHistoryWithCanonicalTodosandEmitCanonicalTodoStatedesktop/app.goHistoryForTabinternal/serve/serve.goHistoryWithCanonicalTodosinGET /history