Skip to content

feat: per-flow state lifecycle, rotating-token support, and field-review #3 fixes - #54

Merged
jyotir-aditya merged 6 commits into
mainfrom
feat/state-lifecycle
Jul 9, 2026
Merged

jyotir-aditya merged 6 commits into
mainfrom
feat/state-lifecycle

Conversation

@jyotir-aditya

Copy link
Copy Markdown
Contributor

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)

  • useState is restored immediately before the flow that declares it (new workers/src/browser/storage-state.ts: 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; multiple state names per run work.
  • The run's first flow keeps the context-creation fast path — the only path that can restore IndexedDB token caches (Firebase/MSAL).

Rotating (single-use) refresh tokens

  • After a flow that restored a state passes, the live (post-rotation) session is re-captured to the same name (refreshState, default true; opt out on flows that end logged out). Saved state can no longer go stale-by-design on rotating backends.
  • New verfix run --fresh-state discards the selected flows' saved states so login re-authenticates from scratch.

Companion fixes (from the same review)

  • fix(workers): AI call timeout clamped to the remaining per-run budget; breaker message reworded ("Xs spent, budget Ys" instead of "30s spent of 20s").
  • feat(workers): stale restored-session note appended to fix_hint when a post-restore failure coincides with a 401/403 on an auth-looking endpoint (deterministic, no new failure type, query strings stripped from hints).
  • feat(cli): verfix show --filter <pattern> for --network/--console, pretty output leads with a ⚠ N failed request(s) summary, JSON gains an additive failed_requests array.
  • chore: engine → 0.1.8, cli → 0.3.12, changelog.

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

  • New regression test 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, batched clearState+useState, refreshState: false opt-out.
  • New workers/test/assertions/stale-state-hint.test.ts; circuit-breaker test extended.
  • Full workers suite, CLI suite (11/11 incl. saveState/useState e2e), JSON-purity guard, and testbed smoke test all green.

🤖 Generated with Claude Code

…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.
@jyotir-aditya
jyotir-aditya merged commit 06d053e into main Jul 9, 2026
2 checks passed
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