notes
All repositories: gitoria
8.7 KB
# notes mission 007 — notes#4: offline and sync in pure Hybriel — BUILT, one Hybriel gap (the editor offline)**notes-offline.js and sw.js are deleted**, along with their routes. The notes page is now plain Hybriel(`components/notes.hl`). `project.hl` has `offline = [Notes]`, so hl:web's generated worker, its kept state per user andits queue do the offline work. No hand-written JS is added (login.js and the vendored md-editor.js stay, as before).Branch w7. Not pushed, not deployed.## Hybriel #166 first (repros of mission 005, re-run on the vendored 0f396652)- `repro-rowkidless`: `client booted (window.__hl): true rows: one,two`. It was `false` + a TypeError on a832f73b.- `repro-rehydrate`: `offline reload: client booted (window.__hl): true rows: one,new`. Fixed.- `proto` (the design probe): an offline put is queued, kept over an offline reload, and replayed when back online. Theserver has both puts.## What was built (design of report 001)- `lib/notes.hl`: `notesFor(user)` gives the page's list. A save carries `by` (the login tag) and `since`; a save whose`by` + `base` match the note's `by` + `since` CONTINUES that browser's run, so queued saves made from one old base donot conflict with each other. The conflict rule is unchanged: the later edit wins and the other version becomes acopy. A browser that lost keeps writing into ITS copy (`copyOf`, `by`, `since`) instead of making a new copy forevery save. `removeNote` finds a never-synced note by `local`. The field is named `since` because `from` is areserved word.- `components/notes.hl`: `notes` (server-fed, kept offline). `rows` = notes, then `__hlQueue`, then this tab's`edits`, derived in the browser (the helper statics stay in this file). Statement-form faces `notesPut` and`notesDrop` are queued offline. Push `notesChanged(user, list)` goes to every tab of that user (audience inproject.hl). A 1 s CSS tick (`notesTick`) sends what was typed 0.6 s ago and calls the value-form `notesPull` every10 s and on `reconnected`. Sidebar links are claimed in place (`e.preventDefault()` + `history.replaceState`). A notemade offline has the id `l…` until its first save lands; then the address follows the server id. Log-out is the face`notesLogOut`, after which hl:web forgets that user's state, queue and documents. The UI keeps the same tags and ids.- The JSON API `/api/notes` stays (the gate uses it to read the server), now with `by` = '' (no continuation).## Works offline (gate, real Chrome, CDP offline on the page AND its worker, always RELOADED offline first)The kept page boots from hl:web's worker with no socket. It shows the list and the open note, and says "Offline — …".An existing note was edited and a new note written, both with real keys. Both wait in hl:web's queue and the serverhas neither. After another offline reload both are still there. Back online, the server has both, the new note has aserver id (in the address too), and device B shows the edit in its open note. Two devices both offline (serverstopped): B's later edit is the note and A's is kept as a copy. One device offline in Chrome and one online: the onlineedit wins, the offline one becomes a copy, and A's editor then shows the winner. Log-out: no note text is left in anyIndexedDB database, the queue is empty, and no kept document holds a note. PWA: manifest, icons, installable, andexactly one worker (`/__hl/sw.js`); `/sw.js` and `/notes-offline.js` answer 404.## Hybriel gap (Atlas → Anton) — this part is stopped, no workaround**hl:web offline keeps no app `file`/`directory` route, and an app cannot add a URL to the worker's precache.**- The page boots offline, but a script it loads from its own route (notes: `/md-editor.js`, the Markdown editor)fails to load.- Without the script the note opens in the plain `<textarea>` that `<md-editor>` wraps. Typing, the queue and sync allwork, but there is no Markdown view or toolbar until a reload online. Today's sw.js kept it.- Cause: `worker.hl answer()` → "everything else goes to the network untouched". `WebFramework.hl precacheList()`holds only the runtime, the package halves, the stylesheet, the modules, the manifest, the icons, the favicon andthe kept pages.- Repro: `notes-w7/.scratch/w7/repro-appfile/`. Run `REPRO_PORT=8731 ../../../bin/hybriel project.hl`, then`node run.mjs`. Output: `online: … widget.js ran: true` / `kept by the worker: /__hl/hl-runtime.js /__hl/app.css/__hl/web/client.js /page.hl /__hl/manifest.webmanifest /` / `offline: page shown: true widget.js ran: false`.- Proposal: an `offlineFiles = ['/md-editor.js', …]` setting, or keep every `file` route a kept page's View loads(`script { src }` / `link { href }` literals).- The gate checks this and FAILS on it (2 checks, below). I did not change the md-editor route's cache headers: thatwould be a workaround.## Gate (`NOTES_GATE_PORT=8720 NOTES_GATE_IDENT_PORT=8721 NOTES_GATE_CHROME=8722-8729 node tests/browser.mjs`)- Old code, old gate: **57 passed, 0 failed**.- New code, new gate: **62 passed, 2 failed** (64 checks). Both failures are the gap: "the Markdown editor is thereoffline" and "tables: offline … with the table" (the text itself is there).- Rewritten (they tested the JS files):- the worker keeps the page and the shell (`hl-shell-*`);- exactly one worker, `/__hl/sw.js`; `/sw.js` and `/notes-offline.js` answer 404;- the offline section now runs on Chrome offline instead of a stopped server;- the sync waits: socket open and hl:web's queue empty (was `__notesOffline.sync()`);- log-out scans every IndexedDB and every kept document.- New checks:- no hand-written notes JS on the page;- the offline reload booted from the worker with no socket;- the editor is there offline;- the offline edits wait in the queue while the server has neither;- three checks for one device offline and one online.- **Fails on old code** (the new gate against `git archive 0176c4b`, `NOTES_GATE_SOFT=1` so that a timed-out wait doesnot stop the run): 58 passed, 6 failed. That run was 59/6; the +1 is the check removed later, which passedthere. The failures:- hl:web worker keeps the page and shell;- one `/__hl/sw.js` worker;- no hand-written JS;- the sidebar says it is offline (old JS never says it under CDP offline);- the edits wait in hl:web's queue;- the one-offline precondition (A's edit waits in the queue).- Passing on old code as well, as they should (same behaviour as today): the one-offline conflict outcome, both log-outchecks, and "the editor is there offline" (old sw.js kept md-editor.js; the new code fails it = the gap).- The log-out check passes on old code, so I ran it on a mutated copy where `client.hl forget()` returns at once:it fails (61/3; the run was 62/3 with the since-removed check passing).- A check that did not fail under that mutation ("offline reload after log-out shows no notes") was removed.- Flake: "B follows the delete" timed out in 1 of 6 runs and did not come back in the later runs.`NOTES_GATE_DEBUG=1` dumps both devices' state if it happens again.## Real data (`node tests/realdata-offline.mjs <newest backup> 8720 8722-8726`)- Data: `notes.worldapi.org-20261019-2028.tgz`, storage/mpackdb only, as a copy (deleted after: `copy deleted: true`).The session is a file for az5b2 → 0muh6o5a3kkd.- **6 passed, 0 failed**:- all **28** live notes are listed by id;- after an offline reload, 28 are listed with no socket;- an edit typed offline with real keys is not on the server while offline;- back online, it is in the SAME note (no copy, still 28 notes);- the server logged no error.- The mission said 49 notes. This backup has 42 note records: 28 live and 14 tombstones.## Screenshots: checked as text and colours (computed styles + PNG pixel counts, no image viewer)- Every shot: header rgb(15,20,25) (token `darker`), page rgb(25,30,35), brand rgb(220,220,170) yellow, nohorizontal overflow.- 1280: list 320 px beside the reader 889 px.- 390: the list is hidden while a note is open, the reader is 358 px.- Offline: the md-editor surface rgb(35,40,45) is gone (phone 3.9 % → 0 %); the plain textarea (dark, 358/889 px)shows instead (the gap).- Files: `.scratch/gate-*.png` and `.scratch/realdata-{390,1280}-{online,offline}.png`.## Not covered- A log-out made while offline: `notesLogOut` is a statement-form face of the shell, not of the kept page.- Text typed less than ~1 s before Log out is not sent: the tick has not fired yet. The old JS sent it first.## Commits (branch w7)510aff7 server continuation · e5785b0 the page in Hybriel · 52a2aca gate · 632223f delete notes-offline.js + sw.js ·7f6a409 README + realdata-offline · 2cce9c9 code order (`let` 0 never reassigned) + gate soft/debug · (this report).Nothing of mine is left running on 8720–8739.
Branches
Latest commits
- 447da53dnotes mission 014: report — remaining gates and lisbeth E2E proofmre
- fd9f92c3notes mission 014: report (partial), LOG, STATUSmre
- b2501360notes mission 014: open() sets asking=false before flush(0) (hybriel#196)mre
- 9414ce59notes mission 014: merge theme 76f99f6, components 3794c59, strict single-press openAsk (fails on old open())mre
- c08c655anotes 013: theme re-copied from layouts 76f99f6 (menu marks the current page), current = true on the menu item, e2e marker checks, reportmre
- 21c8f65dnotes mission 012: STATUSmre
- 0bbb3dd9notes mission 012: delete section of the browser gate de-flaked (openAsk: calm wait, press again when the question closes by itself); report 012mre
- f431bdf8notes mission 011: notes on the layouts theme (ListFirst shell), styles cut, check-theme gate, E2E extended; reportmre
- 1a8603d1notes mission 011 WIP: deploy.sh gate summary also matches check-theme, browser.mjs logout via the user menumre
- dae2e508notes mission 011 WIP: theme dbe3de7, shell on AppHeader/MainMenu/UserMenu/Sidebar + ListFirst, styles cut to the app's own, check-theme gate, e2e auditmre
- fd36da27notes mission 010: the note editor is the Hybriel MdEditor block (components.hybriel 1442e58, verbatim); md-editor.js, its route, script tag and offlineFiles retired; gate 66/0, realdata-offline 12/0, round-trip and Chrome E2E tests; report 010mre
- efa92170notes tests/identkit.mjs: refuse a taken ident port, cold-wait deadline, emit, identities; mission 009 reportmre
- f3dec0f1Merge branch 'w7'mre
- d1cf966dre-vendor hybriel 97bcf128: offlineFiles for the editor script, 44 px taps, 390 px offline checks, mission 008mre
- 4a610a21paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
- eeaea980report 007: say which runs included the removed checkmre
- 8a8ad9banotes mission 007: report, LOG, STATUSmre
- 2cce9c96code order: plain declarations where never reassigned (letcount 0 never); gate: scan every IndexedDB at log-out, soft mode for old-code runs, drop a check that could not failmre
- 7f6a4090README: offline in Hybriel (hl:web offline, continuation, known md-editor gap); gate waits report instead of crash; realdata-offline checkmre
- 632223f2notes#4: delete notes-offline.js and sw.js (hl:web's generated worker and kept state replace them)mre