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
- c028ac61Merge branch 'notes-pr7-kunibert' into mainAtlas
- 9cc92bdfKeep conflict and history fixes while awaiting queued save supportAtlas
- a5c27cb6Allow real edits back to earlier text and honor configured identAtlas
- 15c46ced|||PR Preserve note edits, conflict bases and visible historyAtlas
- 4c6e0bf6Merge branch 'notes13-day61' into mainAtlas
- eb51864f|||PR Back/Forward via navigate, server drafts, Hybriel day61Atlas
- 3537cf7eMerge branch 'vendor-day59' into mainAtlas
- c13d188b|||PR Vendor Hybriel day59Atlas
- 24c95433Merge branch 'notes17-ghost-note' into mainAtlas
- ae1075b2Preserve rejected drafts during note ID adoptionAtlas
- 383cce23|||PR Prevent saved local edits from restoring deleted notesAtlas
- 99ca1cf6Merge branch 'vendor-day56' into mainAtlas
- 649cef37|||PR Vendor Hybriel day56Atlas
- aadd0abcMerge branch 'hl-standard-2' into mainAtlas
- 52ffac9f|||PR Keyboard and reload checks for the notes gate (HL-STANDARD F21, F5)Atlas
- 617ee8c0Merge branch 'hl-standard' into mainAtlas
- 452458ee|||PR Type the function parameters of notes' own .hl files (HL-STANDARD L10)Atlas
- 23758cd6Re-vendor complete Hybriel plugins and runtime to day44mre
- 5d7cc700Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
- 3e07b1cfVendor complete Hybriel day39 plugin sources and librariesmre