Skip to content

fix(flow): parse rpc error envelopes and workflow history - #38

Closed
google-labs-stitch[bot] wants to merge 2 commits into
mainfrom
stitch/parse-rpc-errors-and-workflow-history-jm1-ab58bba7-0156-4f9d-a8dc-b4a0df7d95a1
Closed

google-labs-stitch[bot] wants to merge 2 commits into
mainfrom
stitch/parse-rpc-errors-and-workflow-history-jm1-ab58bba7-0156-4f9d-a8dc-b4a0df7d95a1

Conversation

@google-labs-stitch

@google-labs-stitch google-labs-stitch Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Parse Google Flow batchexecute RPC error envelopes and inspect full workflow history arrays so generation, character reference upload, and scene video extend operations fail fast with upstream error details while preserving primary media status and download URLs.

Changes

  • Scope CDP body reads and parse live-verified batchexecute JSPB error envelopes (src/cdp.rs, src/engine.rs, src/generation.rs):
    • Derive flow.google.com from FLOW_URL in is_flow_host alongside labs.google and aisandbox-pa.googleapis.com.
    • Invoke Network.getResponseBody strictly when network_tx.receiver_count() > 0 and the response is a Flow-host POST matching (status >= 400 && is_generation_rpc_url(url)) || (status == 200 && has_generation_batchexecute_rpc(url)), skipping idle traffic, unrelated 4xx/5xx responses, and non-generation batchexecute calls.
    • Match BATCH_GENERATION_RPC_IDS (including LcEY2c, SPrCad, sAVZzc, jeNy9c, and maseQ) as exact comma/%2C-separated tokens on /batchexecute rpcids query parameters (has_generation_batchexecute_rpc) and filter wrb.fr frames by exact frame[1] RPC ID (is_generation_rpc_id) so co-batched non-generation RPC errors never fail a generation job.
    • Decode live Flow Boq JSPB wrb.fr (Yp = [2, 9, 10] payload oneof, ic(a, b, Wa) extension-pivot indexing, and google.rpc.Status array on field 5) and er batch error frames (fields 2, 4, 9, 10), suppressing trailing er frames once a generation wrb.fr data frame has resolved in the same envelope.
  • Keep primary media status separate from history[1..] failures (ts/types.ts, ts/scene_tiles.ts, ts/read_store_snapshot.ts, src/assets.rs):
    • Read scene clip arrays and workflow history maps across build-configured fields (Uc/Cg, Tc/tg, Oc/Yf) and structural fallbacks, deduplicating workflows per scene tile.
    • Keep media_status and media_error bound strictly to the tile's primary media (primaryStatus || null and primaryError) so an old history[1..] failure never overrides a "pending" or "success" primary media item, while preserving primary_ready and cold-cache as29s URL lookups.
    • Key failed_history markers uniquely as id:<cleanId> (or id:<cleanId>#<occ>) and anon:<index> (<key>|<status>|<error>) and deduplicate by <key> in mergeFailedHistory while upgrading empty error text.
  • Baseline-aware failure detection (src/scenes.rs, src/generation.rs):
    • Compare watched and scene clips against baseline failed_history, media_error, primary_media_id, and media_status (FlowAsset::new_failure, watch_baseline, and clip_entered_error) so first and repeated history[1..] failures abort on the next 4-second poll tick without false positives on prior failed variants.

Verification

  • Passed RUSTFLAGS="-D warnings" cargo build --release --locked --bin flow-mcp, cargo xtask ci, cargo xtask collect-licenses, cargo deny --locked --workspace check, and ./target/release/flow-mcp --headless doctor --json (boq_labs-ai-sandbox-frontend_20261120.00_p0) with zero warnings and all .rs and .ts files well below 800 code lines.
  • Verified live Flow Boq JSPB batchexecute wire format against https://labs.google/fx/tools/flow and ran an out-of-tree headless Chrome + MCP stdio E2E suite verifying primary "pending" -> "done" flow_edit with prior failed history, co-batched cPZSdc error + Z9cAtf JSPB extension dictionary, sAVZzc wrb.fr google.rpc.Status fast-fail, repeated empty-ID flow_video extend fast-fail, and CDP wire-level Network.getResponseBody call counts.

Verification summary


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

- Match flow.google.com and parse HTTP 200 batchexecute error frames
- Add LcEY2c, SPrCad, sAVZzc, jeNy9c, and maseQ to generation RPC IDs
- Preserve primary clip URLs when workflow history[1..] items fail
- Track failed history items so video extend aborts on the next poll

@byteland-app byteland-app left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parser in src/cdp.rs combines errors from all frames into one excerpt. src/generation.rs:291–319 then aborts generation if any generation RPC is listed in the batch URL, even when that RPC succeeded and a different frame failed. Keep frame-level RPC IDs and match them to the expected request and operation. Add a mixed success and failure fixture and cover an er frame with no RPC ID separately.

@byteland-app

Copy link
Copy Markdown
Contributor

Changes requested.

  1. ts/read_store_snapshot.ts: mediaStatus = histFail.status ?? primaryStatus lets an old history failure override the status of a new primary media. summarizeHistoryFailures scans all history items. Example: after an old failed variant, a new flow_edit shows media_status: failed while the new media is still pending, and primary_failed in src/generation.rs ends the edit as failed. Compare against the baseline media_error, or read only the new history items.
  2. src/generation.rs (inspect_generation_network): a 200 response with error_excerpt now stops the job. BATCH_GENERATION_RPC_IDS is matched with contains, so an error frame of another RPC in the same batchexecute request can fail a good generation. The frame format (frame[5] not null) is not verified on live Flow.
  3. src/cdp.rs: Network.getResponseBody runs for every 4xx or 5xx response from flow.google.com and for every 200 batchexecute POST. Limit it to the requests that you need.
  4. mergeFailedHistory: the marker id|status|error is not unique when the id is empty, and can count one failure twice.

This PR overlaps with #43 (history parsing), #39, #44, #46 and #28. Rebase after #43 is decided.

- Keep primary media status and error separate from history failures
- Compare watched and scene clip failures against baseline snapshots
- Match generation batchexecute rpcids and wrb.fr frames by exact ID
- Decode JSPB field offsets and google.rpc.Status arrays from wrb.fr
- Read CDP response bodies only for active generation POST responses
- Key failed history markers by unique ID or anonymous index
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed in ca1deec:

  1. Preserve primary media_status / media_error and compare failures against baseline (ts/read_store_snapshot.ts, src/assets.rs, src/generation.rs, src/scenes.rs):

    • Removed the histFail.status / histFail.error fallback on mediaStatus and mediaError in readStoreTiles, keeping media_status and media_error strictly bound to the tile's primary media (primaryStatus || null and primaryError). A tile with an older failed variant in history now reports "pending" (and media_error: null) while a new flow_edit media item is generating, and "success" once ready.
    • Updated wait_for_new_assets (src/generation.rs) to track a mutable watch_baseline: Option<FlowAsset>, clear stale failure baselines if a failed tile restarts, check FlowAsset::new_failure(&prev.failed_history) for newly appended history failures, and require watched.media_error != prev.media_error || watched.primary_media_id != prev.primary_media_id || !prev_primary_failed before treating primary failure state as new. Updated clip_entered_error (src/scenes.rs) similarly so non-failed "pending" / "scheduled" primary states are never flagged by pre-existing failed_history entries.
  2. Exact rpcids + per-frame wrb.fr RPC matching, verified against live Google Flow (src/generation.rs, src/cdp.rs):

    • Replaced substring URL matching for /batchexecute with has_generation_batchexecute_rpc(url) (is_generation_rpc_id), which parses exact comma/%2C-separated tokens from the rpcids query parameter (preventing URL path/query substring false matches while keeping REST /v1/video: and /v1/flow: matching in is_generation_rpc_url).
    • Verified the live Boq AiSandboxAngularFrontend _b client runtime (Wp "wrb.fr", payload oneof Yp = [2, 9, 10], ic(a, b, Wa) JSPB extension-pivot field indexing, _.iq google.rpc.Status array on field 5, and DA "er" batch frames on fields 2, 4, 9, 10 in _.FD.prototype.na):
      • jspb_msg_field / jspb_submsg_field handle trailing JSPB extension-pivot plain objects (e.g. {"48448350": ...}), format_wrb_error treats any wrb.fr frame with non-null payload fields 2, 9, or 10 as data and requires field 5 to be a JSON Array (google.rpc.Status), and collect_envelope_errors checks is_generation_rpc_id(rpc_id) on frame[1] so co-batched non-generation RPC errors (e.g. cPZSdc) or trailing er frames after resolved generation data do not fail a valid generation.
  3. Restrict Network.getResponseBody strictly to needed requests (src/cdp.rs):

    • Scoped pending_bodies tracking and Network.getResponseBody in handle_network_event to network_tx.receiver_count() > 0 && should_inspect_response_body(&req_method, status, &url): Flow-host POST requests where (status >= 400 && is_generation_rpc_url(url)) || (status == 200 && has_generation_batchexecute_rpc(url)). Idle traffic, unrelated 4xx/5xx responses, and non-generation batchexecute calls no longer trigger Network.getResponseBody.
  4. Unique failed_history keys for empty IDs without double-counting (ts/read_store_snapshot.ts, src/assets.rs):

    • Removed synthesized primaryFailMarker / candPrimaryMarker (which could duplicate a failed history[0] item when t.Fb and history[0] differed on id or hydrated error text), deduplicated seenWorkflows per scene tile, keyed summarizeHistoryFailures entries as id:<cleanId> (or id:<cleanId>#<occ> if repeated) and anon:<anonIndex> (<key>|<status>|<error>), and updated mergeFailedHistory to deduplicate by <key> while upgrading empty error messages when a second source provides hydrated text.

Also checked #43 — since it is still open under review (mergeable_state against main is clean), this branch remains cleanly based on main and is ready to rebase as soon as #43 lands or is closed.

@byteland-app

Copy link
Copy Markdown
Contributor

Closing this pull request. It conflicts with main, and main now supports Google Flow build 20261129.06_p0 with new field names in the code that this change edits. Please open a new pull request on current main if the change is still needed.

@byteland-app
byteland-app deleted the stitch/parse-rpc-errors-and-workflow-history-jm1-ab58bba7-0156-4f9d-a8dc-b4a0df7d95a1 branch December 1, 2026 03:30
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Merged main (254474d, v2.4.0), aligned snapshot and scene history reads with Google Flow build boq_labs-ai-sandbox-frontend_20261129.06_p0 (Pc/Xg, createdIso, and snapshotFormat()?.trim), and opened #58 on current main.

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