mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 21:07:01 -06:00
fix(codex): accept bounded upstream prompt provenance (#127730)
Allow exact upstream prompt provenance to use the existing 512 KiB settled-projection budget while preserving ordinary text bounds and aggregate accounting. Co-authored-by: Marvinthebored <marvin.assistant@lindsey.jp>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { AgentMessage } from "openclaw/plugin-sdk/agent-harness-runtime";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { projectSettledCodexMessages } from "./settled-turn-projection.js";
|
||||
import { attachUpstreamUserText } from "./upstream-prompt-provenance.js";
|
||||
|
||||
function message(value: unknown): AgentMessage {
|
||||
return value as AgentMessage;
|
||||
@@ -196,6 +197,53 @@ describe("projectSettledCodexMessages", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves upstream user text above the ordinary message limit", () => {
|
||||
const upstreamUserText = "x".repeat(64 * 1024 + 1);
|
||||
|
||||
expect(
|
||||
projectSettledCodexMessages([
|
||||
attachUpstreamUserText(
|
||||
message({ role: "user", content: "[Telegram metadata] decorated prompt" }),
|
||||
upstreamUserText,
|
||||
),
|
||||
toolCall(),
|
||||
toolResult(),
|
||||
])[0],
|
||||
).toEqual({
|
||||
type: "message",
|
||||
role: "user",
|
||||
content: [{ type: "input_text", text: upstreamUserText }],
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects upstream user text above the projection limit", () => {
|
||||
expect(() =>
|
||||
projectSettledCodexMessages([
|
||||
attachUpstreamUserText(
|
||||
message({ role: "user", content: "[Telegram metadata] decorated prompt" }),
|
||||
"x".repeat(512 * 1024 + 1),
|
||||
),
|
||||
toolCall(),
|
||||
toolResult(),
|
||||
]),
|
||||
).toThrow("oversized upstream user text");
|
||||
});
|
||||
|
||||
it("charges upstream user text against the aggregate byte limit", () => {
|
||||
expect(() =>
|
||||
projectSettledCodexMessages([
|
||||
attachUpstreamUserText(
|
||||
message({ role: "user", content: "decorated" }),
|
||||
"x".repeat(400 * 1024),
|
||||
),
|
||||
message({ role: "user", content: "x".repeat(60 * 1024) }),
|
||||
message({ role: "user", content: "x".repeat(60 * 1024) }),
|
||||
toolCall(),
|
||||
toolResult(),
|
||||
]),
|
||||
).toThrow("exceeds the byte limit");
|
||||
});
|
||||
|
||||
it("does not let provenance hide non-text user content", () => {
|
||||
expect(() =>
|
||||
projectSettledCodexMessages([
|
||||
|
||||
@@ -93,7 +93,10 @@ function projectUserMessage(message: Extract<AgentMessage, { role: "user" }>): J
|
||||
type: "message",
|
||||
role: "user",
|
||||
content: [
|
||||
{ type: "input_text", text: requireBoundedText(upstreamUserText, "upstream user text") },
|
||||
{
|
||||
type: "input_text",
|
||||
text: requireBoundedText(upstreamUserText, "upstream user text", MAX_PROJECTION_BYTES),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user