Skip to content

fix(shared): open Codex citations to percent-encoded file URLs - #46754

Merged
juliusmarminge merged 3 commits into
pingdotgg:mainfrom
saphid:hunter/c-c889ba55eb
Dec 1, 2026
Merged

juliusmarminge merged 3 commits into
pingdotgg:mainfrom
saphid:hunter/c-c889ba55eb

Conversation

@saphid

@saphid saphid commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Problem

A Codex file citation whose path is a file: URL had its existing % escapes escaped a second time, so the chip opened a different file. Citing file:///tmp/a%20b.ts opened the literal file /tmp/a%20b.ts instead of /tmp/a b.ts.

Deterministic repro on origin/main (facc02ea36a6ea8735b11abaca7c2937eb68098a): render :codex-file-citation{path="file:///tmp/a%20b.ts" line_range_start="7"}. Chat Markdown goes through renderCodexInlineDirectivesAsMarkdown → resolveCodexFileCitationLink → codexFileCitationMarkdown. Then pass the link destination to parseMarkdownFileLink, which gives the path the file chip opens.

  • Observed: href file:///tmp/a%2520b.ts#L7 → { path: "/tmp/a%20b.ts", line: 7 }
  • Expected: href file:///tmp/a%20b.ts#L7 → { path: "/tmp/a b.ts", line: 7 }. A literal path /tmp/a%20b.ts must still open the file with the percent in its name.

Change

markdownDestinationPath no longer turns % into %25 for a file:/ URL when its escapes decode, because the URL is already percent-encoded. If a file URL has a malformed escape, such as %FF, it is escaped exactly as on main. Raw #, ? and spaces at either end of the path are still escaped. Literal POSIX, Windows, UNC and relative paths are unchanged. The label of an encoded file URL is now decoded (a b.ts), so it matches the link and the citation shows only the chip. The resolver is shared, so web, Electron, mobile chat and copied citation Markdown all get the fix.

Scope

Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.

Verification

  • New table in packages/shared/src/codexFileCitations.test.ts (decodes file URL escapes once but keeps literal percents):
    • Each row checks the href, the label, the parsed target with line 7, and that isMarkdownFileLinkLabel is true (chip only).
    • On base, the encoded file URL row fails with expected 'file:///tmp/a%2520b.ts#L7' to be 'file:///tmp/a%20b.ts#L7'.
    • The rows for the literal /tmp/a%20b.ts, file:///tmp/a#b.ts, file:///tmp/a?b.ts, the trailing-space file:///tmp/a.ts and the malformed file:///tmp/a%FF#b.ts (still /tmp/a%FF#b.ts at line 7) lock in what main already does.
  • After the fix, codexFileCitations.test.ts and markdownLinks.test.ts pass (240 tests). vp run check:changed exited 0 on the final commit (format, lint, knip, typecheck, tests).
  • Before/after transcript on base and on the fix, with href, label, opened target and whether the label is chip-only for each row: https://gist.github.com/saphid/734f678c3ee846a200ba6ddb5b215b89
  • I didn't change how a :N suffix is read. A citation of file:///tmp/a.ts%3A42 now opens /tmp/a.ts at line 42, because parseMarkdownFileLink reads a trailing :N as a line number before it reads #L7. Main does the same for the literal path /tmp/a.ts:42 and the raw URL file:///tmp/a.ts:42 (transcript rows 6 and 7). On main, %3A42 opened /tmp/a.ts%3A42, a different file that doesn't exist, so neither version opened the right file. Changing that rule would change every Markdown file link, which is a separate change.

Not shown: no click-through in a real client with Replay (dev). The resolver → parser round trip above is the code the chip uses. sandbox: URIs are unchanged.

Authored by Claude Opus 5.5 (Model Hub); reviewed by GPT-6.2 Sol (Codex).

Not shown

  • .github/pull_request_template.md:12 — Clarify the web/Electron repro: the live renderer resolves the directive directly in wordsHast.ts, then ChatMarkdown rewrites the file URI and passes the parsed path to the file chip. The directive-to-Markdown round trip covers mobile and copy.
  • .github/pull_request_template.md:25 — No real-client click-through or before/after screenshots were captured. For scenarios:prove, create both a b.ts and a%20b.ts with distinct line-7 content, click the encoded citation, and assert which file opens.
  • .github/pull_request_template.md:25 — The test summary reports check:changed exit 0 on the reviewed HEAD, but the linked evidence does not include the check log and the read-only review did not rerun it.

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Dec 1, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Dec 1, 2026
@macroscopeapp

macroscopeapp Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at d12bd44

Macroscope's review found this PR approvable — This fixes percent-encoded file citation links and makes their filenames readable. The change is limited to link formatting, with existing rendering safeguards retained.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

File citation generation now recognizes file: URLs case-insensitively and decodes valid percent escapes for labels and Markdown destinations. Tests cover decoded escapes, literal percent sequences, and invalid URL escapes.

Changes: File citation handling

Layer / File(s) Summary
Handle encoded file citation paths
packages/shared/src/codexFileCitations.ts, packages/shared/src/codexFileCitations.test.ts
Citation generation decodes valid file URL paths for labels and preserves their percent escapes in Markdown destinations. Tests check generated links, parsed paths, line numbers, and labels.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: Minimal · up to d12bd

This fixes Codex file citations with percent-encoded paths, such as spaces, so they open the right file. The change is small and covered by new tests. The one known edge case (an encoded colon suffix treated as a line number) is deliberately left for separate work.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Codex citations now open percent-encoded file URLs correctly. The PR fixes double-encoding of % escapes in file: URLs in packages/shared, and the title matches that sc…
Description check Passed The description follows the template's Problem, Change, Scope, and Verification sections. It gives a clear reproduction, the expected behavior, the decoding and escaping rules, and a rationale for no …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: Codex citations now open percent-encoded file URLs correctly. The PR fixes double-encoding of % escapes in file: URLs in packages/shared, and the title matches that scope. It follows the conventional commit format.

Full details: Description check

Explanation

The description follows the template's Problem, Change, Scope, and Verification sections. It gives a clear reproduction, the expected behavior, the decoding and escaping rules, and a rationale for no linked issue. Verification lists specific tests and results. Template items about the web/Electron repro, real-client click-through, and check log evidence are noted as gaps in the 'Not shown' section. The description is mostly complete, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 56996d4 and d12bd44.

Files selected for processing: 2

  • packages/shared/src/codexFileCitations.test.ts
  • packages/shared/src/codexFileCitations.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Dec 1, 2026
@macroscopeapp
macroscopeapp Bot dismissed their stale review December 1, 2026 12:27

Dismissing prior approval to re-evaluate d12bd44

@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Web client, Chromium, 1280 × 800, light theme; isolated fresh databases on both commits. On both commits, seed a fresh citation-demo project containing a b.ts and a%20b.ts with SPACE_NAMED_FILE and PERCENT_NAMED_FILE respectively on line 7. Seed a Replay thread whose user message contains A: a Codex file citation to file:///a%20b.ts at line 7 and B: a citation to the literal /a%20b.ts at line 7. Open the thread, expand its message, click A and capture the file panel, then click B and capture it. Assert A opens the space-named file and displays a b.ts · L7; B retains the percent-named file.

Scenario: Codex file URL decodes percent escapes while a literal path preserves them

Proven: the scenario fails on base 7a9d2131fa and passes on head d12bd44041.

Base 7a9d2131fa Head d12bd44041
Result ❌ failed
ASSERTION_FAILED: expected "// line 1// line 2// line 3// line 4// line 5// line 6PERCENT_NAMED_FILE" to contain "SPACE_NAMED_FILE"
✅ passed
A file URL line 7 Base 7a9d2131fa: A file URL line 7 Head d12bd44041: A file URL line 7
B literal path line 7 Base 7a9d2131fa: B literal path line 7 Head d12bd44041: B literal path line 7
failure Base 7a9d2131fa: failure

Scenario source

The directives were seeded in a user message and exercised the shared Markdown citation renderer. Base opens PERCENT_NAMED_FILE for A; head opens SPACE_NAMED_FILE. Both highlight line 7.

Not shown:

  • A live Codex-generated assistant reply was not exercised; the scenario seeds identical directives in a user message through the shared Markdown renderer using Replay.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Dec 1, 2026
@juliusmarminge
juliusmarminge merged commit 39bc9cf into pingdotgg:main Dec 1, 2026
60 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants