-
Notifications
You must be signed in to change notification settings - Fork 544
fix(compact): report upstream usage for native compact turns #945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ import { | |
| } from "../src/codex/auth-context"; | ||
| import { supportsNativeResponsesCompactEndpoint } from "../src/providers/openai-tiers"; | ||
| import { acquireNativeMainProfileDrain, tryAdmitTurn } from "../src/server/lifecycle"; | ||
| import type { RequestLogContext } from "../src/server/request-log"; | ||
| import type { OcxConfig, OcxProviderConfig } from "../src/types"; | ||
|
|
||
| const originalFetch = globalThis.fetch; | ||
|
|
@@ -166,6 +167,44 @@ describe("supportsNativeResponsesCompactEndpoint (#422)", () => { | |
| }); | ||
| }); | ||
|
|
||
| describe("native compact usage reporting", () => { | ||
| test("the buffered upstream body fills the request log usage and stays intact for the client", async () => { | ||
| const config = { | ||
| defaultProvider: "openai-apikey", | ||
| providers: { | ||
| "openai-apikey": { | ||
| adapter: "openai-responses", | ||
| baseUrl: "https://api.openai.com/v1", | ||
| authMode: "key", | ||
| apiKey: "sk-test", | ||
| }, | ||
| }, | ||
| } as unknown as OcxConfig; | ||
| globalThis.fetch = (async () => jsonResponse(completedPayload("native summary"))) as typeof fetch; | ||
| const logCtx: RequestLogContext = { model: "", provider: "" }; | ||
| const previousUsageDebug = process.env.OPENCODEX_USAGE_DEBUG; | ||
| process.env.OPENCODEX_USAGE_DEBUG = "1"; | ||
| let response: Response; | ||
| try { | ||
| response = await handleResponsesCompact( | ||
| compactionRequest(baseCompactionBody({ model: "openai-apikey/gpt-5.5" })), | ||
| config, | ||
| logCtx, | ||
| ); | ||
| } finally { | ||
| if (previousUsageDebug === undefined) delete process.env.OPENCODEX_USAGE_DEBUG; | ||
| else process.env.OPENCODEX_USAGE_DEBUG = previousUsageDebug; | ||
| } | ||
| expect(response.status).toBe(200); | ||
| expect(await response.json()).toEqual(completedPayload("native summary")); | ||
| expect(logCtx.usage).toMatchObject({ inputTokens: 10, outputTokens: 5, totalTokens: 15 }); | ||
| // The compact body is replacement history; even with usage debug on it must | ||
| // never be sampled into the debug log. | ||
| expect(logCtx.usageDebugBodyKind).toBeUndefined(); | ||
| expect(logCtx.usageDebugBodySample).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
Comment on lines
+170
to
+206
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win Cover the remaining response-log branches. This test checks usage and complete body preservation only. It does not exercise Add assertions for As per path instructions, source behavior changes require focused regression coverage in 🤖 Prompt for AI AgentsSource: Path instructions |
||
|
|
||
| describe("native Codex pool compaction", () => { | ||
| test("keeps a Spark reset cooldown separate from a Terra compact request (#590)", async () => { | ||
| const testDir = mkdtempSync(join(tmpdir(), "ocx-compact-scope-")); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert the complete upstream payload.
Lines 189-190 check only
body.usage. A regression that removesid,status, oroutputwould still pass, although this PR must preserve the complete upstream body.Proposed assertion
🤖 Prompt for AI Agents