Skip to content

test: pin recorded session move identity events - #191

Merged
abogartz merged 3 commits into
abogartz:mainfrom
WhollyMindless:test/identity-event-fidelity
Oct 31, 2026
Merged

abogartz merged 3 commits into
abogartz:mainfrom
WhollyMindless:test/identity-event-fidelity

Conversation

@WhollyMindless

@WhollyMindless WhollyMindless commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #176 via option 1: preserve live evidence and extend the identity-event fidelity checks.

A real isolated OpenCode 2.2.2 service emitted session.moved after POST /api/session/:sessionID/move. Its outer location still named directory A, while data.location named destination B. The existing adapter already chooses B correctly. Preserve that normalized envelope in a separate fixture with host version, date, procedure, extraction disclosure, and limitations; leave the original 2.1.4 two-turn recording untouched.

Export the identity trigger list from the adapter and require every entry to be both protocol-declared and observed in a recording. Replay the recorded move through the plugin's event subscription, starting with an established A binding and an API fallback row still pointing to A, then verify that the next durable write belongs to B without another API lookup. These are characterization tests of existing behavior; the production behavior change only shares the existing three-event list. Parsing and rebinding behavior are unchanged.

The move extract must now declare nonempty host, recordedAt, and procedure metadata, and every retained envelope must decode and encode unchanged through the lockfile-pinned @opencode/schema 2.0.32 SessionEvent.All schema, rejecting excess properties. This catches malformed fixture data, not a fabricated but schema-valid recording. The fixture explicitly states that other frames were dropped. README and source comments distinguish the two recordings and the identity/capture checks. The original recording's absent-move assertion deliberately preserves its historical workload; future captures should be separately identified.

Validation at 50deaa6, Windows/Bun 1.4.4: 48 focused tests pass; full gate passes typecheck, lint, 727 unit tests (12 existing skips), and 11 real-host E2E tests. Seven temporary fixture mutations pass the prior fidelity tests and fail the new checks: missing provenance, blank host, blank date, empty procedure, missing durable envelope, durable version 2, and an appended bare session.idle event. All mutations were restored before the gate. The original four behavioral mutation checks are documented in the maintainer review of 9a66584.

The live observation establishes emission on 2.2.2; plugin rebinding is tested by replay. Raw SSE capture frames are not included, and schema/provenance checks do not authenticate origin. This does not establish 2.1.4 move behavior or live rebinding across supported versions. The recording (2.2.2), CI host pin (2.0.26), and plugin/schema pin (2.0.32) are distinct. Investigation: #176 (comment).

Please feel free to decline or close this if you prefer a different fixture or compatibility-testing policy for the project.

@abogartz abogartz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: APPROVED_WITH_NITS

Reviewed at head 9a66584 (macOS / Bun 1.4.3; CI pins 1.4.4). This closes the empirical half of #176 and I could not break it. Findings are about making the new rule enforceable, not about the observation.

The recording holds up. Rather than take the provenance block's word for it, I re-ran the fixture's own procedure against real, fully isolated OpenCode services (fresh HOME + all four XDG dirs, throwaway store, scripted model): two runs on the CI-pinned 2.0.26 and three on 2.2.2 downloaded from npm — the exact claimed version. Every non-guessable property matches: POST /api/session → 200, POST …/move → 204, the session row names B afterwards, the outer location still carries the stale source A while data.location names B, durable.aggregateID == data.sessionID, durable.version: 1, durable.seq: 4 (3/3 runs, both versions), and the JSON key order id,created,type,location,data,durable — which matches the wire serializer, not the .d.ts declaration order (type,durable,location,data). A hand-authored file would have had to guess the stale-outer-location quirk, the sequence number, and the serializer's key order. seq: 4 is exactly what that procedure produces (created=0, inbox.enqueued=1, execution.started=2, inbox.delivered=3, moved=4). The envelope also decodes cleanly against the pinned @opencode/schema SessionEvent.Moved, which rejects the usual fabrication tells (missing durable, version: 2, non-evt_ id, properties instead of data).

Claims I checked against the tree

Body claim Verification Result
production change only shares the existing three-event list git diff 525ed89 HEAD -- src/ is src/host.ts:26-37 only: the inline !== chain became IDENTITY_EVENT_TYPES.includes, plus a no-op typeof guard; no second identity list exists in src/ confirmed
original 2.1.4 recording untouched --stat -- test/fixtures/ shows only host-session-move.json added; host-events.jsonl absent from the diff confirmed
46 focused / 725 unit (12 skips) / 11 e2e reproduced: 46 pass, 725 / 12 / 0 (base58 is 722/12/0 → +3), 11 e2e pass; lint 409 warnings / +0, typecheck clean confirmed
four mutations all failed the intended tests (a) move omitted from the observed set → fidelity test dies +["session.moved"]; (b) session.idle added as an identity trigger → dies +["session.idle"]; (c) prefer outer location → the new replay test times out and the pre-existing host.test.ts:51 precedence case dies; (d) handler removed → replay + host.test.ts:21 die (44 pass/2 fail). All four landed (re-read before believing) confirmed
replay goes through the plugin's subscription, not an internal helper neutering ctx.event?.subscribe at src/index.ts:1425 kills the replay test — it really exercises for await (const raw of eventApi.subscribe(...)) → sessionIdentityEvent → rememberSessionDir confirmed
rebind happens with no further API lookup load-bearing but secondary: expect(getCalls.length).toBe(lookups) alone survives a bolted-on fallback because bindSessionFromApi short-circuits on sessionDirFirm/apiBindTried; with those guards removed and a real second session.get re-binding to A, the test dies at line 86. A rescue-by-fallback cannot pass confirmed

Red-on-base framing, so nobody misreads it: on 525ed89 the ported fidelity file passes (7/0) and the ported replay file passes (5/0). These are characterization tests pinning existing behaviour to a real recording — the net's teeth are the mutation cases (a)/(b), which do work.

Nits

  • The "observed in a live recording" rule has no provenance or schema gate — a fabricated line satisfies it. test/event-fidelity.test.ts:39 consumes only moveRecording.events.map(e => e.type). I verified nothing anywhere reads the fixture's provenance (grep over src/ + test/), and I confirmed by probe: delete the whole provenance block and the fidelity file still passes (7/0); appending an invented {"type":"session.idle"} event likewise changes nothing. So src/host.ts:26-27's promise of "an observation from a live host" is documentation, not an assertion — and #136 was exactly the bug class of a name accepted on paper. Ask: two cheap assertions in that file — (i) provenance.host / recordedAt / procedure are present and non-empty, (ii) each recorded envelope round-trips through the pinned @opencode/schema decoder. Fabrication then requires constructing a schema-valid envelope rather than one string.
  • The fixture reads as a recording but is an undeclared one-event extract. procedure step 2 has the subscriber live before POST /api/session, yet only session.moved survives while durable.seq: 4 implies three earlier frames on the same aggregate; my captures of that procedure yielded 31–34 events, and normalization declares only ID/path masking. One sentence — "other frames from the run were dropped; only the frame under test is retained" — also stops a future reader concluding the 2.2.2 stream is thin.
  • README drift. README.md:91 still describes the fidelity net as resting on the single host-events.jsonl recording (as does src/index.ts:219); neither mentions the 2.2.2 fixture or that identity triggers now carry their own observed check.
  • Related to the last point: expect(observed.has("session.moved")).toBe(false) at line 61 is a good honesty guard, but it means a future re-recording that includes a move will fail spuriously. Deliberate, I think — worth a comment so the next person doesn't "fix" it.

Residuals (all honestly disclaimed in the body, none blocking)

Nothing binds the file to a run beyond its own text (no capture log, projectID: "global" never appeared in my three captures — though subpath: "" is reachable, and neither field is read by the parser); keeping the raw SSE frames beside the normalized fixture would be a hard receipt. Live rebinding across a real move is still untested — an e2e/ scenario asserting the next memory_remember line's repoPath would close it. And host versions are now three-wide (fixture 2.2.2, CI e2e pin 2.0.26, @opencode/plugin 2.0.32), which matters more now that this event's shape is load-bearing for identity.

Not verified: Windows (I captured on macOS only), Bun 1.4.4, and 2.1.4 move behaviour — the last is out of scope by your own limits.

@WhollyMindless

Copy link
Copy Markdown
Contributor Author

Addressed the four nits in 50deaa6:

  • Added nonempty host/date/procedure checks and an actual decode/encode equality check for every retained envelope using SessionEvent.All from the lockfile-pinned @opencode/schema 2.0.32. Excess properties are rejected. These are fixture-integrity checks, not authentication of capture origin.
  • The normalization note now explicitly says other frames were dropped and only the session.moved frame under test is retained. No recorded envelope values were changed.
  • README and the capture-vocabulary source comment now identify the separate 2.2.2 extract and observed identity-trigger check. README also distinguishes the recording, CI host, and schema versions.
  • Added an explicit comment that the absent-move assertion pins the original two-turn workload; a future recording containing a move should be identified separately rather than silently rewriting that historical observation.

Seven temporary mutations all pass the old fidelity file and fail the strengthened file: remove provenance, blank host, blank recordedAt, empty procedure, remove durable, change durable.version to 2, and append a bare invented session.idle event. Restored all fixtures before validation.

48 focused tests passed. Full Windows/Bun 1.4.4 gate passed: typecheck, lint, 727 unit tests (12 skipped), and 11 real-host E2E tests. No runtime parsing/rebinding behavior changed in this follow-up. Hosted CI is running for the pushed head.

The nonblocking residuals remain explicit: this does not add the original raw SSE frames, authenticate provenance, or claim live plugin rebinding was exercised. The PR body now also calls the replay tests characterization tests, as your red-on-base observation warrants.

@abogartz abogartz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 2: APPROVED

Re-verified at 50deaa6. The nit is closed, and closed by assertion rather than by prose — which was the point.

My round-1 fabrications, re-run against the new head. I had two ways round; both now die, and I tested a third:

Probe Round 1 Round 2
Delete the whole provenance block from test/fixtures/host-session-move.json 7 pass / 0 fail (fail) the move extract declares its recording provenance — 8/1
Append an invented {"type":"session.idle"} frame 7 pass / 0 fail (fail) every retained envelope round-trips through the pinned host schema — 8/1
Corrupt one field (durable.seq → "4") passed silently (fail) same round-trip test — 8/1

The second probe is the one that mattered: the recorded rule is "observed in a live recording", and #136 was exactly the bug class of a name accepted on paper. onExcessProperty: "error" means a made-up frame cannot even sit in that file without being shaped like a real host event, and I confirmed the decoder is the lockfile-pinned @opencode/[email protected], not something looser.

The line I most expected you not to add, you added. expect(observed.has("session.moved")).toBe(false) now carries a comment saying it deliberately pins the original two-turn workload, and that a future capture containing moves belongs in a separately identified recording rather than a silent rewrite of this historical absence or a broadened conclusion. That is the easy corruption path for this kind of fixture — somebody "fixes" the stale observation to make a newer claim true — and it is now documented as off-limits in the place where the temptation occurs.

The README bullet is scoped the way the evidence actually is: "These checks reject missing metadata and malformed envelopes; they do not authenticate the capture", and "live plugin rebinding remains unverified", with the recording-version distinction from the CI host pin (2.0.26). Fabricating a fully schema-valid envelope with the right non-guessable values is still possible in principle — nothing here changes that, and the authenticity evidence remains what I measured in round 1: the stale outer location, durable.seq: 4, and the wire-serializer key order, reproduced against real 2.0.26 and 2.2.2 hosts. The new tests raise the floor; they don't claim to nail the ceiling.

Gates at this head: typecheck clean, biome exit 0 at 409 warnings — flat versus base, unit 727 pass / 12 skip / 0 fail (round 1 measured 725; the +2 are these two cases), real-host e2e 11 pass / 0 fail. Fixture restored clean after each probe.

@abogartz
abogartz merged commit 3764f0c into abogartz:main Oct 31, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.14.28 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

session.moved binds identity but has never been observed on a live host, and the fidelity net only checks it is declared

2 participants