← Back to Pull requests

fix(tui): avoid collisions between generated heading anchors #4205

Closed
unknown closed this pull request without merging on Nov 30, 2026 07:27 UTC
View on GitHub
unknown unknown commented on Nov 30, 2026 05:39 UTC
Author

What a user gets

The TUI file reader resolves heading anchors uniquely when repeated headings collide with headings that already contain numeric suffixes. For # Target, # Target-1, # Target, opening #target-2 previously reported “Heading not found”; it now opens the third heading.

Track both each base slug's suffix counter and every emitted anchor, including generated ones, before allocating the next slug. This also handles an authored Target-1 following a generated target-1.

How you verified it

Tested commit 25844a931a4aaf6e7a9c0088834c5d74ef1de1d2 on Windows, Node 24.14.1:

  • All three new collision cases fail on base f2fe3e529 with “Heading not found.”

  • npx vitest run packages/tui/test/reading-anchor-fences.test.ts packages/tui/test/reading-regressions.test.ts packages/tui/test/reading-journey.test.ts — 11 passed; 12 journey tests could not execute because their shared setup's symlinkSync fails with EPERM on this Windows account.

  • Running reading-journey.test.ts on clean base f2fe3e529 reproduces the same 12 setup failures. Running the two other files alone on this commit passes all 11 tests.

  • npm run build — passed.

  • npm run lint — passed.

  • git diff origin/main...HEAD --check — passed.

  • Full npm test was not rerun on this branch. An earlier attempt on the sibling host-label branch hit failures in unchanged repository packaging/policy/POSIX-oriented checks on Windows and was interrupted after it stopped making progress; workspace suites were not reached.
  • Anything you were unsure about

    Verification exercises file-reader output with fixtures, including existing fenced-example and combining-mark cases; no native terminal session was exercised.

    If this is security-related

    N/A.

  • One concern per PR; no version bump; no CHANGELOG.md edit

  • Tests added or updated where the change is testable

  • I listed the checks I ran, their results, and any checks I could not run
  • <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    Bug Fixes
    Improved heading-anchor matching when repeated headings would otherwise produce slugs that conflict with existing headings.
    Tests
    Added coverage for anchor resolution with repeated headings and conflicting generated slugs.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 304 lines (+228 / -76) across 3 files Reviewer: openrig-review Review duration: 108m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 304 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.342
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #4205"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.1% (MEDIUM) · Higher = larger blast radius
    40.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.4% · Safe to merge
    17.4%