Skip to content

Commit eed120c

Browse files
plan++
1 parent c3af5ab commit eed120c

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# TASK-123: Fix clock table schema parity with oracle
2+
3+
## Status
4+
- [ ] Planned
5+
6+
## Priority
7+
medium
8+
9+
## Assigned To
10+
(unassigned)
11+
12+
## Parent Docs / Cross-links
13+
- Divergence documented in: `.tasks/done/TASK-074-cross-impl-compat-expanded.md`
14+
- Test: `zig/harness/test-oracle-parity.sh` (Test 2)
15+
- Zig clock table creation: `zig/src/as_crr.zig`
16+
- Gap backlog: `research/zig-cr/92-gap-backlog.md`
17+
18+
## Description
19+
The Zig `__crsql_clock` table schema differs from the Rust/C oracle in two ways:
20+
21+
1. **Column naming**: Zig uses `pk` column, Rust/C uses `key` column
22+
2. **Index**: Rust/C has an index on the clock table, Zig has 0 indexes
23+
3. **Strict**: Rust/C uses STRICT tables, Zig does not
24+
25+
These differences may cause cross-implementation database sharing issues.
26+
27+
## Files to Modify
28+
- `zig/src/as_crr.zig` - clock table creation
29+
30+
## Acceptance Criteria
31+
- [ ] `__crsql_clock` table schema matches oracle exactly
32+
- [ ] Column names match (change `pk` to `key` - careful with pks table relation!)
33+
- [ ] Index structure matches oracle (add `_dbv_idx` on `db_version`)
34+
- [ ] Strict mode enabled
35+
- [ ] `zig/harness/test-oracle-parity.sh` Test 2 passes
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# TASK-124: Fix site_id preservation on cross-implementation DB open
2+
3+
## Status
4+
- [ ] Planned
5+
6+
## Priority
7+
medium
8+
9+
## Assigned To
10+
(unassigned)
11+
12+
## Parent Docs / Cross-links
13+
- Divergence documented in: `.tasks/done/TASK-074-cross-impl-compat-expanded.md`
14+
- Test: `zig/harness/test-oracle-parity.sh` (Test 4b, 4c)
15+
- Zig site_id handling: `zig/src/site_identity.zig`
16+
- Zig init handling: `zig/src/ffi/init.zig`
17+
- Gap backlog: `research/zig-cr/92-gap-backlog.md`
18+
19+
## Description
20+
When Rust/C opens a database created by Zig, the site_id is not preserved correctly.
21+
22+
**Current behavior:**
23+
- Zig creates DB with site_id: A6C2BD7D1EF644D4B72C5C97D0B50B78
24+
- Rust/C opens same DB and reads site_id: (empty or different)
25+
26+
**Expected behavior:**
27+
Both implementations should read the same site_id from an existing database.
28+
29+
**Investigation Notes:**
30+
The issue might be due to missing version information in `crsql_master`. Rust/C implementation checks for a minimum version before accepting a database.
31+
32+
## Files to Modify
33+
- `zig/src/ffi/init.zig` - initialization (version writing)
34+
- `zig/src/site_identity.zig` - site_id storage/retrieval
35+
36+
## Acceptance Criteria
37+
- [ ] When Rust/C opens a Zig-created DB, site_id is preserved
38+
- [ ] When Zig opens a Rust/C-created DB, site_id is preserved
39+
- [ ] `zig/harness/test-oracle-parity.sh` Test 4b and 4c pass

research/zig-cr/92-gap-backlog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
Goal: invalidate the hypothesis that "Zig is done" by expanding cross-implementation parity coverage and adding real-system tests.
1414

15+
### Open Gaps (Parity Divergences)
16+
- [ ] **TASK-123** — Fix clock table schema parity (pk vs key, index) `.tasks/backlog/TASK-123-fix-clock-table-schema-parity.md`
17+
- [ ] **TASK-124** — Fix site_id preservation on cross-open `.tasks/backlog/TASK-124-fix-site-id-cross-open-parity.md`
18+
1519
### Parity/Coverage Tasks (ready to assign)
1620
- [x] **TASK-070** — Cover missing C suites: ext-data + sandbox ✓ `.tasks/done/TASK-070-zig-parity-extdata-sandbox.md`
1721
- ext-data: 15/15 tests pass (test-extdata.sh)
@@ -203,4 +207,4 @@ Goal: invalidate the hypothesis that "Zig is done" by expanding cross-implementa
203207
- **Round 51 (2025-12-20)**:
204208
- TASK-121: Fix rows_impacted ROLLBACK reset divergence (18/18 pass)
205209
- TASK-122: Fix no-op UPDATE db_version divergence (14/14 pass)
206-
- **Zero oracle divergences remaining**
210+
- **Remaining divergences**: TASK-123 (clock schema), TASK-124 (site_id cross-open)

zig/src/merge_insert.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,10 @@ pub fn setWinnerClock(
316316
seq: i64,
317317
) MergeError!void {
318318
var buf: [1024]u8 = undefined;
319+
// Note: Clock table uses "key" column, not "pk" - must match as_crr.zig schema
319320
const sql = std.fmt.bufPrintZ(&buf,
320321
\\INSERT OR REPLACE INTO "{s}__crsql_clock"
321-
\\ ("pk", "col_name", "col_version", "db_version", "site_id", "seq")
322+
\\ ("key", "col_name", "col_version", "db_version", "site_id", "seq")
322323
\\VALUES (?, ?, ?, ?, ?, ?)
323324
, .{table_name}) catch return MergeError.BufferOverflow;
324325

0 commit comments

Comments
 (0)