fix(integration): restore codex and memory pipeline contracts (#4474)

Thanks @KooshaPari! Rebased onto release/v3.8.32 (clean cherry-pick — coexists with #4467's specialty changes, 118/118 unit + 12/12 memory-pipeline integration). Codex fingerprint ordering + memory-search contract fixes land.
This commit is contained in:
KooshaPari
2026-06-21 04:58:49 -07:00
committed by GitHub
parent 912239f46d
commit 21d61c69d7
6 changed files with 57 additions and 10 deletions

View File

@@ -49,11 +49,11 @@ export const CLI_FINGERPRINTS: Record<string, CliFingerprint> = {
"instructions",
"store",
"reasoning",
"prompt_cache_key",
"tools",
"tool_choice",
"include",
"service_tier",
"prompt_cache_key",
"client_metadata",
"parallel_tool_calls",
"metadata",

View File

@@ -2,7 +2,11 @@ import { z } from "zod";
import { retrieveMemories } from "@/lib/memory/retrieval";
import { createMemory, deleteMemory, listMemories } from "@/lib/memory/store";
import { MemoryType } from "@/lib/memory/types";
import { getMemorySettings, toMemoryRetrievalConfig, DEFAULT_MEMORY_SETTINGS } from "@/lib/memory/settings";
import {
getMemorySettings,
toMemoryRetrievalConfig,
DEFAULT_MEMORY_SETTINGS,
} from "@/lib/memory/settings";
export const MemorySearchSchema = z.object({
apiKeyId: z.string(),
@@ -44,7 +48,10 @@ export const memoryTools = {
const config = {
...baseConfig,
maxTokens: args.maxTokens || (baseConfig.maxTokens ?? DEFAULT_MEMORY_SETTINGS.maxTokens),
enabled: true,
maxTokens:
args.maxTokens ??
(memorySettings.enabled ? memorySettings.maxTokens : DEFAULT_MEMORY_SETTINGS.maxTokens),
};
const memories = await retrieveMemories(args.apiKeyId, config);

View File

@@ -10,6 +10,7 @@ const harness = await createChatPipelineHarness("memory-pipeline");
// The harness sets DATA_DIR before importing DB modules, so these must resolve after that.
const { extractFactsFromText } = await import("../../src/lib/memory/extraction.ts");
const { retrieveMemories } = await import("../../src/lib/memory/retrieval.ts");
const { invalidateMemorySettingsCache } = await import("../../src/lib/memory/settings.ts");
const { injectMemory, formatMemoryContext } = await import("../../src/lib/memory/injection.ts");
const {
BaseExecutor,
@@ -45,12 +46,14 @@ function dropFts5Artifacts() {
test.beforeEach(async () => {
BaseExecutor.RETRY_CONFIG.delayMs = 0;
await resetStorage();
invalidateMemorySettingsCache();
dropFts5Artifacts();
});
test.afterEach(async () => {
BaseExecutor.RETRY_CONFIG.delayMs = harness.originalRetryDelayMs;
await resetStorage();
invalidateMemorySettingsCache();
});
test.after(async () => {

View File

@@ -0,0 +1,36 @@
import test from "node:test";
import assert from "node:assert/strict";
const { applyFingerprint } = await import("../../open-sse/config/cliFingerprints.ts");
test("Codex CLI fingerprint orders prompt_cache_key before include", () => {
const body = {
model: "gpt-5.5-low",
stream: true,
input: [{ role: "user", content: "hello" }],
instructions: "You are Codex.",
store: false,
reasoning: { effort: "low" },
tools: [],
tool_choice: "auto",
include: ["reasoning.encrypted_content"],
prompt_cache_key: "conv-codex",
service_tier: "priority",
};
const result = applyFingerprint("codex", {}, body);
const orderedKeys = Object.keys(JSON.parse(result.bodyString));
assert.deepEqual(orderedKeys.slice(0, 10), [
"model",
"stream",
"input",
"instructions",
"store",
"reasoning",
"prompt_cache_key",
"tools",
"tool_choice",
"include",
]);
});

View File

@@ -119,7 +119,7 @@ test("memory search respects a configured zero token budget", async () => {
assert.equal(result.data.totalTokens, 0);
});
test("memory search keeps globally disabled memory disabled with explicit maxTokens", async () => {
test("memory search runs explicitly even when global memory injection is disabled", async () => {
await settingsDb.updateSettings({ memoryEnabled: false, memoryMaxTokens: 2000 });
invalidateMemorySettingsCache();
@@ -137,9 +137,10 @@ test("memory search keeps globally disabled memory disabled with explicit maxTok
});
assert.equal(result.success, true);
assert.equal(result.data.count, 0);
assert.deepEqual(result.data.memories, []);
assert.equal(result.data.totalTokens, 0);
assert.equal(result.data.count, 1);
assert.equal(result.data.memories.length, 1);
assert.match(result.data.memories[0].content, /TypeScript/i);
assert.ok(result.data.totalTokens > 0);
});
test("memory clear deletes only older filtered entries and reports the deleted count", async () => {

View File

@@ -372,12 +372,12 @@ test("web-cookie provider validators surface auth and subscription failures", as
__setPplxTlsFetchOverride(async () => {
return { status: 403, headers: new Headers(), text: null, body: null };
});
__setGrokTlsFetchOverride(async () => {
return { status: 401, headers: new Headers(), text: "Unauthorized", body: null };
});
globalThis.fetch = async (url, init = {}) => {
const target = String(url);
if (target.includes("grok.com/rest/app-chat/conversations/new")) {
return new Response(JSON.stringify({ error: "unauthorized" }), { status: 401 });
}
if (target.includes("app.blackbox.ai/api/auth/session")) {
const cookie = (init.headers as Record<string, string>)?.Cookie || "";
if (cookie.includes("expired-cookie")) {