惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
月光博客
月光博客
IT之家
IT之家
B
Blog RSS Feed
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - Franky
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
博客园_首页
B
Blog
V
V2EX
腾讯CDC
Vercel News
Vercel News
量子位
Microsoft Security Blog
Microsoft Security Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(reply): defer context compaction safely · openclaw/op...
keshavbotage · 2026-05-27 · via Recent Commits to openclaw:main

@@ -3,7 +3,7 @@ import {

33

resolveContextEngine,

44

resolveContextEngineOwnerPluginId,

55

} from "../../context-engine/registry.js";

6-

import type { ContextEngineRuntimeContext } from "../../context-engine/types.js";

6+

import type { ContextEngine, ContextEngineRuntimeContext } from "../../context-engine/types.js";

77

import {

88

captureCompactionCheckpointSnapshotAsync,

99

cleanupCompactionCheckpointSnapshot,

@@ -26,6 +26,7 @@ import {

2626

} from "../harness/selection.js";

2727

import { resolveContextConfigProviderForRuntime } from "../openai-codex-routing.js";

2828

import { ensureRuntimePluginsLoaded } from "../runtime-plugins.js";

29+

import { DEFERRED_CONTEXT_ENGINE_COMPACTION_REASON } from "./compact-reasons.js";

2930

import type { CompactEmbeddedPiSessionParams } from "./compact.types.js";

3031

import { asCompactionHookRunner, runPostCompactionSideEffects } from "./compaction-hooks.js";

3132

import {

@@ -64,6 +65,88 @@ function shouldFallbackAfterHarnessCompaction(

6465

);

6566

}

666768+

const DEFERRED_CONTEXT_ENGINE_COMPACTION_SCHEDULE_FAILURE_REASON =

69+

"failed to schedule background context-engine maintenance";

70+71+

function shouldDeferOwningContextEngineBudgetCompaction(params: {

72+

compactParams: CompactEmbeddedPiSessionParams;

73+

contextEngine: ContextEngine;

74+

}): boolean {

75+

// Request-time budget compaction for context-engine-owned transcripts can

76+

// spend the whole reply preflight budget. Only defer engines that explicitly

77+

// advertise background turn maintenance, leaving native/current-session

78+

// harness compaction synchronous.

79+

return (

80+

params.compactParams.deferOwningContextEngineCompaction === true &&

81+

params.compactParams.trigger === "budget" &&

82+

params.contextEngine.info.ownsCompaction === true &&

83+

params.contextEngine.info.turnMaintenanceMode === "background" &&

84+

typeof params.contextEngine.maintain === "function"

85+

);

86+

}

87+88+

async function disposeContextEngine(contextEngine: ContextEngine): Promise<void> {

89+

try {

90+

await contextEngine.dispose?.();

91+

} catch (err) {

92+

log.warn("context engine dispose failed after deferred maintenance", {

93+

errorMessage: formatErrorMessage(err),

94+

});

95+

}

96+

}

97+98+

async function deferOwningContextEngineBudgetCompaction(params: {

99+

compactParams: CompactEmbeddedPiSessionParams;

100+

contextEngine: ContextEngine;

101+

contextEngineRuntimeContext: ContextEngineRuntimeContext;

102+

}): Promise<EmbeddedPiCompactResult> {

103+

let deferredScheduled = false;

104+

try {

105+

await runContextEngineMaintenance({

106+

contextEngine: params.contextEngine,

107+

sessionId: params.compactParams.sessionId,

108+

sessionKey: params.compactParams.sessionKey,

109+

sessionFile: params.compactParams.sessionFile,

110+

reason: "turn",

111+

runtimeContext: params.contextEngineRuntimeContext,

112+

config: params.compactParams.config,

113+

disposeDeferredContextEngineAfterMaintenance: true,

114+

onDeferredMaintenance: () => {

115+

deferredScheduled = true;

116+

},

117+

});

118+

} catch (err) {

119+

log.warn("failed to defer context-engine budget compaction", {

120+

errorMessage: formatErrorMessage(err),

121+

});

122+

}

123+124+

if (!deferredScheduled) {

125+

await disposeContextEngine(params.contextEngine);

126+

log.warn(

127+

`[compaction] failed to schedule context-engine-owned budget compaction background maintenance ` +

128+

`(sessionKey=${params.compactParams.sessionKey ?? params.compactParams.sessionId})`,

129+

);

130+

return {

131+

ok: false,

132+

compacted: false,

133+

reason: DEFERRED_CONTEXT_ENGINE_COMPACTION_SCHEDULE_FAILURE_REASON,

134+

failure: { reason: "deferred_compaction_not_scheduled" },

135+

};

136+

}

137+138+

log.info(

139+

`[compaction] deferred context-engine-owned budget compaction to background maintenance ` +

140+

`(sessionKey=${params.compactParams.sessionKey ?? params.compactParams.sessionId} ` +

141+

`scheduled=${String(deferredScheduled)})`,

142+

);

143+

return {

144+

ok: true,

145+

compacted: false,

146+

reason: DEFERRED_CONTEXT_ENGINE_COMPACTION_REASON,

147+

};

148+

}

149+67150

/**

68151

* Compacts a session with lane queueing (session lane + global lane).

69152

* Use this from outside a lane context. If already inside a lane, use

@@ -165,6 +248,18 @@ export async function compactEmbeddedPiSession(

165248

`native harness compaction could not use its session binding; falling back to context engine: ${harnessResult.reason ?? "unknown"}`,

166249

);

167250

}

251+

if (

252+

shouldDeferOwningContextEngineBudgetCompaction({

253+

compactParams: params,

254+

contextEngine,

255+

})

256+

) {

257+

return await deferOwningContextEngineBudgetCompaction({

258+

compactParams: params,

259+

contextEngine,

260+

contextEngineRuntimeContext,

261+

});

262+

}

168263

const sessionLane = resolveSessionLane(params.sessionKey?.trim() || params.sessionId);

169264

const globalLane = resolveGlobalLane(params.lane);

170265

const enqueueGlobal =