Repository navigation
fs service: read changed agent files alone, one pass at a time, only for sessions something reads (the supervisor's idle 225-290% CPU) - #419
Conversation
…e pass at a time, and only while something reads it; a workflow writing into a session with thousands of agents no longer walks the whole subagents/ tree per write (the supervisor at 225-290% CPU, 4,233 files, about 75 writes a minute) Every AGENT_SIDECAR change re-walked the session's subagents/ tree (a stat, a meta read and a prompt read per agent), chained one walk per change, for any bound session; main's fs.scan binds every indexed session. Now SubagentReader.update brings a listing up to date from the changed paths (a new agent, a meta written, patched or gone, an append, a relocation; deeper than the walk looks is ignored as the walk ignores it) and answers null where only a walk can settle the change. Per session one pass runs at a time: a caller's walk (fs.subagents, agentEvents, a follow's start, the reconcile tick) is shared by every caller that asked while it waited; changes drive a pass at once after a quiet spell and at most one per AGENT_SETTLE_MS (100 ms) otherwise, AGENT_RETRY_MS (5 s) after a failed one. Change-driven passes and the reconcile tick list only a session something reads: a follow of it (the backfill's Agent lookup) or a client holding it open (host.interest; the task-graph store, fs.subagentsChanged's only reader, watches only sessions in a tab or on screen and starts with fs.subagents); a session read before gathers its changes until a client holds it again. fs.subagentsChanged fires on the same agent-set-and-meta comparison, now made per entry. Bench (src/engine-host/fs/subagents-bench.test.ts, MAWS_BENCH=1; 2,020 agents, 4,040 files): at 10 writes/s for 20 s, 220 walks and 271% CPU before, 0 walks and 1% after; at 40 writes/s for 10 s, 441 walks, 325% CPU and 23.6 s of backlog after the writes stopped before, 0 walks, 1% and no backlog after. Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
…iles reported before it are read, and a quiet history follow brings its session's agent listing up to date first (review findings on the relist change) The engine writes a child's meta before the parent's Agent tool result, and the backfill looks the child up once, when it folds that result. With passes at most one per AGENT_SETTLE_MS, a meta that landed within that window of the last pass could still be unread when the result was folded, and the child then had no subagent.started or subagent.finished. A follower is now poked once the session's listing has caught up with every change gathered so far (agentsCaughtUp, which starts the owed pass at once rather than after the window; a listing in its failure retry does not hold the fold). The quiet follow (eventsSnapshot's older history of a live session) built its backfill on whatever listing was held, which a session nothing read no longer keeps current: it now reads the changes gathered meanwhile first, or walks a session never listed, as the session's own follow does. Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
…fore it (the reconcile tick's, a rescan's and a relocation's too), and a listing whose pass failed is owed a pass once its retry wait has passed (second review round) The ordering barrier moves into pokeFollows itself, so no entry point folds a transcript record ahead of an agent meta reported before it; a picked follower's new location still applies at once. agentsCaughtUp counted only gathered paths as owed, so after a failed pass consumed them, a quiet follow started past the retry wait trusted the stale listing; a stale listing is now owed a pass too. AGENT_RETRY_MS can be set per service (agentRetryMs) for tests. Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
…ore before the follower reads, since the follower reads what the transcript holds by then (the tick test's 1-in-10 failure under load) A poke asked while a walk ran waited for that walk alone; a meta reported while it waited, and the parent's tool result written after it, were then read by the follower ahead of the meta's pass. The poke now waits for what was reported meanwhile too, once more and no further, so a steady stream of agent writes cannot hold a follower back. The tick test writes the child, lets its changes be reported, then writes the parent's result, as the engine orders them. Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
…session, and a follow's fold that can still run ahead of a child's meta inside the watcher's debounce (residue of the relist change) Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook) # Conflicts: # docs/tech-debt-tracker.md
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f04865db7c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (appSessionId === null) continue; | ||
| try { | ||
| await this.listAgents(sessionId); | ||
| if (this.agentsRead(sessionId)) await this.listAgents(sessionId); // one nothing reads is walked when it is next asked for |
There was a problem hiding this comment.
Mark skipped listings stale when reconciling sidecars
If a previously listed session is inactive when a nameless watch event triggers a rescan, this now skips its listing without recording that changes may have been missed. When the session is reopened, noteInterest only schedules recorded changes or stale listings, and quietFollow trusts agentsCaughtUp for an existing cache, so neither necessarily performs a fresh walk. A quiet history request before the next reconcile tick can therefore backfill against the old agent list and permanently omit the missed children's lifecycle events; a later listing refresh does not refold that history. Mark skipped cached listings stale so their next reader performs the deferred reconciliation.
Useful? React with 👍 / 👎.
…RE_MINOR 14 Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
…rt --engine-host with a child, a pending permission and #419's listing, (f)/(g) branch on host.holder (older host kept by an e2e seam), (f) deferred by a held tool call, cross-build hands over between two capable builds; host.op runs in flight finish their claim before the engine host exits Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
Why
The owner's engine host (
maws-supervisor, master 3adf9c9) ran at 225–290% CPU for 25 minutes while the app sat idle. Every agent sidecar change (subagents/**/agent-<id>.jsonl|.meta.json) re-walked the session's wholesubagents/tree throughSubagentReader.list, doing a readdir, then a stat, a meta read and a prompt read per agent. The walks were chained one per change, and this happened for any bound session, which in practice is every indexed one, because main'sfs.scan { known }binds them all. A terminal session had 4,233 files undersubagents/and a workflow writing about 75 files a minute, so the cost was changes × files and never let up.What changes
SubagentReader.update,src/engine-host/fs/subagents.ts): brings a listing up to date by reading only the changed agent files. It handles a new agent, a meta written, patched or removed, a transcript append, a deletion and a relocation. A file deeper than the walk looks is ignored, as the walk ignores it. Each touched entry is read by the same per-entry code the walk uses and inserted in the walk's order. The result isnull, and the caller walks instead, when the result could be wrong: a path that names no agent file, a directory under an agent transcript's name, a failed read, or a sort tie.FsService,src/engine-host/fs/service.ts):fs.subagents,agentEvents, a follow's start, the reconcile tick) is shared by every caller that asked while it was waiting.AGENT_SETTLE_MS(100 ms) under load; after a failed pass the next one waitsAGENT_RETRY_MS(5 s).Agentlookup) or sessions a client holds open (host.interest). With no interest source wired (tests, diagnostics), every bound session counts, as before.agentsCaughtUpinpokeFollows). That covers the transcript-change poke, the agent-file poke, the reconcile tick, rescans and relocations. The pass those changes are owed starts immediately, skipping the 100 ms gap. While the follower waits, it waits once more for any changes reported in the meantime, but no further than that. The engine writes a child's meta before the parent'sAgenttool result, and the backfill looks the child up only once, when it folds that result. A listing whose pass failed is owed a pass once its retry wait has passed.eventsSnapshot's older pages of a live session) bring the session's listing up to date before they start: a session nothing has been reading gets its gathered changes read, and a session never listed is walked.fs.subagentsChangedstill fires on the same agent-set-and-meta comparison, now made entry by entry.fs.subagentsanswers are still fresh walks.Who reads the agent listings
fs.subagentsChanged: main forwards it to the app windows (src/main/ipc/events.ts), and no main-side tap or service reads it. In the renderer, its only consumer is the task-graph store (src/renderer/src/tools/agents/store.ts), and only while a component watches a session (the Subagents and Background tools and summaries, or the harness). A watch begins withfs.subagents, a fresh walk, and then applies the change events. Those components show sessions in a tab or on screen, which is the set main reports ashost.interest(src/main/sessions/interest.ts). The engine host merges every client's set and already feeds the result toFsService.watchInterestfor releasing follows.this.agents: inside the host it feedssubagentLookupfor each follow's backfill (Agenttool use →subagent.startedwith the meta and prompt, retried at the tool result and at the task notification).Measurement
Bench:
src/engine-host/fs/subagents-bench.test.ts, run withMAWS_BENCH=1. One bound session with 2,020 agents (4,040 files, a third under workflow runs) receives a steady mix of writes: appends, meta patches and new agents. Each write is reported as the watcher would report it. CPU is process user+system time minus the writer's own, measured until the service has caught up. One walk of the tree costs about 150–260 ms wall and 570–770 ms CPU. The "after" numbers come from the final head; earlier commits of this branch measured the same to within 1%.The bench also checks that the last
fs.subagentsChangednames the same agents a fresh walk finds.Tests
src/engine-host/fs/subagents.test.ts: each incremental case is compared against a fresh walk of the tree it left: a new agent (transcript, then meta, in a run), a patched meta (untouched entries keep their identity), an append, a deletion (either order or the transcript alone), a meta with no transcript, a relocation into a run, an agent deeper than the walk looks, and the cases that answernull.src/engine-host/fs/service.test.ts("the agent listing under change"):Agentresult only after the child's meta is read.Gate
Run 41251802912 on tree
e7a62e32c5147a7949d49a02294adef976a3488b(head b840aa9, after merging master 18b5584) passed static, unit, unit:darwin, probes, and the e2e groups default, lane-a, agents, transcript, supervisor, side, available and c12. Before the merge, the same set passed on f04865d (run 41249576549).No e2e spec imports the changed files, so the coverage planner reached no group. The e2e groups were chosen because their specs run the real store, transcripts or the agent tools.
Left out
fs.subagents,agentEventsand a follow's start still walk the whole tree: one walk per user action.docs/tech-debt-tracker.md.Agentresult before the meta is reported. This window predates the change, and the transcript change's own poke is always ordered. Logged indocs/tech-debt-tracker.md.subagents/is still seen only by the reconcile or a rescan, as before.host.interestwould get nofs.subagentsChangedfor its open sessions. Every current app reports interest.Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)