fix(cli): match context show resources by scan-root containment#26617
Open
kylecarbs wants to merge 1 commit into
Open
fix(cli): match context show resources by scan-root containment#26617kylecarbs wants to merge 1 commit into
kylecarbs wants to merge 1 commit into
Conversation
`coder exp chat context show <path>` filtered the snapshot by res.SourcePath == src.Path. Built-in and working-directory scan roots overlap user sources, and the agent attributes each overlapping resource to the first (built-in / working-dir) root, leaving SourcePath empty. As a result, showing such a source reported zero resources. Match a resource to a source when SourcePath is equal, or when the resource's own path lies at or under the source root. Path containment uses POSIX semantics because agent context paths are absolute POSIX paths even when the CLI runs on a Windows host. MCP servers are keyed by a server name rather than a filesystem path, so they continue to match only by SourcePath. Add TestContextResourceFromSource covering explicit SourcePath matches, built-in-root containment, symlinked resources outside a root, prefix-boundary safety, and MCP-server matching. Generated by Coder Agents on behalf of @kylecarbs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
coder exp chat context show <path>reports 0 resources for many valid sources (for example a built-in root like~/.coderor the workspace working directory), even though those resources are present in the snapshot and injected into chat context.Root cause
The
showhandler filtered the snapshot withres.SourcePath == src.Path. Built-in and working-directory scan roots overlap user sources, and the resolver (agent/agentcontext/resolve.go) deduplicates overlapping scan roots by attributing each resource to the first (built-in / working-dir) root. That leavesSourcePathempty on the resource, so an exact-SourcePathfilter matches nothing for the overlapping source.Fix
Match a resource to a source when:
SourcePathequals the source path (unchanged, explicit attribution), orSource) is equal to, or lies under, the source root.Containment uses POSIX path semantics (
strings.HasPrefix(p, dir+"/")after trimming a trailing slash) because agent context paths are absolute POSIX paths even when the CLI runs on a Windows host, and the boundary check avoids false positives like/a/bcmatching/a/b.MCP servers are keyed by a server name rather than a filesystem path, so they continue to match only by
SourcePathand are never matched by containment.Tests
Adds
TestContextResourceFromSource(table-driven) covering: explicitSourcePathmatch, built-in-root containment with emptySourcePath, skills under a skills root, exact file source, different-subtree non-match, a symlinked resource resolved outside a root, prefix-boundary safety, and MCP-server matching bySourcePathonly.gofmt,go vet ./cli/, andgo build ./cli/...are clean.Related investigation
This is one of several issues found while investigating reports about the recently merged chat-context system. It is a self-contained, low-risk fix opened independently of the others:
context showreturns 0 resources due to scan-root dedupe leavingSourcePathempty..mcp.jsonpaths in the Agents page UI.Remaining items from the investigation are architectural (lazy-load/bloat, skill scope precedence, raw-path plumbing, backend server-to-config linkage, startup-timing re-pin, stale-pin rebind-on-open) and are deferred for design sign-off.
Generated by Coder Agents on behalf of @kylecarbs.