Skip to content

fix(browser): bound ARIA snapshots by character budget - #25

Merged
Ooooze merged 3 commits into
AtomicBot-ai:mainfrom
Bartok9:sera/aria-char-budget
Jul 28, 2026
Merged

fix(browser): bound ARIA snapshots by character budget#25
Ooooze merged 3 commits into
AtomicBot-ai:mainfrom
Bartok9:sera/aria-char-budget

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

summariseAriaSnapshot only capped lines. Dense short-line SPA trees still push tens of kB into small local-model contexts (8k–16k), which is the failure mode described in #21.

Fix

  • Order-preserving maxChars pack (default 24_000) applied after noise drop, before the line cap
  • Size-truncation footer so the agent knows to scroll/navigate
  • maxChars: 0 / non-finite disables the budget
  • Unit coverage for the pack footer path

Test plan

  • vitest run src/tools/browser/browser-tools.test.ts
  • Optional: browser.read_aria on a heavy SPA and confirm footer + smaller prompt payload

Addresses #21

Agent-Owner: sera

@sosidudku1

Copy link
Copy Markdown
Collaborator

Thanks @Bartok9. The line cap alone cannot see how wide a line is, so a char budget is the right second axis. Worth noting for anyone reading #21 later: the crude version of that problem is already fixed on main, and what your patch covers is the remaining case, short dense lines that pass the line cap.

This is queued for merge review. Sorry for the slow first response, we are going through the whole browser batch this week.

Two things I noticed while reading it.

maxChars: 0.4 passes the <= 0 guard and then Math.trunc makes it 0, which returns an empty array and wipes the snapshot. Math.max(1, Math.trunc(...)) closes it.

The new test passes dropNoise: false, but playwright-backend.ts:126 is the only real call site and passes no options, so noise dropping and the char budget always run together there. A test with both defaults would cover what actually executes.

Also, minor: the comment above packLinesToCharBudget describes scoring lines with refs higher, but it packs in order and cuts the tail. The behaviour is fine, the comment just promises more than it does.

Merge order: #24 re-exports two symbols from here without introducing them, so this one goes first.

@Bartok9

Bartok9 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @sosidudku1, all three addressed in 9d2aa43:

  • maxChars 0.4 wipe: now Math.max(1, Math.trunc(...)), so a sub-1 budget truncates to one char instead of returning an empty array.
  • defaults coverage: added a test that exercises the char budget and noise dropping together (the playwright-backend path where both run with no options), plus a fractional-maxChars regression test.
  • comment: corrected — packLinesToCharBudget packs positionally and cuts the tail; no ref/name scoring. The comment now says exactly that.

31/31 green. Agreed on merge order behind #24.

@Ooooze

Ooooze commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

The character-budget approach is a solid fix for the context-exhaustion problem in #21 — order-preserving pack after noise-drop, before the line cap, with a clear truncation footer. Two cleanup items before merge:

  1. pnpm-lock.yaml shouldn't be in this diff. This repo uses npm (package-lock.json), not pnpm — the new 5097-line pnpm-lock.yaml looks like it got committed from a local pnpm install and isn't related to the ARIA fix. Could you drop it from the branch?
  2. Test location. The new tests landed in browser-tools.test.ts, which is already over the repo's 300-line-per-file guideline even before this PR's additions. Would you mind splitting the new ARIA-budget cases into a dedicated aria-compressor.test.ts?

Logic itself looks correct and tsc/tests are clean otherwise — thanks for the fix!

Bartok9 added 3 commits July 28, 2026 12:37
Line-only caps still let dense short-line SPA trees flood small
local-model contexts. Add an order-preserving maxChars pack (default
24k) before the line cap, with a size-truncation footer so the agent
knows to scroll or navigate.

Addresses AtomicBot-ai#21

Agent-Owner: sera
Signed-off-by: Bartok9 <danielrpike9@gmail.com>
- Math.max(1, trunc(maxChars)) so 0<maxChars<1 no longer wipes the snapshot
- add test exercising char budget + noise dropping together (real call site)
- add fractional-maxChars regression test
- correct packLinesToCharBudget comment (positional pack, no ref scoring)

Signed-off-by: Bartok9 <danielrpike9@gmail.com>
…st.ts

Split the summariseAriaSnapshot suite out of browser-tools.test.ts (617->487
lines, under the 300+ file-size concern) into aria-compressor.test.ts. Also
drops the stray pnpm-lock.yaml that got committed from a local pnpm install;
repo uses npm/package-lock.json.
@Bartok9
Bartok9 force-pushed the sera/aria-char-budget branch from 9d2aa43 to 9979273 Compare July 28, 2026 16:38
@Bartok9

Bartok9 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Ooooze — both addressed:

  1. pnpm-lock.yaml dropped. It got committed from a local pnpm install; the repo uses npm/package-lock.json. Rebased cleanly on main and removed it — no longer in the diff.
  2. Test location. Moved the whole summariseAriaSnapshot suite out of browser-tools.test.ts (617 → 487 lines) into a dedicated aria-compressor.test.ts. The ARIA-budget cases live there now.

36/36 green, tsc clean. Diff is now just aria-compressor.ts, the new test file, and the index.ts re-export.

Bartok9 added a commit to Bartok9/atomic-agent that referenced this pull request Jul 28, 2026
…ests

- processLooksLikeChromium is now tri-state (chromium/other/unknown). A failed
  probe (no /proc, ps timeout, unexpected platform) returns 'unknown', which
  clearStaleChromeLocks treats as keep-locks instead of the previous
  false -> clear path that could pull locks from a live browser.
- clearStaleChromeLocks accepts isAlive/probe injection so the dead-pid test
  asserts deterministically; added live-chromium (keep), live-other (clear),
  and fail-open unknown (keep) cases.
- index.ts: drop DEFAULT_ARIA_MAX_CHARS/packLinesToCharBudget re-exports that
  belong to AtomicBot-ai#25 so this branch builds on its own (tsc clean).
@Ooooze

Ooooze commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Confirmed — pnpm-lock.yaml is gone and the ARIA-budget suite now lives in its own file. 36/36 green, tsc clean. Merging, thanks for the quick turnaround!

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.

3 participants