Repository navigation
feat: per-flow state lifecycle, rotating-token support, and field-review #3 fixes - #54
Merged
Merged
Conversation
…en support Restore a flow's useState immediately before that flow runs (in-page seed: cookies via addCookies, web storage via a routed blank page on the saved origin) instead of once per run at context creation — a clearState flow batched ahead of a useState flow now gets a genuinely clean slate, and multiple state names per run work. The run's first flow keeps the context-creation fast path (the only way to restore IndexedDB token caches). After a flow that restored a state passes, re-capture the live session to the same name (refreshState, default true) so backends with single-use/rotating refresh tokens never leave the saved state stale. Opt out with refreshState: false. New escape hatch: verfix run --fresh-state discards the selected flows' saved states so login flows re-authenticate from scratch. Regression test (npm run test:state) drives a real rotating-token mini-app through save, restore, rotation survival, batched clearState+useState, and the refreshState opt-out.
Records what shipped on this branch and specs the three remaining confirmed items (AI budget clamp + message, stale-session fix_hint enrichment, show --network --filter + anomaly summary) with implementation hints so they can be picked up independently. Declines a new failure type, the validate batching warning, and cross-run healing memory, with reasons.
Each AI HTTP call had a fixed 30s timeout while the per-run budget is 20s, so one slow call could spend 30s of a 20s budget and open the breaker with the nonsensical '30s spent of 20s'. chatCompletion now short-circuits when under 2s of budget remains and otherwise threads min(30s, remaining) down to fetchWithTimeout via CompletionOptions.timeoutMs; adapter timeout logs report the actual value, and the exhaustion message reads 'Xs spent, budget Ys'. Retry semantics, thresholds, and the AI_TIME_BUDGET_MS override unchanged.
A restored useState session invalidated server-side (single-use token spent after refreshState: false, expiry, server-side logout) fails as a bare selector_not_found with the real cause buried in network logs. When a flow restored a state and its selector/url/timeout failure coincides with a 401/403 on an auth-looking request, the fix_hint now appends a note naming the rejected endpoint (query string stripped so tokens never reach logs) and pointing at re-running the saving flow or --fresh-state. Deterministic, no new failure type — hint text only, which is contract-safe.
…onsole verfix show --network gains a case-insensitive substring --filter on URLs (--console filters text/source_url) and prints failed requests (status >= 400 or 0) first under a warning header in pretty mode; JSON output adds an additive failed_requests array without restructuring existing fields. Docs and generated agent instructions updated; roadmap backlog #3 items ticked.
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
Triages and fixes everything genuine from the third agent field review (rotating-token SaaS run). Full triage recorded in ROADMAP.md § Field-review backlog #3.
Per-flow storage-state lifecycle (the core fix)
useStateis restored immediately before the flow that declares it (newworkers/src/browser/storage-state.ts: cookies viaaddCookies, web storage via a routed blank page on the saved origin) instead of once per run at context creation. AclearStateflow batched ahead of auseStateflow now gets a genuinely clean slate; multiple state names per run work.Rotating (single-use) refresh tokens
refreshState, defaulttrue; opt out on flows that end logged out). Saved state can no longer go stale-by-design on rotating backends.verfix run --fresh-statediscards the selected flows' saved states so login re-authenticates from scratch.Companion fixes (from the same review)
fix_hintwhen a post-restore failure coincides with a 401/403 on an auth-looking endpoint (deterministic, no new failure type, query strings stripped from hints).verfix show --filter <pattern>for--network/--console, pretty output leads with a⚠ N failed request(s)summary, JSON gains an additivefailed_requestsarray.Contract safety
No JSON contract field renamed or restructured; no new failure taxonomy types. All changes are additive (
refreshState,--fresh-state,--filter,failed_requests, hint text).Test plan
workers/test/engine/state-lifecycle.test.ts(npm run test:state): real Chromium against a mini-app with a single-use-token backend — save, restore, rotation survival across runs, batchedclearState+useState,refreshState: falseopt-out.workers/test/assertions/stale-state-hint.test.ts; circuit-breaker test extended.🤖 Generated with Claude Code