[docs] TwoTabs: Analysis, review, the trap measured, G1.8 closed

This commit is contained in:
2026-11-07 15:07:33 +01:00
parent b67fa3603d
commit 8c19459bb6
8 changed files with 141 additions and 4 deletions
+1
View File
@@ -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) |
+1
View File
@@ -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
+64
View File
@@ -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<br/>packages/storage: appendCare"] -->|"IndexedDB write, then post 'log'"| bc(("BroadcastChannel<br/>rosea-changes"))
bc -->|"'log' | 'place'"| b["tab B<br/>packages/storage: onChange"]
b --> app["apps/rosea wiring"] --> ui["packages/ui<br/>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) |
+1 -1
View File
@@ -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. |
+13
View File
@@ -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 :<port>`). 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.
+53
View File
@@ -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.