fix(jsonl-merge): equal-ts entries must converge across machines#1770
Open
jbetala7 wants to merge 1 commit into
Open
fix(jsonl-merge): equal-ts entries must converge across machines#1770jbetala7 wants to merge 1 commit into
jbetala7 wants to merge 1 commit into
Conversation
The JSONL append merge driver sorted timestamped entries by (0, ts) with no further tiebreaker. Equal-ts entries then fell back to stable-sort insertion order (base, ours, theirs), but git assigns the local side to "ours", so two machines resolving the same conflict emitted equal-ts lines in opposite order. The merged files diverged and never converged. gstack-telemetry-log uses second-granularity timestamps, so same-ts collisions are routine. Add the line content as the final sort tiebreaker so the order is total and side-independent. Add a regression test that runs the driver with the two sides swapped and asserts identical output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1769
Repro / observed problem
bin/gstack-jsonl-mergeis the git merge driver for append-only JSONL statefiles (telemetry, learnings, timeline). Its header promises deterministic
resolution: "both appends survive, ordered by wall-clock timestamp where
available, content hash otherwise." That promise breaks when two different
entries share the same
ts:Root cause
The sort key for a timestamped line was
(0, ts)with no further tiebreaker.Python's sort is stable, so equal-
tsentries keep insertion order(
base, ours, theirs). Git assigns the local side to%A("ours"), so thesame logical merge runs with
ours/theirsswapped on the two machines, andthe equal-
tslines come out in opposite order. The merged files diverge andnever converge; the next sync is another conflict, resolved differently again.
gstack-telemetry-logstamps second-granularity timestamps(
date -u +%Y-%m-%dT%H:%M:%SZ), so same-tscollisions are routine. Lineswithout a
tswere already safe — they order by SHA-256 of the content, whichis side-independent.
Fix
Add the line content as the final sort tiebreaker (
(0, ts, line), and(1, h, line)for the hash path for symmetry). Equal-tsentries now order bycontent, identically on every machine. One-line behavioral change to the sort
key.
Testing
New
test/jsonl-merge.test.ts(6 tests,bun test):tsentries resolve identically with the two sides swapped (theconvergence regression — fails on
main: emitsa,bvsb,a; passeswith the fix)
tsand plain non-JSON lines also resolve side-independentlytsours/theirsfiles tolerated (added-file merge)Verified the convergence test fails on
origin/main's driver and passes withthe change.
bash -nclean,git diff --checkclean.