Skip to content

fix(diff): compare a bare diff snapshot against the last snapshot - #2544

Open
cavalcanticampos wants to merge 1 commit into
vercel-labs:mainfrom
cavalcanticampos:fix/diff-snapshot-last-baseline
Open

cavalcanticampos wants to merge 1 commit into
vercel-labs:mainfrom
cavalcanticampos:fix/diff-snapshot-last-baseline

Conversation

@cavalcanticampos

Copy link
Copy Markdown

Fixes #1755.

What changes for users

agent-browser diff snapshot without --baseline now does what the help text, the docs and the MCP tool description already say: it compares the current page against the last snapshot taken on the tab. On an unchanged page it reports no changes instead of every line as an addition.

agent-browser open file:///.../snapshot_diff_probe.html
agent-browser snapshot
agent-browser diff snapshot        # before: 6 additions; now: no changes

This takes option 1 from the issue (the docs describe the intent), since the help text, README.md, docs/content/docs/diffing.mdx and the MCP description all promise it.

How it works

  • DaemonState keeps last_snapshot_text, the text of the last snapshot per page session. It is bounded to 32 entries, like snapshot_revisions.
  • snapshot records its tree there, for both full and delta responses.
  • diff snapshot with no --baseline reads it as the baseline, and after a successful diff stores its own capture, so repeated diffs report what changed since the previous one. A failed diff (for example an unmatched --selector) changes nothing, as with the ref map today.
  • With no snapshot yet on the tab, the baseline is still empty, so every line is an addition, same as before.
  • --baseline <file> is unchanged.

The help text and diffing.mdx now say "on the current tab" and mention that a diff counts as a snapshot.

Verification

On Linux (WSL2), rustc 1.99:

  • cargo fmt -- --check, cargo clippy -- -D warnings: clean.
  • cargo test: 2051 passed, 204 ignored. Two new unit tests cover per-tab replacement and the 32-entry bound.
  • New e2e e2e_diff_snapshot_without_baseline_uses_last_snapshot (headless Chrome, the snapshot_diff_probe fixture): snapshot, then a bare diff snapshot reports no change; after editing the button text, it reports exactly 1 addition and 1 removal; a third bare diff reports no change. cargo test e2e_diff -- --ignored --test-threads=1: all 3 diff e2e tests pass.
  • The same new e2e on main's actions.rs fails with the bug from the issue (@@ -0,0 +1,6 @@, the whole page as additions).

Not run: the docs site suite (pnpm --filter docs ...). The docs change is one sentence in diffing.mdx.

Related: #1647 asks for -i/--interactive on diff snapshot. With this change that matters more, since a snapshot -i followed by a bare diff snapshot compares an interactive tree with a full one. I opened that as a separate PR to keep this one focused.

🤖 Generated with Claude Code

`diff snapshot` without `--baseline` is documented to compare against the
last snapshot taken in the session, but the daemon used an empty baseline,
so every line of an unchanged page came back as an addition.

The daemon now keeps the text of the last snapshot per tab (bounded to 32
tabs, like the delta snapshot revisions) and uses it as the implicit
baseline. A diff snapshot's own capture becomes the next baseline, so
repeated diffs report what changed since the previous one.

Fixes vercel-labs#1755

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

@cavalcanticampos is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

diff snapshot without --baseline compares against an empty baseline, not the last snapshot

1 participant