OverviewFilesCommitsIssuesDocsReleasesPeers

atproto-room commits / 9370e72

0.2.25: healPlan splits a heal across commits to fit the relay's 200-op limit
indigo drops a #commit with more than 200 ops (verify.go MaxCommitOps, an error in strict mode). A heal restates every path touched since the fork point, so a wide window produced one commit the relay would drop. Partial heals carry `restates` (the window's fork-point rev); the last part carries `asserts`, `heals` and `partsFrom`. healPlan subtracts a partial's update/delete paths (a `create` in a partial is an ordinary diff op the AppView ignores over a stale copy, so that path is still owed), but only for partials no fork frame reaches. A split heal is effective only if no fork reaches its FIRST part. Returns `window` so a final with nothing left still restates one path and is appended. Tests: 3 new healPlan cases. Suite 81/81. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9370e72aad13b448d0a73e496d0b0f5d04bf6143
by plankatron <fleeky@gmail.com> · 2026-10-13T16:12:33.000Z

Changed files (3) +55 -4

lib/commit-line.js +24 -3
……@@ -114,7 +114,15 @@ export function commitLine (frames) {
114114// frame has a rev at or above it, and every fork frame below it is either one it knew or one an earlier
115115// effective heal covered. Forks covered by an effective heal are done; any other fork reopens a window.
116116//
117// Returns null (nothing to heal) or { from, paths: Set, heals: [commitCid] }.
117// SPLIT HEALS. indigo drops a #commit with more than 200 ops (verify.go MaxCommitOps), so a window wider
118// than that is restated over several commits: partial ones carry `restates` (the window's fork-point
119// rev), the last carries `asserts`, `heals` and `partsFrom` (the first partial's rev). A partial's paths
120// are not restated again — unless a fork frame reaches its rev, because then a consumer may have taken
121// the fork and skipped it. For the same reason a split heal is effective only if no fork frame reaches
122// its FIRST part.
123//
124// Returns null (nothing to heal) or { from, paths: Set (still to restate), window: Set (every path of the
125// window), heals: [commitCid], partsFrom }.
118126export function healPlan ({ line, losers }) {
119127 if (!losers || losers.length === 0) return null
120128 const all = line.concat(losers)
……@@ -133,10 +141,11 @@ export function healPlan ({ line, losers }) {
133141 for (const h of line) {
134142 if (h.asserts === undefined) continue
135143 const knew = new Set((h.heals || []).map(String))
144 const reach = h.partsFrom || h.rev
136145 let effective = true
137146 for (const l of losers) {
138147 const c = String(l.commitCid)
139 if (l.rev >= h.rev) { effective = false; break }
148 if (l.rev >= reach) { effective = false; break }
140149 if (!covered.has(c) && !knew.has(c)) { effective = false; break }
141150 }
142151 if (effective) for (const c of knew) covered.add(c)
……@@ -148,8 +157,20 @@ export function healPlan ({ line, losers }) {
148157 for (const l of open) { const r = forkPointRev(l); if (from === null || r < from) from = r }
149158 const paths = new Set()
150159 for (const f of all) if (f.rev > from) for (const op of (f.ops || [])) paths.add(op.path)
160 const window = new Set(paths)
161 // Partials of THIS window that no fork reaches: their paths are done.
162 let maxLoserRev = ''
163 for (const l of losers) if (l.rev > maxLoserRev) maxLoserRev = l.rev
164 let partsFrom = null
165 for (const f of line) {
166 if (f.restates === undefined || f.restates !== from || f.rev <= maxLoserRev) continue
167 if (partsFrom === null || f.rev < partsFrom) partsFrom = f.rev
168 // Only update/delete restate a path for every consumer; a `create` in a partial is an ordinary diff op
169 // the reference AppView ignores over a stale copy, so that path is still owed.
170 for (const op of (f.ops || [])) if (op.action !== 'create') paths.delete(op.path)
171 }
151172 const heals = losers.filter((l) => l.rev > from).map((l) => String(l.commitCid))
152 return { from, paths, heals }
173 return { from, paths, window, heals, partsFrom }
153174}
154175
155176// path -> record CID string after replaying `frames` in order onto `start` (a Map, copied). Uses only the
package.json +1 -1
……@@ -1,6 +1,6 @@
11{
22 "name": "atproto-room",
3 "version": "0.2.24",
3 "version": "0.2.25",
44 "description": "Attestation-gated, encrypted multi-writer room engine — StateBase (keet-model admission) + Lease + signer + RepoBase + LabelBase/LabelRoom + serve-membrane. Extracted from hyper-proto-peer; consumed by the atproto peer (repo devices) and the co-authored labeler.",
55 "type": "module",
66 "main": "index.js",
test/commit-line.test.mjs +30 -0
……@@ -131,3 +131,33 @@ test('healPlan: a fork the heal never KNEW (arrived late, below it) reopens the
131131 t.ok(plan && plan.paths.has('p/late'), 'the late fork\'s paths are restated')
132132 t.alike(plan.heals.sort(), ['cB', 'cLate'])
133133})
134
135const upd = (path) => ({ action: 'update', path, cid: 'y' })
136
137test('healPlan: a partial heal\'s update/delete paths are done; its CREATE paths are still owed', async (t) => {
138 const log = [f('3a', 'c1', null), f('3b', 'cA', 'c1', { ops: [op('p/a'), op('p/c')] }), f('3b', 'cB', 'c1', { ops: [op('p/b')] }),
139 f('3c', 'part1', 'cA', { ops: [upd('p/a'), op('p/c')], restates: '3a' })]
140 const plan = healPlan(commitLine(log))
141 t.alike([...plan.paths].sort(), ['p/b', 'p/c'], 'p/a restated by update; p/c only by a create, which a stale consumer ignores')
142 t.is(plan.partsFrom, '3c')
143 t.ok(plan.window.has('p/a'), 'the window still names every path')
144})
145
146test('healPlan: a fork reaching a partial means it may have been skipped — its paths are owed again', async (t) => {
147 const log = [f('3a', 'c1', null), f('3b', 'cA', 'c1', { ops: [op('p/a')] }), f('3b', 'cB', 'c1', { ops: [op('p/b')] }),
148 f('3c', 'part1', 'cA', { ops: [upd('p/a')], restates: '3a' }), f('3c', 'zSib', 'cA', { ops: [op('p/z')] })]
149 const plan = healPlan(commitLine(log))
150 t.ok(plan.paths.has('p/a'), 'restated again')
151 t.is(plan.partsFrom, null)
152})
153
154test('healPlan: a split heal is effective only if no fork reaches its FIRST part', async (t) => {
155 const base = [f('3a', 'c1', null), f('3b', 'cA', 'c1', { ops: [op('p/a')] }), f('3b', 'cB', 'c1', { ops: [op('p/b')] }),
156 f('3c', 'part1', 'cA', { ops: [upd('p/a')], restates: '3a' }),
157 f('3d', 'final', 'part1', { ops: [upd('p/b')], asserts: '3a', heals: ['cB'], partsFrom: '3c' })]
158 t.is(healPlan(commitLine(base)), null, 'closed')
159 // A fork at the first part's rev, known to the final: a consumer may have skipped part1.
160 const forked = base.concat([f('3c', 'zFork', 'cA', { ops: [op('p/z')] })])
161 forked[4] = f('3d', 'final', 'part1', { ops: [upd('p/b')], asserts: '3a', heals: ['cB', 'zFork'], partsFrom: '3c' })
162 t.ok(healPlan(commitLine(forked)), 'reopened')
163})