Validate idle goal tails through their stored wire bindings

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-10-30 14:30:03 -05:00
1 parent a904fa3965
commit 98f05fcd5b
2 files changed
+15 -7

No files matched your search

@@ -3,8 +3,10 @@ import { isSettledRemoteWarmControlState } from "./remote-warm-session-recovery.
const identity = { runId: "run", normalizedSessionId: "session", runnerInstanceId: "runner", environmentLeaseId: "lease", turnId: "turn", itemId: "item" };
const terminal = { eventType: "run.terminal", envelope: { ...identity } };
const snapshot = { eventType: "session.goal.snapshot", envelope: { ...identity, sourceInstanceId: "runner", sourceKind: "runner",
payload: { schema: "paperclip.session_goal.snapshot.v1", goal: null, workingNow: false } } };
const goal = { schema: "paperclip.session_goal.snapshot.v1", goal: null, workingNow: false };
const notification = { schema: "paperclip.prp.event.v1", eventType: "session.goal.snapshot", runId: identity.runId,
normalizedSessionId: identity.normalizedSessionId, sourceInstanceId: "runner", sourceKind: "runner", payload: goal };
const snapshot = { eventType: "session.goal.snapshot", envelope: { ...identity, payload: notification } };
const state = (events: unknown[]) => ({ identity, commands: [{ status: "completed" }], committedEvents: events });
describe("settled remote warm control evidence", () => {
@@ -16,13 +18,15 @@ describe("settled remote warm control evidence", () => {
});
it.each([
["active goal", { ...snapshot, envelope: { ...snapshot.envelope, payload: { ...snapshot.envelope.payload, goal: { status: "active" } } } }],
["provider work", { ...snapshot, envelope: { ...snapshot.envelope, payload: { ...snapshot.envelope.payload, workingNow: true } } }],
["active goal", { ...snapshot, envelope: { ...snapshot.envelope, payload: { ...notification, payload: { ...goal, goal: { status: "active" } } } } }],
["provider work", { ...snapshot, envelope: { ...snapshot.envelope, payload: { ...notification, payload: { ...goal, workingNow: true } } } }],
["unknown event", { ...snapshot, eventType: "unknown" }],
["new turn", { ...snapshot, eventType: "turn.started" }],
["foreign run", { ...snapshot, envelope: { ...snapshot.envelope, runId: "other" } }],
["foreign session", { ...snapshot, envelope: { ...snapshot.envelope, normalizedSessionId: "other" } }],
["foreign source", { ...snapshot, envelope: { ...snapshot.envelope, sourceInstanceId: "other" } }],
["foreign source", { ...snapshot, envelope: { ...snapshot.envelope, payload: { ...notification, sourceInstanceId: "other" } } }],
["foreign lease", { ...snapshot, envelope: { ...snapshot.envelope, environmentLeaseId: "other" } }],
["foreign notification", { ...snapshot, envelope: { ...snapshot.envelope, payload: { ...notification, runId: "other" } } }],
["missing payload", { ...snapshot, envelope: { ...identity } }],
])("holds a %s suffix", (_name, suffix) => {
expect(isSettledRemoteWarmControlState(state([terminal, suffix]), identity)).toBe(false);
@@ -32,9 +32,13 @@ export function isSettledRemoteWarmControlState(control: Record<string, unknown>
if (!matchesSession(events[terminalIndex])) return false;
return events.slice(terminalIndex + 1).every(event => {
const envelope = record(record(event).envelope);
const payload = record(envelope.payload);
const notification = record(envelope.payload);
const payload = record(notification.payload);
return record(event).eventType === "session.goal.snapshot" && matchesSession(event) &&
envelope.sourceInstanceId === identity.runnerInstanceId && envelope.sourceKind === "runner" &&
Object.entries(identity).every(([key, value]) => envelope[key] === value) &&
notification.schema === "paperclip.prp.event.v1" && notification.eventType === "session.goal.snapshot" &&
notification.sourceInstanceId === identity.runnerInstanceId && notification.sourceKind === "runner" &&
notification.runId === identity.runId && notification.normalizedSessionId === identity.normalizedSessionId &&
payload.schema === "paperclip.session_goal.snapshot.v1" && payload.goal === null && payload.workingNow === false;
});
}