Repository navigation
fix(clock): read the Lamport floor past counterless __stamps rows; opt-in skipMalformed - #300
Conversation
observedDocCounter threw "malformed stamp tuple" on any document with an autogrow connect, because the applier keeps each grow's requested slot shape in __stamps under a ["grow_request", ...] key. Those rows carry no counter; skip them so producers can take a Lamport floor from real documents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 26b6aea)
…ves alone A deleted subgraph instance leaves its definition id in __stamps under an ["interior_route", ...] key, which made the floor read throw the same way. Skip both companion row kinds, and test that the grow's own stamp still counts and fails closed and that reservations are never skipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 733fbe3)
… op-pool sweep Every generated op-pool document now asserts its Lamport floor is readable, so a new counterless __stamps row fails a test instead of producers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit e88fec4)
…keep minting
observedDocCounter(doc) still fails closed on a malformed row (ADR-021).
observedDocCounter(doc, { skipMalformed: true }) returns the maximum over the
readable rows of both ledgers plus the count it passed over, so a producer
can stamp above every valid counter instead of refusing or dropping to zero.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 14b33ac)
… schema doc The floor read's companion prefixes are derived from GROW_REQUEST_TAG and INTERIOR_ROUTE_TAG in doc.ts, which the applier's key builders also use. Amendment A25 records the companion skip and the opt-in lenient read. The lenient tests now cover null rows, non-JSON reservation keys and a non-map ledger root, which still throws. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit a226b3a)
… boundary skipped counts malformed rows only; the docs now say companion rows are not counted. Tests pin that a neighbouring or nested tag still fails closed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit be9f782)
…oor; skip companion rows by value shape Lenient mode dropped a malformed row entirely, so a row like [900, 42, op] could leave the floor at a lower readable counter and the producer would mint under it. Count a valid first element even when the row is skipped. Companion rows are now skipped only when their value has the shape the applier stores (string for interior_route, [string, string|null, boolean] for grow_request), so a counter under a companion-looking key is still counted.
The applier stores a grow's widget field as sent, so a grow with a non-string widget wrote a row the exact-shape check rejected, and the strict floor became unreadable again after one such connect. Skip a grow_request row whenever its first element is not a number; a counter-shaped row under that key is still counted.
…s root Applies the accepted Lamport decision D2: with skipMalformed, a __clock_reservations root that is not a readable map counts as one skipped entry instead of throwing. Winning counters live in __stamps, whose root still has to be readable in either mode; the strict read and the clock store refuse both.
|
Warning Review limit reached
This review includes 3 billable files and costs up to $0.75.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 48 minutes for your next included review. View limit details
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Companion stamp tags src/doc.ts, src/applier.ts |
The code defines exported tag constants for grow_request and interior_route. The serialized keys use these constants. |
Counter read behavior src/clock.ts, src/read.ts, docs/multiplayer-schema.md, test/clock.test.ts, test/define-subgraph.test.ts, test/permutation/full-op-pool.permutation.test.ts |
observedDocCounter skips counterless companion rows. Strict mode remains the default; skipMalformed returns the maximum readable counter and the number of skipped rows. Tests cover malformed rows, retained interior-route stamps, replica counters, and operation groups. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Suggested reviewers: jaeone94
Merge Risk: 
Minimal · previous review 68297
-
Companion rows are excluded from counter reads. No merge-blocking issue was identified.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 7 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
jaeone94
left a comment
There was a problem hiding this comment.
LGTM. I checked every __stamps write in the applier: grow_request and interior_route are the only rows that are not stamp tuples, and the permutation sweep now catches any new one. The strict path skips them too, so the doc host stops throwing without opting in. salvageCounter accepts the same range as validateLamportCounter(…, true), so lenient mode can only over-estimate the floor.
Two notes, neither blocking:
- Rollout. The patch release that carries this also crosses 0.3.13, which brings #276 (DynamicGroup rows). So the cloud dochost bump inherits the same gate as Comfy-Org/cloud#16862: it waits until Cloud serves the cloud/1.60 frontend line. The PM-2212 fix reaches Cloud then, not right after this merges. It may be simpler to move #16862 to the new version and do one bump.
skipMalformed. Nothing in the package uses lenient mode yet. Is a dochost change planned to opt in and logskipped?
Nit: GROW_REQUEST_TAG and INTERIOR_ROUTE_TAG are appended after widgetStorageOf in the otherwise alphabetical ./doc.js import in applier.ts.
Carries Simon's #280 forward onto current
main(his six commits, cherry-picked with authorship kept). #280 had gone stale and conflicting; this replaces it.Problem
observedDocCounteris how a producer finds the Lamport floor to stamp above. It throws__stamps contains a malformed stamp tupleon ordinary documents, because the applier itself writes two counterless companion rows into__stamps:["grow_request", …]from an autogrow connect (growInputSlot);["interior_route", …]from deleting a subgraph instance (applyDeleteNode).After one autogrow connect or one subgraph-instance delete, the floor is unreadable on that document from then on. Cloud's doc host catches the throw and skips the Lamport lift (
services/agent/dochost/src/lamport.ts,documentCounter), so on those documents the agent's edits fall back to the old counter and can be LWW-dropped behind a person's earlier edit again, the case Comfy-Org/cloud#14881 fixed.Fix
observedDocCounterpasses over__stampsrows whose canonical key starts withgrow_requestorinterior_route. The tags are shared with the applier's key builders (GROW_REQUEST_TAG,INTERIOR_ROUTE_TAGindoc.ts). Reservations are never skipped. The counters those ops carry are still counted through their own stamps.observedDocCounter(doc, { skipMalformed: true })returns{ counter, skipped }for producers that must keep minting. The default call still fails closed, andDocDerivedLamportClockStorekeeps the strict read.mainhas since used).Changes on top of #280 (from an adversarial review)
[900, 42, op]was skipped whole, so the floor could stay at a lower readable counter and the producer would mint under 900. Over-estimating the floor is safe; under-estimating it is the LWW loss this whole fix is about.interior_routeonly when the value is a string,grow_requestonly when its first element is not a number. A counter-shaped row under a companion-looking key is counted, not dropped.__clock_reservationsroot counts as one skipped entry instead of throwing. An unreadable__stampsroot still throws in both modes.widgetas sent, so a grow with a non-string widget must still leave the floor readable; a test runs that real connect throughapplyOps.Red / green
main(src/clock.tsfrommain, tests from this branch): 3 failures, allTypeError: __stamps contains a malformed stamp tuple(autogrow floor, lenient mode, floor after subgraph delete).{counter: 50}instead of900; companion-keyed counter row hidden (undefinedinstead of60); real grow withwidget: 5threwmalformed stamp tuple.npm test1892 passed / 2 skipped (1894);check:purity,check:imports,check:pins,check:profile-claims,check:coderabbit,check:stateless,check:adrs,verify:corpus,lint,typecheckall pass.__stampsrow fails a test instead of failing producers.Invariants
check:statelesspasses.observedDocCountergains an overload andLenientDocCounteris exported. The one-argument call keeps its signature and fail-closed behaviour.After merge
Release a patch version, then bump the pin in cloud's
services/agent/dochostso the agent's Lamport lift works on documents with autogrow connects or deleted subgraph instances.