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

推荐订阅源

WordPress大学
WordPress大学
Engineering at Meta
Engineering at Meta
D
DataBreaches.Net
月光博客
月光博客
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
U
Unit 42
腾讯CDC
爱范儿
爱范儿
J
Java Code Geeks
有赞技术团队
有赞技术团队
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
B
Blog
Stack Overflow Blog
Stack Overflow Blog
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
Microsoft Azure Blog
Microsoft Azure Blog
T
Tailwind CSS 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
test(trajectory): cover truncated usage preservation · op...
joshavant · 2026-06-27 · via Recent Commits to openclaw:main

@@ -313,4 +313,178 @@ describe("Codex trajectory recorder", () => {

313313

expect(parsed.data.droppedFields).toContain("messagesSnapshot");

314314

expect(Buffer.byteLength(JSON.stringify(parsed), "utf8")).toBeLessThanOrEqual(256 * 1024);

315315

});

316+317+

it("drops oversized preserved fields when needed to keep completion events bounded", async () => {

318+

const tmpDir = makeTempDir();

319+

const sessionFile = path.join(tmpDir, "session.jsonl");

320+

const attempt = {

321+

sessionFile,

322+

sessionId: "session-1",

323+

sessionKey: "agent:main:session-1",

324+

runId: "run-1",

325+

provider: "codex",

326+

modelId: "gpt-5.4",

327+

model: { api: "responses" },

328+

} as never;

329+

const oversizedUsage = Object.fromEntries(

330+

Array.from({ length: 100 }, (_value, index) => [`field-${index}`, "x".repeat(5_000)]),

331+

);

332+

const recorder = createCodexTrajectoryRecorder({

333+

cwd: tmpDir,

334+

attempt,

335+

env: {},

336+

});

337+338+

const trajectoryRecorder = expectTrajectoryRecorder(recorder);

339+

recordCodexTrajectoryCompletion(trajectoryRecorder, {

340+

attempt,

341+

threadId: "thread-1",

342+

turnId: "turn-1",

343+

timedOut: false,

344+

result: {

345+

aborted: false,

346+

attemptUsage: oversizedUsage,

347+

assistantTexts: ["x".repeat(32_000)],

348+

messagesSnapshot: [{ role: "assistant", content: "x".repeat(32_000) }],

349+

} as never,

350+

});

351+

await trajectoryRecorder.flush();

352+353+

const parsed = JSON.parse(

354+

fs.readFileSync(path.join(tmpDir, "session.trajectory.jsonl"), "utf8"),

355+

);

356+

expect(parsed.data).toMatchObject({

357+

truncated: true,

358+

reason: "trajectory-event-size-limit",

359+

});

360+

expect(parsed.data.usage).toBeUndefined();

361+

expect(parsed.data.droppedFields).toEqual(

362+

expect.arrayContaining(["usage", "assistantTexts", "messagesSnapshot"]),

363+

);

364+

expect(Buffer.byteLength(JSON.stringify(parsed), "utf8")).toBeLessThanOrEqual(256 * 1024);

365+

});

366+367+

it("preserves usage on non-final oversized model completion events", async () => {

368+

const tmpDir = makeTempDir();

369+

const sessionFile = path.join(tmpDir, "session.jsonl");

370+

const attempt = {

371+

sessionFile,

372+

sessionId: "session-1",

373+

sessionKey: "agent:main:session-1",

374+

runId: "run-1",

375+

provider: "codex",

376+

modelId: "gpt-5.4",

377+

model: { api: "responses" },

378+

} as never;

379+

const firstUsage = {

380+

input: 384_954,

381+

output: 5_624,

382+

cacheRead: 333_824,

383+

reasoningTokens: 2_038,

384+

total: 724_402,

385+

};

386+

const secondUsage = { input: 12, output: 3, total: 15 };

387+

const recorder = createCodexTrajectoryRecorder({

388+

cwd: tmpDir,

389+

attempt,

390+

env: {},

391+

});

392+393+

const trajectoryRecorder = expectTrajectoryRecorder(recorder);

394+

recordCodexTrajectoryCompletion(trajectoryRecorder, {

395+

attempt,

396+

threadId: "thread-1",

397+

turnId: "turn-1",

398+

timedOut: false,

399+

result: {

400+

aborted: false,

401+

attemptUsage: firstUsage,

402+

assistantTexts: ["first"],

403+

messagesSnapshot: Array.from({ length: 20 }, (_value, index) => ({

404+

role: index % 2 === 0 ? "user" : "assistant",

405+

content: `message-${index} ${"x".repeat(32_000)}`,

406+

})),

407+

} as never,

408+

});

409+

recordCodexTrajectoryCompletion(trajectoryRecorder, {

410+

attempt,

411+

threadId: "thread-1",

412+

turnId: "turn-2",

413+

timedOut: false,

414+

result: {

415+

aborted: false,

416+

attemptUsage: secondUsage,

417+

assistantTexts: ["final answer"],

418+

messagesSnapshot: [{ role: "assistant", content: "final answer" }],

419+

} as never,

420+

});

421+

await trajectoryRecorder.flush();

422+423+

const events = fs

424+

.readFileSync(path.join(tmpDir, "session.trajectory.jsonl"), "utf8")

425+

.trim()

426+

.split(/\r?\n/u)

427+

.map((line) => JSON.parse(line));

428+

expect(events).toHaveLength(2);

429+

expect(events[0].data).toMatchObject({

430+

truncated: true,

431+

usage: firstUsage,

432+

});

433+

expect(events[1].data).toMatchObject({

434+

turnId: "turn-2",

435+

usage: secondUsage,

436+

assistantTexts: ["final answer"],

437+

});

438+

expect(events[1].data.truncated).toBeUndefined();

439+

});

440+441+

it("redacts secrets before preserving usage in truncated completion events", async () => {

442+

const tmpDir = makeTempDir();

443+

const sessionFile = path.join(tmpDir, "session.jsonl");

444+

const attempt = {

445+

sessionFile,

446+

sessionId: "session-1",

447+

sessionKey: "agent:main:session-1",

448+

runId: "run-1",

449+

provider: "codex",

450+

modelId: "gpt-5.4",

451+

model: { api: "responses" },

452+

} as never;

453+

const recorder = createCodexTrajectoryRecorder({

454+

cwd: tmpDir,

455+

attempt,

456+

env: {},

457+

});

458+459+

const trajectoryRecorder = expectTrajectoryRecorder(recorder);

460+

recordCodexTrajectoryCompletion(trajectoryRecorder, {

461+

attempt,

462+

threadId: "thread-1",

463+

turnId: "turn-1",

464+

timedOut: false,

465+

result: {

466+

aborted: false,

467+

attemptUsage: {

468+

total: 1,

469+

apiKey: "sk-test-secret-token",

470+

authorization: "Bearer sk-other-secret-token",

471+

},

472+

assistantTexts: ["done"],

473+

messagesSnapshot: Array.from({ length: 20 }, (_value, index) => ({

474+

role: index % 2 === 0 ? "user" : "assistant",

475+

content: `message-${index} ${"x".repeat(32_000)}`,

476+

})),

477+

} as never,

478+

});

479+

await trajectoryRecorder.flush();

480+481+

const parsed = JSON.parse(

482+

fs.readFileSync(path.join(tmpDir, "session.trajectory.jsonl"), "utf8"),

483+

);

484+

const preservedUsage = JSON.stringify(parsed.data.usage);

485+

expect(parsed.data.truncated).toBe(true);

486+

expect(preservedUsage).toContain("redacted");

487+

expect(preservedUsage).not.toContain("sk-test-secret-token");

488+

expect(preservedUsage).not.toContain("sk-other-secret-token");

489+

});

316490

});