Skip to content

Fix #7693: mcpx(source): a symlink loop entry aborts the whole @dir: resolve — ELOO #7704

Closed as not planned

Description

@developing-today

Implement GitHub issue #7693 in developing-today/code: mcpx(source): a symlink loop entry aborts the whole @dir: resolve — ELOOP is neither skipped like a dangling link nor pinned like a permission error

Problem

In mcpx's directory source walk, one symlink loop entry makes the whole @dir: resolve fail — while the two neighboring bad-link cases are tolerated:

  • a dangling symlink is skipped (pkgs/mcpx/internal/source/source.go:174-180: os.Stat failure is continued past only when errors.Is(err, fs.ErrNotExist), comment "A dangling link has no regular target to read");
  • a directory cycle (a dir symlink pointing back to an ancestor) is skipped by the os.SameFile ancestor guard in the same walk (source.go:152-157);
  • a symlink loop (a link to itself, or two links pointing at each other) makes os.Stat fail with ELOOP ("too many levels of symbolic links"), which is neither of the above: source.go:181 returns the error and the entire directory resolution aborts with zero files read — including every healthy regular file sitting next to the loop.

A loop link, like a dangling link, has no regular target to read. The current split — tolerate a missing target and a directory cycle, but let a loop target deny the whole source — is an untested gap, not a pinned decision: the pinned cases in the shipped tests are dangling-skip (source_test.go:245 TestDirectorySkipsDanglingLinkAndFollowsLinkOutsideRoot), directory-cycle-safety (source_test.go:191), and permission-error propagation (source_unix_test.go:73 TestDirectoryReportsInaccessibleSymlinkTarget, which pins EACCES as a returned error and must keep behaving that way). No test covers the ELOOP case.

Evidence (verified this run, laptop, main 8a0a1c0)

Probe at ~/git/fleet/probe-mcpx-eloop on the laptop: the real pkgs/mcpx/internal/source/source.go copied verbatim (md5 768194633188160a349eafd555defe53, identical to the file on main) into a standalone module, driven through the exported source.Resolve("@dir:"+root, …):

  • control (regular.ts + dangling.ts → missing): resolves OK, files = [regular.ts] — matches the shipped pin;
  • self-loop (regular.ts + loop.ts → loop.ts): fails — reading …/loop.ts: stat …/loop.ts: too many levels of symbolic links, zero files returned;
  • pair loop (regular.ts + a.ts → b.ts, b.ts → a.ts): fails the same way at a.ts, zero files returned;
  • control (directory back-link to the root itself): resolves OK, files = [regular.ts] — the ancestor guard tolerates the directory cycle.

So one stray looped link (easily produced by a bad ln -s pair or a tool that links a directory's contents into itself at file level) takes down every launcher/prefix/hook that reads its source from that directory, with an error that names the link but gives no way to keep the healthy remainder.

Related: closed #1727 covered non-regular files in directory sources (FIFO/socket/symlink-to-directory); this is the distinct remaining Stat-error class for file entries. The Go source lives only in this repo (pkgs/mcpx); dezren39/darwin-nix only wraps/launches the built mcpx, so no cross-repo set applies. Found via a pr-diff-review REVIEW-FINDING on PR #3744 that was left as decide-and-test material; verified independently this run before filing.

Why it matters

@dir: sources feed mcpx launchers, prefixes, and error hooks. A single looped symlink — which the directory-cycle guard already proves the walk intends to survive at directory level — currently denies the whole source instead of just the unreadable entry. Robustness here should be uniform: an entry with no readable regular target is skipped (dangling, loop), while genuinely informative errors (permission) still surface, per the existing pin.

Acceptance criteria

  • A directory containing a self-loop symlink or a mutually-looping symlink pair, plus at least one regular file, resolves successfully and returns exactly the regular files (the loop entries skipped), for both the self-loop and pair-loop shapes.
  • Regression tests for both loop shapes land in pkgs/mcpx/internal/source (mirroring the style of TestDirectorySkipsDanglingLinkAndFollowsLinkOutsideRoot), and fail on the pre-fix code.
  • The pinned permission behavior is unchanged: TestDirectoryReportsInaccessibleSymlinkTarget still passes — only the ELOOP class changes disposition, not EACCES or other Stat errors (or, if the fix deliberately widens/narrows which Stat errors skip, the disposition of each class is named in the PR and the affected pins updated with rationale).
  • The existing source suite (go test ./pkgs/mcpx/internal/source/..., or the package's normal CI route) is green with the new tests.

Rules from the repo owner: (1) Deliver the finished work as a pull request in this run; put "Fixes #7693" in the PR description so the issue closes on merge. (2) Cover the whole set in the one PR: if the issue names a set (files, subcommands, cases), fix every member, and batch any directly related dependency updates into the same PR — never one PR per item or per dependency. (3) Run the relevant tests and checks before opening the PR. (4) Merging is permitted but never required: merge only when checks pass and you are reasonably certain the PR is correct and low-risk — otherwise leave it open, and state your confidence and what a human should check. (5) If you hit a genuine blocker (missing credentials, a decision only the owner can make), stop and say exactly what is needed in your final summary instead of guessing. (6) Detached-session clause: never use the question tool — if you hit a question, record it and the default you chose in your final summary and keep working.


Launched by pm-dispatch for developing-today/code. Queue task and OpenCode session ids follow in a comment below.

Activity

  1. developing-today commented on Nov 8, 2026

    @developing-today
    ContributorAuthor

    Dispatch launch FAILED at enqueue before a queue task was created, so this dispatch never became real. Closing this tracking issue as not planned so it does not linger as an orphan (#4917).

    Error: queue RPC enqueue_repo_task failed (HTTP 503): {"code":"PGRST002","details":null,"hint":null,"message":"Could not query the database for the schema cache. Retrying."}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions