Skip to content

feat(ci): ratchet raw repo connectionId host checks; migrate the cheap ones - #31096

Merged
nwparker merged 5 commits into
mainfrom
nwparker/repo-host-read-ratchet
Oct 20, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/repo-host-read-ratchet

Conversation

@nwparker

@nwparker nwparker commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​195 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​194
Prod 21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​283 $\color{#cf222e}{\Huge{\mathbf{−}}}$​78 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​205

ELI5

A project row records which machine it lives on in two ways: the old connectionId field, and the newer executionHostId (for example ssh:gpu). Newer rows sometimes fill in only the newer one. A lot of code still decides "is this project on SSH?" by reading only the old field, so it treats those newer SSH projects as local and runs commands on the wrong computer. Codex review 6 found three bugs of this kind.

This PR adds a drop-in helper that reads both fields, switches the easy existing checks over to it, and adds a CI ratchet so new raw checks can't creep back in.

This follows #31054 (worktree base), #31055 (project dedupe) and #31066 (CLI host), all merged.

What Changed

  • getRepoRoutingConnectionId(repo) (src/shared/execution-host.ts) replaces a raw repo.connectionId in routing and "is this SSH?" checks.
    • It never answers local for a row whose raw field is set.
    • It also finds a row that names SSH only as executionHostId: 'ssh:<target>', which the raw field reported as local.
    • On a contradictory ssh:B row with connectionId: 'A', B wins, as everywhere getRepoExecutionHostId is used.
    • Every "is this SSH?" check therefore answers the same as before for every row except the ones the raw field got wrong.
  • The ratchet is config/scripts/check-repo-host-read-ratchet.mjs plus config/repo-host-read-baseline.txt.
    • It counts raw <repo>.connectionId reads per file in src/main, src/shared and src/cli. Comments, assignments, tests and the resolver modules are excluded.
    • It is a lower bound, and its header says so: destructuring and rows not named repo/*Repo* aren't seen.
    • Counts may only go down. It runs in pnpm lint and in the pr.yml static job, and its failure text names the helpers to use instead.
    • It follows the style of the existing id-only-store-write ratchet, using the shared runCountRatchet and the existing comment stripper.
  • Migrated 71 reads. For a row that names SSH only through executionHostId, each of these used to run or route locally and now refuses or routes over SSH:
    • every runtime GitHub/GitLab command passing repo.connectionId ?? null
    • the PR/MR head-ref fetches
    • preserved-branch cleanup
    • the runtime and IPC base-ref queries
    • the desktop worktrees:resolvePrBase IPC handler, whose git/gh routing read the raw field while its head-ref fetches did not
    • background worktree preparation
    • the trash sweep
    • the scan-cache TTL
    • usage metadata
  • Left for later: 95 reads remain in the baseline, mostly ownership and migration code where the raw field is the point, or where the swap needs more than a mechanical edit.

Why

The three review items (#4 worktree base, #6 CLI host, #7 project dedupe) are one bug class: host identity read from a legacy field or dropped. Fixing three call sites would leave the class alive.

A drop-in helper plus a shrink-only ratchet makes the safe path the easy one, and stops new raw checks from landing.

I chose a per-file count over per-function entries, because the existing count ratchets show it is stable under refactors.

Renderer files are out of scope for now: they belong to the renderer strict-read-routes work.

Linked Issue

N/A (internal review finding: Codex review 6, class fix for #4/#6/#7).

Visual Proof

N/A. This is CI tooling and server-side routing; nothing is drawn differently.

Testing

  • Automated tests added/updated, or explained why not below
  • config/scripts/check-repo-host-read-ratchet.test.mjs checks what counts and what doesn't: reads, writes, comments, type positions, other receivers, and the excluded files.
  • src/shared/repo-routing-connection-id.test.ts checks the helper on every row shape, and that it agrees with the raw field whenever that field is set.
  • pr-head-tracking-ref.test.ts adds a fetch that refuses an executionHostId-only SSH row.
  • worktrees-ssh-pr-head-fetch.test.ts adds a PR-base IPC that refuses local git for that row. It fails on main.
  • runtime-provider-command-ssh-routing.test.ts covers one GitHub and one GitLab runtime command site.
  • The migrated modules' existing suites still pass (157 tests).
  • The full local static-analysis job passes, including all ratchets.

Review

  • Codex (gpt-6.1-sol, high): no findings, on both the original and the final head.
  • Opus round 1:
    • P2, fixed: the half-migrated PR-base IPC handler.
    • P3, fixed: the contract wording for contradictory rows, the ratchet's report false positive, the lower-bound wording, and command-site tests.
    • P3, declined: switching to an AST-based ratchet. The regex is enough as a stated lower bound.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH: this is the point of the change.
  • Wire: unchanged.
  • Mixed versions: no effect.
  • GitLab: covered alongside GitHub.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0be40ac4-1545-42c1-8a99-45fad7c89bd7
📥 Commits

Reviewing files that changed from the base of the PR and between ccfafa0 and 6ff45e9.

📒 Files selected for processing: 3
  • config/repo-host-read-baseline.txt
  • config/scripts/check-repo-host-read-ratchet.mjs
  • config/scripts/check-repo-host-read-ratchet.test.mjs
💤 Files with no reviewable changes: 1
  • config/repo-host-read-baseline.txt

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

📝 Walkthrough

Repository operations now derive routing IDs from execution-host data or legacy connection IDs. GitHub, GitLab, IPC, and worktree operations use the resolved ID. The change adds tests for SSH routing and a static-analysis ratchet that tracks selected raw connection-ID reads against a baseline.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 6ff45

The new lint and static-analysis ratchet can block ordinary source changes when harmless quoted text resembles a repository-host read.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 31.58% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 24 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description covers the required change, reason, testing, visual-proof exception, review notes, scope, and checklist. It explains that the linked issue is an internal review finding.
Title check Passed The title clearly summarizes the CI ratchet and migration of raw repo connectionId host checks.
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: Docstring Coverage

Explanation

Docstring coverage is 31.58% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 24 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Codex review 6 class fix (#4/#6/#7): host decisions read off a repo row's
legacy connectionId miss rows that name SSH only as executionHostId.

- getRepoRoutingConnectionId (shared/execution-host.ts): drop-in for a raw
  repo.connectionId routing check that also finds executionHostId-only SSH.
- check-repo-host-read-ratchet: per-file count of raw repo connectionId
  reads in src/main, src/shared, src/cli; counts may only shrink.
- Migrated 66 cheap reads: runtime GitHub/GitLab commands, PR/MR head ref
  fetches, preserved-branch cleanup, ref queries, base-ref IPC, worktree
  preparation, trash sweep, scan cache TTL, usage metadata.
…s a stated lower bound

Review follow-up (Opus on #31096):
- worktrees:resolvePrBase decided git/gh routing on the raw connectionId while
  its head-ref fetches already used the resolver; one resolved connectionId
  now drives all of it (test fails on main).
- getRepoRoutingConnectionId's contract is stated exactly: never local when the
  raw field is set; on a contradictory ssh row executionHostId wins.
- The ratchet regex no longer matches report.connectionId; header and docs
  say it is a lower bound.
- Regression tests for a runtime GitHub and GitLab command site.
@nwparker
nwparker force-pushed the nwparker/repo-host-read-ratchet branch from 78069e0 to a79b3ad Compare October 20, 2026 10:16

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3ace6565-44e9-4f1d-a510-c729ccbeadd7
📥 Commits

Reviewing files that changed from the base of the PR and between 63246eb and 0825d2d.

📒 Files selected for processing: 27
  • .github/workflows/pr.yml
  • config/repo-host-read-baseline.txt
  • config/scripts/check-repo-host-read-ratchet.mjs
  • config/scripts/check-repo-host-read-ratchet.test.mjs
  • config/scripts/pr-preflight-gates.test.mjs
  • package.json
  • src/main/github/pr-head-tracking-ref.test.ts
  • src/main/github/pr-head-tracking-ref.ts
  • src/main/gitlab/mr-head-tracking-ref.ts
  • src/main/ipc/repos/base-ref-query-handlers.ts
  • src/main/ipc/worktrees-ssh-pr-head-fetch.test.ts
  • src/main/ipc/worktrees/create/register-review-base-handlers.ts
  • src/main/runtime/runtime-github-issue-comment-commands.ts
  • src/main/runtime/runtime-github-repository-query-commands.ts
  • src/main/runtime/runtime-github-review-mutation-commands.ts
  • src/main/runtime/runtime-github-review-query-commands.ts
  • src/main/runtime/runtime-gitlab-mutation-commands.ts
  • src/main/runtime/runtime-gitlab-query-commands.ts
  • src/main/runtime/runtime-preserved-branch-cleanup.ts
  • src/main/runtime/runtime-provider-command-ssh-routing.test.ts
  • src/main/runtime/runtime-repository-ref-queries.ts
  • src/main/runtime/runtime-worktree-scan-cache.ts
  • src/main/usage-worktree-metadata.ts
  • src/main/worktree-create-preparation.ts
  • src/main/worktree-trash.ts
  • src/shared/execution-host.ts
  • src/shared/repo-routing-connection-id.test.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.


/** Raw `<repo>.connectionId` reads in one file's code; comments are prose and do not count. */
export function countRawRepoHostReads(text) {
return [...stripSlashComments(text).matchAll(RAW_READ)].length

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Exclude string literals from raw-read counts.

stripSlashComments preserves quoted text, so this regex counts a string such as 'Replace repo.connectionId with getRepoRoutingConnectionId(repo)' as a property read. If a developer adds that message to a scanned file, the ratchet can fail pnpm lint and the static-analysis job although the code adds no raw read. Use a token-aware count that excludes literal text but still counts reads inside template interpolations.

nwparker and others added 2 commits October 20, 2026 12:53
…ected rows

A copy of connectionId into a projected row decides nothing; migrating it to
the resolver would change what the projection publishes. The sidebar feed
catalog's copy (added after the baseline) and two older projections no longer
count; baseline pruned to 91.
@nwparker
nwparker merged commit 12bf328 into main Oct 20, 2026
51 checks passed
@zpyoung zpyoung mentioned this pull request Oct 21, 2026
1 of 2 tasks
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.

1 participant