ui-server: the wikilink map stats every file it walks although the directory entry already has the type
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 79/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- bun, typescript
- Domain
- backend, performance
Research direction
Start in packages/ui-server/src/files/walker.ts at buildWikilinkMap (lines 449–515) and read the entry handling around lines 461–493. Add or locate the test in packages/ui-server/tests/files-walker.test.ts for regular files and symlinks, then run it and packages/ui-server/tests/wikilink-reliability.test.ts. Done means only symlinks are stat-ed, in-brain symlink notes remain mapped, outside targets stay excluded, and existing map results remain unchanged.
Written by the indexing model from the issue text.
Description
Context
buildWikilinkMap (packages/ui-server/src/files/walker.ts:449-515) walks the whole brain to map note slugs
to paths. It lists each directory with readdir(abs, { withFileTypes: true }) (:461), and then awaits
stat() on every entry (:477-482). The only thing it reads from the result is whether the entry is a
directory (:493); size and modification time are never used. For everything except a symbolic link the
directory entry from readdir already answers that question.
GET /api/files/wikilinks rebuilds the map at most every 30 seconds, or on ?refresh=1
(WIKILINK_TTL_MS, packages/ui-server/src/routes/files.ts:24; the route at :284-292). The client asks for
it when a markdown surface first needs a wikilink (packages/ui-react/src/stores/file-state.ts:159).
Measured cost (auditor micro-benchmark, synthetic tree of 10,000 files in 200 directories, warm file cache,
one server-class machine; not a device or production figure): the serial walk with a stat per entry took
103 to 121 ms; the same walk trusting the directory entry took 10 to 12 ms. The walk grows with the brain,
and every non-markdown attachment is stat-ed too.
Related: #1799 (file browsing and .gitignore when anchored snapshots are unavailable) and #1800 (symlinked
brain roots) change the same file.
Scope
- In
buildWikilinkMap, decide "is a directory" from the directory entry, and callstatonly when the
entry is a symbolic link. The symlink branch keeps itsrealpathcontainment check
(packages/ui-server/src/files/walker.ts:483-491). - The resulting map, including which path wins when two files share a slug, is unchanged.
Out of scope
listDirectory(packages/ui-server/src/files/walker.ts:217-262). It returns size and modification time,
so it needs itsstat.- Extracting the entry-filter block that
listDirectoryandbuildWikilinkMapboth carry into one helper.
It is a real duplicate, but merging it widens this diff into the listing path that #1799 and #1800 are
changing. - Caching the parsed
.gitignorematcher (loadIgnore,packages/ui-server/src/files/walker.ts:180-191).
That read goes through the anchored snapshot path #1799 owns, and it was not measured. - The per-directory
safeResolveandrealpathcalls (:455,:458); they guard against cycles and
escapes. - The 30-second cache and the route.
Acceptance criteria
- A test builds a brain with regular files, a nested directory, a symlink to a directory inside the
brain and a symlink to a directory outside it, replacesfs/promisesstatwith a counting double
for the walk (restoring the complete original in teardown), and assertsstatis called only for the
two symlinks. It fails on the tree before the change, where every entry is stat-ed. Mutation: call
statfor every entry again and the count assertion fails. - The same test asserts notes under the in-brain symlinked directory are in the map and notes under the
outside one are not. Mutation: drop the symlink branch and the in-brain symlinked notes disappear. - For the fixtures of
packages/ui-server/tests/files-walker.test.tsand
packages/ui-server/tests/wikilink-reliability.test.ts, the map is unchanged: both files pass with no
expected value changed, including the first-wins precedence for a shared slug.
Verification
bun run test packages/ui-server/tests/files-walker.test.ts
bun run test packages/ui-server/tests/wikilink-reliability.test.ts
NODE_OPTIONS=--max-old-space-size=6144 bun run typecheck
bun run lint
bun run check:pr --base origin/main
Contract impact
- This touches the integration contract, so it needs the
contractlabel, aCONTRACT:commit prefix, and the doc updated in the same commit. - This changes a published package's behaviour, so it needs a changeset.
The wikilink map returned by GET /api/files/wikilinks is identical; only the number of filesystem calls
changes.
It edits files under a published package's src, so scripts/check-changeset.ts requires a (patch) changeset
even though outputs are unchanged.
Found by a repository audit on 2026-11-26 (main 87b96b10c); independently reviewed before filing.
- Dominant language
- TypeScript
- Stars
- 5
- Forks
- 0
- Avg merge
- 8h 3m
- Merged PRs (30d)
- 606
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from schlessera/brain-kit
-
agent-ready area: ui-server priority: p3 type: refactor
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
schlessera/brain-kit#4833 ·
Maintainers usually reply within 1 day
-
ui-sdk: the turnId doc comment tells client authors echoing is optional, which a rev 3 host refusesOpenagent-ready area: ui-sdk priority: p3 type: docs
Difficulty 1/5 1-3 hours Newbie friendliness 86/100
schlessera/brain-kit#4824 ·
Maintainers usually reply within 1 day
-
agent-ready area: ui-react blocked priority: p3 type: refactor
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
schlessera/brain-kit#4819 ·
Maintainers usually reply within 1 day
-
jobs: every command writes on open, so a read fails with "database is locked" during a long writeOpenagent-ready area: modules priority: p2 type: fix
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
schlessera/brain-kit#4809 ·
Maintainers usually reply within 1 day
-
agent-ready area: ui-server priority: p3 type: fix
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
schlessera/brain-kit#4807 ·
Maintainers usually reply within 1 day
All issues in schlessera/brain-kit
Similar issues
-
enhancement good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
backend enhancement priority:P3
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
geolens-io/geolens#4161 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
xdelmo/Portfolio-minimal#667 ·
Maintainers usually reply within 1 day
-
external-issue to-triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
supabase/supabase#54162 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
CyberTimon/RapidRAW#2303 ·
Maintainers usually reply within 1 day