Skip to content

fix(flow): coordinate agent sessions and answer replays - #59

Open
google-labs-stitch[bot] wants to merge 4 commits into
mainfrom
stitch/coordinate-agent-sessions-and-replays-jm1-d695d2df-8818-492b-b079-b2b0b331abcd
Open

google-labs-stitch[bot] wants to merge 4 commits into
mainfrom
stitch/coordinate-agent-sessions-and-replays-jm1-d695d2df-8818-492b-b079-b2b0b331abcd

Conversation

@google-labs-stitch

Copy link
Copy Markdown
Contributor

Supersedes #40 on current main with support for Google Flow front end builds boq_labs-ai-sandbox-frontend_20261120.00_p0 and boq_labs-ai-sandbox-frontend_20261129.06_p0.

Summary

This change coordinates Flow Agent session state, turn hydration, media status reconciliation, and elicitation answer replay across the Rust runtime (src/agent.rs) and TypeScript browser helpers (ts/):

  • Disconnected server turns and local turn hydration (ts/agent_turns.ts, ts/agent_chat.ts): On main, getAgentSession turns with STORED_TURN_IN_PROGRESS and no open stream report terminal statuses or lose partial local blocks, and loadStoredTurns skips hydration when counts match after a local failure. This change reports in_progress with connected: false, keeps richer partial blocks from local.Vh while clearing transient disconnect errors, and re-hydrates in loadStoredTurns when turns.length > localTurns.length or local turns contain unpersisted non-stopped failures while preserving unsaved trailing local turns when server persistence lags.
  • Draft session tracking, queue lock retention, and cache purge (src/agent.rs, ts/agent_chat.ts, ts/agent_wire.ts, ts/frontend_builds.ts, ts/frontend_nov29_agent.ts, ts/agent_protocol.ts, ts/index.ts, ts/types.ts): On main, unpersisted draft sessions are invisible to get_session, delete_session leaves stale entries in local transport and TanStack Query caches, and a create_session timeout drops the JobQueue execution guard while Flow continues generating. This change tracks allocated draft IDs in AgentState.drafts, syncs persisted sessions on list_sessions and get_session, retains the draft and spawns hold_while_active with the JobQueue lock when create_session encounters a CDP error/timeout or post-submission outcome_unknown / agent_submission_not_observed, and purges local transport entries (transport.ka.yL), verified turn-store sessionSignals (["oa", "ka"] on boq_labs-ai-sandbox-frontend_20261120.00_p0 and ["ta", "ka"] on boq_labs-ai-sandbox-frontend_20261129.06_p0 via own property descriptors), and TanStack Query cache entries (CREATION_AGENT_SESSION, CREATION_AGENT_SESSIONS) via agentPurge on delete_session and pre-submission or unpersisted terminal create_session failures.
  • Cold-load user profile settlement (ts/agent_chat.ts, ts/agent_settings.ts): On main, canSendReady returns agent_not_ready on cold page loads while ["USER_PROFILE"] is still settling after ["PROJECT_DETAILS", projectId]. This change waits for ["USER_PROFILE"] query settlement (with prefix query fallback and a post-settlement tick flush) when bound.canSend() (composer[canSendField]) remains false.
  • Turn media status and tile reconciliation (ts/agent_turns.ts, ts/agent_attachments.ts, ts/frontend_builds.ts, ts/frontend_nov29_upload.ts): On main, legacy _.yjb tool results omit status fields and turn.Tf.Bx keeps stale PENDING or GENERATING statuses after project tiles finish or fail. This change parses status, error_code, and error on legacy tool results and reconciles turn media items against live project tile variants (readAgentProjectTiles, resolveRequestedAsset, isReadyVariant), reading upsampled video variants from verified build descriptors (yn on boq_labs-ai-sandbox-frontend_20261120.00_p0 and bo on boq_labs-ai-sandbox-frontend_20261129.06_p0).
  • Memory blocks and elicitation output detection (ts/agent_protocol.ts, ts/agent_turns.ts): On main, view_agent_memory tool calls drop from turn blocks and turns that produce view_agent_memory blocks or non-failed media items misclassify an unanswered elicitation card as agent_elicitation_expired. This change emits { type: "view_agent_memory" } blocks and counts view_agent_memory blocks and non-failed media items as productive turn output in expiredElicitationError.
  • Sequential question cards, immediate turn completion, and lock-free reconnect replay (src/agent.rs, ts/agent_turns.ts, ts/agent_chat.ts, ts/agent_wire.ts, ts/frontend_nov29_agent.ts): On main, pendingActions exposes all unanswered question cards at once, respond fails when an answer completes a turn immediately or when a live stream drops before re-emitting an unanswered card on reconnect, and hold_while_active holds the AgentState mutex across CDP polls. This change exposes only the first unanswered question card in pendingActions, checks card acceptance with isActionAccepted and isActionStillUnaccepted (reading verified streamSubscription: Wj on boq_labs-ai-sandbox-frontend_20261120.00_p0 and Ak on boq_labs-ai-sandbox-frontend_20261129.06_p0), records question answers (PendingAnswer) in AgentState.answers for replay via agentReplay, releases the AgentState mutex before agentBusy and agentReplay CDP calls, and handles CDP errors explicitly in purge_session_state and hold_while_active.

Verification

  • Verified Google Flow front end builds:
    • boq_labs-ai-sandbox-frontend_20261120.00_p0
    • boq_labs-ai-sandbox-frontend_20261129.06_p0
  • Run cargo xtask ci (formatting, license headers, 800-code-line ceiling, doc examples, forbidden constructs, tsc --noEmit, flow contracts, clippy -D warnings, rustdoc, debug build, and cargo deny).
  • Run RUSTFLAGS="-D warnings" cargo build --release --locked --bin flow-mcp, cargo xtask collect-licenses, and cargo deny --locked --workspace check.
  • Run flow-mcp --headless doctor --json (flow-build: ok on boq_labs-ai-sandbox-frontend_20261129.06_p0).
  • Verify runtime behavior across Flow boq_labs-ai-sandbox-frontend_20261120.00_p0 and boq_labs-ai-sandbox-frontend_20261129.06_p0 workspaces.

- Report disconnected server turns as in progress and hydrate failures
- Track draft sessions in Rust and purge deleted or failed sessions
- Wait for user profile query settlement before send checks
- Reconcile turn media status and errors against live project tiles
- Parse memory blocks and preserve non-failed media turn completion
- Expose one question card at a time and replay dropped answers
- Keep create_session drafts and queue locks on post-send errors
- Release the state lock before agentBusy and agentReplay calls
- Preserve unsaved local turns when stored turns lag in loadStoredTurns
- Clear only verified turn-store session signals in adaptAgentWire
- Accept respond calls when the turn ends immediately after submission
- Handle CDP errors in purge_session_state and hold_while_active
- Combine question and permission checks into isActionAccepted
- Resolve Agent attachment and composer binding merge conflicts
- Add session signals and stream subscription for build 20261129.06
- Read upsampled video variants from verified build descriptors
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.

0 participants