V2-SPEC §5.2 (write-side, staged before read-side M9). Migration #2 (rides
the M8 runner, chains 0→1→2 — verified on real .10 data, version 2, all
counts preserved):
- principals table + devices.principal_id (every v1 device backfills to one
synthetic 'owner' principal — byte-identical to v1 until a share opts in).
- members(share, principal_id, role, can_reshare) + shares.acl_mode. A share
with zero grants is 'legacy' (every device an implicit owner = v1); the
first grant flips it to 'explicit' = deny-by-default.
- EffectiveRole(device, share) resolves device→principal→role; legacy⇒owner.
- Push write gate: role>=editor AND the access.writable clamp (which can only
REMOVE write). Legacy shares reduce to the v1 writable bit exactly.
- devbox-hub member set/rm/list + principal <device> <principal> admin CLI —
the populate path, so the role layer has a real consumer now (no dead code).
Tests: legacy↔explicit lifecycle, deny-by-default, viewer<editor, HTTP push
gate (403 unmembered/viewer, opens at editor). 18 pkgs -race green; hub
cross-compiles linux/amd64; windows builds.
The v2 foundation (V2-SPEC §5.1). Two things land:
- PRAGMA user_version migration runner in internal/hub/meta: ordered,
append-only, each step in its own txn with the version bump LAST so a
crash rolls back cleanly. Backs up an existing DB to <path>.pre-v2.bak
(VACUUM INTO) before migrating; refuses a DB written by a newer build.
Every later v2 schema change rides this.
- Re-key snapshots from a GLOBAL id PK to per-(share, id). v1's global id
meant identical content pushed to two shares collided on one row, so the
second share never counted its chunk refcounts (undercount) and recorded
no snapshot row. Per-share rows fix the refcount and let each share own
its history. Wire id/Head stays the manifest hash — clients unchanged.
Migration also backfills any share head left rowless by the v1 idempotent
push, restoring the head-has-a-row invariant. GC reworked to prune per
(share, id), decrementing each share's chunks and freeing a shared
manifest blob at most once.
Tests: cross-share refcount, migration versioning + refuse-newer, and a
realistic populated-v1 -> v2 upgrade (data preserved, backup written,
head backfill). All 17 pkgs -race green; hub cross-compiles linux/amd64.
Deferred to M8-3 (conflict sidecar): restore/deploy conflict-copy — a naive
version breaks restore-reproduces-snapshot; it needs the base/ancestor
awareness the sidecar introduces. snapshot_chunks edge table deferred to
M9 (no consumer yet; the runner makes adding it a one-line migration).
The hub read request bodies with unbounded io.ReadAll / json.Decode and ran
http.ListenAndServe with zero timeouts — a single client could OOM it or hold
connections open (slowloris). Now:
- handleBlob caps the body at 256 MiB, decode() caps JSON at 8 MiB, both via
http.MaxBytesReader -> 413 when exceeded.
- serve uses an http.Server with ReadHeaderTimeout/ReadTimeout/IdleTimeout +
MaxHeaderBytes. WriteTimeout intentionally unset so the long-lived /v1/events
SSE stream isn't killed. [fanned-out subagent: harden-dos]
Snapshots are content-addressed with a GLOBAL id, so two shares with identical
content collide on one snapshots row and the idempotent push skips the refcount
bump — a chunk two share heads both need ends up refcount=1. The old GC then
pruned the 'old' snapshot for one share and freed chunks/manifests the OTHER
share's live head still pointed at. Permanent cross-share data loss.
Rework runGC as mark-and-sweep from every share's live snapshots as roots:
nothing reachable from a kept snapshot is ever deleted, whatever the refcounts
say. Never prune a snapshot that is any share's head. Plus hardening:
- DeleteSnapshot floors refcount at 0 and only decrements if the row existed
(no negative counts from a double-delete).
- DeleteChunkRow is now conditional (WHERE refcount<=0) and reports if it
deleted, so a push that re-references a chunk mid-GC isn't corrupted.
Cross-share repro test + existing single-share GC test both green.
Deferred to v2 (documented): proper per-(share,id) refcount accounting — needs
a schema migration of the live hub; the ground-truth GC makes it safe meanwhile.