fix(codex): retain bounded hook prompt context · openclaw/openclaw@88ad407
vincentkoc
·
2026-06-21
·
via Recent Commits to openclaw:main
File tree
extensions/codex/src/app-server
| Original file line number | Diff line number | Diff line change |
|---|
@@ -255,11 +255,11 @@ describe("projectContextEngineAssemblyForCodex", () => {
|
255 | 255 | expect(fitted).toContain("[truncated "); |
256 | 256 | }); |
257 | 257 | |
258 | | -it("keeps the current request when a hook appends oversized context", () => { |
| 258 | +it("keeps the current request and fitting hook context after projecting history", () => { |
259 | 259 | const before = "OpenClaw assembled context for this turn:\n<conversation_context>\n"; |
260 | | -const context = `recent context ${"c".repeat(200)}`; |
| 260 | +const context = `recent context ${"c".repeat(800)}`; |
261 | 261 | const request = "\n</conversation_context>\n\nCurrent user request:\nkeep this request"; |
262 | | -const hookAppend = `\n\nhook context ${"h".repeat(800)}`; |
| 262 | +const hookAppend = "\n\nhook context survives"; |
263 | 263 | const promptText = `${before}${context}${request}${hookAppend}`; |
264 | 264 | const maxChars = 420; |
265 | 265 | |
@@ -274,9 +274,9 @@ describe("projectContextEngineAssemblyForCodex", () => {
|
274 | 274 | }); |
275 | 275 | |
276 | 276 | expect(fitted.length).toBeLessThanOrEqual(maxChars); |
277 | | -expect(fitted).toContain("recent context"); |
| 277 | +expect(fitted).toContain("[truncated "); |
278 | 278 | expect(fitted).toContain("Current user request:\nkeep this request"); |
279 | | -expect(fitted).not.toContain("hook context"); |
| 279 | +expect(fitted).toContain("hook context survives"); |
280 | 280 | }); |
281 | 281 | |
282 | 282 | it("keeps the original input when a hook appends context without a projection", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -168,10 +168,16 @@ export function fitCodexProjectedContextForTurnStart(params: {
|
168 | 168 | if (request.length >= maxChars) { |
169 | 169 | return truncateOlderContext(request, maxChars); |
170 | 170 | } |
171 | | -const contextBudget = maxChars - request.length; |
| 171 | +const appendedContext = params.promptText.slice(requestRange.end); |
| 172 | +// Hook-appended context is newer than the projected history. Retain it |
| 173 | +// before trimming the projection, while the full current request remains |
| 174 | +// the hard boundary that must survive a bounded turn/start input. |
| 175 | +const fittedAppendedContext = truncateOlderContext(appendedContext, maxChars - request.length); |
| 176 | +const contextBudget = maxChars - request.length - fittedAppendedContext.length; |
172 | 177 | const fittedContext = truncateOlderContext(context, contextBudget); |
173 | | -const beforeContextBudget = maxChars - fittedContext.length - request.length; |
174 | | -return `${truncateOlderContext(beforeContext, beforeContextBudget)}${fittedContext}${request}`; |
| 178 | +const beforeContextBudget = |
| 179 | +maxChars - fittedContext.length - request.length - fittedAppendedContext.length; |
| 180 | +return `${truncateOlderContext(beforeContext, beforeContextBudget)}${fittedContext}${request}${fittedAppendedContext}`; |
175 | 181 | } |
176 | 182 | const contextBudget = maxChars - beforeContext.length - afterContext.length; |
177 | 183 | if (contextBudget > 0) { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。