Skip to content

Agent cache replay executes steps too fast, causing navigation failures #1561

@hoverlover

Description

@hoverlover

Description

When replaying cached agent executions, steps are executed immediately after each other without waiting for page navigation to complete. This causes subsequent steps to run on the wrong page, leading to failed workflows.

Steps to Reproduce

  1. Record an agent workflow that includes navigation (e.g., login → click link → search)
  2. Run the workflow again to trigger cache replay
  3. Observe that steps after navigation-triggering actions fail or execute on the wrong page

Expected Behavior

After an action triggers page navigation (detected by URL change), replay should wait for the page to fully load before executing the next step.

Actual Behavior

Replay proceeds immediately to the next step without waiting for navigation, causing:

  • Actions to execute on the previous page
  • XPath selectors to fail or match wrong elements
  • Workflow failures despite having valid cached data

Root Cause

In AgentCache.ts, the replay methods (replayAgentActStep, replayAgentFillFormStep, replayAgentKeysStep) execute cached actions but don't wait for navigation to complete before continuing to the next step.

Proposed Fix

After executing each action during replay:

  1. Capture URL before action
  2. Execute the action
  3. Check URL after action
  4. If URL changed, call page.waitForLoadState("load") before continuing

This ensures the page is fully loaded before the next step executes.

Related

This issue was discovered while testing the fix for #1558 (custom tool caching). Both issues affect agent cache replay reliability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions