Skip to content

Commit 89757c4

Browse files
test(e2e): make Pi synthetic-todo phase historian-veto aware
The Pi pipeline now defers drains and heuristics while a historian run is in flight (OpenCode-parity veto), so phase 6's single execute turn can land on a vetoed pass and never inject the synthetic pair. Wait for the compartment lease to free and retry the execute turn under pressure until a non-vetoed busting pass performs the injection. Co-authored-by: Alfonso [Magic Context] <288211368+alfonso-magic-context@users.noreply.github.com>
1 parent 16453c4 commit 89757c4

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

packages/e2e-tests/tests/pi-long-running-session.test.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,29 @@ describe("long-running Pi Magic Context session", () => {
399399
const stateJson = normalizedTodos(ACTIVE_TODOS);
400400
expect(readMeta<{ last_todo_state: string }>(h, sessionId, "last_todo_state")?.last_todo_state).toBe(stateJson);
401401
await send("turn 20: Pi pressure to make synthetic todowrite visible on next execute", "pi phase 6 pressure", HIGH_USAGE);
402-
await send("turn 21: Pi execute pass injects synthetic todowrite", "pi phase 6 synthetic execute");
402+
// The injection lands on the next cache-busting pass that is NOT
403+
// vetoed by an in-flight historian. Phase 5's publication can
404+
// legitimately trigger a follow-up historian run over the remaining
405+
// tail; while it runs, execute passes defer mutations (matching
406+
// OpenCode's compartment-running veto). Retry the execute turn
407+
// WITH pressure until a non-vetoed pass injects the pair — a
408+
// low-usage turn after the historian finishes would never bust,
409+
// so pressure is what invites the execute pass the injection rides.
403410
const syntheticCallId = computeSyntheticCallId(stateJson);
404-
const syntheticPair = findSyntheticTodoPair(mainRequests().at(-1)!.body, syntheticCallId);
411+
let syntheticPair: ReturnType<typeof findSyntheticTodoPair> = null;
412+
for (let attempt = 0; attempt < 6 && syntheticPair === null; attempt += 1) {
413+
// The historian holds the compartment lease while running; wait
414+
// for it to free so this attempt's pass is not veto-deferred.
415+
await h.waitFor(() => {
416+
const lease = h
417+
.contextDb()
418+
.prepare("SELECT holder_id FROM compartment_state_lease WHERE session_id = ?")
419+
.get(sessionId) as { holder_id: string } | null;
420+
return lease === null ? true : null;
421+
}, { timeoutMs: 60_000, label: "historian lease free before synthetic-todo execute" });
422+
await send(`turn 21 (try ${attempt + 1}): Pi execute pass injects synthetic todowrite`, "pi phase 6 synthetic execute", HIGH_USAGE);
423+
syntheticPair = findSyntheticTodoPair(mainRequests().at(-1)!.body, syntheticCallId);
424+
}
405425
expect(syntheticPair).not.toBeNull();
406426
expect(JSON.stringify(mainRequests().at(-1)!.body)).toContain("<session-history>");
407427
expect(JSON.stringify(mainRequests().at(-1)!.body)).toContain("Long Pi e2e chunk");

0 commit comments

Comments
 (0)