Skip to content

fix(commands): scan skill folders on the file threads, not the server's (#2254) - #2311

Merged
devswha merged 5 commits into
mainfrom
fix/commands-slow-skill-folders
Oct 29, 2026
Merged

devswha merged 5 commits into
mainfrom
fix/commands-slow-skill-folders

Conversation

@devswha

@devswha devswha commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

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 and
command folder the agent reads (paneCommands -> AGENT_SOURCES[agent].discover ->
server/skills/walk.ts), with synchronous readdirSync/statSync/openSync/realpathSync, on the
server'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
~/.claude links) one request took 10-27 s, and every terminal stream, typed key, /api/health and
herdr RPC waited with it.

Change

  • The scan runs on fix(files): read the disk for the file routes on bounded background threads (#790) #2256's file threads (server/file-pool.ts) as a new commands task
    (server/file-tasks.ts). At most 2 of the 4 threads run a scan at once (scans), so the file
    routes keep the others; a scan past the cap waits, and the tasks behind it still take a free thread.
  • scanPaneCommands (server/commands.ts):
    • a request waits for its scan at most 45 s, counted from when the request arrived (its herdr
      lookups included), then gets 503 file_busy with retry-after: 1, before Bun's 60 s idle cutoff;
    • the scan goes on: a request for the same scan made meanwhile (the menu asks again after a failed
      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);
    • a scan still waiting for a thread when its last request leaves is dropped, so it holds no waiting
      place;
    • an answer a request received is never kept: the next request scans again and sees a skill added
      on disk since (as before).
  • A Bun thread keeps the environment the process started with, so the scan is handed the server's
    home and environment (serverEnv); pi, Codex and Claude read PI_CODING_AGENT_DIR, ProgramData
    and ProgramFiles from it instead of process.env.
  • The machine proxy passes on a PC's Retry-After with its 503.
  • The New session dialog's skill list (useAgentSkills, moved out of NewSessionDialog.tsx) asks again on
    503 file_busy after the larger of Retry-After and a 1/2/5/15/30 s pause, then shows the error;
    the pane menu already retried (usePaneCommands). ApiError carries retryAfterMs.
  • scripts/bench-file-access.ts gains a commands case (--slow-root with a project/.claude;
    --cases filters 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$', the
server in a child process (port 0, mkdtemp state, stand-in herdr socket), /api/health probed every
5 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/skills and ~/.claude/commands linked to the
project's, as the reporter's were. The raw scan there takes 20.6 s. Median [min-max] of 3 runs, ms:

main 9faf067 this branch
max event-loop lag 28725 [28452-33286] 62 [35-65]
slowest /api/health 28736 [28466-33298] 67 [40-68]
/api/health answers during the scan 2 [1-3] 4923 [4697-5143]
the commands request itself 28730 [28468-33322] 26686 [24567-27799]

Known limits

  • A scan stuck in a system call that never returns keeps its thread (and one of the 2 scan slots)
    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.
  • LOW, not changed: server/skills/omo.ts also bounds its walk by os.homedir(), which on a thread is
    the 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), as
    Windows sets them.

Tests

  • server/pane-routes.test.ts: a Claude pane whose .claude/settings.json is a FIFO held by a writer
    thread, 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 released
    and 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 most scans scans run while a file task takes a free thread; a scan's
    own deadline; the server's PI_CODING_AGENT_DIR reaches the thread; a request's wait counts from its
    start, and a queued scan nobody waits for frees its waiting place.
  • server/machine-proxy.test.ts: a PC's 503 keeps its Retry-After.
  • src/lib/useAgentSkills.hook.test.ts: a busy answer is asked again and listed, a longer Retry-After
    is honoured, tries are bounded, and closing stops them. scripts/new-session-skills-browser-qa.ts
    answers Codex's skill list busy once and still shows its chips.
  • Mutations: each fix removed (scan cap, serverEnv, scan deadline, join, abort of a queued scan, wait
    from start, unclaimed hand-over, its entry and size bounds, Retry-After) fails its test.
  • Targeted suites (commands, all server/skills, pane routes, file pool/routes/view, http idle
    timeout, 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 fast on e35141e (this head): all steps pass, 8,411 unit tests, 0 fail. (Runs
    started from a shell that exported PYTHONUNBUFFERED=1 failed server/codex-processes.test.ts,
    untouched here: its holding() helper reads one chunk of a python3 child's stdout and expects the
    whole READY\n, which unbuffered Python writes in two parts under load. LOW, test-only.)

Reviews

  • omo-native-code-reviewer on 8144a77: PASS, two MEDIUM, both fixed in 628c9ce with tests (a queued
    scan nobody waits for kept a shared waiting place; a scan finishing between the menu's retries was
    thrown away). LOWs listed above.
  • Codex Sol 6.1 Fast xhigh on 8144a77: FAIL, one MEDIUM (the wait began after the herdr lookups and
    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.
  • Codex Sol 6.1 Fast xhigh, final round on the delta 8144a77..628c9ce: FAIL, one MEDIUM (unclaimed
    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.

devswha and others added 4 commits October 29, 2026 11:04
…'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]>
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 5d3b515 and e35141e.

Files selected for processing: 20
  • changelog.d/commands-scan-off-server-thread.md
  • scripts/bench-file-access.ts
  • scripts/new-session-skills-browser-qa.ts
  • server/commands.ts
  • server/file-pool.test.ts
  • server/file-pool.ts
  • server/file-tasks.ts
  • server/machine-api.ts
  • server/machine-proxy.test.ts
  • server/pane-routes.test.ts
  • server/pane-routes.ts
  • server/skills/claude.ts
  • server/skills/codex.ts
  • server/skills/index.ts
  • server/skills/pi.ts
  • src/components/NewSessionDialog.tsx
  • src/lib/api.ts
  • src/lib/i18n.test.ts
  • src/lib/useAgentSkills.hook.test.ts
  • src/lib/useAgentSkills.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 29, 2026

Copy link
Copy Markdown
Owner Author

CodeRabbit did not review this head (review limit reached). This PR changes an HTTP contract (/api/pane/commands and /api/agent/commands can now answer 503 file_busy with Retry-After), so here are the code-review agents' findings and how each was resolved.

omo-native-code-reviewer on 8144a77: PASS

  • MEDIUM: a scan still waiting for a thread kept one of the 64 shared waiting places for up to 5 minutes after every request for it had left, so file routes could be refused. Fixed in 628c9ce: each scan counts its waiters, and one that no thread has taken yet is dropped when its last waiter leaves. Test: server/file-pool.test.ts "counts a request's wait from when it began, and drops a scan still waiting for a thread once nobody waits for it" (fails with the drop removed).
  • MEDIUM: a scan that finished between the menu's retries (2/5/15/30 s) reached nobody, and the next retry started it again, so a scan longer than about 2 minutes might never be delivered. Fixed in 628c9ce: an answer that reached no waiter is kept 35 s and handed to the next identical request once. Test: server/pane-routes.test.ts "hands a scan that finished after its request gave up to the next request once, then scans again" (fails without it).
  • LOW (left as is, listed under Known limits): skills/omo.ts also bounds its walk by os.homedir(), which is the starting HOME on a thread; the copied environment is read with Windows' exact variable names; a scan stuck in a call that never returns keeps its slot; the pre-scan lookups could push the 503 past the idle cutoff (fixed below with Codex's MEDIUM).

Codex Sol 6.1 Fast xhigh on 8144a77: FAIL

  • MEDIUM: the 45 s wait began after the herdr lookups, so with slow lookups the 503 could come after Bun's 60 s idle cutoff and the client would get a closed socket. Fixed in 628c9ce: the wait counts from the route's start. Test: same file-pool test (with the old timing it waits 30 s and times out).
  • LOW: the machine proxy dropped a PC's Retry-After on a 503. Fixed in 628c9ce. Test: server/machine-proxy.test.ts "passes on a PC's 503 with its Retry-After".

Codex Sol 6.1 Fast xhigh, final round on 8144a77..628c9ce: FAIL

  • MEDIUM: unclaimed answers had no size bound (32 abandoned scans of large catalogs held about 136 MiB for 35 s). Fixed in 28535aa: at most 16 answers, about 8 MiB of text in all, oldest dropped first; one larger than that is not kept. Test: server/file-pool.test.ts "keeps a bounded number of unclaimed scan answers" (fails without either bound). Per the review policy's last-round rule this fix was not sent back to Codex; the merge pass reviews it.

No CRITICAL or HIGH finding was raised. bun run check fast on 28535aa: all steps pass, 8,407 unit tests, 0 fail.

…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]>
@devswha

devswha commented Oct 29, 2026

Copy link
Copy Markdown
Owner Author

Merge-pass M1 (the New session dialog's skill list treated the new 503 file_busy as a permanent error): fixed in e35141e.

  • The dialog's skill read moved into src/lib/useAgentSkills.ts unchanged, then gained the retry: on 503 file_busy the list stays "on its way" (no rows cleared, no error note) and is asked for again after the larger of the PC's Retry-After and its own 1/2/5/15/30 s pause (each at most 60 s). After those five tries it shows the error as before. A new agent, folder or closing the dialog cancels a pending retry. ApiError now carries retryAfterMs.
  • src/lib/useAgentSkills.hook.test.ts (real React, real fetchAgentCommands, only fetch stubbed): busy then listed; a Retry-After: 4 waits 4 s, not 1 s; bounded at 6 reads, then the note; no further read after closing. The first three fail on 28535aa's read (the error note is shown and nothing is asked again); the last fails with the cleanup's clearTimeout removed.
  • scripts/new-session-skills-browser-qa.ts: Codex's list is answered 503 file_busy once, and the dialog still shows its chips with no error. Passes on e35141e (all 7 checks); with the retry list emptied it times out waiting for the chips.
  • bun run check fast on e35141e: all steps pass, 8,411 unit tests, 0 fail.

@devswha

devswha commented Oct 29, 2026

Copy link
Copy Markdown
Owner Author

Merging e35141e (closes #2254; thanks to @PayrollFuchs for the report and the measurements). GET /api/pane/commands and /api/agent/commands scanned every skill and command folder synchronously on the server's only thread, so on a slow filesystem (the reporter's 9p bind mount) one request stalled every terminal stream, key and RPC for 10-27 s. The scan now runs on #2256's file threads as a commands task, at most 2 of the 4 at once so file routes keep the others; a request waits at most 45 s and then gets 503 file_busy with retry-after: 1, while the scan goes on and a retry joins it. The lane's slow-mount bench: server loop stall 28.7 s -> 62 ms. The merge pass's review blocked the first head on one MEDIUM: the New session dialog's skill list did not retry file_busy and stayed on an error note; e35141e adds the retry (src/lib/useAgentSkills.ts: Retry-After or 1/2/5/15/30 s, capped at 60 s, cancelled on agent/folder change and close), and the re-review verified recovery without user action, cancellation, no request storm and the cap with deterministic clocks. Worker parity with the old scan, file routes not starved, joined-failure propagation and responsiveness were verified on the first round; 396 tests, file-pool suite 10/10 in a row, typecheck clean; omo and Codex PASS. Not filed (LOW): useAgentSkills.ts:48-49 allows five retries, six requests in all, not five in all.

@devswha
devswha merged commit 010a44d into main Oct 29, 2026
21 checks passed
@devswha
devswha deleted the fix/commands-slow-skill-folders branch October 29, 2026 03:10
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.

/api/pane/commands blocks the whole server for 10–27 s when skill folders are on a slow filesystem

1 participant