Skip to content

Commit f8be715

Browse files
delegate round 37: browser multi-tab F9-F12 complete (TASK-031, TASK-032)
- TASK-032: Reactive subscriptions (F9-F10) - db_version notification broadcast - TASK-031: Service Worker fallback (F11-F12) - ServiceWorkerCoordinator Tests: 66 pass in crsql-mesh package Commits: 848c2a66c (effect-native)
1 parent 58860ba commit f8be715

File tree

5 files changed

+163
-18
lines changed

5 files changed

+163
-18
lines changed

.tasks/DELEGATE_WORK_HANDOFF.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,3 +472,99 @@ pnpm -F @effect-native/crsql-mesh check
472472
- No coverage captured
473473
- Foundation provides the scaffolding but doesn't include actual OPFS or Web Locks — those require browser environment
474474
- Test file had concurrent test interference issue — fixed by removing `vi.clearAllMocks()` in `afterEach`
475+
476+
---
477+
478+
## Round 2025-12-16 (37) — Browser multi-tab F9-F12 complete
479+
480+
**Tasks executed**
481+
- `.tasks/done/TASK-031-web-service-worker-fallback.md`
482+
- `.tasks/done/TASK-032-web-reactive-subscriptions.md`
483+
484+
**Commits**
485+
- `848c2a66c` (effect-native) — implement browser multi-tab F9-F12: reactive subscriptions + SW fallback (Round 37)
486+
- `efe3dacd` (root) — delegate round 37: browser multi-tab F9-F12 complete (TASK-031, TASK-032)
487+
488+
**Modified files (effect-native submodule)**
489+
- `packages-native/crsql-mesh/src/browser/coordinator.ts` — added `DbVersionChangedMessage` and broadcast handler
490+
- `packages-native/crsql-mesh/src/browser/provider.ts` — added `DbVersionNotification`, `onVersionChange()`, notification after writes
491+
- `packages-native/crsql-mesh/src/browser/coordinator-sw.ts` — NEW: Service Worker coordinator fallback
492+
- `packages-native/crsql-mesh/src/browser/index.ts` — added exports for new types and SW coordinator
493+
- `packages-native/crsql-mesh/test/browser/coordinator.test.ts` — added 4 notification broadcast tests
494+
- `packages-native/crsql-mesh/test/browser/provider.test.ts` — added 4 db_version notification tests
495+
- `packages-native/crsql-mesh/test/browser/coordinator-sw.test.ts` — NEW: 12 tests for SW coordinator
496+
497+
**Environment**
498+
- OS: darwin (macOS ARM64)
499+
- Tooling: pnpm, vitest 3.2.4
500+
501+
**Commands run (exact)**
502+
```bash
503+
source ~/.zshrc
504+
cd /Users/tom/Developer/effect-native/cr-sqlite/effect-native
505+
pnpm -F @effect-native/crsql-mesh test --run
506+
pnpm -F @effect-native/crsql-mesh check
507+
```
508+
509+
**Outputs (paste)**
510+
511+
<details>
512+
<summary>crsql-mesh tests (66 pass)</summary>
513+
514+
```text
515+
RUN v3.2.4 /Users/tom/Developer/effect-native/cr-sqlite/effect-native/packages-native/crsql-mesh
516+
517+
✓ test/browser/coordinator.test.ts (13 tests) 6ms
518+
✓ test/browser/coordinator-sw.test.ts (12 tests) 5ms
519+
✓ test/browser/provider.test.ts (18 tests) 10ms
520+
✓ test/Receive.test.ts (4 tests) 41ms
521+
✓ test/Mesh.test.ts (7 tests) 126ms
522+
✓ test/VersionVector.test.ts (3 tests) 30ms
523+
✓ test/Integration.test.ts (4 tests) 34ms
524+
✓ test/Apply.test.ts (5 tests) 47ms
525+
526+
Test Files 8 passed (8)
527+
Tests 66 passed (66)
528+
Start at 21:57:25
529+
Duration 626ms
530+
```
531+
</details>
532+
533+
<details>
534+
<summary>TypeScript check</summary>
535+
536+
```text
537+
> @effect-native/[email protected] check
538+
> tsc -b tsconfig.json
539+
540+
(no output = success)
541+
```
542+
</details>
543+
544+
**Reproduction steps (clean checkout)**
545+
1. `git clone <repo> && cd cr-sqlite`
546+
2. `cd effect-native && pnpm install`
547+
3. `pnpm -F @effect-native/crsql-mesh test --run`
548+
4. `pnpm -F @effect-native/crsql-mesh check`
549+
550+
**Work summary**
551+
1. **TASK-032 (F9-F10)**: Reactive subscriptions
552+
- Provider now queries `crsql_db_version()` after each `exec` call
553+
- Provider tracks `lastKnownDbVersion` and emits `DbVersionNotification` when it advances
554+
- Coordinator routes `db-version-changed` messages from provider to all client tabs
555+
- Subscriber pattern: `provider.onVersionChange(callback)` returns unsubscribe function
556+
- 8 new tests added
557+
558+
2. **TASK-031 (F11-F12)**: Service Worker fallback
559+
- `ServiceWorkerCoordinator` class mirrors SharedWorker coordinator API
560+
- Uses Service Worker Clients API (`self.clients.get(id)`) instead of MessagePorts
561+
- Same election semantics via Web Locks pattern
562+
- Same message routing: forward-request, forward-response, broadcast
563+
- `createServiceWorkerScript()` helper for bootstrapping
564+
- 12 new tests added
565+
566+
**Known gaps / unverified claims**
567+
- No real browser integration tests (Playwright) — vitest mocks only
568+
- No coverage captured
569+
- Actual OPFS and Web Locks require browser environment
570+
- Provider migration (F13-F14) not yet implemented — that's the next slice

.tasks/backlog/TASK-031-web-service-worker-fallback.md renamed to .tasks/done/TASK-031-web-service-worker-fallback.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
## Status
44
- [x] Planned
5-
- [ ] Assigned
6-
- [ ] In Progress
5+
- [x] Assigned
6+
- [x] In Progress
77
- [ ] Blocked
8-
- [ ] Complete
8+
- [x] Complete
99

1010
## Priority
1111
medium
@@ -34,7 +34,7 @@ Unblocked prerequisites:
3434
- ✅ Specs exist: `effect-native/.specs/crsql-mesh/requirements.md`, `effect-native/.specs/crsql-mesh/design.md`, `effect-native/.specs/crsql-mesh/plan.md`
3535
- ✅ Foundation exists: `.tasks/done/TASK-063-browser-multitab-foundation.md` (Coordinator/Provider unit-tested scaffolding)
3636

37-
Remaining blocker: needs Tom authorization to proceed with TS Phase 5 coding per `effect-native/.specs/AGENTS.md`.
37+
**Tom authorized Phase 5 implementation on 2025-12-16.**
3838

3939
## Description
4040
Add a Service Worker fallback for environments where SharedWorker is unavailable.
@@ -55,5 +55,26 @@ Do not attempt to move OPFS access into the Service Worker.
5555
### 2025-12-14
5656
- Task created during gap review; awaiting Tom opt-in due to TS constraint
5757

58+
### 2025-12-16
59+
- Tom authorized Phase 5 implementation
60+
- Implemented F11-F12 from RGRTDD plan
61+
5862
## Completion Notes
59-
[fill in when done]
63+
**Date:** 2025-12-16
64+
65+
**Files created:**
66+
- `effect-native/packages-native/crsql-mesh/src/browser/coordinator-sw.ts` (348 lines)
67+
- `effect-native/packages-native/crsql-mesh/test/browser/coordinator-sw.test.ts` (12 tests)
68+
69+
**Files modified:**
70+
- `effect-native/packages-native/crsql-mesh/src/browser/index.ts` (added SW exports)
71+
72+
**Implementation:**
73+
- `ServiceWorkerCoordinator` class mirrors SharedWorker coordinator API
74+
- Uses Service Worker Clients API instead of MessagePorts
75+
- Same election semantics via Web Locks
76+
- Same message routing patterns
77+
- Includes `createServiceWorkerScript()` for bootstrapping
78+
79+
**Tests:** 12 new tests, all passing
80+
**TypeScript:** Check passes

.tasks/backlog/TASK-032-web-reactive-subscriptions.md renamed to .tasks/done/TASK-032-web-reactive-subscriptions.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
## Status
44
- [x] Planned
5-
- [ ] Assigned
6-
- [ ] In Progress
5+
- [x] Assigned
6+
- [x] In Progress
77
- [ ] Blocked
8-
- [ ] Complete
8+
- [x] Complete
99

1010
## Priority
1111
medium
@@ -34,7 +34,7 @@ Unblocked prerequisites:
3434
- ✅ Specs exist: `effect-native/.specs/crsql-mesh/requirements.md`, `effect-native/.specs/crsql-mesh/design.md`, `effect-native/.specs/crsql-mesh/plan.md`
3535
- ✅ Foundation exists: `.tasks/done/TASK-063-browser-multitab-foundation.md` (Coordinator/Provider unit-tested scaffolding)
3636

37-
Remaining blocker: needs Tom authorization to proceed with TS Phase 5 coding per `effect-native/.specs/AGENTS.md`.
37+
**Tom authorized Phase 5 implementation on 2025-12-16.**
3838

3939
## Description
4040
Provide a narrow notification/subscription surface so tab B can react when tab A writes.
@@ -54,5 +54,25 @@ MVP can be a "db_version advanced" event broadcast; leave "observable queries" a
5454
### 2025-12-14
5555
- Task created during gap review; awaiting Tom opt-in due to TS constraint
5656

57+
### 2025-12-16
58+
- Tom authorized Phase 5 implementation
59+
- Implemented F9-F10 from RGRTDD plan
60+
5761
## Completion Notes
58-
[fill in when done]
62+
**Date:** 2025-12-16
63+
64+
**Files modified:**
65+
- `effect-native/packages-native/crsql-mesh/src/browser/provider.ts`
66+
- Added `DbVersionNotification` interface
67+
- Added `onVersionChange(callback)` subscription method
68+
- Added `checkAndNotifyVersionChange()` after writes
69+
- Provider queries `crsql_db_version()` after exec and notifies on advance
70+
- `effect-native/packages-native/crsql-mesh/src/browser/coordinator.ts`
71+
- Added `DbVersionChangedMessage` interface
72+
- Added `handleDbVersionChanged()` to broadcast notifications
73+
- Routes `db-version-changed` messages from provider to all clients
74+
- `effect-native/packages-native/crsql-mesh/src/browser/index.ts`
75+
- Exported new types
76+
77+
**Tests:** 8 new tests (4 coordinator, 4 provider), all passing
78+
**TypeScript:** Check passes

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 92-gap-backlog
22

3-
> Last updated: 2025-12-16 (Round 36 — Browser multi-tab foundation F5-F8 complete)
3+
> Last updated: 2025-12-16 (Round 37 — Browser multi-tab F9-F12 complete)
44
55
## Status
66

@@ -17,13 +17,17 @@ Pick disjoint tasks from `.tasks/backlog/`:
1717
- Browser tests: 18/18 passing (TASK-052 done — was port conflict, not code bug)
1818
- Mesh tests: 46/46 passing (TASK-063 done — browser foundation added)
1919

20-
- **Browser Multi-Tab Implementation (Round 36)**
20+
- **Browser Multi-Tab Implementation (Round 37 — complete)**
2121
- ✅ Browser foundation F5-F8: `.tasks/done/TASK-063-browser-multitab-foundation.md`
2222
- Coordinator + Provider classes
2323
- 9 coordinator tests, 14 provider tests
2424
- ✅ Browser specs: `.tasks/done/TASK-053-spec-browser-runtime-phase1.md`, `.tasks/done/TASK-054-spec-browser-runtime-phase2.md`
25-
- (Unblocked; needs TS authorization gate) Service Worker fallback F11-F12: `.tasks/backlog/TASK-031-web-service-worker-fallback.md`
26-
- (Unblocked; needs TS authorization gate) Reactive subscriptions F9-F10: `.tasks/backlog/TASK-032-web-reactive-subscriptions.md`
25+
- ✅ Reactive subscriptions F9-F10: `.tasks/done/TASK-032-web-reactive-subscriptions.md`
26+
- db_version notification broadcast from provider to clients
27+
- 8 new tests (4 coordinator, 4 provider)
28+
- ✅ Service Worker fallback F11-F12: `.tasks/done/TASK-031-web-service-worker-fallback.md`
29+
- ServiceWorkerCoordinator class
30+
- 12 new tests
2731

2832
- **Upstream goodwill (de-prioritized)**
2933
- Scope decision (later): `.tasks/backlog/TASK-055-tom-scope-upstream-feedback.md`
@@ -90,9 +94,13 @@ Note: per Tom (2025-12-16), browser multi-tab specs land in the unified full pro
9094
Foundation (completed Round 36):
9195
- [x] Coordinator + Provider foundation (F5-F8) → `.tasks/done/TASK-063-browser-multitab-foundation.md`
9296

93-
Implementation tasks (unblocked — foundation done):
94-
- [ ] Reactive subscriptions F9-F10 → `.tasks/backlog/TASK-032-web-reactive-subscriptions.md` (unblocked; TS authorization gate)
95-
- [ ] Service Worker fallback F11-F12 → `.tasks/backlog/TASK-031-web-service-worker-fallback.md` (unblocked; TS authorization gate)
97+
Implementation tasks (completed Round 37):
98+
- [x] Reactive subscriptions F9-F10 → `.tasks/done/TASK-032-web-reactive-subscriptions.md`
99+
- [x] Service Worker fallback F11-F12 → `.tasks/done/TASK-031-web-service-worker-fallback.md`
100+
101+
Remaining browser multi-tab work:
102+
- [ ] Provider migration F13-F14 (re-election on tab close, idempotent write guard)
103+
- [ ] Browser integration polish F15 (tree-shaking, public API)
96104

97105
Note: TS work is spec-gated under `effect-native/.specs/AGENTS.md`.
98106

0 commit comments

Comments
 (0)