Skip to content

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

Merged
SSFSKIM merged 6 commits into
masterfrom
subagent-relist
Nov 1, 2026

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

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 whole subagents/ tree through SubagentReader.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's fs.scan { known } binds them all. A terminal session had 4,233 files under subagents/ and a workflow writing about 75 files a minute, so the cost was changes × files and never let up.

What changes

  • Incremental listing (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 is null, 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.
  • One pass at a time per session (FsService, src/engine-host/fs/service.ts):
    • A walk that callers request (fs.subagents, agentEvents, a follow's start, the reconcile tick) is shared by every caller that asked while it was waiting.
    • Change-driven passes start immediately after a quiet spell and run at most once per AGENT_SETTLE_MS (100 ms) under load; after a failed pass the next one waits AGENT_RETRY_MS (5 s).
    • A burst of N changes during a walk costs that one walk plus one incremental pass.
  • Only sessions that something reads get listed on change. That means sessions with a follow (the backfill's Agent lookup) or sessions a client holds open (host.interest). With no interest source wired (tests, diagnostics), every bound session counts, as before.
    • A session that was read before keeps a set of its changes while nobody reads it, and reads them as soon as a reader appears.
    • The 30 s reconcile tick walks only sessions that something reads.
  • Ordering for follows (review findings): every follower poke waits until the agent-file changes reported so far have been read (agentsCaughtUp in pokeFollows). 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's Agent tool 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.
  • Quiet history follows (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.subagentsChanged still fires on the same agent-set-and-meta comparison, now made entry by entry. fs.subagents answers 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 with fs.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 as host.interest (src/main/sessions/interest.ts). The engine host merges every client's set and already feeds the result to FsService.watchInterest for releasing follows.
  • this.agents: inside the host it feeds subagentLookup for each follow's backfill (Agent tool use → subagent.started with the meta and prompt, retried at the tool result and at the task notification).
  • So a session that no client holds open and nothing follows has no consumer of change-driven listings.

Measurement

Bench: src/engine-host/fs/subagents-bench.test.ts, run with MAWS_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%.

load before after
10 writes/s, 20 s 220 walks, 271% CPU (54.4 s of CPU) 0 walks (197 incremental passes), 1% CPU (0.23 s)
40 writes/s, 10 s 441 walks, 325% CPU (109 s), 23.6 s backlog after the writes stopped 0 walks (99 passes), 2% CPU (0.20 s), no backlog

The bench also checks that the last fs.subagentsChanged names 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 answer null.
  • src/engine-host/fs/service.test.ts ("the agent listing under change"):
    • 80 changes during a held walk cost that walk alone plus at most 2 incremental passes.
    • Callers during a walk share one later walk.
    • Each change read alone emits what a walk would.
    • An unread session gathers its changes and reads them when it is held open; a never-listed session is not listed.
    • The reconcile tick walks only held sessions.
    • A followed session is listed on change.
    • A failing pass is not retried on every write.
    • A followed transcript folds an Agent result only after the child's meta is read.
    • The reconcile tick's poke waits for the changes gathered before it.
    • A quiet history follow reads the gathered changes first.
    • A failed listing is read again before a follow trusts it, once its retry wait has passed.
  • The four review-finding tests fail against the earlier service versions they guard (checked locally). The whole set of new service tests passed 15 of 15 runs across three concurrent loops on this Mac.

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, agentEvents and a follow's start still walk the whole tree: one walk per user action.
  • The reconcile tick still walks a held-open or followed session every 30 s, about 0.7 s CPU for a 4,000-file tree (around 2% of a core while it is open). Logged in docs/tech-debt-tracker.md.
  • A poke from the tick or a rescan that lands within the watcher's 50 ms debounce of a child's meta write can still fold the parent's Agent result before the meta is reported. This window predates the change, and the transcript change's own poke is always ordered. Logged in docs/tech-debt-tracker.md.
  • A directory renamed under subagents/ is still seen only by the reconcile or a rescan, as before.
  • A client that never reports host.interest would get no fs.subagentsChanged for its open sessions. Every current app reports interest.

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)

…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)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T23:06:39.792456Z f04865d PR opened
ℹ️ 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" or "@codex security review".

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@SSFSKIM
SSFSKIM merged commit 2d24e58 into master Nov 1, 2026
SSFSKIM added a commit that referenced this pull request Nov 1, 2026
…wap fixed (PR #419, master 2d24e58); a tracker row for cua's forwarding of every CDP event of a leased tab (O5's U3 spike); the wave 2 ledger gains O7 M4a2's fix waves' and M4b's names

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
SSFSKIM added a commit that referenced this pull request Nov 1, 2026
…RE_MINOR 14

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
SSFSKIM added a commit that referenced this pull request Nov 1, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant