Auto-close tabs opened by browser-harness runs#354
Open
hamanori wants to merge 1 commit into
Open
Conversation
## 変更内容(What) - `new_tab()` が作成した targetId を CLI プロセス内で追跡する `_OPENED_TABS` を追加した。 - `close_opened_tabs()` / `opened_tabs()` / `keep_opened_tabs()` を追加し、今回の実行で開いたタブだけを閉じられるようにした。 - `browser-harness -c` の `exec()` を `try/finally` で包み、例外終了時も既定では `close_opened_tabs()` を実行するようにした。 - タブを意図的に残す場合の逃げ道として `BH_KEEP_TABS=1` と `keep_opened_tabs()` を用意した。 - `tests/unit/test_tab_cleanup.py` を追加し、通常 cleanup、明示 opt-out、例外時 cleanup、環境変数 opt-out を検証した。 ## 変更理由(Why) - 汎用 CDP profile で Web 調査後のタブが閉じられず、ニュース調査や検索タブが蓄積してブラウザが使いにくくなっていたため。 - 従来は skill / 運用ドキュメント上の「閉じる」手順に依存しており、エージェントや cron が途中失敗した場合に後片付けが漏れる構造だったため。 ## 実装方法(How) - 既存タブや別エージェントのタブを巻き込まないよう、`list_tabs()` の差分ではなく、この Python プロセスの `new_tab()` 経由で作成した targetId だけを管理対象にした。 - cleanup は `Target.closeTarget` の best-effort とし、個別 close 失敗は主処理の例外を上書きしない設計にした。 - 長時間ユーザーに見せたいタブを残せるよう、明示的な opt-out だけを許可した。 ## 影響範囲・注意事項 - `browser-harness -c` で `new_tab()` を使ったタブは、既定で実行終了時に閉じられる。 - タブを残したい調査では `BH_KEEP_TABS=1 browser-harness -c ...` またはスクリプト内で `keep_opened_tabs()` を呼ぶ必要がある。 - `switch_tab()` で既存タブを操作した場合や、別プロセスが開いたタブは自動 cleanup 対象外。 Co-Authored-By: OpenAI Codex <noreply@openai.com>
bb4fafe to
e83393c
Compare
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.
[fix] browser-harness実行終了時に作成タブを自動クリーンアップする
変更内容(What)
new_tab()が作成した targetId を CLI プロセス内で追跡する_OPENED_TABSを追加した。close_opened_tabs()/opened_tabs()/keep_opened_tabs()を追加し、今回の実行で開いたタブだけを閉じられるようにした。browser-harness -cのexec()をtry/finallyで包み、例外終了時も既定ではclose_opened_tabs()を実行するようにした。BH_KEEP_TABS=1とkeep_opened_tabs()を用意した。tests/unit/test_tab_cleanup.pyを追加し、通常 cleanup、明示 opt-out、例外時 cleanup、環境変数 opt-out を検証した。変更理由(Why)
実装方法(How)
list_tabs()の差分ではなく、この Python プロセスのnew_tab()経由で作成した targetId だけを管理対象にした。Target.closeTargetの best-effort とし、個別 close 失敗は主処理の例外を上書きしない設計にした。影響範囲・注意事項
browser-harness -cでnew_tab()を使ったタブは、既定で実行終了時に閉じられる。BH_KEEP_TABS=1 browser-harness -c ...またはスクリプト内でkeep_opened_tabs()を呼ぶ必要がある。switch_tab()で既存タブを操作した場合や、別プロセスが開いたタブは自動 cleanup 対象外。Co-Authored-By: OpenAI Codex noreply@openai.com
Summary by cubic
Automatically closes tabs opened during
browser-harnessruns to prevent leftover clutter. Tabs created vianew_tab()are tracked and closed on exit, including on errors, with an opt-out.Bug Fixes
new_tab()using_OPENED_TABS; addopened_tabs(),keep_opened_tabs(), andclose_opened_tabs(force=...).-cexit using try/finally; skip whenBH_KEEP_TABSis set to1/true/yes(case-insensitive).Migration
BH_KEEP_TABS=1or callkeep_opened_tabs()in your script.Written for commit e83393c. Summary will update on new commits.