Skip to content

fix(gateway): isolate linked stream project identities - #565

Merged
nixuuu merged 1 commit into
devfrom
fix/linked-thread-project-identity
Nov 12, 2026
Merged

nixuuu merged 1 commit into
devfrom
fix/linked-thread-project-identity

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

When a linked computer watches a home gateway, its project ID translation can change the same live thread row that the home's web and mobile clients receive. A working worktree thread can then show “Unknown project” even though its stored placement is correct. Clone each outbound stream message before translating IDs so local clients keep the home project ID and the peer receives its global ID.

The source of the problem is remoteServe: create(descriptor, message) returns an already typed protobuf message unchanged. Hub subscriptions share those instances, and ConfigIds.map mutates project references in place. Project alias mapping was introduced in #168; #526 and #539/#541/#543 did not introduce this boundary. Both clients resolve projects by exact projectId, so both are affected. The database placement and threadSelect retain the parent project and joined worktree; this is an ID rewrite, rather than evidence of a partial status row. No client merge fallback or cwd-based guess is needed.

The gateway integration regression uses two linked databases with merged project aliases and a side thread inheriting its parent's worktree. A real worker holds a turn open while overview updates and a resumed thread delta arrive. It checks the local/global project IDs and branch before, during and after work, including an unread update while working. The branch-over-directory presentation change remains in #545, which uses the same domain helper on mobile and web.

Validation: scoped nice -n 19 oxlint and oxfmt checks passed; git diff --check passed. Local installation, typecheck, tests, builds, fingerprints, browser and render measurements remain deferred at the maintainer's request while host diagnostics run. GitHub CI will run the required suite. The local commit hook was skipped using its supported SKIP_SIMPLE_GIT_HOOKS switch because commitlint is not installed in this worktree and local install is deferred; CI validates the Angular title.

Copy audit (docs/copy.md §8): no UI strings, labels, errors, empty states or actions changed. The existing “Unknown project” fallback remains; this fix supplies its correct project reference. Documentation change is in Polish. No mobile/native dependencies, client subscriptions or timers changed.

Related: #168
Related: #545

@nixuuu
nixuuu force-pushed the fix/linked-thread-project-identity branch from 74733e1 to 01ffab4 Compare November 12, 2026 09:37
Clone outbound stream messages before mapping shared project IDs so local Hub subscribers retain their home project and worktree metadata.

Related: #168
@nixuuu
nixuuu force-pushed the fix/linked-thread-project-identity branch from 01ffab4 to 246138b Compare November 12, 2026 09:39
@nixuuu
nixuuu marked this pull request as ready for review November 12, 2026 11:37
@nixuuu
nixuuu merged commit f7ad51c into dev Nov 12, 2026
10 checks passed
@nixuuu
nixuuu deleted the fix/linked-thread-project-identity branch November 12, 2026 11:38
nixuuu added a commit that referenced this pull request Nov 12, 2026
## Change

Mobile thread rows now share web's working ring, elapsed label, semantic
colours and branch labels. Working titles and metadata retain normal
contrast over the subtle working background on both clients.

- Reuse domain `formatAge` and `workingLabel`: rounded
minutes/hours/days, then weeks from 14 rounded days. `Working` becomes
`Working 1m` once the age is no longer `now`.
- Reuse `threadPlace`: scratch → worktree HEAD (branch or detached
commit) → directory fallback, including Windows paths. A worktree
directory no longer replaces its branch on mobile.
- Share project identity, spinner geometry and working/provider colours.
Preserve existing chromatic pastel project fills; correct the mobile
neutral dark badge and align provider opacity. Keep the documented
native density and reserved status slot.
- Rotate the ring through the installed Reanimated runtime on the UI
thread, only for starting/running rows. The live OS Reduce Motion
setting leaves it static; backgrounding stops rotation. No dependencies
or native configuration changed.

The gateway fix for working worktree rows losing their project is merged
in #565 and included through the rebase onto `f7ad51cc`. It prevents the
linked stream from rewriting shared Hub messages in place. This PR owns
the shared branch-over-directory label.

## Performance

`SidebarThreadStatus` selects its formatted string from one shared
foreground clock. An unchanged string does not trigger a React render.
The list and full rows do not subscribe to ticks; the tree comparator no
longer compares obsolete age strings. Animation has no JS frame loop.

Measured actual React component render counters before (`f7ad51cc`) and
after (`5e0fba8d7`), excluding mounts, with 12 mounted main rows: one
working and 11 idle. Used the real list, tree comparator, row, status
and clock; native hosts and unrelated leaf controls were adapted in an
external diagnostic harness.

| Scenario | Before | After |
| --- | --- | --- |
| 61 seconds working without data updates: full rows | 0 renders, 0/s |
0 renders, 0/s |
| Same interval: elapsed status text | No elapsed label | 1 render,
about 0.016/s |
| 200 immutable updates to the working thread at 20 Hz | 200 working-row
renders in 10.166 s (19.67/s) | 200 in 10.202 s (19.60/s) |
| Untouched rows during those updates | 0 renders | 0 renders |

This establishes JS render isolation, not native scrolling, Hermes
timing or animation frame performance. Native animation and scrolling
still require the device checks below.

## Verification

- Rebased onto `origin/dev` at `f7ad51cc`, including #565, and pushed.
CI is green on `5e0fba8d7`: Static checks, all four test shards, Web and
Linux binaries, aggregate Typecheck/tests/builds, and commitlint.
- Local `bun install`, `bun run gen:check`, root `bun run lint`, `bun
run format:check`, and mobile typecheck passed. Focused domain checks
passed (20 tests, 85 assertions);
`tests/integration/sidebar-lifecycle.test.ts` passed (6 tests, 60
assertions). The full `check:tmp` was intentionally not repeated, as
requested by the maintainer.
- Expo ESLint passes all 11 changed mobile source files. The full mobile
Expo lint command reports existing errors in untouched files (57 errors,
8 warnings, including AttachmentViewer, ImageCanvas, Skeleton and
useOverlaySwipe); these are outside this PR. CI's required static checks
pass.
- EAS CLI 27.4.1 production fingerprints match before/after: iOS
`6ddec9ef559ee0095ac33e94ff9418a942053b17`; Android
`5f6eae3ab278f1cd543e9ed763f923a319b65ec9`. Fingerprint baseline was dev
`34dedaace`; its only mobile change beyond the requested rebase base is
JS in ThreadSyncProgress, with no changed native inputs.
- Real Chromium review passed in light/dark at 1280×800 and 390×844,
with short, typical and long titles/project/branch labels. Checked
working ring and elapsed text, normal title/meta contrast, subtle
background, pastel project badges, provider colours,
branch-over-directory output, truncation and absence of horizontal
overflow. Reduced-motion emulation yields `animation: none`; no browser
runtime errors. Screenshots and diagnostic artifacts remain outside the
repository. No web UI tests were added.

Native visual verification was unavailable: this Linux host has no iOS
runtime or Android SDK, and the linked device host twice returned
“Device list failed: Could not communicate with device support. Try
refreshing devices.” No native build or publication was started.

Maintainer device checks: scroll a list with one and several working
threads; verify smooth rotation and scrolling, normal contrast in both
themes, `Working 1m` without row movement, and Pinpoint plus its
checkout branch throughout working updates. Toggle OS Reduce Motion
while open, then background/resume: rotation should stop appropriately
and elapsed time should catch up. Native frame/scroll performance
remains unmeasured here.

## Copy audit — docs/copy.md §8

- `Working` → `Working 1m`: existing web wording with elapsed context;
sentence case, one idea, no new term. `Working` remains for an age of
`now`.
- Day-only ages → shared rounded day/week labels (for example, 13.5 days
→ `2w`); document the compact formatter contract in the copy guide.
- Worktree directory → branch/`Detached at <commit>`: existing domain
terminology and identical client fallback order. Scratch remains
`scratch folder`.
- Parent-routed mobile questions use web's existing `Asking agent`.
Starting, attention/result labels and action text retain established
wording.
- Audit items 1–8 and 10 passed static review: no new actions, errors,
empty states, humour, repeated explanatory text or icon/colour-only
status; live values use tabular digits in a reserved single-line slot.
Item 9 passed web review with short/typical/long labels at desktop and
phone widths; native visual checks remain explicitly assigned above.

Related: #526
Related: #478
Related: #565
nixuuu added a commit that referenced this pull request Nov 12, 2026
An update or restart can surface an authentication failure as “Pair
again” even when the saved computer identity has not changed. Reconnect
now treats RPC authentication failures as retryable and requires
repeated, locally verified TLS pin mismatches before requesting new
trust. A successful handshake with the saved identity clears stale
pairing state.

## Investigation

- The dial catch classified **every**
`ConnectError(Code.Unauthenticated)` as a pin mismatch. That includes
invalid certificate validity, a peer rejecting the client pin, and hello
validation; on a manual route it persisted `pairing_required`, and on
LAN it deleted the route. This behavior exists in the original linking
implementation (#13), before the reported release range.
- Reviewed `v0.2.0-nightly.120..v0.2.0-nightly.137` and the `.133` →
`.137` diff, including #547, #548, #559, #562, #565, #566 and #546. The
full desktop hello grew from 32 capabilities to 33 in #559; both
releases reject more than 32 as `Unauthenticated: Invalid computer
identity` after pinned TLS succeeds. Merged #574 fixes this capability
overflow, including compatibility with the older validator. This branch
is rebased onto that fix in `dev`. Full source evidence:
#573 (comment).
- Identity and the 20-year certificate are persisted in
`computer_identity`; the private key uses the existing encrypted secrets
key. Desktop keeps the same Canopy data directory, database,
app/keychain name and `secrets.enc` across versions and channel changes.
Keychain/decryption failure stops startup rather than replacing the
identity. Reinstalling while preserving that data preserves trust;
deleting it creates a new identity.
- Production starts computer links, including loading identity and
peers, before opening Network access. There is no demonstrated
listener-before-store race in that path. The new readiness guard also
makes an early or stopping link service explicitly return `Unavailable`.
- `manual` means entered by the user, including a LAN/Tailscale address;
it is separate from the network's address type. A bad manual path must
not override another route or an incoming connection proving the saved
pin. The capability-count rejection is source-proven for the reported
version pair's full desktop configuration; incident logs would still be
needed to attribute every earlier report or explain successful
re-pairing.

## Changes

- Use a local `CertificatePinMismatch` signal emitted only after TLS
proof of possession and validation of a different self-signed
certificate. Override ConnectError's inherited structural
`Symbol.hasInstance` check so ordinary RPC errors cannot impersonate
this local class. Without this override the new LAN test correctly
caught a real route-deletion bug, not test timing. Invalid/expired
certificates remain rejected without declaring an identity change.
- Exhaust routes first. Require the same different certificate at the
same manual route in two consecutive failed rounds. A matching pinned
TLS connection or ready incoming link outweighs stale addresses. Only a
verified pin mismatch removes a discovered LAN route. Saved pins are
never replaced automatically.
- Clear confirmation evidence after pinned TLS verification, a
successful handshake, explicit pairing, route edits and unlink. Existing
successful handshake recovery also clears a persisted `pairing_required`
after restart.
- Use the shared reason “{name}'s identity changed. Pair again to trust
it.” for linked computer availability and app updates, including the
relay's name when its identity changed. Remove the contradictory
automatic-retry explanation for that state. Add stable auth-failure
classifications to diagnostics without logging certificates, keys,
addresses or RPC payloads.
- Document persistence and recovery. No proto changes, protocol bump or
migration.

## Regression coverage

Added gateway↔gateway integration scenarios using independent databases
and real TLS listeners:

1. Repeated startup `Unauthenticated` on manual and LAN routes preserves
trust and resumes; verify the LAN route remains after each attempt. RPC
error text cannot impersonate a local pin mismatch, and failed TLS
connections cannot confirm a manual route's identity change.
2. An early listener returns `Unavailable` for both `Pair` and `Connect`
until ready.
3. Both gateway/core restarts reuse persisted identities/certificates
and reconnect; a protocol-1 `.133` hello without new capabilities links
with a `.137` hello and resumes after upgrading.
4. A real new key requires confirmed pairing, receives no RPC, never
replaces the pin, and has consistent availability/update explanations.
5. A persisted stale pairing state heals after restart; a valid
alternate route outweighs a stale manual address with another key.

The older-version scenario exercises the compatible wire
hello/capability set, not archived app binaries. Installer and OS
keychain behavior was inspected in source, not exercised on
macOS/Windows.

## Validation

- After maintainer clearance, ran only the two authorized test files,
sequentially, at `nice -n 19`, using `TMPDIR=/var/tmp` and `bun run
check:tmp`: `linked-pairing-recovery.test.ts` **10 pass**,
`linked-capability-compatibility.test.ts` **3 pass**. Both
temp-directory checks passed. The original LAN failure reproduced before
the fix (8 pass / 1 fail); the strengthened assertion confirmed deletion
immediately after the first auth failure.
- Changed-file formatting and lint passed; `git diff --check` is clean.
Earlier dependency install and repository formatting/lint checks passed
before the original push.
- CI validates generation, full typechecking, all test shards and builds
for the rebased head. Browser verification remains pending; the UI
change reuses existing components and only changes status explanations.

## Copy audit (§8)

“{name} must be paired again” / “Link it again…” / “unavailable, trying
again automatically” → “{name}'s identity changed. Pair again to trust
it.” The text states the verified problem and the explicit trust action,
uses two short sentences and avoids TLS jargon. The compact action badge
remains “Pair again”. Names are interpolated as whole values and
existing wrapping/layout remains in place; short/long-name checks at
desktop/phone widths have not been run yet.

Related: #13
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