Dashboard › opencode-lore › Session 1PYUWCKQRFBC
1PYUWCKQRFBCO86RLIndependent immutable security/privacy/pentest review in /home/byk/Code/opencode-lore-responses-accumulation. Candidate stable change vsutownopktwxvuvywqszxnkqwultovt, head a8546e30bf105242fb6f78a05d9d6cb7b2f3ed6e, base exact 2cbf40060c67df229731cf1b9e34d5bf22ec2145, expected plain diff SHA-256 bd34f024169d371c4b1c3e26bf3f0b66f43ce7540014db109d1ae9dd38b60631. Exactly 3 changed paths: packages/gateway/src/pipeline.ts, packages/gateway/src/stream/openai-responses.ts, packages/gateway/test/openai-responses-recall-aware-stream.test.ts. Read AGENTS.md, quality/REVIEW.md, package scripts. Strict read-only: no edits/format/install/VCS mutation/server/network/production DB/exhaustive suite. Verify identity/status/conflicts/hash/files start/end. Inspect all changed lines and relevant parsing/state/output/callback/logging/persistence/cancellation paths. Attack malformed/forged lifecycle event names, item_reference identity/lifecycle/collisions, limit-crossing private accumulation, sparse/omitted indices and safe integer bounds, terminal-only data, callback/postResponse leakage, public wire redaction, failed output, usage accounting, rollback exact-once, resource/CPU/address-space bounds, cancellation and retries. Validate reference events always accumulate privately before suppression/limits and never appear publicly. Assess fail-first and guard-removal discrimination. Report substantive PASS/CONCERN/MUST-FIX with current file:line evidence and residual risks; end exactly MERGE or DO-NOT-MERGE. Use lore recall CLI if context missing; never return warning-only/progress-only.
<skill_content name="jj-guide"> # Skill: jj-guide # jj Guide for AI Agents Jujutsu (jj) is a Git-compatible VCS with mutable commits, automatic snapshotting, no staging area, and first-class conflicts. This skill teaches you how to use it safely from a non-interactive agent environment. If `.jj/` exists in the repo root, this is a jj repo. **Use `jj` commands, not `git`.** In a colocated repo (`.jj/` *and* `.git/`), git tools can read the state, but mutations should go through `jj` so the operation log stays consistent. ## Critical Rules - **NEVER** use interactive flags (`-i`, `--interactive`). TUI prompts hang in agent environments. This applies to `jj split -i`, `jj squash -i`, `jj commit -i`, `jj resolve`, `jj diffedit`, etc. - **ALWAYS** pass `-m "msg"` when describing/committing. Without `-m`, an editor opens and hangs. - **VERIFY** mutations with `jj st` and `jj log` after `squash`, `abandon`, `rebase`, `restore`, `commit`. ...
<path>/home/byk/Code/opencode-lore-responses-accumulation</path> <type>directory</type> <entries> .craft.yml .git .github/ .gitignore .jj/ .lore.md .oxfmtrc.json .oxlintrc.json AGENTS.md CHANGELOG.md codecov.yml LICENSE node_modules/ package.json packages/ patches/ pnpm-lock.yaml pnpm-workspace.yaml quality/ README.md scripts/ stryker.config.mjs supabase/ tsconfig.base.json tsconfig.json vitest.config.ts vitest.evals.config.ts vitest.mutation.config.ts (28 entries) </entries>
<path>/home/byk/Code/opencode-lore-responses-accumulation/AGENTS.md</path> <type>file</type> <content> 1: <!-- This section is maintained by the coding agent via lore (https://github.com/BYK/loreai) --> 2: ## Long-term Knowledge 3: 4: For long-term knowledge entries managed by [lore](https://github.com/BYK/loreai) (gotchas, patterns, decisions, architecture), see [`.lore.md`](.lore.md) in the project root. 5: <!-- End lore-managed section --> 6: 7: ## Review 8: 9: See [`quality/REVIEW.md`](quality/REVIEW.md) for the review heuristics and workflow — regression-test discipline, adversarial-order state setup, fan-out registry coverage, recurring bug-class batteries, and the two-reviewer rule. Every non-trivial PR requires an adversarial correctness review before merge. 10: 11: # Project Overview 12: 13: Lore is a **three-tier memory architecture** for AI coding agents. ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/quality/REVIEW.md</path> <type>file</type> <content> 1: # Review Heuristics — Lore 2: 3: This document codifies the review bar for pull requests. It exists because 4: adversarial review has repeatedly caught correctness bugs that a green test 5: suite missed — skip/early-return branches, lifecycle sequences, and fan-out 6: registry gaps. Institutionalizing these patterns so they compound. 7: 8: The review workflow (§6) is referenced from AGENTS.md. 9: 10: --- 11: 12: ## 1. Regression-test discipline 13: 14: Every adversarial-review finding that surfaces a defect **must** land a 15: deterministic regression test in the same PR. The test: 16: - fails on the base branch (proving it reproduces the bug), 17: - passes on the fix (proving the fix works), 18: - drives the *real* precondition, not an artificially-constructed state (e.g. ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/package.json</path>
<type>file</type>
<content>
1: {
2: "name": "lore-monorepo",
3: "private": true,
4: "type": "module",
5: "license": "FSL-1.1-Apache-2.0",
6: "description": "Monorepo root for Lore — three-tier memory architecture",
7: "main": "./packages/opencode/src/index.ts",
8: "exports": {
9: ".": "./packages/opencode/src/index.ts"
10: },
11: "packageManager": "pnpm@10.28.0",
12: "volta": {
13: "node": "24.16.0",
14: "pnpm": "10.28.0"
15: },
16: "pnpm": {
17: "onlyBuiltDependencies": [
18: "esbuild",
19: "onnxruntime-node",
20: "sharp"
21: ],
22: "overrides": {
23: "basic-ftp": "5.3.1",
24: "ip-address": "10.2.0",
25: "fast-xml-parser": "5.7.3",
26: "@huggingface/hub": "2.11.0",
27: "onnxruntime-node": "1.27.0",
28: "yaml": ">=2.8.3",
29: "esbuild": ">=0.28.1",
30: "@opentelemetry/core": ">=2.8.0",
31: ...
The working copy has no changes. Working copy (@) : quqnzmlz 34cd6f80 (empty) (no description set) Parent commit (@-): vsutowno a8546e30 fix/responses-accumulation-order | fix(responses): accumulate private references Warning: These bookmarks have conflicts: fix/responses-private-references Hint: Use `jj bookmark list` to see details. Use `jj bookmark set <name> -r <rev>` to resolve.
vsutowno ben@byk.im 2026-09-17 01:54:33 fix/responses-accumulation-order a8546e30 fix(responses): accumulate private references rwunmtrq ben@byk.im 2026-09-16 21:25:39 21ad2a5c fix(responses): complete accumulation boundaries pxrvwsvv 41898282+github-actions[bot]@users.noreply.github.com 2026-09-15 08:31:50 main 2cbf4006 feat(cch): add seeds for Claude Code up to 2.1.272 (#1780)
M packages/gateway/src/pipeline.ts M packages/gateway/src/stream/openai-responses.ts M packages/gateway/test/openai-responses-recall-aware-stream.test.ts
bd34f024169d371c4b1c3e26bf3f0b66f43ce7540014db109d1ae9dd38b60631 -
(no output)
vsutowno ben@byk.im 2026-09-17 01:54:33 fix/responses-accumulation-order a8546e30 fix(responses): accumulate private references rwunmtrq ben@byk.im 2026-09-16 21:25:39 21ad2a5c fix(responses): complete accumulation boundaries lrqlyykx ben@byk.im 2026-09-16 20:56:53 ca83ea53 fix(responses): close lifecycle gaps tklkqxyt ben@byk.im 2026-09-16 11:46:06 ce88c614 fix(responses): complete lifecycle reconciliation kvpmnlwn ben@byk.im 2026-09-15 23:51:09 683dff02 fix(responses): bound sparse lifecycle coordinates lplymwvl ben@byk.im 2026-09-15 23:51:09 df49b0ce fix(responses): preserve limit-crossing state pxrvwsvv 41898282+github-actions[bot]@users.noreply.github.com 2026-09-15 08:31:50 main 2cbf4006 feat(cch): add seeds for Claude Code up to 2.1.272 (#1780)
...output truncated...
Full output saved to: /home/byk/.local/share/opencode/tool-output/tool_0aed42422001sfIXf1t7iKq1yM
+ if (!response.body) throw new Error("missing follow-up body");
+ return { reader: response.body.getReader() };
+ },
+ },
+ );
+
+ const output = await drain(client);
+ expect(outcomes).toEqual([false]);
+ expect([recallCalls, followUps]).toEqual(
+ stream === "principal" ? [0, 0] : [1, 1],
+ );
+ expect(output).toContain(
+ stream === "principal" ? PUBLIC_GATEWAY_ERROR : PUBLIC_RECALL_ERROR,
+ );
+ expect(output).not.toContain(privateText);
+ expect(output).not.toContain(event);
+ expect(JSON.stringify(completedResponse)).not.toContain(privateText);
+ },
+ );
+
+ test.each([
+ ["summary", "output_item.done", true, "summary_text"],
+ ["summary", "terminal", false, "summary_text"],
+ ["content", "output_item.done", true, "reasoning_text"],
+ ...
diff --git a/packages/gateway/src/pipeline.ts b/packages/gateway/src/pipeline.ts
index 004e03b3e2..de8aadf7e5 100644
--- a/packages/gateway/src/pipeline.ts
+++ b/packages/gateway/src/pipeline.ts
@@ -7933,6 +7933,7 @@
acc: ResponsesAccState,
event: string,
parsed: Record<string, unknown>,
+ outputOffset = 0,
): ResponsesAccState | undefined => {
if (opts.validation !== "codex") return undefined;
let normalizationState = codexNormalizationStates.get(acc);
@@ -7940,11 +7941,21 @@
normalizationState = makeResponsesAccState();
codexNormalizationStates.set(acc, normalizationState);
}
+ // Tighten Codex's local exclusive ceiling by the continuation shift. This
+ // rejects an omitted index while the normalizer derives it, before either
+ // normalization or accumulation can retain an out-of-range item.
+ const localSparseCeiling = Math.max(
+ 0,
+ Math.min(
+ opts.maxSSEFrames ?? ...
diff --git a/packages/gateway/src/stream/openai-responses.ts b/packages/gateway/src/stream/openai-responses.ts
index 4c33c821b5..5623788876 100644
--- a/packages/gateway/src/stream/openai-responses.ts
+++ b/packages/gateway/src/stream/openai-responses.ts
@@ -824,6 +824,7 @@
if (item.type === "text") {
if (item.content) {
for (const part of item.content) {
+ if (!part) continue;
if (part.type === "output_text" && typeof part.text === "string") {
content.push({ type: "text", text: part.text });
} else {
Found 100 matches (more matches available)
/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/http-body.ts:
Line 39: import { cancelAndReleaseReader } from "./stream/anthropic";
Line 101: cancelAndReleaseReader(reader, signal.reason);
Line 139: cancelAndReleaseReader(reader, signal.reason);
/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/recall.ts:
Line 45: import { cancelAndReleaseReader } from "./stream/anthropic";
Line 1403: cancelAndReleaseReader(reader, probeSignal.reason);
Line 1442: cancelAndReleaseReader(reader, signal?.reason);
/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/pipeline.ts:
Line 217: type ResponsesAccState,
Line 248: cancelAndReleaseReader,
Line 6932: if (activeReader) cancelAndReleaseReader(activeReader, streamSignal.reason);
Line 7127: cancelAndReleaseReader(reader);
Line 7591: ...
Found 53 matches
/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/stream/openai-responses.ts:
Line 9: * response.output_item.added → response.output_text.delta (repeated) →
Line 10: * response.output_item.done → response.function_call_arguments.delta →
Line 48: export interface ResponsesAccState {
Line 100: "item_reference",
Line 556: export function makeResponsesAccState(): ResponsesAccState {
Line 582: export function applyResponsesEvent(
Line 615: case "response.output_item.added": {
Line 644: case "response.output_item.done": {
Line 815: export function finalizeResponsesAcc(
Line 895: .filter((item) => item.type !== "item_reference"),
Line 996: case "response.output_item.added": {
Line 1045: case "response.output_item.done": {
Line 1190: event === "response.output_item.added" ||
Line 1191: event === "response.output_item.done"
Line 1304: event: "response.output_item.added" | ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
7790: * The recall execution callback abstracts the pipeline-scope dependencies
7791: * (`executeRecall` + follow-up forwarding + recall store), so this function
7792: * stays a self-contained streamer in the Responses module.
7793: */
7794: export function streamResponsesRecallAware(
7795: upstreamResponse: Response,
7796: opts: {
7797: onComplete: (response: GatewayResponse, successful: boolean) => void;
7798: onTransactionReady?: (transaction: {
7799: commit: () => void;
7800: rollback: () => void;
7801: }) => void;
7802: sessionID?: string;
7803: /** Emergency ceiling for the request-owned recall chain. */
7804: maxRecallExecutions?: number;
7805: /** @deprecated Use `maxRecallExecutions`. */
7806: maxRecallDepth?: number;
7807: noStore?: boolean;
7808: maxDeferredBytes?: number;
7809: ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
8324: const collectCompletedRecall = (
8325: acc: ResponsesAccState,
8326: outputIndex: number,
8327: parsedInputs: Map<number, RecallArguments>,
8328: pending: PendingResponsesRecall[],
8329: ): boolean => {
8330: const rawItem = acc.rawItems.get(outputIndex);
8331: if (
8332: rawItem?.type !== "function_call" ||
8333: rawItem.name !== RECALL_TOOL_NAME
8334: ) {
8335: return false;
8336: }
8337: if (pending.some((recall) => recall.outputIndex === outputIndex)) {
8338: throw new Error(`duplicate recall completion for index ${outputIndex}`);
8339: }
8340: const input =
8341: parsedInputs.get(outputIndex) ?? parseRecallArguments(rawItem.arguments);
8342: const recallItem = acc.items.get(outputIndex);
8343: const toolUseId =
8344: recallItem?.type === "tool_use" ? ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
8884: );
8885: }
8886: }
8887: }
8888: lifecycle.content.set(contentIndex, contentState);
8889: }
8890: if (
8891: event.startsWith("response.reasoning_summary") &&
8892: (!Number.isSafeInteger(parsed.summary_index) ||
8893: (parsed.summary_index as number) < 0)
8894: ) {
8895: throw new Error(`invalid Responses summary_index for ${event}`);
8896: }
8897: if (
8898: ((event.startsWith("response.output_text") ||
8899: event.startsWith("response.refusal")) &&
8900: declaredType !== "message") ||
8901: (event.startsWith("response.reasoning_summary") &&
8902: declaredType !== "reasoning") ||
8903: (event.startsWith("response.function_call_arguments") &&
8904: declaredType !== ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
9444: const assertTerminalReasoningMatchesLifecycle = (
9445: lifecycle: OutputLifecycle,
9446: actual: Record<string, unknown>,
9447: outputIndex: number,
9448: ): void => {
9449: assertReasoningPartsMatchLifecycle(
9450: actual.summary,
9451: lifecycle.reasoning,
9452: "summary_text",
9453: "terminal reasoning summary",
9454: outputIndex,
9455: );
9456: assertReasoningPartsMatchLifecycle(
9457: actual.content,
9458: lifecycle.content,
9459: "reasoning_text",
9460: "terminal reasoning content",
9461: outputIndex,
9462: );
9463: const collections: Array<
9464: [unknown, ReadonlyMap<number, TextPartLifecycle>, string]
9465: > = [
9466: [actual.summary, lifecycle.reasoning, "reasoning summary"],
9467: [actual.content, lifecycle.content, "reasoning ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
9834: );
9835: return result;
9836: };
9837: const settleFollowUp = async (
9838: input: Parameters<typeof opts.runFollowUp>[0],
9839: ): ReturnType<typeof opts.runFollowUp> => {
9840: const operation = opts.runFollowUp({
9841: ...input,
9842: resultText: recallBudgetGuidance(
9843: input.resultText,
9844: input.finalRecallRound ? recallBudget.stopReason() : undefined,
9845: ),
9846: });
9847: const cancelLateReader = async (): Promise<void> => {
9848: try {
9849: const late = await operation;
9850: cancelAndReleaseReader(late.reader, signal.reason);
9851: } catch {
9852: // The aborted request no longer observes the callback result.
9853: }
9854: };
9855: if (signal.aborted) {
9856: void cancelLateReader();
9857: throw ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
10304: const principalTransportStage = () =>
10305: ordinaryToolEmitted
10306: ? ("post_tool" as const)
10307: : principalEventEmitted
10308: ? ("post_output" as const)
10309: : ("pre_output" as const);
10310: const reportContinuationFailure = (
10311: category: RecallContinuationFailureCategory,
10312: ): void => {
10313: if (continuationFailureReported) return;
10314: continuationFailureReported = true;
10315: reportRecallContinuationFailure(category);
10316: };
10317: // Recall items are gateway-internal and must stay hidden on every exit,
10318: // including failures raised before marker replacement. ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
10900: chunk: Uint8Array;
10901: candidateIndex?: number;
10902: transactional: boolean;
10903: }> = [];
10904: let deferredContinuationBytes = 0;
10905: const holdContinuation = (
10906: chunk: Uint8Array,
10907: candidateIndex?: number,
10908: ): void => {
10909: const transactional = candidateIndex === undefined;
10910: if (transactional) reserveTransactionalBytes(chunk);
10911: else {
10912: deferredContinuationBytes += chunk.byteLength;
10913: if (deferredContinuationBytes > maxDeferredBytes) {
10914: ...
Found 100 matches (more matches available)
/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/test/openai-responses-recall-aware-stream.test.ts:
Line 195: "response.reasoning_summary_text.delta",
Line 196: "response.reasoning_summary_text.done",
Line 197: "response.reasoning_summary_part.added",
Line 198: "response.reasoning_summary_part.done",
Line 199: "response.reasoning_text.delta",
Line 200: "response.reasoning_text.done",
Line 241: ? "response.reasoning_summary_text.delta"
Line 270: case "response.reasoning_summary_text.delta":
Line 279: case "response.reasoning_summary_text.done":
Line 280: beforeTrigger = sseEvent("response.reasoning_summary_text.delta", {
Line 294: case "response.reasoning_summary_part.added":
Line 307: case "response.reasoning_summary_part.done":
Line 308: beforeTrigger = sseEvent("response.reasoning_summary_part.added", {
Line 326: case ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/test/openai-responses-recall-aware-stream.test.ts</path>
<type>file</type>
<content>
5180: summary: [{ type: "summary_text", text: "prefix" }],
5181: },
5182: }),
5183: completed("resp_summary_prefix"),
5184: ]),
5185: {
5186: onComplete: () => {},
5187: onRecall: async () => ({ anchorText: "", resultText: "" }),
5188: runFollowUp: async () => {
5189: throw new Error("should not run");
5190: },
5191: },
5192: );
5193:
5194: expect(await drain(client)).not.toContain("response.failed");
5195: });
5196:
5197: test("accepts indexed reasoning-text content lifecycles", async () => {
5198: const client = streamResponsesRecallAware(
5199: streamFrom([
5200: created("resp_reasoning_text", "gpt-5.6-terra"),
5201: sseEvent("response.output_item.added", {
5202: output_index: ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
11540: throw new RecallContinuationFailure(
11541: "depth_exhausted",
11542: );
11543: } else {
11544: nextAcc = finalizeResponsesAcc(contState);
11545: const pendingNextRecall = contPending[0];
11546: const contentPosition = nextAcc.content.findIndex(
11547: (block) =>
11548: block.type === "tool_use" &&
11549: block.id === pendingNextRecall.toolUseId,
11550: );
11551: if (contentPosition < 0) {
11552: throw new RecallContinuationFailure(
11553: "missing_recall_block",
11554: ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/stream/openai-responses.ts</path> <type>file</type> <content> 1: /** 2: * OpenAI Responses API SSE stream accumulator. 3: * 4: * Parses upstream Responses API streaming events and accumulates the full 5: * response into a `GatewayResponse`. The Responses API uses a different 6: * SSE event lifecycle than Anthropic: 7: * 8: * response.created → response.in_progress → 9: * response.output_item.added → response.output_text.delta (repeated) → 10: * response.output_item.done → response.function_call_arguments.delta → 11: * response.function_call_arguments.done → 12: * response.completed 13: * 14: * Reuses `parseSSEStream` from the Anthropic stream module since the 15: * underlying SSE wire format is the same. ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
18880: resp,
18881: sessionState.sessionID,
18882: sessionState.resolvedConversationTTL,
18883: genAiSpan,
18884: endGenAiSpan,
18885: () => {
18886: sessionState._dirty = true;
18887: },
18888: );
18889: },
18890: dropStreamingFinalizer,
18891: true,
18892: requestCredentialFingerprint(req.rawHeaders, config) ?? undefined,
18893: );
18894: }
18895: async function captureUnsuccessfulResponses(
18896: operation: Promise<GatewayResponse>,
18897: ): Promise<{ response: GatewayResponse; successful: boolean } | undefined> {
18898: try {
18899: return { response: await operation, successful: true };
18900: } catch (error) {
18901: if (!(error instanceof ResponsesTerminalError)) throw error;
18902: ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
18720: currentModifiedReq = followUp;
18721: // Recall can consume another quota window or omit quota metadata entirely.
18722: // Keep this turn's ordered updates so the rebuilt stream reports every
18723: // bucket, with newer updates following older ones.
18724: if (currentResp.codexRateLimits?.length) {
18725: continuationResp.codexRateLimits = [
18726: ...currentResp.codexRateLimits,
18727: ...(continuationResp.codexRateLimits ?? ...
+ test("accumulates the principal event that crosses the retained-state limit", async () => {
+ test.each(LIFECYCLE_ONLY_EVENTS)(
+ test.each(
+ test("retains a sparse principal Codex function call resolved by the limit-crossing done event", async () => {
+ test("accumulates a continuation item_reference before suppressing it", async () => {
+ test("accumulates a principal item_reference before its retained-state limit", async () => {
+ test("accumulates a continuation item_reference before its retained-state limit", async () => {
+ test("preserves an accepted sparse message content coordinate", async () => {
+ test("preserves sparse Codex content when done and terminal snapshots omit content", async () => {
+ test.each(["absent", "empty"] as const)(
+ test.each(["absent", "empty"] as const)(
+ test.each(
+ test.each(["principal", "continuation"] as const)(
+ test.each(
+ test.each([
+ test.each([
+ test.each([
+ test("accumulates the continuation event that crosses ...
Found 30 matches
/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/test/openai-responses-recall-aware-stream.test.ts:
Line 969: test("accumulates the principal event that crosses the retained-state limit", async () => {
Line 1070: "retains principal %s state when it crosses the retained-state limit",
Line 2550: test("accumulates a continuation item_reference before suppressing it", async () => {
Line 2600: test("accumulates a principal item_reference before its retained-state limit", async () => {
Line 2644: test("accumulates a continuation item_reference before its retained-state limit", async () => {
Line 2764: test("preserves an accepted sparse message content coordinate", async () => {
Line 3307: test("preserves sparse Codex content when done and terminal snapshots omit content", async () => {
Line 4426: "rejects repeated terminal reasoning ciphertext %s after done B",
Line 4477: test("rejects malformed terminal ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/test/openai-responses-recall-aware-stream.test.ts</path>
<type>file</type>
<content>
2400: type: "web_search_call",
2401: id: "ws_terminal_metadata",
2402: action: { type: "search", query: "lore" },
2403: },
2404: terminalItem: {
2405: type: "web_search_call",
2406: id: "ws_terminal_metadata",
2407: status: "completed",
2408: action: { type: "search", query: "lore" },
2409: },
2410: },
2411: ])(
2412: "accepts terminal enrichment with optional $name",
2413: async ({ doneItem, terminalItem }) => {
2414: const client = streamResponsesRecallAware(
2415: streamFrom([
2416: created("resp_terminal_metadata", "gpt-5.6-terra"),
2417: sseEvent("response.output_item.added", {
2418: output_index: 0,
2419: item: doneItem,
2420: }),
2421: ...
Found 24 matches
/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/test/openai-responses-recall-aware-stream.test.ts:
Line 6190: test("rejects reference identities colliding with synthetic markers", async () => {
Line 6531: test("rejects continuation references colliding with principal identities", async () => {
Line 7213: test("rejects continuation identities that collide with principal output", async () => {
Line 8885: test("rejects an upstream item that collides with the synthetic anchor ID", async () => {
Line 9077: test("rejects a call_id that collides with the synthetic anchor ID", async () => {
/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/test/anthropic-client-openai-upstream-stream.test.ts:
Line 187: // it falls back to the fixed DEFAULT_PORT and two files collide, and in the
/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/test/recall.test.ts:
Line 3134: test("replaces raw ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/test/openai-responses-recall-aware-stream.test.ts</path>
<type>file</type>
<content>
6100: item_id: "fc_failed_companion",
6101: arguments: companionArgs,
6102: }),
6103: sseEvent("response.output_item.done", {
6104: output_index: 1,
6105: item: {
6106: type: "function_call",
6107: id: "fc_failed_companion",
6108: call_id: "call_failed_companion",
6109: name: "read",
6110: arguments: companionArgs,
6111: },
6112: }),
6113: sseEvent("response.completed", {
6114: response: {
6115: id: "resp_failed_companion",
6116: model: "gpt-5.6-terra",
6117: status: "completed",
6118: output: [
6119: {
6120: type: "function_call",
6121: id: "fc_failed_companion",
6122: ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/stream/openai-responses.ts</path>
<type>file</type>
<content>
1160: if (item.type === "message") return "text";
1161: if (item.type === "function_call") return "tool_use";
1162: return null;
1163: }
1164:
1165: function codexEventItemKind(event: string): "text" | "tool_use" | null {
1166: if (
1167: event === "response.output_text.delta" ||
1168: event === "response.output_text.done" ||
1169: event === "response.refusal.delta" ||
1170: event === "response.refusal.done" ||
1171: event === "response.content_part.added" ||
1172: event === "response.content_part.done"
1173: ) {
1174: return "text";
1175: }
1176: if (
1177: event === "response.function_call_arguments.delta" ||
1178: event === "response.function_call_arguments.done"
1179: ) {
1180: return "tool_use";
1181: }
1182: return null;
1183: }
1184:
1185: function ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/package.json</path>
<type>file</type>
<content>
1: {
2: "name": "@loreai/gateway",
3: "version": "0.40.0",
4: "type": "module",
5: "license": "FSL-1.1-Apache-2.0",
6: "description": "Lore as a transparent LLM proxy — context management for any AI coding client",
7: "main": "./dist/index.cjs",
8: "types": "./dist/index.d.cts",
9: "exports": {
10: ".": {
11: "types": "./dist/index.d.cts",
12: "bun": "./dist/index.bun.js",
13: "require": "./dist/index.cjs",
14: "default": "./dist/index.cjs"
15: }
16: },
17: "bin": {
18: "lore": "./dist/bin.cjs",
19: "lore-gateway": "./dist/bin.cjs"
20: },
21: "scripts": {
22: "typecheck": "tsc --noEmit",
23: "build": "tsx script/build.ts",
24: "bundle": "tsx script/bundle.ts",
25: "build:binary": "tsx script/build.ts --binary",
26: "build:binary:sea": "tsx script/build-binary-sea.ts",
27: ...
RUN v4.1.8 /home/byk/Code/opencode-lore-responses-accumulation
Test Files 1 passed (1)
Tests 50 passed | 227 skipped (277)
Start at 10:19:34
Duration 15.27s (transform 8.47s, setup 1.31s, import 12.71s, tests 611ms, environment 0ms)
Found 100 matches (more matches available)
/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/test/cache-warmer.test.ts:
Line 466: const breakpoints = (fromStore.messages as Array<{ content: unknown[] }>)
Line 492: const breakpoints = (result.messages as Array<{ content: unknown[] }>)
/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/test/openai-responses-recall-aware-stream.test.ts:
Line 369: part: { type: "output_text", text: "content value", annotations: [] },
Line 507: test("forwards a principal response.failed exactly once when no recall occurs", async () => {
Line 749: const seen: Array<{ outputIndex: number; contentPosition: number }> = [];
Line 1048: expect(completedResponse?.content).toEqual([]);
Line 1049: expect(completedResponse?.rawOutputItems).toEqual([]);
Line 1064: expect(outcomes).toEqual([false]);
Line 1117: expect(completedResponse?.content).toEqual([]);
Line ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/test/openai-responses-recall-aware-stream.test.ts</path>
<type>file</type>
<content>
930: runFollowUp: async () => {
931: throw new Error("should not run");
932: },
933: },
934: );
935: const out = await drain(client);
936: expect(out).toContain("response.failed");
937: expect(out).toContain(PUBLIC_GATEWAY_ERROR);
938: expect(out).not.toContain(PUBLIC_RECALL_ERROR);
939: expect(retries).toBe(0);
940: expect(errors).toEqual([
941: "openai-responses recall-aware stream failed category=principal_resource_limit",
942: ]);
943: });
944:
945: test("does not retry a pre-output principal resource limit", async () => {
946: let retries = 0;
947: const client = streamResponsesRecallAware(
948: streamFrom([created("resp_pre_output_limit", "gpt-5.6-terra")]),
949: {
950: maxStreamBytes: 1,
951: onComplete: () => ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/src/stream/openai-responses.ts</path>
<type>file</type>
<content>
1745:
1746: /**
1747: * Normalize one sparse Codex event and advance an independent normalization
1748: * state. Callers that also accumulate the event must use a separate state: the
1749: * Codex normalizer binds omitted indices and may seed done-only items.
1750: */
1751: export function normalizeCodexResponsesEvent(
1752: state: ResponsesAccState,
1753: event: string,
1754: parsed: Record<string, unknown>,
1755: maxSparseIndex = DEFAULT_MAX_SSE_FRAMES,
1756: ): void {
1757: validateCodexResponsesEvent(state, event, parsed, maxSparseIndex);
1758: if (
1759: (event === "response.function_call_arguments.delta" ||
1760: event === "response.function_call_arguments.done") &&
1761: state.argumentDoneItems.has(parsed.output_index as number)
1762: ) {
1763: malformedResponsesEvent();
1764: }
1765: if (event === ...
Found 60 matches
/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/test/openai-responses-recall-aware-stream.test.ts:
Line 2310: type: "item_reference",
Line 2497: test("never forwards response-side item_reference lifecycle events", async () => {
Line 2507: type: "item_reference",
Line 2514: type: "item_reference",
Line 2523: output: [{ type: "item_reference", id: "msg_server_only" }],
Line 2538: expect(out).not.toContain("item_reference");
Line 2540: expect(JSON.stringify(completedResponse)).not.toContain("item_reference");
Line 2544: acc.rawItems.get(0)?.type === "item_reference" &&
Line 2550: test("accumulates a continuation item_reference before suppressing it", async () => {
Line 2557: item: { type: "item_reference", id: "msg_followup_server_only" },
Line 2561: item: { type: "item_reference", id: "msg_followup_server_only" },
Line 2587: ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/test/openai-responses-recall-aware-stream.test.ts</path>
<type>file</type>
<content>
2260: expect.objectContaining({
2261: id: "fc_terminal_name",
2262: call_id: "call_terminal_name",
2263: name: "read",
2264: }),
2265: );
2266: expect(completedResponse?.content).toEqual([]);
2267: expect(completedResponse?.rawOutputItems).toEqual([]);
2268: expect(recallCalls).toBe(0);
2269: });
2270:
2271: test("rejects malformed terminal output items", async () => {
2272: const client = streamResponsesRecallAware(
2273: streamFrom([
2274: created("resp_terminal_malformed", "gpt-5.6-terra"),
2275: textItem(0, "answer", "msg_terminal_malformed"),
2276: sseEvent("response.completed", {
2277: response: {
2278: id: "resp_terminal_malformed",
2279: model: "gpt-5.6-terra",
2280: status: ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/gateway/test/openai-responses-recall-aware-stream.test.ts</path>
<type>file</type>
<content>
3080: status: "completed",
3081: },
3082: }),
3083: completed("resp_sparse_promotion_limit"),
3084: ]),
3085: {
3086: validation: "codex",
3087: maxDeferredBytes: 16 * 1024,
3088: maxHiddenRecallBytes: 1,
3089: maxRetainedStateBytes: 64 * 1024,
3090: onComplete: (response, didSucceed) => {
3091: completedResponse = response;
3092: successful = didSucceed;
3093: },
3094: onRecall: async () => {
3095: recallCalls++;
3096: return { anchorText: "anchor", resultText: "result" };
3097: },
3098: runFollowUp: async () => {
3099: throw new Error("should not run");
3100: },
3101: },
3102: );
3103:
3104: const output = await drain(client);
3105: ...
RUN v4.1.8 /home/byk/Code/opencode-lore-responses-accumulation
Test Files 1 passed (1)
Tests 41 passed | 236 skipped (277)
Start at 10:22:57
Duration 13.66s (transform 7.87s, setup 1.38s, import 10.92s, tests 1.05s, environment 0ms)
e04bcad76518a4d55cf7d48c39ab28cf7c462e6c5cf42072b47a84ce051134dd packages/gateway/src/pipeline.ts 46943c92c9dc972617ec8a48d56fb3b9fd47a8d00da7b61b3f15af149e65803b packages/gateway/src/stream/openai-responses.ts 65eb9cda08c0a24d8be9f138bde01840375cfcd8168c53b2e582eead3ba66ae2 packages/gateway/test/openai-responses-recall-aware-stream.test.ts
packages/gateway/src/pipeline.ts | 792 +++--- packages/gateway/src/stream/openai-responses.ts | 1 + ...st/openai-responses-recall-aware-stream.test.ts | 2567 +++++++++++++++++++++- 3 files changed, 3105 insertions(+), 255 deletions(-)
<path>/home/byk/.local/share/opencode/tool-output/tool_0aed42422001sfIXf1t7iKq1yM</path>
<type>file</type>
<content>
1: diff --git a/packages/gateway/src/pipeline.ts b/packages/gateway/src/pipeline.ts
2: index 004e03b3e2..de8aadf7e5 100644
3: --- a/packages/gateway/src/pipeline.ts
4: +++ b/packages/gateway/src/pipeline.ts
5: @@ -7933,6 +7933,7 @@
6: acc: ResponsesAccState,
7: event: string,
8: parsed: Record<string, unknown>,
9: + outputOffset = 0,
10: ): ResponsesAccState | undefined => {
11: if (opts.validation !== "codex") return undefined;
12: let normalizationState = codexNormalizationStates.get(acc);
13: @@ -7940,11 +7941,21 @@
14: normalizationState = makeResponsesAccState();
15: codexNormalizationStates.set(acc, normalizationState);
16: }
17: + // Tighten Codex's local exclusive ceiling by the continuation shift. ...
<path>/home/byk/.local/share/opencode/tool-output/tool_0aed42422001sfIXf1t7iKq1yM</path>
<type>file</type>
<content>
1264: +function sparseCoordinateScenario(
1265: + kind: SparseCoordinateKind,
1266: + coordinate: number,
1267: + suffix: string,
1268: + value = "private sparse coordinate value",
1269: +): { added: string; trigger: string; itemId: string } {
1270: + const itemId = `item_sparse_coordinate_${kind}_${suffix}`;
1271: + if (kind === "output") {
1272: + return {
1273: + added: "",
1274: + trigger: sseEvent("response.output_item.added", {
1275: + output_index: coordinate,
1276: + item: {
1277: + type: "message",
1278: + id: itemId,
1279: + role: "assistant",
1280: + content: [{ type: "output_text", text: value }],
1281: + },
1282: + }),
1283: + itemId,
1284: + };
1285: + }
1286: + const reasoning = kind === "summary";
1287: + return {
1288: + added: ...
<path>/home/byk/.local/share/opencode/tool-output/tool_0aed42422001sfIXf1t7iKq1yM</path>
<type>file</type>
<content>
2664: + ],
2665: + },
2666: + }),
2667: + ]);
2668: + const client = streamResponsesRecallAware(
2669: + streamFrom([
2670: + created("resp_terminal_reasoning_principal", "gpt-5.6-terra"),
2671: + recallCall(0, { query: "accepted" }),
2672: + completed("resp_terminal_reasoning_principal"),
2673: + ]),
2674: + {
2675: + validation: "codex",
2676: + onComplete: () => {},
2677: + onRecall: async () => {
2678: + recallCalls++;
2679: + return {
2680: + anchorText: buildAnchor("accepted"),
2681: + resultText: "memory",
2682: + };
2683: + },
2684: + runFollowUp: async () => {
2685: + followUps++;
2686: + if (!followUp.body) throw new Error("missing follow-up ...
The working copy has no changes. Working copy (@) : quqnzmlz 34cd6f80 (empty) (no description set) Parent commit (@-): vsutowno a8546e30 fix/responses-accumulation-order | fix(responses): accumulate private references Warning: These bookmarks have conflicts: fix/responses-private-references Hint: Use `jj bookmark list` to see details. Use `jj bookmark set <name> -r <rev>` to resolve.
vsutowno ben@byk.im 2026-09-17 01:54:33 fix/responses-accumulation-order a8546e30 fix(responses): accumulate private references rwunmtrq ben@byk.im 2026-09-16 21:25:39 21ad2a5c fix(responses): complete accumulation boundaries pxrvwsvv 41898282+github-actions[bot]@users.noreply.github.com 2026-09-15 08:31:50 main 2cbf4006 feat(cch): add seeds for Claude Code up to 2.1.272 (#1780)
M packages/gateway/src/pipeline.ts M packages/gateway/src/stream/openai-responses.ts M packages/gateway/test/openai-responses-recall-aware-stream.test.ts
bd34f024169d371c4b1c3e26bf3f0b66f43ce7540014db109d1ae9dd38b60631 -
(no output)
e04bcad76518a4d55cf7d48c39ab28cf7c462e6c5cf42072b47a84ce051134dd packages/gateway/src/pipeline.ts 46943c92c9dc972617ec8a48d56fb3b9fd47a8d00da7b61b3f15af149e65803b packages/gateway/src/stream/openai-responses.ts 65eb9cda08c0a24d8be9f138bde01840375cfcd8168c53b2e582eead3ba66ae2 packages/gateway/test/openai-responses-recall-aware-stream.test.ts
Found 2 matches
/home/byk/Code/opencode-lore-responses-accumulation/packages/core/src/log.ts:
Line 51: error(message: string, attrs?: Record<string, unknown>): void;
Line 497: export function error(...args: unknown[]): void {
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/core/src/log.ts</path>
<type>file</type>
<content>
450: fd = openLogFileForAppend(path);
451: writeFileSync(fd, line, "utf8");
452: } catch {
453: // Silently degrade — logging failure shouldn't crash the app
454: } finally {
455: if (fd !== undefined) closeSync(fd);
456: }
457: }
458:
459: // ---------------------------------------------------------------------------
460: // Public API
461: // ---------------------------------------------------------------------------
462:
463: /** Log an informational status message. Suppressed unless LORE_DEBUG=1. */
464: export function info(...args: unknown[]): void {
465: const msg = redactSensitiveLogText(formatArgs(args));
466: if (isDebug && !readStderrSilenced())
467: console.error("[lore]", ...safeArgs(args));
468: sink?.info(msg);
469: writeToFile("info", msg);
470: }
471:
472: /** Log a warning. Suppressed unless LORE_DEBUG=1. ...
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/core/src/log.ts</path>
<type>file</type>
<content>
360: const info = fstatSync(fd);
361: if (!info.isFile()) {
362: throw new Error(`Refusing non-regular rotated log file: ${path}`);
363: }
364: assertCurrentOwner(info, path);
365: assertSameFile(existing, info, path);
366: unlinkSync(path);
367: } finally {
368: closeSync(fd);
369: }
370: }
371:
372: /**
373: * Resolve the log file path. Returns `undefined` in test environments
374: * or if the directory cannot be created.
375: */
376: function resolveLogPath(): string | undefined {
377: if (process.env.NODE_ENV === "test") return undefined;
378: try {
379: const dir = dataDir();
380: mkdirSync(dir, { recursive: true, mode: LOG_DIRECTORY_MODE });
381: validateLogDirectory(dir);
382: const path = join(dir, "lore.log");
383: // Harden both active and previously rotated logs immediately. ...
Found 4 matches
/home/byk/Code/opencode-lore-responses-accumulation/packages/core/src/log.ts:
Line 150: function formatArgs(args: unknown[]): string {
Line 175: export function redactSensitiveLogText(value: string): string {
Line 206: function safeArgs(args: unknown[]): string[] {
Line 218: function sanitizedError(error: Error): Error {
<path>/home/byk/Code/opencode-lore-responses-accumulation/packages/core/src/log.ts</path>
<type>file</type>
<content>
140: export function silenceStderr(silenced = true): void {
141: (globalThis as Record<string, unknown>)[STDERR_SILENCED_KEY] = silenced;
142: }
143:
144: /** Whether stderr output is currently silenced (embedded/TUI mode). */
145: export function isStderrSilenced(): boolean {
146: return readStderrSilenced();
147: }
148:
149: /** Format variadic args into a single string for the sink. */
150: function formatArgs(args: unknown[]): string {
151: return args
152: .map((a) =>
153: typeof a === "string" ? a : a instanceof Error ? a.message : String(a),
154: )
155: .join(" ");
156: }
157:
158: /** Extract the first Error instance from the args list, if any. ...
MUST-FIX — terminal item_reference forms can reach the public wire. assertTerminalOutputMatches() accepts an item_reference as a match for any streamed item with the same ID, regardless of item type (packages/gateway/src/pipeline.ts:9534-9554). stripHiddenReferenceOutput() removes it only when its ID exists in referenceIdentities (:9699-9718). A terminal reference to an ordinary streamed message therefore survives, and the no-recall path forwards that terminal verbatim (:10714-10725). This breaks the invariant that response-side references and terminal forms never become public. Rebuild or project every terminal containing references from accumulated full items, and add a Codex no-recall regression.
MUST-FIX — done-only Codex references bypass private accumulation and suppression. consumeReferenceEvent() creates reference state only for response.output_item.added; a done event without prior reference state returns undefined (packages/gateway/src/pipeline.ts:9627-9673). The caller then sends it through generic Codex done-only synthesis (:10429-10445, :8511-8537) and eventually forwards it as an ordinary event (:11749-11760). Test explicit and omitted indices on principal and continuation streams. Either reject done-only references before generic synthesis or synthesize a private completed reference lifecycle and suppress it.
MUST-FIX — forged lifecycle names still bypass the new allowlist. assertSparseCoordinates() rejects forged reasoning_summary and reasoning_text names only (packages/gateway/src/pipeline.ts:8435-8457). The validator still interprets any response.content_part… prefix (:8500-8503, :8748-8782), and its fallback treats an arbitrary name ending in .done as a real completion (:8798-8860). For example, response.content_part.private.done can carry a reasoning_text secret, satisfy later reconciliation, and be forwarded before recall detection at :11749-11760. ...
Date: Sep 17, 2026 * 🔴 (10:05) User required that recall never execute from an incomplete principal, reflected by the test `"never executes recall from an incomplete principal"` in `packages/gateway/test/openai-responses-recall-aware-stream.test.ts`. * 🟡 (10:05) The incomplete-principal regression test was extended with a `response.reasoning_summary_text.done` SSE event for `output_index: 0`, `…
Date: Sep 17, 2026 * 🟡 [requested-review] (10:02) User requested an independent, immutable security/privacy/pentest review of `/home/byk/Code/opencode-lore-responses-accumulation`, covering candidate stable change `vsutownopktwxvuvywqszxnkqwultovt` at head `a8546e30bf105242fb6f78a05d9d6cb7b2f3ed6e` against exact base `2cbf40060c67df229731cf1b9e34d5bf22ec2145`. * 🔴 (10:02) User stated the expect…