Skip to content

refactor(webapp): delete the relay, and everything it needed to survive - #244

Merged
ssowonny merged 1 commit into
mainfrom
feat/delete-the-relay
Sep 20, 2026
Merged

ssowonny merged 1 commit into
mainfrom
feat/delete-the-relay

Conversation

@ssowonny

Copy link
Copy Markdown
Contributor

TL;DR

  • −1,768 / +389. The co-editing relay is deleted, along with every mechanism that existed to compensate for it.
  • Two browsers editing one file now converge instead of producing conflict copies.
  • Solo mode is gone as a CRDT path — an unreachable hub leaves the editor open and saving, it just has no live collaboration.
  • Conflict copies and If-Match stay: they guard the file from writers that never touch a CRDT at all.

What was deleted, and why each existed

The relay never parsed a frame, so nobody owned the document. Every property that needs an owner was faked somewhere else:

deleted existed because
the seed claim two clients seeding one file build two documents that duplicate every character on merge
seedClaimGrace a claim that produced nothing left later joiners with a blank document the editor would write to the file
maxRoomBytes + rebuild an append-only log grows without bound; a document does not
resync + replay-the-log reconnect there was no state vector to diff against
announce / re-announce awareness is relayed and never logged, so nobody could be discovered late
solo mode — and this one cost a real user six characters (#234)

None of it is disabled. It's gone, because the property each piece was faking is now simply true.

Two things found while deleting

A stale If-Match with identical content is not a conflict, it's a late arrival. The check ran before the no-op check, so three clients sharing one document produced two conflict copies of text nobody disputed. Ordering them the other way is the whole fix.

stream_guard_test.go tested the streaming guard through /collab. That guard matters more than ever — it's what stops an unflushable writer handing back an empty 200 a client retries forever — so it now targets /events. A websocket is an upgrade, not a stream this guard applies to, which is the same distinction compression draws.

A test that changed meaning

concurrent-edit.spec.ts used to assert a relay-less editor's work was preserved beside a teammate's. It now asserts they converge: every character both people typed, in the file, no conflict copy needed.

stress spec, this morning:  3 paths, 4 versions  (two conflict copies)
stress spec, now:           1 paths, 2 versions

What stays, deliberately

Conflict copies and If-Match. They guard the file against an agent, the CLI, or a device syncing — writers that never touch a CRDT — and removing the relay doesn't close that door.

Verification

Full module: 12 packages ok. Editor e2e: 26 passed including two-person co-editing and the three-editor stress soak. Both architecture diagrams updated and parse-checked — the collabRoom note was the largest single block of "why this is hard" in either file, and is now one note about a hub that owns the document.

🤖 Generated with Claude Code

The co-editing relay never parsed a frame, so nobody owned the document — and
every property that needs an owner had to be faked somewhere else:

  - a seed CLAIM taken under the room lock, because two clients seeding one
    file build two documents whose merge duplicates every character
  - seedClaimGrace, because a claim that produced nothing left every later
    joiner holding a blank document the editor would then write to the file
  - maxRoomBytes and a rebuild-from-scratch, because an append-only log grows
    without bound while a document does not
  - a resync frame and a replay-the-whole-log reconnect, because there was no
    state vector to diff against
  - an announce/re-announce dance, because awareness is relayed and never
    logged, so nobody could be discovered late
  - solo mode, which let a client that lost the relay edit its own COPY of a
    shared document and then overwrite a teammate — six characters of a real
    user's work (#234)

The hub owns it now. None of the above is disabled; it is gone, because the
property each piece was faking is simply true.

  internal/webapp/collab.go          441 lines, deleted with its two tests
  lib/collab.ts                      a provider, now a thin y-websocket wrapper
  /api/config collab.held            removed: with one transport there is
                                     nothing to choose, and a capability flag
                                     nobody reads is exactly the "new
                                     mechanism replacing one that went away"
                                     this stage forbids

Solo survives only as NO LIVE COLLABORATION: a hub that cannot serve the route
leaves the editor open and saving through upload/content. That is deliberately
not a second CRDT path — a client editing its own copy of a shared document is
the thing that caused the data loss in the first place.

Two things found while deleting.

A stale If-Match carrying IDENTICAL content is not a conflict, it is a late
arrival. The check ran before the no-op check, so three clients sharing one
document produced two conflict copies of text nobody disputed. A conflict is a
disagreement; ordering the checks the other way is the whole fix.

stream_guard_test.go exercised the streaming guard THROUGH /collab. The guard
matters more than ever — it is what stops an unflushable writer handing back
an empty 200 a client retries forever — so it now targets /events, the hub's
remaining long-lived stream. A websocket is an upgrade, not a stream this
guard applies to, which is the same distinction compression draws.

e2e/concurrent-edit.spec.ts changed meaning with the architecture: it used to
assert a relay-less editor's work was PRESERVED BESIDE a teammate's, and now
asserts they CONVERGE — every character both typed, in the file, no conflict
copy needed. The stress spec agrees: 1 path, 2 versions, where it reported
three paths and two conflict copies this morning.

Conflict copies and If-Match stay. They guard the file against writers that
never touch a CRDT at all — an agent, the CLI, a device syncing — and removing
the relay does not close that door.

Stage 4 of docs/collab-provider-prd.md, which completes it. Full module: 12
packages ok.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ssowonny
ssowonny merged commit 42739b0 into main Sep 20, 2026
3 checks passed
@ssowonny
ssowonny deleted the feat/delete-the-relay branch September 20, 2026 08:24
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