Repository navigation
fix(commands): scan skill folders on the file threads, not the server's (#2254) - #2311
Conversation
…'s (#2254) GET /api/pane/commands and /api/agent/commands read every skill and command folder the agent would, synchronously, on the server's only thread. On a slow mount (a Windows folder bind-mounted over 9p) that took 10-27 s, and every terminal, typed key and request waited with it. The scan (paneCommands) now runs on #2256's file threads as a `commands` task: at most 2 of the 4 threads run one at a time, so the file routes keep theirs. A request waits for its scan at most 45 s (under the 60 s API idle cutoff) and is then answered 503 file_busy; the scan goes on, and a request for the same scan made meanwhile (the menu asks again after a failed read) waits for it instead of starting another, so a scan slower than one request still answers the next. A finished scan is not kept, so a skill added on disk shows up next time. A Bun thread keeps the environment the process started with, so the server's home and environment are handed to the scan (serverEnv), and pi, Codex and Claude read PI_CODING_AGENT_DIR, ProgramData and ProgramFiles from it. Co-authored-by: sisyphus-dev-ai <[email protected]>
scripts/bench-file-access.ts gains a commands case when --slow-root holds a project/.claude: the pane's home links its .claude/skills and commands to the project's, as the reporter's did, so the scan walks the slow folders twice. --cases runs only the matching cases. Co-authored-by: sisyphus-dev-ai <[email protected]>
…rom the request's start (#2254) Review follow-ups: - A scan still waiting for a thread when its last request gives up is dropped, so it no longer keeps one of the shared waiting places for minutes (and file routes are not refused for it). - A scan that finishes after every request waiting for it gave up is kept for 35 s, longer than the menu's longest pause before it asks again, and handed to the next request once; an answer a request received is still never kept. - A request's wait counts from when it arrived, herdr lookups included, so its 503 always comes before Bun's 60 s idle cutoff. - The machine proxy passes on a PC's Retry-After with its 503. Co-authored-by: sisyphus-dev-ai <[email protected]>
Review follow-up: a request that leaves as soon as its scan starts can be repeated for many folders, and each unclaimed answer was kept 35 s whatever its size. Keep at most 16, of about 8 MiB of text in all, dropping the oldest first; an answer larger than that is not kept. Co-authored-by: sisyphus-dev-ai <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 11 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
CodeRabbit did not review this head (review limit reached). This PR changes an HTTP contract ( omo-native-code-reviewer on 8144a77: PASS
Codex Sol 6.1 Fast xhigh on 8144a77: FAIL
Codex Sol 6.1 Fast xhigh, final round on 8144a77..628c9ce: FAIL
No CRITICAL or HIGH finding was raised. |
…2254) Merge-pass finding: /api/agent/commands can now answer a transient 503 file_busy (a scan of slow skill folders past its wait), but the New session dialog read it once, cleared its skill rows and showed the error until the folder, agent or dialog changed; only pane commands retried. The dialog's skill read moves into useAgentSkills, which keeps the list on its way on a busy answer and asks again after the larger of the PC's Retry-After and its own 1/2/5/15/30 s pause (at most 60 s each); after those five tries it shows the error as before. A new agent, folder or closing cancels a pending retry. ApiError now carries Retry-After. Tests: useAgentSkills.hook.test.ts (busy then listed, a longer Retry-After honoured, bounded tries, no retry after closing; all but the last fail on the old read), and the New session browser QA answers Codex's list busy once and still shows its chips (times out without the retry). Co-authored-by: sisyphus-dev-ai <[email protected]>
|
Merge-pass M1 (the New session dialog's skill list treated the new
|
|
Merging e35141e (closes #2254; thanks to @PayrollFuchs for the report and the measurements). |
Closes #2254. Thanks to @PayrollFuchs for the report and the measurements.
Problem
GET /api/pane/commands(and/api/agent/commands) built the slash menu by scanning every skill andcommand folder the agent reads (
paneCommands->AGENT_SOURCES[agent].discover->server/skills/walk.ts), with synchronousreaddirSync/statSync/openSync/realpathSync, on theserver's only thread. With the folders on a slow filesystem (the reporter's: a Windows folder
bind-mounted into a container over 9p, about 2.8 ms per
stat, 95 skill folders reached twice through~/.claudelinks) one request took 10-27 s, and every terminal stream, typed key,/api/healthandherdr RPC waited with it.
Change
server/file-pool.ts) as a newcommandstask(
server/file-tasks.ts). At most 2 of the 4 threads run a scan at once (scans), so the fileroutes keep the others; a scan past the cap waits, and the tasks behind it still take a free thread.
scanPaneCommands(server/commands.ts):lookups included), then gets
503 file_busywithretry-after: 1, before Bun's 60 s idle cutoff;read, at 2/5/15/30 s) waits for that one instead of starting another; a scan that finishes after
everyone waiting gave up is kept 35 s and handed to the next request once, so a scan slower than
one request's wait still reaches the menu (at most 16 such answers, about 8 MiB of text in all,
the oldest dropped first);
place;
on disk since (as before).
home and environment (
serverEnv); pi, Codex and Claude readPI_CODING_AGENT_DIR,ProgramDataand
ProgramFilesfrom it instead ofprocess.env.Retry-Afterwith its 503.useAgentSkills, moved out ofNewSessionDialog.tsx) asks again on503 file_busyafter the larger ofRetry-Afterand a 1/2/5/15/30 s pause, then shows the error;the pane menu already retried (
usePaneCommands).ApiErrorcarriesretryAfterMs.scripts/bench-file-access.tsgains a commands case (--slow-rootwith aproject/.claude;--casesfilters cases).No herdr RPC, attach, focus, takeover or access-control code changes; read-only devices are still
refused the rows before any scan (#2132).
Measurements
bun scripts/bench-file-access.ts --runs 3 --slow-root <mnt> --cases 'commands|^stat a file$', theserver in a child process (port 0, mkdtemp state, stand-in herdr socket),
/api/healthprobed every5 ms from its own thread, event-loop lag sampled every 5 ms. Mount: a FUSE passthrough that waits 2 ms
before each getattr/readdir/open/read/readlink (no attribute cache), holding a project with 95 skill
folders and 5 command files, the server's
~/.claude/skillsand~/.claude/commandslinked to theproject's, as the reporter's were. The raw scan there takes 20.6 s. Median [min-max] of 3 runs, ms:
/api/health/api/healthanswers during the scanKnown limits
until that call returns, as fix(files): read the disk for the file routes on bounded background threads (#790) #2256's file tasks do; requests for it get 503, the rest of the server
keeps answering.
server/skills/omo.tsalso bounds its walk byos.homedir(), which on a thread isthe process's starting HOME (the same unless HOME changes after the server starts); on Windows the
handed-over environment is read with the variables' exact names (
ProgramFiles,ProgramData), asWindows sets them.
Tests
server/pane-routes.test.ts: a Claude pane whose.claude/settings.jsonis a FIFO held by a writerthread, which the test lets go only from its own thread while the scan is blocked: on main the
writer times out (
timed-out, the server thread was held for the whole read); here it is releasedand the route lists the project's skill. A request past its wait gets 503 and a request for the same
scan joins it (one thread). A scan that finished after its request gave up goes to the next request
once (without a skill added since), and the request after that scans again.
server/file-pool.test.ts: at mostscansscans run while a file task takes a free thread; a scan'sown deadline; the server's
PI_CODING_AGENT_DIRreaches the thread; a request's wait counts from itsstart, and a queued scan nobody waits for frees its waiting place.
server/machine-proxy.test.ts: a PC's 503 keeps itsRetry-After.src/lib/useAgentSkills.hook.test.ts: a busy answer is asked again and listed, a longerRetry-Afteris honoured, tries are bounded, and closing stops them.
scripts/new-session-skills-browser-qa.tsanswers Codex's skill list busy once and still shows its chips.
from start, unclaimed hand-over, its entry and size bounds, Retry-After) fails its test.
server/skills, pane routes, file pool/routes/view, http idletimeout, machine proxy, catalog sources): 529 pass; the three changed test files 11 runs in a row,
8 of them 4 at once, all green.
bun run check faston e35141e (this head): all steps pass, 8,411 unit tests, 0 fail. (Runsstarted from a shell that exported
PYTHONUNBUFFERED=1failedserver/codex-processes.test.ts,untouched here: its
holding()helper reads one chunk of a python3 child's stdout and expects thewhole
READY\n, which unbuffered Python writes in two parts under load. LOW, test-only.)Reviews
scan nobody waits for kept a shared waiting place; a scan finishing between the menu's retries was
thrown away). LOWs listed above.
could pass the 60 s idle cutoff), fixed in 628c9ce with a test; one LOW (the machine proxy dropped
Retry-After), fixed with a test.answers had no size bound: 32 abandoned scans of large catalogs held 136 MiB for 35 s), fixed in the
last commit with a test that fails without either bound. Per the review policy that fix was not sent
to Codex again; the merge pass reviews it.