Skip to content

Commit 78d68de

Browse files
committed
refactor(replay): drive target verification from the engine step loop (#1555 review)
Moves the verify-then-dispatch decision flow into packages/ad-replay's step loop so the four target-verification policy functions (plan{PostResolution,PreDispatch}TargetVerification, derive{ReplayTargetGuardMismatch,WaitLandmark}MismatchEvidence) become engine-private and leave the ad-replay façade. The daemon (session-replay-target-verification.ts) shrinks to the narrow AdReplayStepRuntime capabilities the engine drives: routing (beginTargetVerification), capture (captureObservation), classification (classifyTarget), dispatch (dispatchStep), and wire-building (buildRecordedUnverifiableFailure, buildTargetBindingFailure, buildPostDispatchTargetBindingFailure). Wire output and replay-compat stay byte-identical; the exact-symbol façade gate is updated to the shrunken export list.
1 parent bde2393 commit 78d68de

6 files changed

Lines changed: 915 additions & 513 deletions

File tree

packages/ad-replay/src/index.ts

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,24 @@
33
* suggestion-ranking/vars/identity-vocabulary further narrowed by the P5
44
* review pass; plan-digest/resume and `classifyTargetBindingMatch` further
55
* narrowed by the #1555 review pass, "complete the binding façade instead of
6-
* documenting deviations"). `scripts/layering/package-boundaries.test.ts`
7-
* asserts this file's exact export list — see "the real tree parses,
8-
* declares, and passes R11" — so a stray export fails that gate, not just a
9-
* comment mismatch.
6+
* documenting deviations"; the target-verification policy functions further
7+
* narrowed by the #1555 review's R3 pass, "target verification must happen
8+
* INSIDE the engine"). `scripts/layering/package-boundaries.test.ts` asserts
9+
* this file's exact export list — see "the real tree parses, declares, and
10+
* passes R11" — so a stray export fails that gate, not just a comment
11+
* mismatch.
1012
*
1113
* The binding design (issue comment 5156017698) is `inspectAdReplay` +
12-
* `runAdReplay` and nothing else. As of the #1555 review pass, parsing,
13-
* variable substitution, planning, digest/resume, and classification are ALL
14-
* on-design: `inspectAdReplay`'s manifest carries the digest and the
15-
* `--from`/`--plan-digest` resume math internally, and
16-
* `classifyTargetBindingMatch` moved to its real owner,
17-
* `@agent-device/ad-script` (both daemon consumers — record-time self-check
18-
* and replay-time classification — never went through this façade at all).
19-
*
20-
* ONE deviation remains, reported rather than papered over per the review's
21-
* own instruction ("if a genuine remainder must stay callable from the
22-
* daemon, STOP and report rather than re-exporting"): the four
23-
* target-verification policy functions below, and the `ReplaySelectorPort`
24-
* type family they (and other daemon handlers) need to name. Their sole
25-
* caller, `session-replay-target-verification.ts`, is the daemon's
26-
* verify-then-dispatch orchestrator — it interleaves these PURE decisions
27-
* with daemon-only async work (snapshot capture, `SessionStore` reads,
28-
* coordinator/resume stamping, wire-response sanitization/shaping) that must
29-
* stay outside the engine by design. Moving the CALL SITES for these four
30-
* functions to live only "behind runAdReplay" would require restructuring
31-
* that whole orchestration into new fine-grained `AdReplayStepRuntime`
32-
* capabilities (e.g. a capture capability, a wire-shaping capability) so the
33-
* engine's own code could drive it end to end — a materially larger,
34-
* higher-risk change than the neutral-outcomes and plan/digest/resume work
35-
* in this same pass, and out of scope here; see the #1555 R2 handoff notes.
14+
* `runAdReplay` and nothing else — as of R3, with NO reported deviation: the
15+
* four target-verification policy functions (`planPostResolutionTargetVerification`,
16+
* `planPreDispatchTargetVerification`, `deriveReplayTargetGuardMismatchEvidence`,
17+
* `deriveWaitLandmarkMismatchEvidence`) are called only from
18+
* `./internal/step-loop.ts`'s `verifyAndDispatchStep` — the step loop's own
19+
* verify-then-dispatch orchestration, which drives the daemon-owned pieces
20+
* (capture, classification, dispatch, wire-building) through narrow
21+
* `AdReplayStepRuntime` capabilities instead of the daemon calling the policy
22+
* functions directly. See `./internal/target-verification.ts` and
23+
* `./internal/step-loop.ts` for the split.
3624
*/
3725

3826
// ---------------------------------------------------------------------------
@@ -66,18 +54,12 @@ export type {
6654
// ---------------------------------------------------------------------------
6755
// target-verification.ts — #1478 P5 stage C2a target-verification ENGINE
6856
// policy (pre-capture verification gating, post-dispatch mismatch-evidence
69-
// derivation), split out of `session-replay-target-verification.ts`.
70-
// façade-deviation: that same daemon wire-builder is the direct caller of
71-
// all four functions below — see `./internal/target-verification.ts` for the
72-
// daemon/engine ownership split.
57+
// derivation). As of the #1555 review's R3 pass, its four functions are
58+
// called ONLY from `./internal/step-loop.ts` (`verifyAndDispatchStep`) — the
59+
// engine's own step loop, never the daemon — so nothing from this module is
60+
// re-exported here anymore. See `./internal/target-verification.ts`'s header
61+
// for the full daemon/engine ownership split.
7362
// ---------------------------------------------------------------------------
74-
export {
75-
deriveReplayTargetGuardMismatchEvidence,
76-
deriveWaitLandmarkMismatchEvidence,
77-
planPostResolutionTargetVerification,
78-
planPreDispatchTargetVerification,
79-
} from './internal/target-verification.ts';
80-
export type { ReplayPostDispatchMismatchEvidence } from './internal/target-verification.ts';
8163

8264
// ---------------------------------------------------------------------------
8365
// selector-port.ts — the `ReplaySelectorPort` port TYPE only (#1478 P5 stage
@@ -93,8 +75,9 @@ export type { ReplayPostDispatchMismatchEvidence } from './internal/target-verif
9375
// directly (`session-replay-target-token.ts`, `session-replay-heal.ts`,
9476
// `session-replay-target-classification.ts`, `session-replay-runtime-failure.ts`,
9577
// `session-replay-runtime.ts`, `session-replay-target-verification.ts`) —
96-
// the port rides in as `runAdReplay`'s runtime threads it, but the type
97-
// itself is named at every one of those call sites.
78+
// the port rides in as `runAdReplay`'s runtime threads it (as of R3, also as
79+
// `AdReplayStepRuntime.port` itself, for the engine's own pre-dispatch plan),
80+
// but the type is named at every one of those call sites too.
9881
// ---------------------------------------------------------------------------
9982
export type {
10083
ReplayRecordedTargetDisambiguation,

0 commit comments

Comments
 (0)