From 21d007bd2829a3e92d8d498b04639a58e9ca9ccb Mon Sep 17 00:00:00 2001 From: Sawyer Cutler Date: Sun, 11 Oct 2026 19:10:32 -0700 Subject: [PATCH] refactor(session): replace compactorNoOpFloor with a constant --- src/agent/compaction.test.ts | 6 +++--- src/agent/compaction.ts | 6 +++--- src/agent/director.test.ts | 4 ++-- src/context-compactor.test.ts | 8 ++++---- src/session/compactor.ts | 6 ++---- src/subagent/nudge-director.test.ts | 4 ++-- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/agent/compaction.test.ts b/src/agent/compaction.test.ts index 96efc12cc..9d40fb9cb 100644 --- a/src/agent/compaction.test.ts +++ b/src/agent/compaction.test.ts @@ -24,7 +24,7 @@ import { import { COMPACT_SPACER_TEXT, LEGACY_COMPACT_SPACER_TEXT, - compactorNoOpFloor, + COMPACT_NOOP_FLOOR, } from "../session/compactor.js"; import { buildSummaryPrompt } from "../session/summarizer.js"; @@ -509,7 +509,7 @@ describe("compaction governor", () => { test("never arms at the exact turn count createPruningCompactor no-ops on", () => { // The compactor's own no-op floor; arming at or below it spends a cycle that shrinks nothing. - const floor = compactorNoOpFloor(); + const floor = COMPACT_NOOP_FLOOR; const governor = createCompactionGovernor(() => undefined); governor.noteInferenceDone( inferenceDone(overThreshold), @@ -521,7 +521,7 @@ describe("compaction governor", () => { }); test("arms one turn past the floor createPruningCompactor no-ops on", () => { - const floor = compactorNoOpFloor(); + const floor = COMPACT_NOOP_FLOOR; const governor = createCompactionGovernor(() => undefined); governor.noteInferenceDone( inferenceDone(overThreshold), diff --git a/src/agent/compaction.ts b/src/agent/compaction.ts index c10396bd5..8f6cbd470 100644 --- a/src/agent/compaction.ts +++ b/src/agent/compaction.ts @@ -14,7 +14,7 @@ import { } from "../provider/context-window.js"; import { assistantTextIsCompactSpacerEcho, - compactorNoOpFloor, + COMPACT_NOOP_FLOOR, isCompactSpacerEchoTurn, } from "../session/compactor.js"; import { @@ -24,9 +24,9 @@ import { import { onTurnBoundary } from "./reactor-events.js"; const COMPACTOR_NAME = "pruning-compactor"; -// Compactor no-op floor, from the same helper so it cannot drift; arming +// Compactor no-op floor, shared from the compactor so it cannot drift; arming // at or below spends a cycle that shrinks nothing. -const MIN_TURNS_TO_COMPACT = compactorNoOpFloor(); +const MIN_TURNS_TO_COMPACT = COMPACT_NOOP_FLOOR; // Cap overflow retries so an unshrinkable history cannot loop forever; // cleared once usage drops back under the watermark. const MAX_OVERFLOW_RECOVERIES = 2; diff --git a/src/agent/director.test.ts b/src/agent/director.test.ts index f2a400657..1957a4329 100644 --- a/src/agent/director.test.ts +++ b/src/agent/director.test.ts @@ -23,7 +23,7 @@ import { createPermissionGate } from "../permission/gate.js"; import { COMPACT_SPACER_TEXT, LEGACY_COMPACT_SPACER_TEXT, - compactorNoOpFloor, + COMPACT_NOOP_FLOOR, } from "../session/compactor.js"; import { INFERENCE_ABORT_INTERNAL_RECOVERY, @@ -785,7 +785,7 @@ function makeToolErrorEvent(callId: string, content: string) { // One turn past the compactor's no-op floor (session/compactor.ts), so the // arming check finds history actually worth compacting. const longState = { - turns: Array.from({ length: compactorNoOpFloor() + 1 }, () => ({ + turns: Array.from({ length: COMPACT_NOOP_FLOOR + 1 }, () => ({ role: "user", content: [], timestamp: 0, diff --git a/src/context-compactor.test.ts b/src/context-compactor.test.ts index fb83d951e..36bef2538 100644 --- a/src/context-compactor.test.ts +++ b/src/context-compactor.test.ts @@ -2,7 +2,7 @@ import { defined } from "../testkit/defined.js"; import { describe, test, expect } from "bun:test"; import { createPruningCompactor, - compactorNoOpFloor, + COMPACT_NOOP_FLOOR, buildTurnSummary, COMPACTED_PREFIX, COMPACT_SPACER_TEXT, @@ -93,15 +93,15 @@ describe("createPruningCompactor", () => { expect(result.output).toBe(turns); // Same reference when no compaction needed }); - test("compactorNoOpFloor names the exact turn count apply() no-ops on", async () => { - // The compaction governor derives its arming floor from this function so + test("COMPACT_NOOP_FLOOR names the exact turn count apply() no-ops on", async () => { + // The compaction governor derives its arming floor from this constant so // it never arms a compaction guaranteed to no-op; changing apply()'s // no-op condition without updating the floor breaks that guarantee // silently. const compactor = smallCompactor({ summaryMaxChars: 500, }); - const floor = compactorNoOpFloor(); + const floor = COMPACT_NOOP_FLOOR; // Bodies exceed the pinned tail budget, so past-floor always has a folded // region while at-floor still no-ops on the count check alone. diff --git a/src/session/compactor.ts b/src/session/compactor.ts index 991454dbe..ec3ea4bca 100644 --- a/src/session/compactor.ts +++ b/src/session/compactor.ts @@ -112,9 +112,7 @@ function extraInstructionParameter( } // `apply` no-ops at or below this turn count: one turn cannot shrink. -export function compactorNoOpFloor(): number { - return 1; -} +export const COMPACT_NOOP_FLOOR = 1; // Query tools dedup by full-argument identity: a later identical call // reflects newer workspace state, so older results are stale. run_shell is @@ -884,7 +882,7 @@ export function createPruningCompactor( // Prior compacted summaries fold into the next handoff, not frozen. const shape = resolveCompactionShape(cfg.compactionShape); - if (turns.length <= compactorNoOpFloor()) { + if (turns.length <= COMPACT_NOOP_FLOOR) { return { output: turns, record: { diff --git a/src/subagent/nudge-director.test.ts b/src/subagent/nudge-director.test.ts index 4ab9df954..1cddaa774 100644 --- a/src/subagent/nudge-director.test.ts +++ b/src/subagent/nudge-director.test.ts @@ -6,7 +6,7 @@ import type { ReactorState, } from "@intx/types/runtime"; import { createCorbitsRetryPolicy } from "../agent/retry-policy.js"; -import { compactorNoOpFloor } from "../session/compactor.js"; +import { COMPACT_NOOP_FLOOR } from "../session/compactor.js"; import { SubAgentDirector } from "./nudge-director.js"; import type { AdmissionQueue } from "./admission.js"; import { createTestCapabilities } from "./director-test-harness.js"; @@ -19,7 +19,7 @@ import { const state = { turns: [] } as unknown as ReactorState; const longState = { - turns: Array.from({ length: compactorNoOpFloor() + 1 }, () => ({ + turns: Array.from({ length: COMPACT_NOOP_FLOOR + 1 }, () => ({ role: "user", content: [], timestamp: 0,