Skip to content

fix(computers): keep a revoked relay home's mirror purged - #152

Merged
nixuuu merged 1 commit into
devfrom
fix/relay-mirror-race
Nov 5, 2026
Merged

nixuuu merged 1 commit into
devfrom
fix/relay-mirror-race

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 5, 2026

Copy link
Copy Markdown
Member

computer-relay.test.ts ("explicit reciprocal sharing … without a routing loop") failed on CI in #146 and #147 (attempt 1), on line 258. After the reciprocal share was turned off, W's mirror state existed again as { cursor: "", overview: null }.

Cause: a race on P2.

  1. P1 revokes the grant and cancels the relayed WatchThreadMirror stream before the new catalog reaches P2.
  2. P2 still has W as both, so the next emit starts a new mirror task.
  3. The new catalog then deletes W's both row, with its mirror, and inserts W as origin.
  4. The late INSERT INTO computer_mirror_state lands after that. The new origin row satisfies the foreign key, so the empty state comes back.

Before #36, a removed peer stayed removed and the late insert failed on the foreign key.

Fix

  • mirror.ts creates mirror state only for a direct peer or a relay home/both. The check runs in the same statement, with the peer row locked. Otherwise consume ends as superseded.
  • bot-mirror.ts checkpoints use the same role check.
  • The test adds a check that does not depend on timing: a late consume for the revoked home is rejected and leaves no state. No assertion is changed; no sleeps, retries or longer timeouts.

Evidence

  • The new check fails on the old code (1/1) and passes with the fix: 15/15 runs under load.
  • The other mirror suites pass: thread-mirrors.test.ts and linked-agents.test.ts, 32/32.

Fixes: #36

Revoking one side of a reciprocal Share onward makes the newer catalog
delete the relay entry (cascading its thread and bot mirrors) and
re-insert it as a callback-only origin in the same transaction. A mirror
subscription restarted from the still-current older catalog could then
create its state row against the new origin row, leaving an empty mirror
generation behind.

Mirror state and bot mirror checkpoints are now created only for a direct
peer or a relay home, with the peer row locked in the same statement.

Fixes: #36
@nixuuu
nixuuu merged commit 8b88827 into dev Nov 5, 2026
9 checks passed
@nixuuu
nixuuu deleted the fix/relay-mirror-race branch November 5, 2026 08:46
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