Skip to content

Commit 42ac1a0

Browse files
committed
fix: restore manual mode after compression
1 parent b2f8660 commit 42ac1a0

2 files changed

Lines changed: 40 additions & 8 deletions

File tree

lib/compress/pipeline.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,15 @@ export async function finalizeSession(
8585
entries: NotificationEntry[],
8686
batchTopic: string | undefined,
8787
): Promise<void> {
88-
ctx.state.manualMode = ctx.state.manualMode === "active" ? "active" : false
88+
if (ctx.state.manualMode === "compress-pending") {
89+
ctx.state.manualMode = false
90+
await refreshManualMode(
91+
ctx.state,
92+
toolCtx.sessionID,
93+
ctx.logger,
94+
ctx.config.manualMode.enabled,
95+
)
96+
}
8997
applyPendingCompressionDurations(ctx.state)
9098
await saveSessionState(ctx.state, ctx.logger)
9199

tests/finalize-session.test.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ import { Logger } from "../lib/logger"
66
import {
77
createSessionState,
88
loadManualModeSetting,
9+
saveManualModeSetting,
910
type WithParts,
1011
} from "../lib/state"
1112

12-
function buildConfig(): PluginConfig {
13+
function buildConfig(manualMode = false): PluginConfig {
1314
return {
1415
enabled: true,
1516
debug: false,
1617
pruneNotification: "off",
1718
pruneNotificationType: "chat",
1819
commands: { enabled: true, protectedTools: [] },
19-
manualMode: { enabled: false, automaticStrategies: true },
20+
manualMode: { enabled: manualMode, automaticStrategies: true },
2021
turnProtection: { enabled: false, turns: 4 },
2122
experimental: { allowSubAgents: false, customPrompts: false },
2223
protectedFilePatterns: [],
@@ -40,12 +41,12 @@ function buildConfig(): PluginConfig {
4041
} as PluginConfig
4142
}
4243

43-
function buildToolContext(state: ReturnType<typeof createSessionState>) {
44+
function buildToolContext(state: ReturnType<typeof createSessionState>, manualMode = false) {
4445
return {
4546
client: { session: { get: async () => ({}) } },
4647
state,
4748
logger: new Logger(false),
48-
config: buildConfig(),
49+
config: buildConfig(manualMode),
4950
prompts: {
5051
reload() {},
5152
getRuntimePrompts() {
@@ -75,11 +76,14 @@ test("finalizeSession resets compress-pending to auto mode", async () => {
7576
assert.equal(persisted, false)
7677
})
7778

78-
test("finalizeSession preserves explicit active manual mode", async () => {
79-
const sessionId = `finalize-active-manual-${Date.now()}`
79+
test("finalizeSession restores persisted manual mode after compression", async () => {
80+
const sessionId = `finalize-persisted-manual-${Date.now()}`
81+
const logger = new Logger(false)
82+
await saveManualModeSetting(sessionId, true, logger)
83+
8084
const state = createSessionState()
8185
state.sessionId = sessionId
82-
state.manualMode = "active"
86+
state.manualMode = "compress-pending"
8387

8488
await finalizeSession(
8589
buildToolContext(state) as any,
@@ -91,6 +95,26 @@ test("finalizeSession preserves explicit active manual mode", async () => {
9195

9296
assert.equal(state.manualMode, "active")
9397

98+
const persisted = await loadManualModeSetting(sessionId, logger)
99+
assert.equal(persisted, true)
100+
})
101+
102+
test("finalizeSession restores configured manual mode after compression", async () => {
103+
const sessionId = `finalize-configured-manual-${Date.now()}`
104+
const state = createSessionState()
105+
state.sessionId = sessionId
106+
state.manualMode = "compress-pending"
107+
108+
await finalizeSession(
109+
buildToolContext(state, true) as any,
110+
{ sessionID: sessionId, metadata: () => {}, ask: async () => {} },
111+
[] as WithParts[],
112+
[],
113+
undefined,
114+
)
115+
116+
assert.equal(state.manualMode, "active")
117+
94118
const persisted = await loadManualModeSetting(sessionId, new Logger(false))
95119
assert.equal(persisted, true)
96120
})

0 commit comments

Comments
 (0)