Skip to content

fix(core): replay cached CUA back/forward navigation steps#2014

Open
BABTUNA wants to merge 1 commit intobrowserbase:mainfrom
BABTUNA:fix-agent-cache-back-forward
Open

fix(core): replay cached CUA back/forward navigation steps#2014
BABTUNA wants to merge 1 commit intobrowserbase:mainfrom
BABTUNA:fix-agent-cache-back-forward

Conversation

@BABTUNA
Copy link
Copy Markdown

@BABTUNA BABTUNA commented Apr 19, 2026

why

CUA replay currently records back/forward steps but AgentCache only
replays navback.
This causes cached CUA runs to silently skip history navigation actions,
which can drift page state and break deterministic replay.

what changed

  • Added explicit replay step types for:
    • back
    • forward
  • Updated AgentCache replay switch to execute:
    • back via page.goBack(...)
    • forward via page.goForward(...)
  • Kept existing navback replay behavior for compatibility.
  • Extended unit tests to verify replay of non-act navigation steps:
    • goto
    • navback
    • back
    • forward

test plan

  • prettier --check on touched files
  • eslint on touched files
  • tsc -p packages/core/tsconfig.json --noEmit
  • Unit test coverage added in:
    • packages/core/tests/unit/cache-llm-resolution.test.ts

Summary by cubic

Fixes cached CUA replays skipping browser history. AgentCache now replays back and forward steps to keep page state deterministic.

  • Bug Fixes
    • Added back and forward replay step types and handle them in AgentCache via page.goBack/page.goForward with waitUntil (default domcontentloaded).
    • Preserved existing navback behavior for compatibility.
    • Extended unit tests to cover goto, navback, back, and forward.

Written for commit c3362fc. Summary will update on new commits. Review in cubic

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 19, 2026

⚠️ No Changeset found

Latest commit: c3362fc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run.
Approving the latest commit mirrors it into an internal PR owned by the approver.
If new commits are pushed later, the internal PR stays open but is marked stale until someone approves the latest external commit and refreshes it.

@github-actions github-actions bot added external-contributor Tracks PRs mirrored from external contributor forks. external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. labels Apr 19, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant Runner as Replay Runner
    participant Cache as AgentCache
    participant Ctx as V3Context
    participant Page as Browser Page

    Note over Runner,Page: Replay of Cached Agent Steps

    Runner->>Cache: executeCachedSteps(entry)
    loop For each Step in entry.steps
        
        alt Step: goto
            Cache->>Ctx: awaitActivePage()
            Ctx-->>Cache: page
            Cache->>Page: goto(url, { waitUntil })
        
        else Step: navback (Legacy)
            Cache->>Ctx: awaitActivePage()
            Ctx-->>Cache: page
            Cache->>Page: goBack({ waitUntil })
        
        else NEW: Step: back
            Cache->>Cache: replayAgentBackStep()
            Cache->>Ctx: awaitActivePage()
            Ctx-->>Cache: page
            Cache->>Page: NEW: goBack({ waitUntil })
            Page-->>Cache: navigation complete
        
        else NEW: Step: forward
            Cache->>Cache: replayAgentForwardStep()
            Cache->>Ctx: awaitActivePage()
            Ctx-->>Cache: page
            Cache->>Page: NEW: goForward({ waitUntil })
            Page-->>Cache: navigation complete

        else Other steps (act, keys, etc.)
            Cache->>Cache: process step...
        end

    end
    Cache-->>Runner: result (success/failure)
Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. external-contributor Tracks PRs mirrored from external contributor forks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant