Skip to content

Commit faa5c01

Browse files
committed
fix(session): log stopping voter failures, pin vote interruptibility
1 parent ddab695 commit faa5c01

4 files changed

Lines changed: 49 additions & 7 deletions

File tree

‎packages/core/src/session/runner/llm.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ const layer = Layer.effect(
7878
// and hook continuations loop in-drain so they can never leak across
7979
// turns. A crash loses the count while an already-admitted steer
8080
// survives — up to two fresh grants per crash, bounded and self-limiting.
81+
// An idle-boundary move or location reload drops the continuation the
82+
// same way (the successor starts fresh and the turn ends without a
83+
// vote); fail-closed, documented in the hook docs.
8184
let stoppingContinuations = input.continuation?.stoppingContinuations ?? 0
8285
let entering = true
8386
const promotable = input.promotable ?? "input"
@@ -440,10 +443,12 @@ const layer = Layer.effect(
440443
// session-hook failure channels are `never`), so `catchAll` alone
441444
// would miss it and fail the drain into `Execution.Failed`.
442445
// Interrupts still propagate (the `move.ts` fail-closed idiom).
446+
// Thrown failures are logged: without this a failing voter would
447+
// stop every turn silently and be painful to debug.
443448
Effect.catchCause((cause) =>
444449
Cause.hasInterrupts(cause)
445450
? Effect.failCause(Cause.fromReasons<never>(cause.reasons.filter(Cause.isInterruptReason)))
446-
: Effect.succeed(false),
451+
: Effect.logWarning("stopping voter failed", { sessionID, cause }).pipe(Effect.as(false)),
447452
),
448453
)
449454
})

‎packages/core/test/session-runner.test.ts‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,17 @@ const layer = Layer.unwrap(
438438
sessionID: Session.ID,
439439
force: boolean,
440440
continuation?: SessionRunner.Continuation,
441+
promotable?: SessionInbox.Promotable,
441442
): Effect.Effect<void, SessionRunner.RunError> {
442443
return sessionRunner
443-
.drain({ sessionID, force, continuation })
444+
.drain({ sessionID, force, continuation, promotable })
444445
.pipe(
445446
Effect.flatMap((result) =>
446-
result._tag === "Complete" ? Effect.void : drain(sessionID, false, result.continuation),
447+
result._tag === "Complete"
448+
? Effect.void
449+
: result._tag === "Reloaded"
450+
? drain(sessionID, result.force, result.continuation, promotable)
451+
: drain(sessionID, false, result.continuation, promotable),
447452
),
448453
)
449454
}
@@ -6903,6 +6908,34 @@ describe("SessionRunnerLLM", () => {
69036908
expect(s.requests).toHaveLength(1)
69046909
})
69056910

6911+
scenario("stays interruptible during a stopping vote without admitting a steer", function* (s) {
6912+
let votes = 0
6913+
const entered = yield* Deferred.make<void>()
6914+
const hooks = yield* PluginHooks.Service
6915+
yield* hooks.register("session", "experimental.stopping", () =>
6916+
Effect.sync(() => {
6917+
votes++
6918+
}).pipe(Effect.andThen(Deferred.succeed(entered, undefined)), Effect.andThen(Effect.never)),
6919+
)
6920+
yield* s.llm.push(TestLLM.text("Done", "text-done"))
6921+
yield* s.admit("Start")
6922+
const running = yield* s.resume.pipe(Effect.forkChild)
6923+
yield* Deferred.await(entered)
6924+
yield* s.session.interrupt(sessionID)
6925+
const exit = yield* Fiber.await(running)
6926+
6927+
// The vote must not stall abort: without an interruptible vote region
6928+
// the drain would hang here until teardown instead of settling. This pins
6929+
// delivery, not branch selection — with a non-granting voter, absorbing
6930+
// vs propagating are observationally identical at the drain level (an
6931+
// abstention completes terminally and the coordinator settles stopping
6932+
// executions as interrupted either way).
6933+
expect(Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause)).toBeTrue()
6934+
expect(votes).toBe(1)
6935+
expect(s.requests).toHaveLength(1)
6936+
expect((yield* s.context).filter((message) => message.type === "synthetic")).toHaveLength(0)
6937+
})
6938+
69066939
scenario("treats an empty stopping grant as abstention", function* (s) {
69076940
const hooks = yield* PluginHooks.Service
69086941
yield* hooks.register("session", "experimental.stopping", (event) =>

‎services/www/src/docs/content/build/plugins/effect.mdx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,9 +1387,11 @@ Stopping hooks follow these rules:
13871387
- Multiple hooks run in registration order, and later hooks see the current decision. A gate needing the final word registers last.
13881388
- At most two continuations are granted per turn. Cap exhaustion stops the turn silently without calling hooks.
13891389
- `continuations` is the pre-increment count, so hooks can enforce a tighter limit against it.
1390-
- `step` is the model steps executed this turn; `stepsLimit` is the agent's configured step limit, when set.
1391-
- A throwing hook stops the turn instead of failing it; interruption still propagates. An empty or whitespace-only `text` abstains and the turn ends.
1390+
- `step` is the model steps executed this turn relative to the current step budget: a manual compaction resets the count, mirroring the agent step budget, so a vote right after one can report `step: 0`. `stepsLimit` is the agent's configured step limit, when set.
1391+
- A throwing hook stops the turn instead of failing it, and the failure is logged; interruption still propagates. An empty or whitespace-only `text` abstains and the turn ends.
13921392
- Provider scoping is unavailable for `experimental.stopping`: the event carries no model, so a `providerID` voter would never fire.
1393+
- The vote fires only when no fresh input is waiting: a queued prompt (or pending move) at the boundary starts a new turn instead, with no vote for the finished turn.
1394+
- A location reload or session move landing exactly on the turn boundary ends the turn without a vote. The successor drain starts fresh with the counter at 0 — a missed continuation, never an extra one. A process crash at the same point behaves the same way.
13931395

13941396
This hook is experimental and its name or shape may change.
13951397

‎services/www/src/docs/content/build/plugins/index.mdx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,9 +1547,11 @@ Stopping hooks follow these rules:
15471547
- Multiple hooks run in registration order, and later hooks see the current decision. A gate needing the final word registers last.
15481548
- At most two continuations are granted per turn. Cap exhaustion stops the turn silently without calling hooks.
15491549
- `continuations` is the pre-increment count, so hooks can enforce a tighter limit against it.
1550-
- `step` is the model steps executed this turn; `stepsLimit` is the agent's configured step limit, when set.
1551-
- A throwing hook stops the turn instead of failing it; interruption still propagates. An empty or whitespace-only `text` abstains and the turn ends.
1550+
- `step` is the model steps executed this turn relative to the current step budget: a manual compaction resets the count, mirroring the agent step budget, so a vote right after one can report `step: 0`. `stepsLimit` is the agent's configured step limit, when set.
1551+
- A throwing hook stops the turn instead of failing it, and the failure is logged; interruption still propagates. An empty or whitespace-only `text` abstains and the turn ends.
15521552
- Provider scoping is unavailable for `experimental.stopping`: the event carries no model, so a `providerID` voter would never fire.
1553+
- The vote fires only when no fresh input is waiting: a queued prompt (or pending move) at the boundary starts a new turn instead, with no vote for the finished turn.
1554+
- A location reload or session move landing exactly on the turn boundary ends the turn without a vote. The successor drain starts fresh with the counter at 0 — a missed continuation, never an extra one. A process crash at the same point behaves the same way.
15531555

15541556
This hook is experimental and its name or shape may change.
15551557

0 commit comments

Comments
 (0)