Skip to content

perf: reduce file I/O in SubagentLocator (cherry-pick of upstream #110) - #1

Merged
TheJavaGuy merged 2 commits into
mainfrom
perf/subagent-locator-io
Oct 10, 2026
Merged

TheJavaGuy merged 2 commits into
mainfrom
perf/subagent-locator-io

Conversation

@TheJavaGuy

Copy link
Copy Markdown
Owner

Summary

Cherry-picks the SubagentLocator commit (f7e7c42) from upstream matt1398#110 and adds unit tests for the class, which had no test coverage before.

  • hasSubagents(): treats stat.size > 0 as non-empty and no longer reads the whole subagent file. This runs once per session during the project scan.
  • subagentBelongsToSession(): reads only up to the first non-empty line through createReadStream + readline and no longer loads the whole file. Same pattern as SessionContentFilter.hasNonNoiseMessages.

The upstream PR's second commit (618243f, deletes build/entitlements.mac.plist) is not included. It is unrelated to this change. That file is unused (package.json points to resources/entitlements.mac.plist).

Behavior changes

  • hasSubagents() now returns true for a subagent file that contains only whitespace. Before, it returned false.
  • subagentBelongsToSession() now skips blank lines at the start of the file. Before, a first line of only spaces made it return false.

Known caveat (not addressed)

SshFileSystemProvider.createReadStream passes SFTP stream errors on to its PassThrough, but does not pass destroy() back to the SFTP stream. An early fileStream.destroy() therefore probably leaves the SFTP read handle open. SessionContentFilter already has the same problem. Here it affects only SSH projects that use the old layout, where agent-*.jsonl files sit in the project root.

Test plan

  • pnpm typecheck: clean
  • pnpm test: 735/735 pass (13 new in test/main/services/discovery/SubagentLocator.test.ts)
  • The leading-blank-line test fails against the pre-change code and passes after it
  • ESLint: no errors (3 security/detect-non-literal-fs-filename warnings, the same baseline as the existing discovery tests); Prettier clean

MintCollector and others added 2 commits October 10, 2026 20:17
- hasSubagents(): Remove redundant readFile after stat size check;
  stat.size > 0 is sufficient to confirm non-empty files
- hasSubagentsSync(): Same optimization using statSync instead of
  reading entire file contents
- subagentBelongsToSession(): Use createReadStream + readline to
  stream only the first line instead of reading entire file via
  readFile, then close the stream immediately

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tching

Covers hasSubagents (content, empty files, name filtering, missing dir),
subagentBelongsToSession (match, mismatch, leading blank lines, CRLF,
empty file, invalid JSON, missing file, first line larger than stream
chunk) and getProjectRootSubagentFiles filtering.
@TheJavaGuy
TheJavaGuy merged commit 63d88fe into main Oct 10, 2026
@TheJavaGuy
TheJavaGuy deleted the perf/subagent-locator-io branch October 10, 2026 18:26
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.

2 participants