From 18e9117ed3274b9258043e0b1fe988f51802484a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Bene=C5=A1?= Date: Wed, 18 Nov 2026 00:27:54 +0000 Subject: [PATCH] A subagent's own automatic compaction is background work too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Spec 3.9.0, interactive.md §1 and §3: when a subagent's model is interactive-only, the summary of its conversation is asked of that model's twin, else of a default that is not interactive-only, else it is skipped — said once, to the session the subagent works for — and the subagent goes on. Before, only the session's own compaction went elsewhere. Co-Authored-By: Claude Fable 5.2 --- CHANGELOG.md | 3 ++- harness/interactive.md | 8 ++++++-- src/app.ts | 11 +++++++++++ tests/interactive.test.ts | 22 ++++++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1628548..1bf0ed2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,8 @@ Harness spec 3.9.0: the model last used in a directory, the two types of schedul and its **compaction** (asked for or automatic) are asked of the same model under another provider when the server lists one, else of your global `model` or the server's default when that is not interactive-only; with none, the title stays the one made from your first prompt, - automatic compaction is skipped and said once, and `/compact` is refused with the reason. + automatic compaction is skipped and said once, and `/compact` is refused with the reason. A + subagent's own automatic compaction goes the same way. **Scheduled work never runs on one**: a scheduled session opened on such a model, or a scheduled turn of a session that has come to be on one, is refused before anything is sent (`data.reason: "interactive_only"`), a scheduled run's subagent on one is not started, and a diff --git a/harness/interactive.md b/harness/interactive.md index 62904e1..c5789bb 100644 --- a/harness/interactive.md +++ b/harness/interactive.md @@ -28,7 +28,9 @@ once (the CLI's commit-message draft). is a terminal (a cron job, a pipeline), which is the batch script the terms name. - **Background calls**: what a client asks a model on a session's behalf that is not the answer to the person's turn — **naming the session** (its title) and **compacting it** (the summary, - asked for by the person or by the harness when the window fills). + asked for by the person or by the harness when the window fills). A **subagent's own + automatic compaction** is one too: the subagent is the person's, the summary of its + conversation is not their turn. ## 2. Scheduled work never runs on one @@ -74,7 +76,9 @@ A call that goes elsewhere is otherwise the same call: the summary is asked for conversation and comes back into the same session, whose model does not change. A model that is not interactive-only is asked itself, as before 3.9.0. The model a title is asked of is the client's small model where it has one (the CLI's `small_model`), else the session's; the rule is -applied to whichever it is. +applied to whichever it is. For a subagent's automatic compaction it is the subagent's model +that is looked at — its twin, the same defaults, or skipped and said once to the session it +works for. ## 4. What is outside this diff --git a/src/app.ts b/src/app.ts index 98be20c..eef1ce7 100644 --- a/src/app.ts +++ b/src/app.ts @@ -595,6 +595,7 @@ export function createApp(o: AppOptions): App { return o.asker.plan }, }) + let compactionSkipSaid = false const child = new Engine({ bus: childBus, asker: askerFor(), @@ -609,6 +610,16 @@ export function createApp(o: AppOptions): App { effort: m.ref === engine.model.ref ? engine.effort : startEffort(m), maxSteps: loaded.config.limits?.subagent_steps ?? LOOP.jobs.subagent_steps.default, compaction, + // A subagent's own automatic compaction is background work like the session's + // (interactive.md §3): its twin, a default, or skipped — said once, to the session. + background: (call) => { + const where = backgroundFor(child.model, call) + if (where && !("client" in where) && !compactionSkipSaid) { + compactionSkipSaid = true + bus.emit({ type: "notice", message: `the subagent ${spec.name} is not compacting its conversation: its model is for interactive use only and there is no other model to ask for the summary` }) + } + return where + }, perm: childPerm, toolCtx: { ...baseToolCtx(), diff --git a/tests/interactive.test.ts b/tests/interactive.test.ts index 0649261..66aafe2 100644 --- a/tests/interactive.test.ts +++ b/tests/interactive.test.ts @@ -132,6 +132,28 @@ test("automatic compaction with a twin is the twin's work", async () => { expect(a.engine.model.ref).toBe("plan/coder") }) +test("a subagent's own automatic compaction goes the same way: the twin's work; with nowhere to go, skipped and said once to the session", async () => { + const task = { chunks: [toolCall(0, "t1", "task", JSON.stringify({ agent: "general", description: "look", prompt: "look around" }))] } + const step = { chunks: [toolCall(0, "g1", "glob", JSON.stringify({ pattern: "*" }))] } + fake = fakeProvider([task, step, reply("The subagent's summary."), reply("Found nothing."), reply("The session's summary."), reply("Done.")]) + config(fake.url, { window: 2000 }) + const a = app(project(), { modelTitles: false, mode: "auto" }) + await a.turns.prompt("have a subagent look") + // The session's step, the subagent's first, its summary on the twin, its second, then the + // session's own summary on the twin and its reply. + expect(asked()).toEqual(["plan/coder", "plan/coder", "payg/coder", "plan/coder", "payg/coder", "plan/coder"]) + fake.stop() + + fake = fakeProvider([task, step, reply("Found nothing."), reply("Done.")]) + config(fake.url, { twin: false, other: false, window: 2000 }) + const b = app(project(), { modelTitles: false, mode: "auto" }) + const notices: string[] = [] + b.bus.on((e) => e.type === "notice" && notices.push(e.message)) + await b.turns.prompt("have a subagent look") + expect(asked()).toEqual(["plan/coder", "plan/coder", "plan/coder", "plan/coder"]) + expect(notices.filter((n) => n.includes("the subagent general is not compacting"))).toHaveLength(1) +}) + // ── scheduled work ────────────────────────────────────────────────────────────────────────── test("scheduled work never starts on one: asked for, it is refused; remembered for the directory, it is skipped", () => {