Files
MechaCat02 9ab5aba6b3 feat(sync): protocol 2 — hydration, a counter not a clock, no silent shrinking
The reworked bundle's PORT.md makes row-level last-write-wins conditional
on three gates, each learned by losing real data. The port's sync broke
all three, and had four more ways to lose or stall work. Both ends change,
so this is one protocol version, refused by the other side if mismatched.

Gate 1, hydration. A device now pulls every page the server holds before
it may push anything; it used to push first. The 14 Sep laptop — a
week-old copy re-stamped at boot and pushed over a week of phone work —
is now a test, and the phone's week survives it. Boot writes nothing
syncable either: the lesson opens with the app's own words (the artifact's
seeded turn) and waits for Start, instead of stamping a reply and a
progress edit before a server can even be configured.

Gate 2, a counter. Every row remembers the change_seq it last agreed with
(base_seq). The server applies a write only if that still matches —
compare-and-swap under an advisory lock — and otherwise returns its copy
as a conflict. No clock is compared anywhere: a device an hour fast used
to win every conflict for an hour, and a slow one's newer edit was
silently dropped with HTTP 200. dirty and rev replace the timestamp
watermark, which lost edits whenever a clock moved backwards.

Gate 3, no silent shrinking. A conflict is settled by what each copy
holds (sync/resolve.ts): more reviews, more evidence, a finished unit, the
further roadmap position, the union of learned grammar. A deliberate
shrink is explicit: a reset or a cleared lesson raises a marker every
device obeys, including its own unsynced edits, so a reset is not undone
by a device that had not heard of it. Trimming the transcript is local
and tombstones nothing — it used to delete the other device's turns.

Also fixed on the way:
  · keys travel as JSON arrays — a space in 몇 명 used to stop every
    device's pull at that row, permanently;
  · pulls take a shared lock against pushes, so a change_seq committed
    out of order can no longer be skipped;
  · study_log and peek are per device and summed, so two devices' reviews
    of one day both count;
  · each user's data has an epoch; a server that lost it is detected,
    and the device re-hydrates and offers its data back;
  · a protocol-1 client is refused with 426 rather than half-understood.

Migration 9 adds the columns, re-keys the counters and tombstones; the
server drops protocol-1 rows once (none were deployed). Verified: 14
two-device scenarios against a real Postgres, and two browser profiles
syncing a lesson through the UI.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-16 20:28:35 +02:00

77 lines
2.5 KiB
YAML

name: CI
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# The bundle's own checks come first, before anything else can run.
# Both read only data/, lib/ and fixtures/ and exit non-zero on failure:
# validate.mjs — curriculum sequencing. Baseline: PASS, 0 blocking, 0 advisory.
# audit-gate.mjs — the word gate against 54 real tutor messages.
# Baseline: 7 of 41 and 2 of 13 flagged. Too many
# means it rejects real teaching; too few means
# violations reach the student.
- name: Curriculum validation and gate audit
run: sh run-checks.sh
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- name: Typecheck
run: npm run typecheck
# The sync round-trip needs a real Postgres and a running server: a fake
# would not exercise the compare-and-swap push, the advisory locks that
# keep a pull from skipping a change_seq, or cursor paging — which is
# where sync actually goes wrong.
- name: Start Postgres
run: |
docker run -d --name hankan-pg \
-e POSTGRES_PASSWORD=test -e POSTGRES_DB=hankan \
-p 55432:5432 postgres:16-alpine
for i in $(seq 1 30); do
docker exec hankan-pg pg_isready -U postgres -d hankan && break
sleep 1
done
- name: Start the sync server
env:
DATABASE_URL: postgres://postgres:test@localhost:55432/hankan
HANKAN_TOKEN: test-token
HANKAN_TEST_MODE: "1"
# Keyless, so the tutor endpoint is exercised over real HTTP —
# SSE framing, CORS and auth — without an Anthropic key in CI.
HANKAN_TUTOR_BACKEND: echo
PORT: "8788"
run: |
node --experimental-strip-types server/src/main.ts &
for i in $(seq 1 30); do
curl -sf http://localhost:8788/health && break
sleep 1
done
- name: Tests
env:
HANKAN_TEST_SERVER: http://localhost:8788
run: npm test
# Every word in every unit's words[] must resolve in lemma or surface.
# Runs against the committed band files in app/public/dict/.
- name: Roadmap word coverage
run: npm run dict:assert
- name: Build
run: npm run build