Skip to content

fix(persistence): report a discarded cross-host repo update instead of failing silently - #23379

Merged
nwparker merged 1 commit into
mainfrom
nwparker/repo-host-guard-loud
Sep 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/repo-host-guard-loud

Conversation

@nwparker

@nwparker nwparker commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​98 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​98
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​36 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​30

ELI5

Orca can track the same project on more than one machine — your laptop, an SSH box, a paired remote. Each stored project row remembers which machine it belongs to, and when code saves a change to one of those rows it has to say which machine's row it means.

If it names the wrong machine, the save is thrown away. Until now that happened completely quietly: the code that asked for the save got back the exact same answer it would get if the project had been deleted, so it had no way to tell "you named the wrong machine" from "that project is gone". A bug like that can sit in a shipped release without anyone noticing.

Now, when a save is thrown away because the machine named didn't match, Orca writes an error to the log saying which machine was asked for and which one the project is actually on. Nothing else about the behaviour changes — the same saves succeed and the same saves are refused as before.

What Changed

Store.updateRepo(id, updates, hostId) looks up the row to write by id and — when a third argument is given — by that row's own execution-host stamp. If no row satisfies both, it returns null.

Before: null meant two different things with no way to tell them apart. Either no row with that id existed, or a row existed but under a different host stamp than the caller named. In the second case the caller's write silently evaporated.

After: the lookup moves into a named function, findRepoRowForHostScopedWrite. The returned value is unchanged in every case. What is new is that when the id does exist but only under other host stamps, it logs one console.error naming the repo id, the host that was requested, and the host stamps actually on file. A genuinely missing row logs nothing, so the message only ever appears when a real write was dropped.

The guard's decision is untouched: a matching host still writes, a non-matching host still refuses, and a write aimed at one host still leaves another host's row with the same id alone. There is no signature change and no call site changed, so nothing that currently reads the null return behaves differently.

A second, smaller change in the same file: the internal dependency type for this class now asks for only the two pieces of persisted state it reads (repos and projectGroups) instead of the whole state object. That is what lets the new test build the class directly without a type assertion.

Why

This is the mechanism behind a bug that shipped in v1.4.214 (#22421, fixed in #23300). Git-remote-identity enrichment addressed updateRepo by the host it had just probed — local — rather than by the stamp on the row it was repairing, which was runtime:<env>. No row matched, every write returned null, and the caller treated that as "nothing to do". Projects never resolved their remote identity and stale avatars never repaired, for a whole release, with no error in any log and no failing test.

The underlying shape is a bug generator rather than a one-off: an optional argument that silently turns a write into a no-op, reporting failure with the same value it uses for a routine, expected outcome.

Alternatives considered:

  • Return a discriminated result ({ ok: true, repo } | { ok: false, reason }). The most informative option, but there are 16 production call sites and only 2 pass a host. Changing all 16 is not a small, focused diff; changing only the 2 leaves two parallel APIs for one operation.
  • Throw when the row exists under another host. Loud and tiny, but not safe here. One of the two host-passing callers is the repos:update IPC handler, so a throw crosses into the renderer as a rejected invoke. Several renderer flows treat a falsy result as a graceful "no update" and run rollback logic on it (imported-worktrees-card-actions.ts, new-external-worktrees-inbox-actions.ts). The renderer's repo list can also lag the main-process store, so this path is reachable without any bug, and turning it into a rejection would be a real behaviour change.
  • Remove the ambiguity at the type level (take the row, or a branded host type). The strongest guarantee, but it touches every call site and the Store interface — too large for a targeted fix.

Logging keeps the diff to one production file and zero call-site changes while still ending the silence. Both current host-passing callers pass the row's own stamp correctly, so this does not fire in normal use; it fires exactly when a user-visible or background write is being thrown away.

Linked Issue

Fixes #

Follow-up hardening for #22421 / #23300; no separate issue.

Visual Proof

N/A — no UI or interaction change. The only new observable output is a console.error line in the main-process log on a path that a correct caller never reaches.

Testing

New file: src/main/persistence/tracking-repos/repo-update-host-guard.test.ts (5 tests).

Before the change (production file reverted, test file kept): 1 failed, 4 passed. The failure is the new case —

FAIL  reports a host mismatch instead of returning the same silent null as a missing row
AssertionError: expected [] to have a length of 1 but got +0

After the change: 5 passed. The 4 tests that pass both before and after are there deliberately — they pin the behaviour that must not move (host match writes, missing row returns null silently, a cross-host write leaves the other host's row alone, and the no-host-argument path is unchanged).

The mismatch test reproduces #22421's exact shape: a row stamped runtime:env-1 addressed with local.

Gates, all run locally on macOS:

  • pnpm test src/main/persistence/tracking-repos/ src/main/repo-git-remote-identity-enrichment.test.ts src/main/repo-git-remote-avatar-refresh.test.ts — 150 passed, 1 skipped
  • pnpm tc:node — clean
  • pnpm run check:code-quality:changed — 0 new findings across 2 changed files
  • oxlint src/main/persistence/tracking-repos/ — clean
  • oxfmt --check on both changed files — clean

Platforms: this is host-agnostic in-memory persistence logic with no filesystem, process, or path behaviour, so it is not platform-specific. SSH and paired-runtime rows are covered by the tests (ssh:peer, runtime:env-1 host stamps) rather than by a live remote, since the code under test never reaches a host.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Worth a reviewer's attention:

  • The message is a console.error, matching the [persistence] … convention already used in this directory. If the team would rather this were a warning, or routed through telemetry, say so — the call is in one place.
  • The log fires only when the id exists under a different stamp, never for a missing row, so it cannot become background noise from ordinary deletes.
  • Identity enrichment cannot trip it: writeIdentity checks the current row's stamp and then calls updateRepo with that same stamp synchronously, with no await between, so a mismatch is unreachable on that path.

Caller census behind the "why", for confidence that nothing else is broken today: 16 production call sites reach Store.updateRepo; 14 pass no host and are unaffected. The 2 that pass one — src/main/repo-git-remote-identity-enrichment.ts:151 and src/main/ipc/repos/repo-update-handler.ts:222 — both pass the row's own stamp (the latter via the renderer, which derives it from a row it holds). No caller is currently repeating #22421's mistake.

One adjacent observation, deliberately left alone as out of scope: Store.getRepo(id, hostId) has the same optional-guard shape, and several no-host updateRepo callers resolve a repo that may exist on more than one host and then write by bare id, which picks the first matching row. Neither is a regression and neither is in the repo-row update path this PR touches.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: the cross-host guard is the security-relevant part and is unchanged. A client-local probe still cannot write a peer's row. The log message contains a repo id and execution-host ids (local, ssh:<target-id>, runtime:<env-id>) — no paths, tokens, or account identifiers.
  • Cross-platform: pure in-memory logic; no paths, processes, or shortcuts.
  • Remote SSH: covered — SSH-stamped rows are exactly the rows this guard protects, and the refusal behaviour is untouched.
  • Mobile: unaffected; no mobile code or max-lines budget touched.
  • Backwards compatibility: no signature, persisted-schema, or wire change. Nothing is published to a paired client.
  • Performance: the no-host path is a single find, as before. The extra filter that builds the host list runs only on the failure branch, after a find has already missed.

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)

…f failing silently

`Store.updateRepo` takes an optional `hostId` that must be the row's own
`executionHostId` stamp. When it is anything else the lookup matches no row and
the method returns `null` — the same value a deleted row returns — so the write
is dropped with no error, no log, and no failing test. #22421 shipped exactly
that: identity enrichment addressed the probe host (`local`) instead of a
`runtime:` row's stamp, and every write was discarded for a full release.

Resolve the row through `findRepoRowForHostScopedWrite`, which logs once when the
id exists but only under other host stamps, naming the requested host and the
stored ones. The guard itself is unchanged: a matching host still writes, and a
client-local probe still cannot repair a peer's row.
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: c4a190a7-b23b-4f76-bcea-5efc3c23bbb0

📥 Commits

Reviewing files that changed from the base of the PR and between c15f082 and ed1dad9.

📒 Files selected for processing (2)
  • src/main/persistence/tracking-repos/repo-update-host-guard.test.ts
  • src/main/persistence/tracking-repos/repo-update-operations.ts

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


📝 Walkthrough

Walkthrough

The repository update operations state type is narrowed to include only repos and projectGroups. The new findRepoRowForHostScopedWrite helper checks the execution-host stamp when a host ID is supplied. updateRepo uses the helper and returns null when no matching row is found. Tests cover host mismatches, missing rows, matching hosts, duplicate IDs across hosts, and omitted host IDs.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to ed1da

Host-mismatched updates are now logged without changing which repository rows can be updated. No actionable merge risk remains after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to ed1da

The update still accepts and rejects the same repository writes. A rejected cross-host update now records repository and host identifiers in an error log; no introduced access-control bypass was established, but the handling of those logs is not known.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The observed new exposure is a main-process error-log record for an addressed repository ID with a host mismatch, not an additional repository row made writable by the lookup.

Trust Boundaries and Controls

  • observed — A supplied host ID must match the row’s resolved host identity for a scoped write. IPC normalizes a supplied ID before dispatch, while the enrichment caller derives its update host from its repository snapshot. Authorization outside the inspected IPC handler is not established.

Resilience and Maintainability Implications

  • observed — The tests cover mismatched, missing, matching, duplicate-ID, and unscoped lookup outcomes. They do not establish log retention or persistence behavior after process interruption.

Hardening Proposals

  • proposed — If error logs leave the local application or are broadly accessible, consider limiting or redacting repository and host identifiers in mismatch diagnostics.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the primary change: logging discarded cross-host repository updates instead of failing silently.
Description check ✅ Passed The description is detailed and covers the change, rationale, alternatives, testing, compatibility, security, and checklist items. It references related issues, although the Linked Issue field does no…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Extracted host-scoped row lookup — updateRepo's inline find becomes findRepoRowForHostScopedWrite(repos, id, hostId), returning the same Repo | undefined in every case.
  • Added the missing failure signal — when the id exists only under other host stamps, the new branch emits one console.error naming the repo id, requested host, and stored stamps; a genuinely missing row stays silent.
  • Narrowed the dependency type — RepoUpdateMutationOperations.state is now Pick<PersistedState, 'repos' | 'projectGroups'>, matching what the class actually reads.
  • New test coverage — 5 tests pin the mismatch log, silence on missing rows, host-match writes, cross-host isolation, and the no-host path.

I verified the return-value equivalence against the old predicate (including that !hostId reduces to hostId === undefined for this non-empty ExecutionHostId union), confirmed the sole production construction site (loading-store/repo-lifecycle-operations.ts:251) satisfies the narrowed state type, and ran the new test file locally (5 passed). The mismatch test would fail without the production change, since no log is emitted pre-change.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 0697014 into main Sep 27, 2026
41 checks passed
@nwparker
nwparker deleted the nwparker/repo-host-guard-loud branch September 27, 2026 08:31
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