Skip to content

feat(#115): flip and diffuse from the hand-built timeline - #120

Merged
Enniwhere merged 6 commits into
mainfrom
115-random-flip
Nov 27, 2026
Merged

Enniwhere merged 6 commits into
mainfrom
115-random-flip

Conversation

@Enniwhere

Copy link
Copy Markdown
Contributor

What grew

HandWalk can now append a full sampled row as well as a one-cell jump, and a new engine/step.ts samples either one pinned position (sampleFlip) or every unfrozen position in 0..L-1 order (sampleDiffuse). The worker resolves the same strategy resources and freeze masks the full trajectory uses, seeded by deriveSeed(seed, destinationStep), while TrajectoryCache and computeTrajectory stay untouched. The page gains Flip this token in the pinned inspector and Diffuse one step beside Undo; both append through the existing branch semantics, so undo pops either kind.

Try it

  1. Run npm run dev, open http://localhost:5173, and click Walk it.
  2. Pin a token, click Flip this token, then Undo and Flip again — the same token id returns under seed 42.
  3. Click Diffuse one step; the whole visible row is resampled and appended, and Undo restores the previous row.

The seed-42 Show run recorded Flip token id 2068 and Diffuse row 464, 2068, 7586, 21831.

First place to read

src/lib/engine/step.ts for the two samplers, then trajectoryStore._sampleStep for the worker round-trip and the branch check.

Deviations from the issue text

  • Frozen positions skip sampleStep and consume no draw, so Diffuse performs one draw per unfrozen position, not one per 0..L-1 position. This came from the walk and keeps the full engine's freeze promise.
  • Both buttons stop at the trail's snapshotted maxSteps, not live scheduleStore.T, so a later schedule change cannot resize an existing trail.
  • Flip is also disabled when the pinned position is frozen (WordNet-unmapped), with a one-line inspector note.

Noticed: slice 1 first measured 505 changed lines, over the 500 gate, and was trimmed to 492; slice 2 landed at 417, over the 400 target but under the gate.

Closes #115

Next: run /review on this PR, then /retrospective 115 after merge.

Adds deriveSeed (seed plus destination step, no position mix) and a pure
sampleFlip wrapper around the strategy's coupled sampleStep. The worker
resolves the same kernel resource as the full walk and returns one token;
the store holds one in-flight step and appends through HandWalk.jump. The
pinned inspector gets Flip this token with horizon, in-flight and frozen
guards, an epsilon caveat, and a frozen note; its query reports the
focused position's frozen flag with the visible-row rule. Checked with
check, lint, prettier and vitest (675 tests, including deriveSeed, fake
strategy, seeded lexical repeat and freeze cases).

Plan: 1
Slice: 1/4
Kind: behavioral
Add Diffuse one step beside Undo: the worker samples every unfrozen
position of the visible row once in order, from the same destination-step
stream as Flip, and returns only that row. HandWalk gains a full-row
append and the store appends through it with the same branch/undo
semantics. The freeze helpers move into engine/freeze.ts so compute and
the step share one rule.

Tests cover full-row append/truncate, skipped frozen draws, a seeded
differential against a naive per-position loop, and the store's append
branch and cache isolation. Slice-check: 417 changed (under the 500 gate).

Plan: 1
Slice: 2/4
Kind: behavioral
Extend the hand-walk smoke spec: seed-42 Flip with Enter, undo, Flip
again and compare the token, Diffuse with Space, then undo. The recorded
tokens are flip id 2068 and diffuse row 464, 2068, 7586, 21831.

Ran `npm run e2e`: 10 passed. Slice-check: 50 changed.

Plan: 1
Slice: 3/4
Kind: mechanical
Park the plan's Not doing lines, drop the promoted random-flip entry with a
Promoted note to #115, add the step sampler to the map, and rewrite the
HandWalk comment for full-row append. Update README and AboutPanel to describe
Flip and Diffuse rather than promise them, add the session noticed line, and
bump to 1.20.0.

Verified with `node scripts/slice-check.mjs --budget 150`: check, lint,
format and 681 tests pass; 61 changed lines. The full e2e suite passed in
slice 3 (10 tests), including the flip-repeat and diffuse-step Show.

Plan: 1
Slice: 4/4
Kind: mechanical
The linear schedule's beta_t is 0.0001 at t=0 and 0.02 at most, so the
strategy's stay coin almost always returned the pinned token unchanged.
Flip now passes beta=1 to sampleStep, forcing the active kernel's jump row;
Diffuse keeps the schedule's beta_t. The e2e asserts the flipped token
differs, and its seed-42 ids are recorded on PR #120.

Verified: slice-check 67 changed (check, lint, prettier, 681 tests); targeted
Playwright flip-repeat/diffuse test passed.

Plan: 1
Slice: 1/1
Kind: behavioral
@Enniwhere

Copy link
Copy Markdown
Contributor Author

Follow-up fix: Flip now forces the jump

The earlier seed-42 recording was made before this fix. At the default
linear schedule, beta_t is 0.0001 at $t=0$ and 0.02 at most, so Flip's
$\beta_t$ stay coin almost always returned the pinned token unchanged. Flip
now passes $\beta=1$ to sampleStep, so it always takes the active kernel's
jump row; Diffuse still uses the schedule's beta_t.

Updated seed-42 recording (same steps as the PR body):

  • Flip token id: 41409 (was 2068)
  • After Diffuse one step: 464, 41409, 7586, 21831
  • Undo restores the flipped row; repeating Flip after Undo returns 41409.

Commit ffc2a11. The e2e now asserts the first flipped token differs from
row 0, and the targeted flip-repeat/diffuse test passed.

@Enniwhere

Copy link
Copy Markdown
Contributor Author

Reviewed commit: ffc2a11

Verdict: approve

Blockers

  • None.

Stewardship notes

  • src/lib/engine/rng.ts:24-27 still says Flip's token is Diffuse's draw for the first unfrozen position, but after the follow-up fix Flip forces beta = 1 (src/lib/engine/step.ts:22) while Diffuse passes the schedule's beta (src/lib/engine/step.ts:41). The streams share a seed, not a token; update the comment or delete that sentence.
  • AC2 asks for sampleStep(token, beta, rng) with the current beta, while the implementation deliberately forces beta = 1 (src/lib/engine/step.ts:22, src/lib/stores/trajectory.svelte.ts:223) so Flip always takes a jump. The follow-up comment explains why; record the deviation against AC2 and update the issue/PR wording. The older PR-body Show values (2068 and 464, 2068, 7586, 21831) are superseded by 41409 and 464, 41409, 7586, 21831.
  • Noticed: slice 1 first measured 505 changed lines, over the 500 gate, and was trimmed to 492; slice 2 landed at 417, over the 400 target but under the gate.

What could be deleted or simplified

  • Delete the stale src/lib/engine/rng.ts:24-27 sentence or rewrite it to describe the shared seed without claiming token identity.
  • Delete the src/lib/engine/freeze.test.ts:22-27 test; its name claims a visible-row behavior, but it only calls isFrozenToken with two ids.
  • Update the PR body's pre-fix Show values or delete them, since the follow-up comment has the corrected 41409 pair.

Describe the shared destination-step stream without claiming Flip and
Diffuse draw the same token; Flip forces beta=1. Drop the redundant
freeze test that only checked isFrozenToken with two ids.

Fixes: review 1
Slice: review
Kind: mechanical
@Enniwhere
Enniwhere merged commit 59d744d into main Nov 27, 2026
3 checks passed
@Enniwhere
Enniwhere deleted the 115-random-flip branch November 27, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Random flip and one-step diffusion from the hand-built timeline

1 participant