Skip to content

Link inline-code file references only when the file exists - #6830

Merged
ymichael merged 1 commit into
mainfrom
bb/fix-bb-issue-6664-thr_qzt67dma5p
Nov 2, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/fix-bb-issue-6664-thr_qzt67dma5p

Conversation

@ymichael

@ymichael ymichael commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Inline code that looks like a file name (scheduler.py, thread.idle, bb.app) became a file link, resolved against the workspace root, whenever it matched the path rule: a file extension, a :line suffix, or a ./ or / prefix. Nothing checked whether the file existed, so clicking such a link opened a preview that failed with "HTTP 404: Path does not exist" (#6664).

What changed

Inline code becomes a file link only if the resolved path exists on the machine the files live on. Otherwise it stays plain code. Explicit Markdown links [text](path) are unchanged. This is the fix the issue preferred.

  • The routing carries the machine. MarkdownLocalFileLinkRouting has a new hostId, set where routing is built:

    • useMessageLinkRouting, through the ThreadTimelineNavigation context, which the thread view and plugin chat provide.
    • buildMarkdownFileRouting, which every file preview and plugin document uses.

    When hostId is null, inline code never auto-links.

  • The existence check. MarkdownCode keeps the same path rule. Each match renders MarkdownInlineCodeFileLink, which uses a new useHostPathExists(hostId, path) hook. The hook is a React Query query per path, backed by a per-host batcher: every path asked for in the same render goes out as one sdk.hosts.pathsExist request, split at PATHS_EXIST_MAX_PATHS. Answers are cached for 10 seconds, like the existing existence checks. A match renders as plain code until the answer is true.

  • No wire changes. This reuses the existing POST /api/v1/hosts/:id/paths/exist endpoint. There are no protocol, SDK, CLI or server changes.

  • Trade-offs:

    • A link appears a moment after the message renders.
    • A file created after the check links once the 10-second cache expires and the message re-renders.
    • When the host is offline, everything renders as plain code.
    • Directories count as existing.

How you verified

  • New tests in markdown-preview.test.tsx:
    • src/app.ts:4 (exists) links to file:///workspace/src/app.ts#L4, while scheduler.py, thread.idle and bb.app stay <code>, and all four paths go out in one pathsExist call. This fails on main, where all four are links.
    • Routing with no host keeps inline code as code.
    • The existing inline-code cases now run against a mocked host. The non-file cases also assert that no existence request is sent.
  • Turbo: pnpm exec turbo run typecheck lint test --filter=@bb/app passes (652 test files).
  • Real app (pnpm start:worktree, real Claude Code turn, fixture repo with README.md and src/app.ts):
    • In the thread, README.md, src/app.ts:2 and ./src/app.ts link. scheduler.py, missing/file.ts:10, thread.idle, bb.app and 127.0.0.1:8791 stay code. One pathsExist request carried every path.
    • Clicking src/app.ts:2 opens the preview at line 2.
    • Inside the README.md file preview, src/app.ts:3 links and nope.py stays code.

Fixes #6664

AGENT GENERATED

🤖 Generated with Claude Code

Inline code such as `scheduler.py` or `thread.idle` became a file link
whenever it looked like a path, so clicking it opened a file preview that
failed with "Path does not exist". Local file link routing now carries the
machine its files live on, and inline-code candidates are checked there
through the existing pathsExist API, batched per render tick. They stay
plain code unless the file exists, and never link when the machine is
unknown. Explicit Markdown links are unchanged.

Fixes #6664

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 78671a2 into main Nov 2, 2026
30 checks passed
@ymichael
ymichael deleted the bb/fix-bb-issue-6664-thr_qzt67dma5p branch November 2, 2026 18:38
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.

Inline-code file links point to files that don't exist (404 in file preview)

1 participant