Skip to content

fix(flow): reconcile Agent turns and session caches - #47

Closed
google-labs-stitch[bot] wants to merge 1 commit into
mainfrom
stitch/reconcile-agent-turns-and-caches-jm1-1160ac54-dbb9-4348-8b63-aca72bcc1d30
Closed

google-labs-stitch[bot] wants to merge 1 commit into
mainfrom
stitch/reconcile-agent-turns-and-caches-jm1-1160ac54-dbb9-4348-8b63-aca72bcc1d30

Conversation

@google-labs-stitch

Copy link
Copy Markdown
Contributor

Summary

This change reconciles flow_agent browser state, caches, tile media, and question streams in TypeScript without extra Chrome DevTools Protocol round-trips, new AGENT_EXPORTS symbols, or changes to src/agent.rs:

  • Merge partial blocks, text, response IDs, and media from local.Vh[i] into saved when saved.getState() === STORED_TURN_IN_PROGRESS, report status: "in_progress" with connected: false, and omit local disconnect errors such as STREAM_ERROR_SERVER.
  • Hydrate stored server turns in loadStoredTurns when local.Vh holds unpersisted failed turns or stale client errors, and compute new turn numbers as saved.length + 1.
  • Purge failed unpersisted initial drafts, support delete_session on idle unsaved drafts, evict CREATION_AGENT_SESSION and CREATION_AGENT_SESSIONS entries from QueryClient, and reset qg() when it matches a deleted or purged session.
  • Settle both ["PROJECT_DETAILS", projectId] and ["USER_PROFILE"] queries before reading canSend() so cold Enterprise loads report accurate send readiness.
  • Read status, error_code, and error from legacy tool result rows, reconcile streaming and legacy turn media against live project tiles (resolveRequestedAsset, isReadyVariant, and legacyMedia), add view_agent_memory to ReplyBlock, and suppress false elicitation timeouts when view_agent_memory or non-failed media exists.
  • Emit only the first unanswered question card in pending_actions, wait on detached Wvc streams in respond, verify question card acceptance (card.Qj !== undefined), and replay accepted answers across Dwc / _.Cwc reconnects and resume.

Verification

  • Ran an end-to-end headless Chrome verification harness against the boq_labs-ai-sandbox-frontend_20261120.00_p0 layout (79/79 assertions passed).
  • Passed cargo fmt --all -- --check, cargo xtask check, cargo xtask ci, RUSTDOCFLAGS="-D warnings" cargo doc --locked --workspace --no-deps --document-private-items, RUSTFLAGS="-D warnings" cargo build --release --locked --bin flow-mcp, and cargo xtask collect-licenses.

Automated PR initiated by user @byteland-app via Stitch Loop.

- Merge local partial output into disconnected in-progress turns
- Hydrate stored turns before send when local turns hold errors
- Purge failed drafts, deleted session queries, and selected IDs
- Wait for project details and user profile before send checks
- Reconcile media statuses and elicitation timeouts with tiles
- Replay question answers across detached streams and reconnects

Copy link
Copy Markdown
Contributor

ts/agent_reconcile.ts:698–735 sends an answer and checks the local card immediately. If the acknowledgement arrives later on the same stream, it sends the same answer again. The polling replay at lines 584–616 can also send repeatedly on that stream. Separate read-only turn recovery from replay. Check the server response ID and user message before merging local and stored turn data. Continue the replay design in #40 with one in-flight answer per session, turn, action, and stream. Closing this overlapping implementation.

@byteland-app
byteland-app deleted the stitch/reconcile-agent-turns-and-caches-jm1-1160ac54-dbb9-4348-8b63-aca72bcc1d30 branch November 25, 2026 07:46
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed all review points in commit 2211e52 on branch stitch/reconcile-agent-turns-and-caches-jm1-1160ac54-dbb9-4348-8b63-aca72bcc1d30 while keeping PR #47 closed in favor of #40:

  • Separated read-only turn recovery from replay: Removed question sending, polling loops, and map hooks from ts/agent_reconcile.ts, keeping get_turn, list_messages, conversation, and mergeDisconnectedTurn strictly read-only.
  • Tracked one in-flight answer per (session, turn, action, stream): Added ts/agent_replay.ts (sendQuestionOnStream, replayQuestionAnswers, hasInFlightAnswer) keyed by the live stream wrapper and its active channel token so respond does not require immediate local card.Qj mutation and neither respond nor agentReplay resends an in-flight answer on the same stream while its acknowledgement is pending.
  • Guarded disconnected turn merges: Added canMergeDisconnectedTurn in ts/agent_reconcile.ts (with raw StoredTurn field 6 response ID extraction in ts/agent_turns.ts) to check the user message text, user media and character attachment IDs, and server response ID before merging local partial turn data with stored turn data.
  • Continued the fix(flow): coordinate agent sessions and answer replays #40 replay design: Coordinated AgentState (drafts, answers), agentPurge, and agentReplay across src/agent.rs and ts/agent_chat.ts during hold_while_active and resume.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant