Skip to content

CLI: a pinned session keeps its tab when Ardia lists it without an address mid-navigation - #183

Open
shivamhwp wants to merge 1 commit into
ardia-browser:mainfrom
shivamhwp:cli-blank-url-keeps-tab
Open

shivamhwp wants to merge 1 commit into
ardia-browser:mainfrom
shivamhwp:cli-blank-url-keeps-tab

Conversation

@shivamhwp

@shivamhwp shivamhwp commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Closes ardia-browser/ardia#4665

While a tab navigates, Target.getTargets can list the page with url: "" for a few milliseconds. refreshTargets keeps only targets whose URL starts with a page scheme, so it called forgetTarget on the session's own tab, which drops opened, created and the app-tab pairing. With --pin-tab the next tab <targetId> then failed with tab_not_found. When the target came back at its new URL, tab list showed it as openedBySession: false, and tab close refused it as one of the user's tabs. That matches the issue's report.

Now a page target the session already knows keeps its last row while its URL is empty, and is updated when the real URL comes back. A page first seen without an address is still left out, as before. A new flag, tab_blank_url_kept, is set on a command during which this happened. It is registered with the daemon (metrics.ts), the client (browse/tables.ts) and cli_command (command-metrics.ts), and the telemetry list in plugin.json describes it (750 of 800 characters). Watch its rate in cli_command to see how often Ardia lists a tab with an empty URL.

What Ardia reports during the navigation. Ardia 0.2.49 (build 141) on a Mac mini, macOS 27.0.1, hidden test instance, polling Target.getTargets every 20 ms around the issue's Page.navigate. No targetDestroyed and no new target, just an empty URL for one poll (seen in 2 of 4 runs, 23 to 120 ms):

{"t":2234,"kind":"poll","targetId":"9194E4D0…","type":"page","attached":true,"url":"https://example.com/"}
{"t":2304,"kind":"poll","targetId":"9194E4D0…","type":"page","attached":true,"url":""}
{"t":2310,"kind":"Target.targetInfoChanged","targetId":"9194E4D0…","type":"page","url":"https://example.com/"}
{"t":2424,"kind":"poll","targetId":"9194E4D0…","type":"page","attached":true,"url":"https://example.com/"}

Headless Chromium 156 does the same, so this isn't Ardia-only.

Before and after, in Ardia. Same Mac and build, through Ardia's own connection (--data-dir). Each round runs the issue's exact steps (pinned tab new, cdp Network.getAllCookies, both network routes, cdp Page.navigate), then 40 quick tab <targetId> lookups so the short window gets hit, then tab list, tab close <targetId> and close. The base is main d87fc6c and the fix is this branch, both built with sh scripts/build.sh (Bun 1.3.14). Runs were interleaved, 12 rounds each:

CLI Rounds where the session lost the tab tab close refused
Command Line 0.7.0 as Ardia installs it 1 / 12 1 / 12
base d87fc6c 0 / 12, then 3 / 12 0 / 12, then 3 / 12
base d87fc6c, with every lookup error caught 12 / 12 12 / 12
this branch, three runs 0 / 36 0 / 36

A base round, the same failure as the issue:

{"lookups":"0:tab_not_found:Tab 9F8DA833… not found; run `ardia browse tab` to list open tabs","row":{"url":"https://example.com/","openedBySession":false,"openedBy":null},"tabClose":{"success":false,"error":"Tab [t64] is one of the user's tabs; ardia browse only closes tabs this session opened"}}

A round on this branch:

{"lookups":{"misses":0,"first":null},"row":{"url":"https://example.com/","openedBySession":true,"openedBy":"pinned-stress-1-14085512"},"tabClose":{"success":true,"error":null}}

On Linux against headless Chromium 156, the same harness lost the tab in 7 of 8 rounds on the base and in 0 of 8 on this branch. The issue's original single script didn't fail on either build in these runs, because it only hits the window by chance.

Tests. The new tests/m3/tabs-nav.test.ts case ("a pinned session still finds its own tab by target id, and keeps it") fails on main with Tab TARGET not found and passes here. The second new case checks that a page first seen with an empty URL is still left out. On Linux x64, these pass at 7d61a7a (rebased onto #184): tsrs --noEmit -p ., tsrs --noEmit -p tests/m3, ts/dist/ardia-ts plugins check plugins/cli, and bun test of tests/m3/tabs-nav.test.ts (25), tests/arch-v3-tabtools.test.ts (8), tests/arch-v3-position-mouse.test.ts (5) and tests/m2c-computer.test.ts (3, three runs). The headless Chromium harness kept the tab in 8 of 8 rounds at 7d61a7a. The Mac runs above are from 65c7727, before the rebase; the fix is the same code. A replay also checked that tab_blank_url_kept reaches cli_command and a collector.

CI at 7d61a7a. The vendored schema check and Manifest v2 pass. The red jobs fail in tests this change doesn't touch:

  • TypeScript on macos-15: 1790 pass and 2 fail.
    • The daemon/waits replay in tests/m3/replay-corpus.test.ts gets an extra Page.createIsolatedWorld. The same error shows on CLI: ardia feedback --help says a public GitHub issue may be opened, not that one always is #182 (run 46038200441), which changes only help text and test fixtures.
    • "Ctrl-C ends the credential read" in tests/shipping/plugin-mode.test.ts ends from SIGINT itself instead of exiting with 130, after its 700 ms wait.
    • Main's own macOS job fails at a86ff86 too (run 46186410358), on "the link > commands, events, frames and errors", which passes here.
  • TypeScript on ubuntu-24.04: cancelled at its 20-minute limit. All its 1743 tests had passed except three in tests/m2c-computer.test.ts, which never reported. That file passes locally, in three runs out of three.
  • Parity on macos-15 and ubuntu-24.04: both cancelled at their time limit, as on main. CLI checks pass collects these jobs, so it fails too.

Not shown: a green full bun run test or bun run test:parity at this head, for the reasons above.

The stress harness
for round in $(seq 1 12); do
  session="pinned-stress-$round-$RANDOM$RANDOM"
  target=$(ardia browse --data-dir "$data" --session "$session" --pin-tab --json tab new | jq -er '.data.targetId')
  sed -e "s|@TARGET@|$target|g" -e "s|@URL@|$url|g" <<'JS' | ardia browse --data-dir "$data" --session "$session" --pin-tab --json script --stdin
async function checked(...args) { const r = await browse(...args); if (!r.ok) throw new Error(r.error); return r.data; }
await checked("tab", "@TARGET@");
await checked("cdp", "Network.getAllCookies", "--target", "@TARGET@");
await checked("network", "route", "**", "--abort");
await checked("tab", "@TARGET@");
await checked("network", "route", "https://example.com/*");
await checked("tab", "@TARGET@");
await checked("cdp", "Page.navigate", "--target", "@TARGET@", "--param", "url=@URL@");
const misses = [];
for (let i = 0; i < 40; i += 1) {
  try { const r = await browse("tab", "@TARGET@"); if (!r.ok) misses.push(i + ":" + r.error); }
  catch (error) { misses.push(i + ":" + error.code + ":" + error.message); }
}
return { misses: misses.length, first: misses[0] ?? null };
JS
  ardia browse --data-dir "$data" --session "$session" --pin-tab --json tab list
  ardia browse --data-dir "$data" --session "$session" --pin-tab --json tab close "$target"
  ardia browse --data-dir "$data" --session "$session" --pin-tab --json close
done

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Tab retention during refresh

Layer / File(s) Summary
Retain known pages and report retention
plugins/cli/ts/src/browse/state/state.ts, plugins/cli/ts/src/browse/metrics.ts, plugins/cli/ts/src/browse/tables.ts, plugins/cli/ts/src/command-metrics.ts, plugins/cli/ts/tests/m3/tabs-nav.test.ts, plugins/cli/plugin.json
refreshTargets retains a previously known page reported with an empty URL, reuses its prior URL, and uses its prior title if the new title is empty. It sets tab_blank_url_kept, which is added to the recognized metric flags and telemetry description. Tests verify pinned-tab ownership through refresh and exclusion of newly seen blank-URL pages.

Suggested reviewers: mantrakp04

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 7d61a

Pinned sessions keep ownership of their tab when Ardia briefly lists it without an address, which fixes the reported tab_not_found and close-refusal problem. No actionable merge risk was found. The author reports unrelated CI failures that also occur on the base.

Security architecture risk: Low · up to 7d61a

The fix keeps a tab from disappearing during navigation without giving the session ownership of new tabs. One narrow risk remains: moving an offscreen tab while its address is unavailable can reopen the previous address instead of preserving the navigation in progress.

Retained concerns

  • Low · reliability · inferred: If a known offscreen page has both a blank URL in the browser’s target listing and an empty live Page URL, handoff can navigate a replacement tab to the cached prior address and then close the original, discarding the navigation in progress. At the base revision, the blank refresh did not supply a cached destination to this fallback. The risk is limited to an existing handoff command; a refresh alone does not navigate or close a tab.
Security review details

Security Blast Radius

  • observed — The exception applies to any already-known page ID returned by the connected browser, not just pinned or session-owned tabs. It keeps those IDs addressable during a blank listing but does not add them to the session’s ownership sets.

Trust Boundaries and Controls

  • observed — Reconnect rejects a different browser instance before refreshing targets. The telemetry path records a fixed boolean for retention and accepts only boolean values for that field, not URLs, titles, or target IDs.

Hardening Proposals

  • proposed — Keep last-known metadata available for listing, but distinguish it from a verified current destination. If handoff cannot confirm a live destination, leave the original tab in place rather than replacing it using the cached URL.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 13e7c906-018d-40ef-8d48-07f6203bc9f0
Commits

Reviewing files that changed from the base of the PR and between 11798a0 and 7d61a7a.

Files selected for processing: 4

  • plugins/cli/plugin.json
  • plugins/cli/ts/src/browse/state/state.ts
  • plugins/cli/ts/src/browse/tables.ts
  • plugins/cli/ts/src/command-metrics.ts
Files skipped from review as they are similar to previous changes: 1

  • plugins/cli/plugin.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

…ssion's

Ardia's Target.getTargets can report a page with url "" for a few
milliseconds while it navigates (seen 23-120 ms on Ardia 0.2.49, macOS,
and in headless Chromium 156). refreshTargets only keeps targets whose
URL has a page scheme, so it forgot the session's tab and with it the
ownership: the next tab <id> failed with tab_not_found, and when the
target came back at its new URL the session no longer owned it and
couldn't close it.

A page target already known keeps its last row while its URL is empty;
a page first seen without an address is still left out. The
tab_blank_url_kept flag is set on a command during which a known tab
was listed without an address; watch its rate in cli_command.

Closes ardia-browser/ardia#4665
@shivamhwp
shivamhwp force-pushed the cli-blank-url-keeps-tab branch from 11798a0 to 7d61a7a Compare November 28, 2026 20:28

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.

CLI briefly loses pinned target after CDP navigation and drops its tab ownership

1 participant