feat(ego-browser): reclaim idle agent task spaces to release renderers - #271
Open
Vitus213 wants to merge 1 commit into
Open
feat(ego-browser): reclaim idle agent task spaces to release renderers#271Vitus213 wants to merge 1 commit into
Vitus213 wants to merge 1 commit into
Conversation
Agent task spaces left by earlier sessions were never auto-closed; their tabs and renderer processes piled up across heredoc/omp rounds (observed ~58 ego helper processes and ~35GB swap over 26h), exhausting memory on long-running setups.
Add a lazy idle reaper:
- taskspace-activity.ts: persist {spaceId->lastTouchedAt} atomically (tmp+rename) to EGO_RECLAIM_STATE_FILE; helpers.selectTaskSpace touches it per use (gated by EGO_RECLAIM_DISABLE).
- taskspace-reclaim.ts: reclaimIdleTaskSpaces() closes agent-owned spaces idle past EGO_RECLAIM_IDLE_S (default 7200s) or over EGO_RECLAIM_MAX_SPACES (default 8). First-sight seeding skips spaces with no record (created before this feature shipped, or in use by a concurrent session) so a fresh deploy never mass-closes them; only ownership==agent is ever reclaimed.
- run.ts execute() and helpers.useOrCreateTaskSpace() each trigger it once per process (state.reclaimDone guard), covering both CLI and embedded app SDK modes.
Env: EGO_RECLAIM_IDLE_S / EGO_RECLAIM_MAX_SPACES / EGO_RECLAIM_DISABLE / EGO_RECLAIM_STATE_FILE. e2e/helpers tests set EGO_RECLAIM_DISABLE=1 to keep call sequences deterministic; dedicated suite in taskspace-{activity,reclaim}.test.mjs.
Verified: npm test 312 pass / 0 fail.
Author
|
@section9-lab @WUXM5 Hi — this PR has been open for a few days with no review. It reclaims idle agent task spaces so their renderer processes are released, cutting memory footprint when agents park between rounds. Happy to adjust scope or add tests if needed — just let me know what would help move this forward. 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.
What
Add lazy idle task-space reclamation so agent task spaces left by earlier sessions — and their renderer processes — get released automatically instead of piling up.
Closes #270.
Why
Today
completeTaskSpaceis the only release path and it is 100% agent-driven; abandoned sessions leak renderer processes and swap climbs monotonically (see #270 for 26h measurements: 20→58 helper processes, 10→35 GB swap). The harness kept no cross-process activity state andlistTaskSpacescarries no timestamp, so there was nothing to time out against.How to verify
Behavior covered by the new
taskspace-reclaim.test.mjs:EGO_RECLAIM_IDLE_S(default 7200s) is closed; a fresh one is keptownership === "user"is never touchedEGO_RECLAIM_MAX_SPACES) reclaims oldest-first when over the capEGO_RECLAIM_DISABLE=1is a no-opnowand skipped (deploy safety — never mass-closes pre-existing / in-use spaces); they only become reclaimable after the idle windowegoruntime → empty result, no throwManual (against a live browser):
Impact
run.ts execute()(CLI mode) andhelpers.useOrCreateTaskSpace()(embedded app-SDK mode), collapsed to once-per-process viastate.reclaimDone.completeTaskSpacebehave identically; agents that forget it now have a safety net.taskspace-e2e.test.mjsandhelpers.test.mjssetEGO_RECLAIM_DISABLE=1in their harness so call-sequence assertions stay deterministic. New suites:taskspace-activity.test.mjs,taskspace-reclaim.test.mjs.EGO_RECLAIM_DISABLE=1opts out.Files
src/taskspace-activity.ts(new) — activity map + atomic persistence + configsrc/taskspace-reclaim.ts(new) — reclaim logic; talks toglobalThis.egodirectly (no helpers import → no cycle); once-per-process guardsrc/helpers.ts—selectTaskSpacetouches activity (gated by disabled);useOrCreateTaskSpacetriggers reclaim (CLI+app-SDK coverage)src/run.ts—execute()triggers reclaim (CLI coverage)src/state.ts—reclaimDoneonce-guardAGENTS.md— Task Spaces section documents the mechanism + envOpen questions for reviewers
useOrCreateTaskSpaceas the app-SDK trigger point — acceptable, or prefer a different hook?