Skip to content

State Primitive Spike: replace Projection + App.hydrate with state-agent#146

Open
taras wants to merge 1 commit into
deterministic-peer-loop-implfrom
state-primitive-spike
Open

State Primitive Spike: replace Projection + App.hydrate with state-agent#146
taras wants to merge 1 commit into
deterministic-peer-loop-implfrom
state-primitive-spike

Conversation

@taras
Copy link
Copy Markdown
Owner

@taras taras commented Apr 30, 2026

Summary

Stacked on PR #119. Replaces the deterministic peer-loop's Projection
agent (5 reducer ops, journal-only) and App.hydrate op with a single
synthetic state-agent (readInitialState, transition) backed by an
example-local authority. The authority is seeded at host startup by
folding recorded state-agent.transition results out of the journal.

The workflow body collapses 5 per-field state locals into one rolling
let state: AppState. The browser binding installs an authority
subscription that fans out every accepted snapshot — no more
per-iteration workflow push, no publishFinalSnapshot.

The spike does not modify any source under packages/. No kernel
changes were required to support the primitive.

Spike conclusion

The state-transition primitive can live above the kernel for this
example. Full report at
notes/state-primitive-spike/report.md.

Two follow-ups escalated (neither blocking):

  • Compiler IR Get<T> collapses to EvalT<unknown>, which forced the
    transition op to return bare AppState (validated as the right
    shape independently — proposal lives durably in
    description.input per PR Payload-sensitive replay: runtime + kernel implementation (PR 2 of 2) #145).
  • Vitest scope teardown halts under full-journal replay through a
    workflow that uses race + inline children. Test reformulated to
    use a 1-event prefix; not a regression.

Test plan

  • 41 tests passing in examples/deterministic-peer-loop (5 new
    state-authority unit tests + 3 new STATE-RE replay tests + 27
    rebaselined conformance tests + 2 DPL-JNL replay tests + 4 misc).
  • Lint clean (pnpm run lint).
  • Format clean (pnpm run format:check).
  • Manual browser smoke per
    notes/state-primitive-spike/manual-smoke.md
    (host restart → re-attach → identical state).

Notes for review

  • This PR is a spike. Decision on what to upstream — to runtime,
    spec work, or kernel — is taken after the report, not as part
    of the spike. The recommended next step in the report is a
    scoped-effects spec amendment, not direct promotion of the
    example-local pattern.
  • All worktree code lives in examples/deterministic-peer-loop/src/.
    No package edits.

The deterministic peer-loop example previously used a five-op `Projection`
agent purely to journal state transitions and an `App.hydrate` op that
pushed per-iteration snapshots into the browser session mirror. This
spike collapses both into a single synthetic `state-agent` agent
(`readInitialState`, `transition`) backed by an example-local authority
that fans out snapshots to subscribers (the browser session manager).

Workflow body now holds one rolling `let state: AppState` seeded via
`StateAgent().readInitialState({})` and reassigned after every accepted
transition. The host's `main.ts` reads `JOURNAL_PATH` directly via
`FileStream` and seeds the authority by folding recorded
`state-agent.transition` results, so live and replay see identical
seeded state.

Replay-bypass holds: the binding handler is never invoked for any
recorded `state-agent.transition` event during replay (verified in
`test/replay/state-replay.test.ts`).

The spike does not touch any package source; no kernel changes were
required. Full report at `notes/state-primitive-spike/report.md`.

Tests: 41 passing across 10 files in
`examples/deterministic-peer-loop` (incl. 3 new STATE-RE tests + 5
new state-authority unit tests + rebaselined 27 conformance + 2
DPL-JNL replay tests).
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.

1 participant