From 8c19459bb685ac62e1d7749c61703528f86bcf87 Mon Sep 17 00:00:00 2001 From: mnovak Date: Sat, 7 Nov 2026 15:07:33 +0100 Subject: [PATCH] [docs] TwoTabs: Analysis, review, the trap measured, G1.8 closed --- .agents/FEATURES.md | 1 + .agents/GAP_ANALYSIS.md | 1 + .agents/features/two-tabs.md | 64 +++++++++++++++++++++++++++++++++ .agents/lessons/README.md | 2 +- .agents/lessons/technical.md | 13 +++++++ .agents/reviews/fix-two-tabs.md | 53 +++++++++++++++++++++++++++ CLAUDE.md | 2 +- HANDOVER.md | 9 +++-- 8 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 .agents/features/two-tabs.md create mode 100644 .agents/reviews/fix-two-tabs.md diff --git a/.agents/FEATURES.md b/.agents/FEATURES.md index 00ad827..7ad66c2 100644 --- a/.agents/FEATURES.md +++ b/.agents/FEATURES.md @@ -8,6 +8,7 @@ One row per feature, with its analysis document (CLAUDE.md §5.1). Gaps live in | Workspace, contracts, gates, PWA shell | 0 | Merged to `main` 2026-11-01 (`d11d242`); built, not deployed. Phase 0 gate still open | [phase0-workspace.md](features/phase0-workspace.md) | [feature-phase0-workspace.md](reviews/feature-phase0-workspace.md) | | Roadmap and gameplay docs, read against the code | 0 | Merged 2026-11-01; Q1–Q7 answered by the author | — | [docs-roadmap-gameplay.md](reviews/docs-roadmap-gameplay.md) | | The Letter slot: page at `#letter`, empty `docs/LETTER.md` | 0 | Merged to `main`; built, not deployed. Invisible until the author writes | [letter-slot.md](features/letter-slot.md) | [feature-letter-slot.md](reviews/feature-letter-slot.md) | +| Two tabs, one garden: what one tab writes, the others see | 1 | Merged to `main`; built, not deployed | [two-tabs.md](features/two-tabs.md) | [fix-two-tabs.md](reviews/fix-two-tabs.md) | | Thorns: touch her; a rush of taps, and she says she has thorns | 1 | Merged to `main`; built, not deployed | [thorns.md](features/thorns.md) | [feature-thorns.md](reviews/feature-thorns.md) | | The day's sentence: her folded petal, one a day, never lost, best at sunset; candidates and `library:verify` | 1 | Merged to `main`; built, not deployed. Invisible until the author verifies sentences | [day-sentence.md](features/day-sentence.md) | [feature-day-sentence.md](reviews/feature-day-sentence.md) | | The in-game sunset: move the chair, half a minute of silence, then the real sunset's time | 1 | Merged to `main`; built, not deployed | [chair-sunset.md](features/chair-sunset.md) | [feature-chair-sunset.md](reviews/feature-chair-sunset.md) | diff --git a/.agents/GAP_ANALYSIS.md b/.agents/GAP_ANALYSIS.md index 6acd0e5..65a42bb 100644 --- a/.agents/GAP_ANALYSIS.md +++ b/.agents/GAP_ANALYSIS.md @@ -59,6 +59,7 @@ sentences). Nothing in Phase 1 is visible to the player yet. | ~~G1.5~~ | ~~The day's sentence and the folded petal~~ | Closed 2026-11-02 on `feature/day-sentence`, for the code: `engine/petal` (5 properties: never lost, verified-later never swaps it, one a day, no repeat until all opened), the `sentence-opened` event, the rose file v2, the petal in the garden; e2e opens one in a fixture build and reloads. 9 of 9 put-back bugs caught. **The shipped app shows no petal until the author verifies sentences (G0.18).** | | ~~G1.6~~ | ~~The in-game sunset: move the chair, watch it again~~ | Closed 2026-11-02 on `feature/chair-sunset`: half a minute with nothing to press, then the real sunset's time; Escape and a tap leave; the offline suite watches one with the server gone. 4 of 4 put-back bugs caught. | | ~~G1.7~~ | ~~Thorns were on the roadmap but undesigned~~ | Closed 2026-11-02 on `feature/thorns`, as the author chose: thorns teach gentleness. `engine/touch` (2 properties: spaced taps are never a rush; one blush a visit); a tremor is one touch; nothing recorded. 6 of 6 put-back bugs caught. | +| ~~G1.8~~ | ~~Two tabs (CLAUDE.md §8, predicted)~~ | Closed 2026-11-07 on `fix/two-tabs`. Measured first: two e2e tests failed (an open tab saw neither care nor a town from the other). Storage announces committed writes on a `BroadcastChannel`; the rose and the garden read again, adding to what they show. No lock needed: nothing stored drifts. 7 of 7 put-back bugs caught. | | G1.3 | Towns have no Czech names (*Vídeň*) | Open. Natural Earth has none; arrives with Czech copy. | ## Design questions — answered diff --git a/.agents/features/two-tabs.md b/.agents/features/two-tabs.md new file mode 100644 index 0000000..a2480a8 --- /dev/null +++ b/.agents/features/two-tabs.md @@ -0,0 +1,64 @@ +# Two tabs, one garden + +Status: built on `fix/two-tabs`. CLAUDE.md §8, *Two tabs, one database (predicted): two event streams +into one store; derived state drifts. Use a `BroadcastChannel` lock.* Review: +[`fix-two-tabs.md`](../reviews/fix-two-tabs.md). + +## 1. Why and what, in the player's terms + +A player may have the garden open twice: two browser tabs, or the installed app and a tab. Whatever +they do in one is now seen in the other within a moment, without a reload: care given, a petal opened, +a rose brought back from a file, a town chosen. + +**Measured first (2026-11-07).** Two e2e tests, written before the fix, failed: a tab already open did +not see care given in the other, nor a town chosen there. The prediction was half right: + +- **No stored state drifts.** There is no `derived` store yet; the log is append-only and every write + is its own IndexedDB transaction (auto-increment ids), so two writers cannot overwrite each other. + The identity's first write already wins in a transaction (rose.md). **No lock is needed.** +- **The views drift.** Each tab read the log once, at start. The harm: she is watered in one tab, the + other still shows her thirsty, the player waters again, and she is too full — a mistake the game + made, blamed on her care. + +## 2. Technical architecture + +```mermaid +flowchart LR + a["tab A
packages/storage: appendCare"] -->|"IndexedDB write, then post 'log'"| bc(("BroadcastChannel
rosea-changes")) + bc -->|"'log' | 'place'"| b["tab B
packages/storage: onChange"] + b --> app["apps/rosea wiring"] --> ui["packages/ui
Rose / Shell reload from storage"] +``` + +| # | Decision | Why | +|:--|:--|:--| +| W1 | **`packages/storage` announces its own writes** on a `BroadcastChannel` named after the database, *after* the write commits: `'log'` (care, a petal, a rose brought back) or `'place'` (the town). | One module owns every write, so no write path can forget to announce. After the commit, so the other tab reads what was written. | +| W2 | **The message is only what changed**, never the data. The other tab reads storage again. | Storage stays the truth; a message can be lost or arrive twice and nothing breaks. | +| W3 | A tab does not hear itself (a `BroadcastChannel` never delivers to the object that posted). | No double reload. | +| W4 | **No lock.** | §1: nothing a lock would protect exists yet. When a `derived` store arrives, its feature doc decides again. | +| W5 | Where `BroadcastChannel` does not exist, nothing is announced and each tab is as before. | Safari has it since 15.4; an older browser loses only the live update, never data. | +| W6 | Nothing on screen says another tab acted. The garden simply is as it is. | Calm; no "updated elsewhere" notices. | + +## 3. Risk analysis + +| Risk | Answer | +|:--|:--| +| **Blame for the game's mistake** (watered twice, too full). | The fix itself. | +| **Privacy**: a message leaves the tab. | A `BroadcastChannel` reaches only this origin's own tabs and workers in this browser profile; it carries one word, never data. Nothing leaves the device. | +| A message from another origin or a malformed one. | The channel is same-origin by definition; anything but `'log'` or `'place'` is ignored. | +| Reachability, offline | Not affected; works offline. | + +## 4. Gap analysis + +Closes CLAUDE.md §8's two-tabs trap (measured, answered) and the review checklist's *two tabs open* +for the log and the town. Not covered: a tab that is mid-pour when the other tab's care arrives keeps +pouring against the new water level (that is the correct level). + +## 5. Verification matrix + +| Case | Kind | Where | +|:--|:--|:--| +| Each write announces after it commits: care, petal, rose brought back → `'log'`; town → `'place'` | unit | `storage/test/changes.test.ts` | +| A failed write announces nothing; a tab does not hear itself; a malformed message is ignored; unsubscribe stops it; `close()` closes the channel | unit | same | +| Without `BroadcastChannel`, storage still works | unit | same | +| The rose reloads her log on `'log'`; the shell reloads the town on `'place'` | unit | `ui/test/two-tabs.test.ts` | +| Built app, two tabs: care in A seen in B without reload; a town chosen in A shown in B | e2e | `e2e/shell.spec.ts` (failed before the fix: the measurement) | diff --git a/.agents/lessons/README.md b/.agents/lessons/README.md index e6a188f..2ab1769 100644 --- a/.agents/lessons/README.md +++ b/.agents/lessons/README.md @@ -11,7 +11,7 @@ and **how to apply it**. | `design.md` | none yet | Wording, silence, empty states. | | [`art.md`](art.md) | 2 | The image pipeline. | | [`code.md`](code.md) | 3 | TypeScript, Svelte, async ordering, Rust. | -| [`technical.md`](technical.md) | 5 | The browser and the build as platforms. | +| [`technical.md`](technical.md) | 6 | The browser and the build as platforms. | | [`testing.md`](testing.md) | 10 | What makes a test worth having, and how a passing test lies. | | `privacy.md` | none yet | What could leave the device or make a person findable. (The geocell finding is in the review, not here: it was caught before it cost anything.) | | [`process.md`](process.md) | 4 | Workflow, commits, credentials, honesty about what shipped. | diff --git a/.agents/lessons/technical.md b/.agents/lessons/technical.md index 492feb8..8f2173f 100644 --- a/.agents/lessons/technical.md +++ b/.agents/lessons/technical.md @@ -70,3 +70,16 @@ listening. This machine runs many projects. **How to apply it.** Before starting a preview, check that the port is free (`netstat -ano | grep :`). After it starts, check the page title before you trust anything the page says. + +## A predicted trap can name the right place and the wrong harm + +**What happened.** CLAUDE.md §8 predicted that two tabs would make stored derived state drift and +prescribed a lock. On 2026-11-07 two e2e tests, written before any fix, showed the real harm was +elsewhere: there was no derived store and the append-only log could not conflict, but each tab's +view went stale, so a player could water the rose twice. A lock would have fixed nothing. + +**Why it bit.** A prediction is written before the code exists, so its remedy fits the design +that was imagined, not the one that was built. + +**How to apply it.** Before acting on a predicted trap, write the test that would show it, run it +against the built app, and fix what fails. Then rewrite the trap's row with what was measured. diff --git a/.agents/reviews/fix-two-tabs.md b/.agents/reviews/fix-two-tabs.md new file mode 100644 index 0000000..218a62e --- /dev/null +++ b/.agents/reviews/fix-two-tabs.md @@ -0,0 +1,53 @@ +# Review — `fix/two-tabs` + +Adversarial self-review (CLAUDE.md §5.3). Analysis: [`features/two-tabs.md`](../features/two-tabs.md). +Reviewed 2026-11-07 on Node 22.11.0, Windows 10. There is no PR: the only remote is Gitea. + +## The measurement + +CLAUDE.md §8 predicted *derived state drifts; use a BroadcastChannel lock*. Two e2e tests were +written first and run against the built app: both **failed** (a tab already open saw neither care +nor a town chosen in another tab). Reading the code explained why, and showed what the +prediction got wrong: there is no `derived` store and the log is append-only, so nothing stored +can drift and no lock is needed. What drifted was each tab's view, which can make the player water +her twice. Both tests pass after the fix. + +## Gates + +Counts are on the merge; HANDOVER repeats them. New: storage +7, ui +3, e2e +2 (the measurement). + +**The app changed** (CLAUDE.md §5.4), invisibly in one tab: another open tab now follows it. +Rebuilt by the e2e and offline runs; **not deployed** (G0.13). + +## Bug drills + +| Put back | Result | +|:--|:--| +| Care is announced before it is written | CAUGHT | +| A petal is never announced | CAUGHT | +| A town is never announced | CAUGHT | +| Any message counts as a change | CAUGHT | +| The rose replaces her view with a stale read | CAUGHT | +| The rose does not listen | CAUGHT | +| The garden ignores a town from another tab | CAUGHT | + +## Findings + +| # | Area | Finding | Resolution | +|:--|:--|:--|:--| +| 1 | Correctness | A tab's own care can still be on its way to IndexedDB when another tab's news makes it read; a plain replace would drop that care from view, and nothing would bring it back. | The read is added to what the tab shows, never replaces it (the log only grows); drilled. | +| 2 | Correctness | Two reads overlapping, finishing out of order. | Same answer: each only adds, so order does not matter. | +| 3 | Correctness | Announcing before the commit would make the other tab read too early. | Announced after `add` / after the transaction resolves; drilled. | +| 4 | Correctness | A tab mid-pour when the other tab's care arrives: the can now measures against the new level. | Accepted: that is the true level. | +| 5 | Design | A town arriving while this tab is searching for one: the search closes and the new town shows. | Accepted: the player's choice in the other tab is the newer one. A tab in the middle of *Change town* keeps its open search (only the shown town updates). | +| 6 | Privacy | A `BroadcastChannel` message. | Same origin, same browser profile only; one word (`log`, `place`), no data. Nothing leaves the device. | +| 7 | Compatibility | Browsers without `BroadcastChannel` (Safari before 15.4). | Each tab keeps its own view, as before; no data is affected; tested with it removed. | +| 8 | Process | The measurement commit would have been red on its own. | The branch was regrouped before pushing so every commit is green: the tests land with the fix. | +| 9 | Process | On 2026-11-07 the root `node_modules` was missing (cause unknown; the code and history were intact). | Restored with `pnpm install --frozen-lockfile`, which also reinstalled the hooks. | +| — | Soul, reachability, offline | Looked; the fix removes a way the game could blame her care for its own mistake. Nothing new is shown or sent; works offline. | — | + +## What was not verified + +- Safari and Firefox (BroadcastChannel across an installed app and a tab); a phone. +- The KeepSafe path across tabs end to end (bringing her back in one tab, seen in the other): + covered by the storage test that a brought-back rose announces `log`, not by an e2e. diff --git a/CLAUDE.md b/CLAUDE.md index 57854ca..27c8dc4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -509,7 +509,7 @@ No timestamp finer than a day, no precise location, no free text, no link to the | **Medical claims in a store listing** | One word like *heal* in marketing copy can pull the product toward medical-device rules. `lint:copy` also runs on store text kept in the repo. | | **IndexedDB is evictable** *(predicted; answered by `keep-her-safe.md`)* | WebKit can discard origin storage after seven days without interaction — exactly the shape of a player who drifted away and comes back. Call `navigator.storage.persist()` where it exists, prompt iOS players to install, and make export-my-rose a first-class feature. A player returning to find their rose gone is the cruellest bug this product could have. | | **The stale service worker** *(answered by `calm-refresh.md`)* | A precached shell keeps serving old JS to a player who has "updated". Detect a waiting worker and offer an explicit, calm *refresh* control. | -| **Two tabs, one database** *(predicted)* | Two event streams into one store; derived state drifts. Use a `BroadcastChannel` lock. | +| **Two tabs, one database** *(measured 2026-11-07; answered by `two-tabs.md`)* | Predicted: derived state drifts, use a lock. Measured: nothing stored drifts (the log is append-only, there is no `derived` store yet), so no lock — but each tab's **view** went stale, and a player could water her twice. `packages/storage` announces each committed write on a `BroadcastChannel`; the other tabs read again, keeping what they already show. When a `derived` store arrives, decide the lock again. | | **GitHub Pages serves under a sub-path** *(predicted)* | A project site lives at `//`, not `/`. Vite `base`, the web manifest `start_url` and `scope`, and the service worker scope must all agree, or the installed app opens a 404 or never updates. The offline suite runs against the same base path. | | **GitHub Pages cannot set response headers** *(predicted)* | No custom CSP or cache headers. The content-security policy goes in a `` tag; caching is controlled by the service worker and hashed filenames. | | **Pages hosts files, not services** | `services/lucerna` cannot live on Pages. It runs on Mark's own server (Phase 4), and the app must work fully without it. | diff --git a/HANDOVER.md b/HANDOVER.md index 6b42c24..6e302c8 100644 --- a/HANDOVER.md +++ b/HANDOVER.md @@ -12,8 +12,8 @@ Rewritten at the end of each session (CLAUDE.md §5.1). Gitea hashes match. Analysis: [`.agents/features/phase0-workspace.md`](.agents/features/phase0-workspace.md). Review, with counts and the mutation results: [`.agents/reviews/feature-phase0-workspace.md`](.agents/reviews/feature-phase0-workspace.md). -- **Gates:** all pass on this machine. Unit tests: 458 (cpu-guard 13, identity 5, schema 19, - content 80, storage 58, art-prep 56, engine 168, ui 59). E2E: 19. Offline: 1. `lint:copy`: 21 files, 0 problems. +- **Gates:** all pass on this machine. Unit tests: 468 (cpu-guard 13, identity 5, schema 19, + content 80, storage 65, art-prep 56, engine 168, ui 62). E2E: 21. Offline: 1. `lint:copy`: 21 files, 0 problems. `validate:library`: 13 of 13 fixtures rejected; 78 candidates pass. - **Built, not deployed:** there is no host yet. - **Roadmap and gameplay docs:** `docs/ROADMAP.md` and `docs/GAMEPLAY.md` are on @@ -93,6 +93,11 @@ Rewritten at the end of each session (CLAUDE.md §5.1). says *Gently. I have thorns.* and rests four seconds. A tremor's taps count as one. Nothing is recorded. Tuning in `TOUCH` (`packages/engine/src/touch/touch.ts`). Review: [`.agents/reviews/feature-thorns.md`](.agents/reviews/feature-thorns.md). +- **Two tabs (2026-11-07):** merged to `main`. Measured first: an open tab did not see care or a + town from another tab, so a player could water her twice. Storage now announces each committed + write on a `BroadcastChannel`; the other tabs read again. No lock: nothing stored can drift. + On this date the root `node_modules` was found missing; `pnpm install --frozen-lockfile` + restored it. Review: [`.agents/reviews/fix-two-tabs.md`](.agents/reviews/fix-two-tabs.md). - **Phase 1 is built in code.** What remains of it is the author's: verified sentences (the petal appears with them), hosting (G0.13), and the gate itself — two weeks of daily play on a phone.