Repository navigation
feat(browser): a browser nobody is using rests - #65
Merged
Merged
Conversation
A bot's Edge kept working after the bot was done: a page with a timer and an animation took 84% of a core with nobody watching, and it only closed after 10 minutes with the panel shut, never with it open. Now the browser rests the moment the bot's turn ends (its state leaves `busy` and `needs_approval`): the daemon takes a picture of the active tab, for the panel, and minimizes Edge's window. The pages count as hidden, so timers, animations and frames stop, as in any minimized window; the same page then takes under 1% of a core. Nothing in the pages is lost. It wakes at once for the bot's next browser tool, for the owner's hands and for a reload, and rests again by itself 20 s after the owner used it while the bot is out of a turn. `BrowserState.resting` tells the app. Closing for lack of use no longer waits for nobody to be watching: the panel opens by itself and kept the browser open for good. Use is a tool of the bot or something the owner did with the browser in their hands, and a browser in their hands does not close. `Page.setWebLifecycleState` was tried first and does not work for this: back to `active`, the page stayed hidden and slow. Spec 21.2, 21.7, 21.8, 21.9 and 21.11 (N3.3), and section 19 has the measurements.
In place of "Live" the panel shows "Resting", with a hint that it costs the computer nothing and wakes when the bot or the owner needs it. The browser button in the bot's header no longer says the bot is using a browser that rests. The preview's Analyst has a resting browser.
docs/spec.md: the browser's profile line keeps both changes: resting (this branch) and deleting a bot, which also closes the browser and deletes its profile (#54).
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.
Stacked on #62 (tabs), which is stacked on #53 (the page filling the panel): until those merge, this diff shows their commits too. The two commits of this PR are the last two.
Why
A bot's Edge kept working after the bot was done with it. Measured with Edge 154 on a page with a busy timer and an animation:
And it only closed after 10 minutes with the panel shut. With the panel open it never closed, and the panel opens by itself.
What
busyandneeds_approval). The daemon takes a picture of the active tab, so the panel has something to show, and minimizes Edge's window (Browser.setWindowBounds). The window was never on screen, but for Edge it exists, and its pages now count as hidden: timers, animations and frames stop, as in any window someone minimized. Nothing is lost: tabs, forms and sessions stay as they were.browser_*tool, when the owner takes control and when they reload. After the owner used it with the bot out of a turn, it rests again by itself (20 s without use, checked every 30 s).idle_minutes(10) without use, where use is a tool of the bot or something the owner did with the browser in their hands. In the owner's hands it does not close.BrowserState.resting, and the panel shows "Resting" in place of "Live", with a hint that it costs the computer nothing and wakes when needed. The header's browser button no longer says the bot is using a browser that rests. Texts in en, pt-BR and es.What was tried and dropped
Page.setWebLifecycleStatewithfrozenstops the page too, but back toactiveit stayed hidden and slow, and aPage.bringToFrontafter that hungRuntime.evaluate.Emulation.setCPUThrottlingRateused more CPU, not less.What it does not do
Memory stays in use while the browser rests (about 450 MB each, up to
max_open= 4) until it closes for lack of use.idle_minutesis still 10; lowering it is a one-line change if that is the wish.Tests
crates/botloftd/tests/browser_rest.rs, with the real Edge and a fake bot's turn: the browser rests when the turn ends, a connection that starts watching then gets the picture, the bot's next tool wakes it with the page having been hidden once and nothing lost, frames come again, the owner's hands wake it and keep it from resting, and a reload wakes it.browser.test.tsxwithFakeBotloft: the "Resting" label and its hint, the header button, and taking control waking it.cargo fmt,clippy -D warnings,cargo test --workspaceandpnpm checkpass. The daemon's suite ran 6 times in a row.pnpm dev): Analyst's browser rests.Still to see with real Claude Code
With a real bot on a page that moves (a video site, a dashboard), after its answer: the panel says "Resting" and Task Manager shows its
msedge.exeprocesses near 0% CPU. Then ask the bot to go on in the same page: it wakes and continues without opening the page again.