Files
pad/web
xarmian d2ceab6120 fix(web): fence every async commit point on the library page on the signed-in identity (BUG-3084) (#1378)
Surface 3 of 7. Three async handlers and FOUR DEFERRED TIMERS — a
population of 7, not the 3 a function-level count sees. The originally
filed survey reported 3; the widened instrument's number is confirmed
again here on the current tree rather than carried from the survey.

What this fixes
----------------------------------------------------------------------

`activateConvention` and `activatePlaybook` COMPOSE A WRITE from state
chosen under the previous identity: the entry the user clicked came from
a list `loadData` fetched then. A click after an identity change is the
current epoch, so every entry capture passes and the previous session's
choice is activated into whatever workspace is on screen now. Both now
take `pageIdentityHeld()` at entry, the same question the roles board's
drag handlers needed.

The four timers are the distinctive class. Each fires three seconds
after its handler returned and clears `toast` — by which time the page
may belong to someone else and be showing THEIR toast. Clearing it then
is a commit by a session that has ended. Driven with fake timers rather
than reasoned about.

`loadData` had no identity bookkeeping at all, and its `$effect` is
keyed on `wsSlug` alone, so nothing re-ran it when the identity moved.
It now has an entry capture, per-arm fences, a generation guard, and an
`onIdentityChange` subscription that resets transient state before
re-loading.

The rules carried from surfaces 1 and 2, not re-derived
----------------------------------------------------------------------

- The epoch is re-stamped AFTER the awaited state is assigned, never
  before the await, and on BOTH arms. Too early and the guard vouches
  for data it has not replaced; missing on a path and a transient error
  pins the fence shut for ever. Bounded on both sides in the guard.
- A continuation that has LOST the identity writes no shared interaction
  state — `resetTransientState()` owns that reset, and a stale
  continuation writing it again can only clobber what the NEW user is
  doing. `activatingTitle` gates both handlers at their first line, so
  this is not cosmetic: a stale release permits a second concurrent
  activation.
- `loadGen` gates the state assignments, not merely `loading`. Different
  question from the identity fence and neither implies the other — both
  loads can belong to the same user, which is what a workspace switch
  produces here.
- The transient-state reset is ENUMERATED against the file's own
  `$state` declarations, with every non-member named and justified, so a
  new piece of interaction state fails the guard rather than waiting for
  a reviewer (CONVE-35).

Evidence
----------------------------------------------------------------------

- Mutation matrix 8/8 detected, positive control green. Four of the
  eight are caught by a BEHAVIOURAL leg independently of the source
  guard, so the semantics are measured and not merely the syntax.
- One mutant (L6, a stale `finally` releasing the activate gate)
  survived its first instrument. The instrument was fixed rather than
  the mutant dropped — the continuation rule cannot govern a `finally`,
  because the success-path check always sits in its window, so the two
  arms are named explicitly instead of pretending a regex expresses
  "which check governs which statement".
- `npx vitest run` from `web/`: 226 files / 3104 tests, 0 failures.
- `npx svelte-check --threshold error`: 0 errors.

Codex round 1
----------------------------------------------------------------------

No P1. Three P2, all taken.

- **Double loads on every identity change.** `loadData` reads
  `authStore.identityEpoch` synchronously via `captureIdentity()` before
  its first await, so the `$effect` took a dependency on the epoch and
  re-ran on an identity change — on top of the listener that already
  re-loads for that event. Eight requests where four were wanted, with
  `loadGen` quietly discarding half: correct on screen, a mystery in a
  network log. Untracked, naming the workspace as the real key, the way
  settings (#1370) suppresses the same class.

  **This is a class, and the merged collection page has it too** (#1374's
  listener plus a `$effect` calling `loadCollection`, which reads the
  epoch the same way). Out of scope here — merged code, a different
  surface — and reported to the lead as its own unit rather than widened
  into this PR.

- **A fenced timer that clears nothing passed every test.** The stale-timer
  leg proves the toast SURVIVES a timer armed by the previous session; it
  says nothing about the timer doing its job when the identity is
  unchanged, and the source guard only looked for `identityHeld(` in the
  callback. Fixing a stale-write by making the write never happen is the
  failure this family already shipped once, as a fence that latched shut
  (#1372). Added: a control leg that advances the clock under an
  unchanged identity and requires the toast to clear, and a guard
  assertion that every timer still assigns `toast = null`.

- **`activatePlaybook` had no driven coverage** — every behavioural leg
  clicked the convention button, so the near-identical playbook handler
  was vouched for only by source text. It now has its own control and
  its own click-after-the-change leg.

Mutation matrix: 11/11 detected at this round, both positive controls green.

Codex round 2
----------------------------------------------------------------------

No P1. Two P2, both the same rule as round 1's and both taken — the
instrument could not tell a commit correctly REFUSED from a commit that
never existed.

- **The load path had no driven leg at all.** The source guard permits
  the fence to sit after the assignments, and nothing held a load open
  across an identity change to notice. The implementation ordering was
  right; the instrument could not say so. Added a leg that holds the
  reload open, moves the identity, then resolves it with different
  content and requires that content not to be painted.
- **Two of the four timers live in CATCH arms, and nothing executed
  them.** A dead branch carrying both `identityHeld()` and `toast = null`
  satisfied the source guard and the whole suite — source text vouching
  for a path nothing runs. This round drove the CONVENTION failure arm
  and the playbook success arm, plus a stale-timer leg on the convention
  failure path. It did NOT reach the playbook failure arm; round 3 found
  that, and the wording here has been corrected rather than left reading
  as though the catch-arm class had been closed.

Per the lead's ruling, the rule those three rounds keep re-teaching is
now in the shared instrument's header (`identityFenceSource.ts`), so
surfaces 4-7 meet it before writing their first assertion: every rule in
that core asks a REFUSAL question, none can distinguish refusal from
absence, and a surface therefore owes one case that keeps USING the page
after an identity change, one unchanged-identity case per fenced commit
proving it still happens, and a driven leg per handler rather than per
handler SHAPE.

Mutation matrix: 14/14 detected at this round, three positive controls green.

Codex round 3
----------------------------------------------------------------------

No P1, and no correctness defect in the page code at all — both findings
are coverage, both on the playbook path, and one of them is that round
2's own write-up overclaimed.

- `activatePlaybook`'s LATE-RESPONSE fence had no driven leg. Round 2
  gave that handler a control and a click-after-the-change leg, which
  between them prove the request starts and that a preflight refusal
  works, and say nothing about the fence after the await. Removing that
  fence left the entire suite passing.
- The playbook FAILURE timer — the fourth of four — still had no driven
  leg. Round 2 named "two of the four timers live in catch arms" as the
  problem and then drove one of them. The prose above is corrected in
  place; a write-up that describes a class and fixes half of it is how a
  reviewer stops being able to trust the next one.

Both now have driven legs, and both mutants (dropping the post-await
fence; unfencing the playbook failure timer) are detected.

Round 3 also confirmed the load-window leg discriminates: it starts from
a rendered baseline, holds a second load, supplies unique content, and
moves the epoch before resolving, so without the fence that content
would be painted.

Mutation matrix: 17/17 detected, four positive controls green. Full
suite: 226 files / 3114 tests, 0 failures; svelte-check 0 errors.

Claude-Session: https://claude.ai/code/session_01PDYjP67KTAcqpFpo3ijAAA
2026-09-14 21:50:16 -04:00
..
2026-03-26 01:52:36 +00:00
2026-03-26 01:52:36 +00:00
2026-03-26 01:52:36 +00:00
2026-03-26 01:52:36 +00:00

Pad Web UI

SvelteKit 2 + Svelte 5 frontend for Pad, compiled to static files and embedded into the Go binary.

Development

npm install
npm run dev          # Dev server at localhost:5173 (proxies API to localhost:7777)
npm run build        # Production build to build/
npm run check        # Type checking with svelte-check

When developing, run the Go backend separately with make dev from the project root.

Building for Production

Do not build in isolation. Always use make build from the project root — this builds the web frontend, then compiles the Go binary with the build output embedded via //go:embed.

Stack

  • Svelte 5 with runes ($state, $derived, $effect)
  • SvelteKit 2 with adapter-static (SPA mode)
  • Tiptap block editor with markdown round-trip
  • svelte-dnd-action for drag-and-drop in board/list views
  • SSE for real-time updates
  • TypeScript throughout

Structure

src/
  routes/                    SvelteKit pages
    +layout.svelte           App shell (sidebar + main)
    +page.svelte             Landing/redirect
    [workspace]/
      +page.svelte           Dashboard (collections, phases, activity)
      +layout.svelte         SSE connection per workspace
      [collection]/
        +page.svelte         Collection view (board/list)
      [collection]/[item]/
        +page.svelte         Item detail + editor
      conventions/            Purpose-built conventions page
      playbooks/              Purpose-built playbooks page
      settings/               Workspace settings
  lib/
    api/client.ts            HTTP API client
    components/
      layout/                Sidebar, navigation
      editor/                Tiptap editor, raw markdown editor
      fields/                FieldEditor, relation picker
      items/                 ItemCard, ItemDetail
      collections/           BoardView, ListView
      common/                StatusBadge, badges, modals
      search/                CommandPalette
    stores/                  Svelte 5 reactive stores
      workspace.svelte.ts    Workspace state
      collections.svelte.ts  Collection + item state
      ui.svelte.ts           Sidebar, mobile state
    types/index.ts           TypeScript types and constants
  app.css                    Global styles and design tokens