feat(tabs): cap the number of open tabs - #520
Closed
daniel771277 wants to merge 1 commit into
Closed
Conversation
✅ Skill review passedReviewed 1 file(s) — no findings. |
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
Nothing ever closes a tab the agent opened — new_tab() only creates them, and close_tab() is opt-in — so a long-running setup accumulates dozens of tabs (50+ here) and the browser bogs down. new_tab() now reaps the oldest tabs beyond BH_MAX_TABS (default 10, 0 disables). Ordering comes from the DevTools /json/list endpoint, which is newest-first; Target.getTargets order is not creation order. about:blank tabs are reapable (they are throwaway harness tabs) but the browser's own UI pages are never touched, and the tab the caller just got back is always kept. The /json/list endpoint is resolved from the DevTools HTTP base the daemon actually connected to (new "http_endpoint" IPC meta) rather than a guessed port, so reaping works for a browser discovered on any port, not just 9222. It returns None for cloud/remote browsers, where reaping is skipped. Cost is negligible: /json/list is ~0.6 ms, and in steady state exactly one Target.closeTarget is added per new_tab (~32 ms per new_tab, within the noise of the unreaped baseline). Clearing a 30-tab backlog is a one-off ~100 ms. Verified on macOS 15 / Chrome 150: with 24 tabs open, the next new_tab() settles the browser at the cap and holds there, the current tab survives, and the endpoint derivation is correct for ws/wss/discovered-port/cloud inputs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author
|
Good catch — fixed in the latest push. |
daniel771277
force-pushed
the
feat/cap-open-tabs
branch
from
July 15, 2026 01:18
789f835 to
5d2e87a
Compare
Author
|
Closing this — handling the change downstream instead. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Nothing ever closes a tab the agent opened.
new_tab()only creates them andclose_tab()is opt-in, so a long-running setup just accumulates tabs — I found 50+ open in my automation Chrome, and the browser bogs down well before that.Fix
new_tab()reaps the oldest tabs beyondBH_MAX_TABS(default 10,0disables)./json/listendpoint, which is newest-first.Target.getTargetsorder is not creation order, so it can't be used for this.about:blanktabs are reapable — they're throwaway harness tabs, and excluding them (they matchINTERNAL) would let blank tabs pile up forever.chrome://,devtools://,chrome-extension://) are never touched, and the tab the caller just got back is always kept.Cost
Negligible.
/json/listis ~0.6 ms, and in steady state exactly oneTarget.closeTargetis added pernew_tab().new_tab()The differences sit inside the run-to-run noise. Clearing a 30-tab backlog is a one-off ~100 ms.
Verification (macOS 15, Chrome 150)
With 32 tabs open, the next
new_tab()settles the browser at 10 tabs and holds there across repeated calls; the tab the caller is working in survives.Independent of #519 (both touch
new_tab(), so whichever lands second needs a trivial rebase).🤖 Generated with Claude Code
Summary by cubic
Cap the number of open tabs by auto-closing the oldest tabs in
new_tab(). Default limit is 10 (configurable viaBH_MAX_TABS), reducing tab bloat and keeping Chrome responsive.new_tab()reaps the oldest tabs beyondBH_MAX_TABS(0 disables) using DevTools/json/list(newest-first); the HTTP base is resolved via daemonmeta: "http_endpoint"so it works on any discovered port; skipped on cloud/remote (no endpoint).chrome://,devtools://, orchrome-extension://pages;about:blanktabs are reapable; negligible overhead (at most one extraTarget.closeTargetpernew_tab()).Written for commit 5d2e87a. Summary will update on new commits.