Autonomous Browser Session Recovery and State Machine
Architect a deterministic state machine and self-healing recovery framework for multi-step browser agent chains.
Use this template to design resilient state tracking, DOM mutation recovery, and loop prevention for web automation agents. It establishes unambiguous step verification, session checkpoints, and telemetry anchors.
Role: Senior Automation and Resiliency Engineer specializing in autonomous browser state machines and fault-tolerant web workflows.
Context
- Session lifecycle model: {{session_lifecycle_model}}
- DOM mutation patterns: {{dom_mutation_patterns}}
- Idempotency key strategy: {{idempotency_keys}}
- Retry and backoff matrix: {{retry_backoff_matrix}}
- Telemetry and event sink: {{telemetry_sink}}
- Agent execution timeout budget: {{agent_execution_timeout}}
Task
Develop an autonomous browser session recovery and state machine framework that maintains transaction integrity, prevents cyclic agent stalls, and remediates volatile DOM failures across complex multi-step web task chains.
Method
- Define discrete finite states (Initialization, Navigation, Assertion, Mutation, Verification, Termination) adapted to {{session_lifecycle_model}}.
- Design a deterministic DOM snapshot and mutation-observer baseline to detect dynamic page shifts against {{dom_mutation_patterns}}.
- Establish an idempotency tracking mechanism using {{idempotency_keys}} to prevent duplicate form submissions or duplicate transactions upon recovery.
- Build an automated state verification engine that checks post-action DOM conditions before the agent advances to subsequent steps.
- Structure a cyclic-loop detector that triggers remediation if an agent repeats identical tool invocations without state progression.
- Map fallback execution paths using {{retry_backoff_matrix}} for transient elements, stale references, and network disconnections.
- Implement session snapshotting and state persistence logic that feeds structured diagnostic events into {{telemetry_sink}} within {{agent_execution_timeout}} limits.
Constraints
- State transitions MUST require explicit assertion verifications and cannot rely on model inference alone.
- Mutating web interactions MUST NOT execute more than once per unique key in {{idempotency_keys}}.
- Recovery routines must terminate and yield gracefully if execution approaches {{agent_execution_timeout}}.
- Session state data must remain strictly isolated from cross-tenant or unauthenticated browser contexts.
Output format
Structure the framework across four dedicated sections:
- State Transition Matrix (formal table containing Current State, Event, Transition Guard, Target State, and Fallback Action)
- DOM Verification & Stale Reference Protocol (explicit logic for handling dynamic hydration and layout shifts)
- Idempotency & Duplicate Action Barrier (step-by-step state checkpointing rules)
- Diagnostic Telemetry Schema (exact JSON event schemas sent to {{telemetry_sink}})
Self-review
- Ensure every transient failure mode identified in {{dom_mutation_patterns}} has a deterministic recovery guard.
- Verify that the idempotency rules strictly enforce zero duplicate mutations.
- Confirm all state transitions have an absolute exit path before reaching {{agent_execution_timeout}}.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.