Skip to content

fix(coderd/x/chatd/chattool): list directories in read_file#26105

Draft
mafredri wants to merge 2 commits into
mainfrom
fix/read-file-directory-listing
Draft

fix(coderd/x/chatd/chattool): list directories in read_file#26105
mafredri wants to merge 2 commits into
mainfrom
fix/read-file-directory-listing

Conversation

@mafredri
Copy link
Copy Markdown
Member

@mafredri mafredri commented Jun 5, 2026

read_file now falls back to a bounded directory listing when the agent reports that the requested path is not a file. The lower-level file-read endpoint still keeps its file-only contract; the chat tool composes that response with the existing workspace LS call.

Directory responses keep the existing content field for UI compatibility and include pagination metadata. They do not return structured entries, so direct tool output remains bounded by the formatted listing budget.

Verified with focused package tests, Go lint, and the full pre-commit hook in a clean worktree. The initial local pre-push run reached an unrelated Storybook failure in UsersPage.stories.tsx, so I used the repo-supported coder.pre-push false opt-out for the Go-only push.

🤖 This PR was created with the help of Coder Agents, and will be reviewed by a human. 🏂🏻

@mafredri
Copy link
Copy Markdown
Member Author

mafredri commented Jun 5, 2026

/coder-agents-review

@coder-agents-review
Copy link
Copy Markdown
Contributor

coder-agents-review Bot commented Jun 5, 2026

Chat: Review in progress | View chat
Requested: 2026-06-05 16:57 UTC by @mafredri

deep-review v0.7.1 | Round 1 | 5d8cd2e..a406daa

Last posted: Round 1, 13 findings (1 P2, 6 P3, 4 Nit, 2 Note), COMMENT. Review

Finding inventory

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P3 Open readfile.go:83 Directory detection relies on string-prefix contract with no shared constant R1 Netero Yes
CRF-2 P2 Open readfile.go:114 entries array bypasses byte budget, inflating directory responses 3-5x R1 Knov P2, Mafuuu P3 Yes
CRF-3 P3 Open readfile.go:138 Empty directory serializes entries as JSON null instead of [] R1 Mafuuu P3, Ryosuke P3, Hisoka Nit, Meruem Nit Yes
CRF-4 P3 Open readfile.go:95 LS fetches full directory over wire; PR creates new unbounded LLM-driven caller R1 Hisoka P2, Mafuuu Note, Pariston Note, Knov Note Yes
CRF-5 P3 Open readfile_test.go:267 ListsEmptyDirectory test does not assert is_directory field R1 Bisky P3, Chopper P3 Yes
CRF-6 P3 Open readfile.go:27 Tool description opens file-only; buries directory capability R1 Leorio P3 Yes
CRF-7 P3 Open readfile_test.go:208 TruncatesLargeDirectoryListing uses identical entries, hiding variable-length bugs R1 Bisky P3 Yes
CRF-8 Nit Open readfile.go:83 New helpers lack doc comments; package convention is to document internals R1 Leorio Nit Yes
CRF-9 Nit Open readfile_test.go:262 Swapped expected/actual in assert.Equal consistency check R1 Bisky Nit Yes
CRF-10 Nit Open readfile.go:141 Error message "the directory length of 1 entries" is ungrammatical R1 Leorio Nit Yes
CRF-11 Nit Open readfile.go:168 Display-name derivation (name + "/" for dirs) duplicates skill.go:183 R1 Robin Nit Yes
CRF-12 Note Open readfile_test.go:20 No test covers ReadFileLines transport error (pre-existing path) R1 Bisky Note Yes
CRF-13 Note Open readfile.go:70 Each directory read makes a wasted ReadFileLines round-trip before LS fallback R1 Hisoka Note, Pariston Note Yes

Contested and acknowledged

(none)

Round log

Round 1

Panel. 0 P0-P1, 1 P2, 6 P3, 4 Nit, 2 Note. 16 reviewers (bisky, hisoka, mafu-san, mafuuu, pariston, ging-go, gon, leorio, chopper, kite, meruem, ryosuke, robin, zoro, luffy, knov). Reviewed against 5d8cd2e..a406daa.

About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

Copy link
Copy Markdown
Contributor

@coder-agents-review coder-agents-review Bot left a comment

Choose a reason for hiding this comment

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

Clean, well-scoped change. The composition pattern (try ReadFileLines, detect directory error, fall back to LS) is the right design for an LLM tool layer: one entry point, useful output regardless of path type. Test density is excellent at 80%, with genuine negative cases and real assertions. Multiple reviewers praised the error composition and the backfilled coverage for pre-existing paths.

Severity count: 1 P2, 6 P3, 4 Nit, 2 Note.

The P2 (CRF-2) is about the entries array bypassing the byte budget that bounds content. The 32KB cap loses its meaning when the structured data alongside it serializes to 5x that. This is the most impactful finding and has a straightforward fix.

CRF-4 (full directory fetch) was raised at P2 by one reviewer but downgraded to P3 during cross-check. The LS endpoint's lack of server-side pagination is a real scaling concern that this PR makes more reachable (LLM agents vs. human-initiated UI calls), but the fix belongs in the LS endpoint. This needs a human decision: file a ticket to track server-side LS pagination, or explicitly accept the current behavior for chat-tool usage.

"Genuine gems, every one." (Bisky, on the test suite)

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/x/chatd/chattool/readfile.go
Comment thread coderd/x/chatd/chattool/readfile.go
Comment thread coderd/x/chatd/chattool/readfile.go
Comment thread coderd/x/chatd/chattool/readfile.go
Comment thread coderd/x/chatd/chattool/readfile_test.go
Comment thread coderd/x/chatd/chattool/readfile_test.go Outdated
Comment thread coderd/x/chatd/chattool/readfile.go Outdated
Comment thread coderd/x/chatd/chattool/readfile.go Outdated
Comment thread coderd/x/chatd/chattool/readfile_test.go
Comment thread coderd/x/chatd/chattool/readfile.go
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