docs(plugin): clarify idle hook restarts, failures and parked notices

This commit is contained in:
Filip Hejmowski 2026-10-26 12:17:29 +01:00
parent 96192c19ff
commit 7f261cc4b8
6 changed files with 49 additions and 6 deletions

View file

@ -7,8 +7,8 @@ import type { SessionStore } from "./store.js"
/**
* Background jobs still running for a Session or any of its descendants. A child's own
* background shell counts even after the child reported to its parent: its completion
* notice wakes the child, which can still change what the parent hears.
* background shell counts even after the child reported to its parent: its notice wakes
* the child again, so the child's work is not finished.
*/
export const outstanding = Effect.fnUntraced(function* (
jobs: Pick<Job.Interface, "runningBackground">,

View file

@ -1256,6 +1256,35 @@ describe("SessionRunnerLLM", () => {
])
})
scenario("runs the idle hook again when a background notice wakes the session", function* (s) {
const jobs = yield* Job.Service
const hooks = yield* PluginHooks.Service
const done = yield* Deferred.make<string>()
yield* jobs.start({
id: "shell-own",
type: "shell",
recovery: { kind: "shell", sessionID, shellID: "shell-own", command: "bun test" },
run: Deferred.await(done),
})
yield* jobs.background("shell-own")
const background: number[] = []
yield* hooks.register("session", "idle", (event) => Effect.sync(() => background.push(event.background.length)))
yield* s.llm.push(
TestLLM.text("Waiting for the tests", "text-waiting"),
TestLLM.text("Tests passed", "text-passed"),
)
yield* s.runPrompt("Start")
yield* Deferred.succeed(done, "ok")
yield* jobs.wait({ id: "shell-own" })
// Admitted the way the shell tool delivers a background notice: the default resume wakes the Session.
yield* s.session.synthetic({ sessionID, text: "Command finished" }).pipe(Effect.orDie)
yield* s.session.wait(sessionID)
expect(background).toEqual([1, 0])
expect(s.requests).toHaveLength(2)
})
scenario("runs the idle hook after a move delivered at the idle boundary", function* (s) {
const runner = yield* SessionRunner.Service
const hooks = yield* PluginHooks.Service

View file

@ -128,7 +128,8 @@ run after interruption, failure, or control-only work such as a manual compactio
plugin that always admits input must bound its own loop.
`event.background` lists background shells and subagents still running for the Session or its descendants. When one
finishes, its notice wakes the Session and the hook runs again, so a plugin that waits for background work can return:
finishes, its notice wakes the Session and the hook runs again, so a plugin that waits for background work can return.
Notices admitted with `resume: false`, such as those recovered after a restart, wait for the next wake instead:
```ts
await ctx.session.hook("idle", async (event) => {
@ -137,6 +138,11 @@ await ctx.session.hook("idle", async (event) => {
})
```
A continuation runs inside the same execution, so a loop that is still going when the server restarts is resumed by
restart recovery and the hook keeps running. Persist your own state if the loop should come back paused. A hook that
fails, fails the execution like any other session hook, so handle errors from slow or remote work such as a judge model
call.
Promise tools use complete executable tool values with async executors:
```ts

View file

@ -130,7 +130,8 @@ run after interruption, failure, or control-only work such as a manual compactio
plugin that always admits input must bound its own loop.
`event.background` lists background shells and subagents still running for the Session or its descendants. When one
finishes, its notice wakes the Session and the hook runs again, so a plugin that waits for background work can return:
finishes, its notice wakes the Session and the hook runs again, so a plugin that waits for background work can return.
Notices admitted with `resume: false`, such as those recovered after a restart, wait for the next wake instead:
```ts
yield *
@ -143,6 +144,11 @@ yield *
)
```
A continuation runs inside the same execution, so a loop that is still going when the server restarts is resumed by
restart recovery and the hook keeps running. Persist your own state if the loop should come back paused. A hook that
fails, fails the execution like any other session hook, so handle errors from slow or remote work such as a judge model
call.
## Reloading A Domain
When data captured by a transform changes, reload the affected domain:

View file

@ -162,7 +162,8 @@ export type SessionIdleBackground =
* of the Session going idle.
*
* `background` lists work that is still running. When it finishes, its notice wakes the Session
* and the hook runs again, so a plugin that waits for background work can simply return.
* and the hook runs again, so a plugin that waits for background work can simply return. Notices
* admitted with `resume: false`, such as those recovered after a restart, wait for the next wake.
*/
export interface SessionIdle {
readonly sessionID: Session.ID

View file

@ -162,7 +162,8 @@ export type SessionIdleBackground =
* of the Session going idle.
*
* `background` lists work that is still running. When it finishes, its notice wakes the Session
* and the hook runs again, so a plugin that waits for background work can simply return.
* and the hook runs again, so a plugin that waits for background work can simply return. Notices
* admitted with `resume: false`, such as those recovered after a restart, wait for the next wake.
*/
export interface SessionIdle {
readonly sessionID: Session.ID