fix: bound subagent completion context · openclaw/openclaw@3c5e68e
2026-05-10
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -300,7 +300,7 @@ export const registerTelegramHandlers = ({
|
300 | 300 | if (!isMultiToggleButton(button) || !isSelectedMultiButton(button)) { |
301 | 301 | return []; |
302 | 302 | } |
303 | | -return [button.callback_data!.slice(`${MULTI_SELECT_PREFIX}toggle|`.length)]; |
| 303 | +return [button.callback_data.slice(`${MULTI_SELECT_PREFIX}toggle|`.length)]; |
304 | 304 | }), |
305 | 305 | ); |
306 | 306 | const updateMultiSelectKeyboard = ( |
@@ -313,7 +313,7 @@ export const registerTelegramHandlers = ({
|
313 | 313 | if (!isMultiToggleButton(button)) { |
314 | 314 | return button; |
315 | 315 | } |
316 | | -const buttonValue = button.callback_data!.slice(`${MULTI_SELECT_PREFIX}toggle|`.length); |
| 316 | +const buttonValue = button.callback_data.slice(`${MULTI_SELECT_PREFIX}toggle|`.length); |
317 | 317 | const baseText = stripMultiSelectPrefix(button.text); |
318 | 318 | const selected = |
319 | 319 | action === "clear" |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -25,6 +25,8 @@ type AgentTaskCompletionInternalEvent = {
|
25 | 25 | replyInstruction: string; |
26 | 26 | }; |
27 | 27 | |
| 28 | +const MAX_CHILD_RESULT_PROMPT_CHARS = 4_000; |
| 29 | + |
28 | 30 | export type AgentInternalEvent = AgentTaskCompletionInternalEvent; |
29 | 31 | |
30 | 32 | export { INTERNAL_RUNTIME_CONTEXT_BEGIN, INTERNAL_RUNTIME_CONTEXT_END }; |
@@ -41,11 +43,23 @@ function sanitizeMultilineField(value: string, fallback: string): string {
|
41 | 43 | return sanitized || fallback; |
42 | 44 | } |
43 | 45 | |
| 46 | +function truncateChildResultForPrompt(value: string): string { |
| 47 | +if (value.length <= MAX_CHILD_RESULT_PROMPT_CHARS) { |
| 48 | +return value; |
| 49 | +} |
| 50 | +return [ |
| 51 | +value.slice(0, MAX_CHILD_RESULT_PROMPT_CHARS).trimEnd(), |
| 52 | +"", |
| 53 | +`[child result truncated: ${value.length - MAX_CHILD_RESULT_PROMPT_CHARS} additional characters omitted]`, |
| 54 | +].join("\n"); |
| 55 | +} |
| 56 | + |
44 | 57 | function formatChildResultDataBlock(value: string): string { |
| 58 | +const safeValue = truncateChildResultForPrompt(value); |
45 | 59 | return ( |
46 | 60 | wrapPromptDataBlock({ |
47 | 61 | label: "Child result", |
48 | | -text: value, |
| 62 | +text: safeValue, |
49 | 63 | }) || "Child result: (no output)" |
50 | 64 | ); |
51 | 65 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -362,6 +362,26 @@ describe("sanitizeUserFacingText", () => {
|
362 | 362 | ); |
363 | 363 | }); |
364 | 364 | |
| 365 | +it("bounds large child completion results before injecting internal context", () => { |
| 366 | +const internal = formatAgentInternalEventsForPrompt([ |
| 367 | +{ |
| 368 | +type: "task_completion", |
| 369 | +source: "subagent", |
| 370 | +childSessionKey: "agent:main:subagent:test", |
| 371 | +childSessionId: "sess_1", |
| 372 | +announceType: "subagent task", |
| 373 | +taskLabel: "Investigate issue", |
| 374 | +status: "ok", |
| 375 | +statusLabel: "completed successfully", |
| 376 | +result: "x".repeat(6_000), |
| 377 | +replyInstruction: "Reply to the user in your own words.", |
| 378 | +}, |
| 379 | +]); |
| 380 | + |
| 381 | +expect(internal).toContain("[child result truncated: 2000 additional characters omitted]"); |
| 382 | +expect(internal.length).toBeLessThan(5_000); |
| 383 | +}); |
| 384 | + |
365 | 385 | it("does not strip inline delimiter mentions that are not standalone marker lines", () => { |
366 | 386 | const input = `Note: ${INTERNAL_RUNTIME_CONTEXT_BEGIN} appears inline and should stay.`; |
367 | 387 | expect(sanitizeUserFacingText(input)).toBe(input); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1237,6 +1237,7 @@ describe("deliverSubagentAnnouncement completion delivery", () => {
|
1237 | 1237 | childSessionKey: "agent:openclaw:subagent:child-123", |
1238 | 1238 | childSessionId: "child-123", |
1239 | 1239 | announceType: "subagent task", |
| 1240 | +taskLabel: "channel completion smoke", |
1240 | 1241 | status: "ok", |
1241 | 1242 | statusLabel: "completed successfully", |
1242 | 1243 | result: "Raw child result that should stay internal.", |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。