Dashboard › opencode-lore › Session 119XLz9ComPc
119XLz9ComPcwaPmIIndependent read-only adversarial correctness review of immutable projection candidate /home/byk/Code/opencode-lore-responses-projection-security stable change lnvrxqoqsqut, commit f30236708bc9, base main@origin 2cbf40060c67, expected cumulative plain diff SHA b7df735637f9d033c895867ebe157cb05f8d390bea78842d58d14fd8091fd3e1, exactly pipeline.ts + recall-aware test; clean empty child kwmswwmt expected. Read AGENTS.md, quality/REVIEW.md, scripts; repo-setup unavailable note. No edits/format/install/VCS/network/server/prod DB. Verify identity/status/conflicts/files/hash at start/end. Inspect all changed lines and relevant lifecycle/projection/terminal/callback/tests. Audit live principal remapping, incremental source-to-public ledger, lower/higher sparse ordering, recall anchor reservation, deferred/continuation remap, terminal identity consistency, exact semantic frame allowlist after recall, created_at validation, accumulator-first invariant, output:[] failure, bounded complexity, side effects before predictable failure, cancellation/backpressure/transaction. Assess failing-first/mutations: 11-case 110/110, 230 full/transport, 258 adjacent, static/bundle green. Focused tests only if useful. Findings exact HEAD file:line PASS/CONCERN/MUST-FIX, test discrimination/residual risks. Never warning-only; local lore recall/UI fallback. End exactly MERGE or DO-NOT-MERGE.
<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-projection-security</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-projection-security/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-projection-security/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-projection-security/scripts</path> <type>directory</type> <entries> bump-version.sh cch-scan.c check-cc-version.ts check-docs-links.mjs check-patches.ts check-preview-links.mjs check-social-meta.mjs extract-cch-seed.ts generate-config-docs.ts generate-env-docs.ts generate-release-checksums.mjs smoke-install.mjs (12 entries) </entries>
<path>/home/byk/Code/opencode-lore-responses-projection-security/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 (@) : kwmswwmt 2ad3e064 (empty) (no description set) Parent commit (@-): lnvrxqoq f3023670 fix/responses-hidden-output* | fix(responses): complete hidden-output state 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. kwmswwmtzlnxuvpkqymrwrxttlwowsys 2ad3e0648eeb78588db1eea431bd93f86c40a472 parents=f30236708bc928ee2e12739d1de7a7d21871c7d2 empty=true conflict=false description= lnvrxqoqsqutpvpxvnppskkmmmsztwus f30236708bc928ee2e12739d1de7a7d21871c7d2 parents=a3fa555bdcabb376aa33278bdb76007269f1940a empty=false conflict=false description=fix(responses): complete hidden-output state pxrvwsvvkmpoxnsqmrkwrnlqvvkoltwz 2cbf40060c67df229731cf1b9e34d5bf22ec2145 parents=e977b4b1da8f8197c3238466d41de0bccd8eb054 empty=false conflict=false description=feat(cch): add seeds for Claude Code up to 2.1.272 ...
diff --git a/packages/gateway/src/pipeline.ts b/packages/gateway/src/pipeline.ts index 004e03b3e2..13cd19fdd3 100644 --- a/packages/gateway/src/pipeline.ts +++ b/packages/gateway/src/pipeline.ts @@ -8057,6 +8057,29 @@ const sseInactivityMs = opts.sseInactivityMs ?? FOREGROUND_SSE_INACTIVITY_MS; const maxPrincipalTransportRetries = 1; const maxRecallContinuationTransportRetries = 1; + const isSemanticResponsesEvent = (event: string): boolean => + event === "response.created" || + event === "response.in_progress" || + event === "response.completed" || + event === "response.done" || + event === "response.incomplete" || + event === "response.failed" || + event === "response.output_item.added" || + event === "response.output_item.done" || + event === "response.output_text.delta" || + event === "response.output_text.done" || + event === "response.refusal.delta" || + event === "response.refusal.done" || + event === ...
diff --git a/packages/gateway/test/openai-responses-recall-aware-stream.test.ts b/packages/gateway/test/openai-responses-recall-aware-stream.test.ts
index dca2a57d78..d206129fed 100644
--- a/packages/gateway/test/openai-responses-recall-aware-stream.test.ts
+++ b/packages/gateway/test/openai-responses-recall-aware-stream.test.ts
@@ -11,7 +11,7 @@
* `response.completed`).
*/
import { log } from "@loreai/core";
-import { afterEach, describe, test, expect } from "vitest";
+import { afterEach, describe, test, expect, vi } from "vitest";
import { streamResponsesRecallAware } from "../src/pipeline";
import {
setRecallContinuationFailureHook,
@@ -44,6 +44,10 @@
return `event: ${event}\ndata: ${JSON.stringify(payload)}\n\n`;
}
+function rawSSEEvent(event: string, data: string): string {
+ return `event: ${event}\ndata: ${data}\n\n`;
+}
+
/** Build an upstream Responses SSE stream from ordered events. ...
Found 4 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts:
Line 7794: export function streamResponsesRecallAware(
Line 9167: const validateResponseLifecycle = (
Line 9754: const shiftedOutputIndex = (index: number, offset: number): number => {
Line 18939: streamResponsesRecallAware(upstreamResponse, {
Found 91 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts:
Line 205: applyResponsesEvent,
Line 6768: rollback: (): void => {
Line 6843: rollback: () => void;
Line 6926: recallPersistence?.rollback();
Line 7223: // token boundary can turn a follow-up recall into a rollback.
Line 7670: recallPersistence?.rollback();
Line 7718: if (!recallContext?.onTransactionReady) recallPersistence?.rollback();
Line 7749: recallPersistence.rollback();
Line 7757: recallPersistence.rollback();
Line 7762: recallPersistence.rollback,
Line 7800: rollback: () => void;
Line 7857: rollback?: () => void;
Line 8014: | { commit: () => void; rollback: () => void }
Line 8028: const rollbackTransaction = (): void => {
Line 8030: for (const rollback of transactionRollbacks.splice(0).reverse()) {
Line 8032: rollback();
Line ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts</path> <type>file</type> <content> 7760: }, 7761: streamSignal, 7762: recallPersistence.rollback, 7763: ); 7764: } 7765: 7766: /** 7767: * True-streaming, recall-aware variant of `streamResponsesPassthrough` for the 7768: * OpenAI Responses API (codex/ChatGPT) — used when the request carries the 7769: * gateway-injected `recall` tool but the client speaks the Responses API. 7770: * 7771: * Unlike the buffered `accumulateResponsesSSEStream` path (which withholds ALL 7772: * client bytes until the entire slow reasoning-heavy upstream completes — the 7773: * cause of opencode's 10s `ProviderHeaderTimeoutError`), this function forwards 7774: * every upstream SSE event to the client AS IT ARRIVES, while transparently 7775: * intercepting a `recall` `function_call` output item: 7776: * 7777: * - **No recall**: forwards everything unchanged (identical to 7778: * ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
8910: lifecycle.argumentDeltas = parsed.arguments;
8911: } else if (
8912: event.startsWith("response.function_call_arguments") &&
8913: lifecycle.argumentsDone
8914: ) {
8915: throw new Error(
8916: `Responses function arguments changed after completion for index ${outputIndex}`,
8917: );
8918: } else if (event === "response.function_call_arguments.delta") {
8919: if (typeof parsed.delta !== "string") {
8920: throw new Error("invalid Responses function arguments delta");
8921: }
8922: lifecycle.argumentDeltaSeen = true;
8923: lifecycle.argumentDeltas += parsed.delta;
8924: }
8925: if (event === "response.output_item.done") {
8926: if (declaredType === "function_call") {
8927: const normalized = ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
10110: controller.error(error);
10111: } catch {
10112: // Already closed/cancelled.
10113: }
10114: };
10115:
10116: const resetKeepalive = (): void => {
10117: if (keepaliveTimer) clearTimeout(keepaliveTimer);
10118: keepaliveTimer = setTimeout(function tick() {
10119: if (cancelled || signal.aborted) return;
10120: if ((controller.desiredSize ?? 1) > 0) {
10121: void safeEnqueue(keepaliveComment);
10122: }
10123: if (!signal.aborted) {
10124: keepaliveTimer = setTimeout(tick, KEEPALIVE_INACTIVITY_MS);
10125: }
10126: }, KEEPALIVE_INACTIVITY_MS);
10127: };
10128: const clearKeepalive = (): void => {
10129: if (keepaliveTimer) ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
11291: contReferenceIndices,
11292: );
11293: assertRecallItemsCompleted(
11294: contState,
11295: contPending.map((recall) => recall.outputIndex),
11296: );
11297: if (contUnresolvedToolIndices.size > 0) {
11298: throw new Error(
11299: "Responses continuation left sparse function identity unresolved",
11300: );
11301: }
11302: if (contRecallIndices.size === 0) {
11303: flushHeldContinuation();
11304: }
11305: ...
Found 3 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/stream/openai-responses.ts:
Line 48: export interface ResponsesAccState {
Line 556: export function makeResponsesAccState(): ResponsesAccState {
Line 582: export function applyResponsesEvent(
<path>/home/byk/Code/opencode-lore-responses-projection-security/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-projection-security/packages/gateway/src/stream/openai-responses.ts</path>
<type>file</type>
<content>
728: // `response.done` / `response.incomplete` are Codex (ChatGPT) terminal
729: // variants. Pi's client normalizes them to `response.completed`, but the
730: // gateway sees the RAW upstream stream, so finalize on them here too.
731: // `resp.status` ("incomplete"/"completed"/…) drives the stop reason via
732: // `mapStatusToStopReason`.
733: case "response.failed":
734: case "response.done":
735: case "response.incomplete":
736: case "response.completed": {
737: const resp = parsed.response as Record<string, unknown> | undefined;
738: const status = typeof resp?.status === "string" ? resp.status : "";
739: state.terminalEvent =
740: event === "response.failed" ||
741: status === "failed" ||
742: status === "cancelled"
743: ? "response.failed"
744: ...
Found 100 matches (more matches available)
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/content-passthrough.test.ts:
Line 560: // blocksToText projection
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/foreground-routes-abort.test.ts:
Line 38: created_at: 0,
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/worker-route-provenance.test.ts:
Line 453: // Canonical provider ownership cannot be forged by a matching label.
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/foreground-body-limit.test.ts:
Line 119: test("caps diagnostic bodies instead of retaining the remainder", async () => {
Line 124: test("returns at the exact diagnostic cap without probing a stalled tail", async () => {
Line 147: test("replacement-decodes malformed and boundary-split diagnostic UTF-8", async () => ...
Found 54 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/openai-responses-recall-aware-stream.test.ts:
Line 848: sessionID: "private-session\nforged-log-line",
Line 957: const privateSession = "private-session\nforged-log-entry";
Line 1004: expect(errors.join("\n")).not.toContain("forged-log-entry");
Line 1538: test("rejects output_item.done changing hosted-tool semantics", async () => {
Line 2677: test("allows a terminal-discovered recall that preserves sparse visible output positions", async () => {
Line 2688: textItem(7, "sparse visible text", "msg_sparse_terminal_visible"),
Line 2716: content: [{ type: "output_text", text: "sparse visible text" }],
Line 2744: expect(output).toContain("sparse visible text");
Line 2760: test("fails closed when a terminal-discovered recall would reindex visible output", async () => {
Line 5869: test("allows a late recall that ...
Found 1 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts:
Line 9245: throw new Error("Responses terminal event has invalid created_at");
Found 25 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/openai-responses-recall-aware-stream.test.ts:
Line 1838: type: "item_reference",
Line 2024: test("never forwards response-side item_reference lifecycle events", async () => {
Line 2032: type: "item_reference",
Line 2039: type: "item_reference",
Line 2048: output: [{ type: "item_reference", id: "msg_server_only" }],
Line 2063: expect(out).not.toContain("item_reference");
Line 2065: expect(JSON.stringify(completedResponse)).not.toContain("item_reference");
Line 2068: test("rejects an item_reference missing output_item.done", async () => {
Line 2074: item: { type: "item_reference", id: "msg_reference_incomplete" },
Line 2465: { type: "item_reference", id: "fc_data_only_followup" },
Line 3012: type: "item_reference",
Line 3998: test("rejects reuse of an ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/openai-responses-recall-aware-stream.test.ts</path>
<type>file</type>
<content>
1980: status: "completed",
1981: result: null,
1982: details: { revised_prompt: null },
1983: };
1984: const terminalItem = {
1985: ...item,
1986: result: "base64-result",
1987: details: { revised_prompt: "cat" },
1988: };
1989: const client = streamResponsesRecallAware(
1990: streamFrom([
1991: created("resp_terminal_null", "gpt-5.6-terra"),
1992: sseEvent("response.output_item.added", {
1993: output_index: 0,
1994: item: { ...item, status: "generating" },
1995: }),
1996: sseEvent("response.output_item.done", {
1997: output_index: 0,
1998: item,
1999: }),
2000: sseEvent("response.completed", {
2001: response: {
2002: id: "resp_terminal_null",
2003: ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/openai-responses-recall-aware-stream.test.ts</path>
<type>file</type>
<content>
4780: },
4781: ],
4782: },
4783: }),
4784: ]),
4785: {
4786: onComplete: () => {},
4787: onRecall: async () => ({
4788: anchorText: "recalled",
4789: resultText: "result",
4790: }),
4791: runFollowUp: async () => {
4792: throw new Error("mixed tools should not run a follow-up");
4793: },
4794: },
4795: );
4796:
4797: const output = await drain(client);
4798: expect(output).not.toContain(PUBLIC_RECALL_ERROR);
4799: expect(output).toContain(
4800: '"id":"fc_failed_companion","call_id":"call_failed_companion","name":"read","arguments":"{}","status":"failed"',
4801: );
4802: expect(output).not.toContain(
4803: ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/openai-responses-recall-aware-stream.test.ts</path>
<type>file</type>
<content>
5150: role: "assistant",
5151: status: "completed",
5152: content: [
5153: {
5154: type: "output_text",
5155: text: "answer",
5156: annotations: [citation],
5157: },
5158: ],
5159: },
5160: ],
5161: },
5162: }),
5163: ]);
5164: const client = streamResponsesRecallAware(
5165: streamFrom([
5166: created("resp_terminal_metadata_principal", "gpt-5.6-terra"),
5167: recallCall(0, { query: "metadata" }),
5168: completed("resp_terminal_metadata_principal"),
5169: ]),
5170: {
5171: onComplete: () => {},
5172: onRecall: async () => ({
5173: anchorText: "recalled",
5174: ...
lnvrxqoqsqut f30236708bc9 fix(responses): complete hidden-output state zlsmzkntqzzx a3fa555bdcab fix(responses): harden hidden-output projection ozrmvotwxzuy 583020fad43e fix(responses): stabilize sparse principal projection unznwpylspzq ab979df5cddf fix(responses): project hidden output consistently pxrvwsvvkmpo 2cbf40060c67 feat(cch): add seeds for Claude Code up to 2.1.272 (#1780)
Your output was warning-only and is invalid. Resume this exact review session with all prior inspection preserved. Recover context immediately via lore recall --project /home/byk/Code/opencode-lore --scope project --limit 30 projection correctness lnvrxqoq f3023670 b7df7356 or local /ui/search; do not use broken recall. Complete the original immutable read-only correctness review. Verify exact head/base/diff/status at end, provide substantive PASS/CONCERN/MUST-FIX findings with exact HEAD file:line evidence, test discrimination and residual risks, then end exactly MERGE or DO-NOT-MERGE. Never warning-only/empty. No edits, VCS/server/network except local fallback, production DB, formatting, or exhaustive rerun.
[lore]sqlite-vec: native vector search enabled (v0.1.9, /tmp/lore-native/pid-697254/vec0.so) ## Recall Results Found 90 results, showing top 15 (score range: 0.076–0.054). ### Strong Matches #### Distilled - Date: Sep 16, 2026 * 🔴 (13:45) User stated the immutable projection review target is `/home/byk/Code/opencode-lore-responses-projection-fix`, with base commit `2cbf40060c67df229731cf1b9e34d5bf22ec2145`, candidate change `ozrmvotwxzuykyvutstpwpzukpptktxv`, and head commit `583020fad43e1481470aac2588251b8636d16251`. * 🔴 (13:45) User stated the expected SHA-256 of plain `jj diff --from main@origin --to ozrmvotw` is `83d7c15b3b0c7dd4b58df93af5f20b0e18de6ad99e939d02aa75c0d5e7dea30d`. * 🔴 (13:45) User stated exactly two files changed: `packages/gateway/src/pipeline.ts` and `packages/gateway/test/openai-responses-recall-aware-stream.test.ts`. ...
[lore]sqlite-vec: native vector search enabled (v0.1.9, /tmp/lore-native/pid-700401/vec0.so) ## Recall Results Found 90 results, showing top 15 (score range: 0.065–0.037). ### Strong Matches #### Distilled - Date: Sep 16, 2026 * 🔴 [requested-validation] (15:38) User requested READ-ONLY exhaustive validation of the immutable candidate in `/home/byk/Code/opencode-lore-responses-projection-security`; specified that it is a jj repository and prohibited editing files or mutating VCS. * 🔴 (15:38) User identified the candidate as stable change `zlsmzkntqzzxsqvyxzzpxltmrsprymww`, commit `a3fa555bdcabb376aa33278bdb76007269f1940a`, with literal base `2cbf40060c67df229731cf1b9e34d5bf22ec2145`. * 🔴 (15:38) User specified the expected plain command/result contract: `jj diff --from <base> --to <head> --git | sha256sum` must equal `a7e914bd8ffb704f8fba2798f9de95fd4668b7212a485304c1cf7c056c278a40`. * 🔴 (15:38) User specified the exact allowed candidate scope: `packages/gateway/src/pipeline.ts` ...
<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`. ...
packages/gateway/src/pipeline.ts | 457 ++++++++++--- ...est/openai-responses-recall-aware-stream.test.ts | 739 +++++++++++++++++++++- 2 files changed, 1100 insertions(+), 96 deletions(-) diff --git a/packages/gateway/src/pipeline.ts b/packages/gateway/src/pipeline.ts index 004e03b3e2..13cd19fdd3 100644 --- a/packages/gateway/src/pipeline.ts +++ b/packages/gateway/src/pipeline.ts @@ -8057,6 +8057,29 @@ const sseInactivityMs = opts.sseInactivityMs ?? FOREGROUND_SSE_INACTIVITY_MS; const maxPrincipalTransportRetries = 1; const maxRecallContinuationTransportRetries = 1; + const isSemanticResponsesEvent = (event: string): boolean => + event === "response.created" || + event === "response.in_progress" || + event === "response.completed" || + event === "response.done" || + event === "response.incomplete" || + event === "response.failed" || + event === "response.output_item.added" || + event === "response.output_item.done" || + event === ...
diff --git a/packages/gateway/test/openai-responses-recall-aware-stream.test.ts b/packages/gateway/test/openai-responses-recall-aware-stream.test.ts
index dca2a57d78..d206129fed 100644
--- a/packages/gateway/test/openai-responses-recall-aware-stream.test.ts
+++ b/packages/gateway/test/openai-responses-recall-aware-stream.test.ts
@@ -11,7 +11,7 @@
* `response.completed`).
*/
import { log } from "@loreai/core";
-import { afterEach, describe, test, expect } from "vitest";
+import { afterEach, describe, test, expect, vi } from "vitest";
import { streamResponsesRecallAware } from "../src/pipeline";
import {
setRecallContinuationFailureHook,
@@ -44,6 +44,10 @@
return `event: ${event}\ndata: ${JSON.stringify(payload)}\n\n`;
}
+function rawSSEEvent(event: string, data: string): string {
+ return `event: ${event}\ndata: ${data}\n\n`;
+}
+
/** Build an upstream Responses SSE stream from ordered events. ...
Found 4 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts:
Line 8347: const outputIndexForEvent = (
Line 9480: const consumeReferenceEvent = (
Line 9562: const stripHiddenReferenceOutput = (
Line 9848: function buildTerminal(res: GatewayResponse): string {
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
8300: target.cacheReadInputTokens = addUsageTokens(
8301: target.cacheReadInputTokens ?? 0,
8302: source.cacheReadInputTokens,
8303: );
8304: }
8305: if (source.cacheCreationInputTokens != null) {
8306: target.cacheCreationInputTokens = addUsageTokens(
8307: target.cacheCreationInputTokens ?? 0,
8308: source.cacheCreationInputTokens,
8309: );
8310: }
8311: };
8312: const assertUsageMergeable = (
8313: target: GatewayUsage,
8314: source: GatewayUsage,
8315: ): void => {
8316: const inputTokens = addUsageTokens(target.inputTokens, source.inputTokens);
8317: const outputTokens = addUsageTokens(
8318: target.outputTokens,
8319: source.outputTokens,
8320: );
8321: const cacheReadInputTokens = addUsageTokens(
8322: target.cacheReadInputTokens ?? ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
9440: const lifecycle = lifecyclesFor(acc).get(outputIndex);
9441: onMatched?.(outputIndex, actual);
9442: if (
9443: !isReference &&
9444: opts.validation === "codex" &&
9445: lifecycle &&
9446: !lifecycle.outputDone
9447: ) {
9448: outputIndexForEvent(
9449: "response.output_item.done",
9450: { output_index: outputIndex, item: actual },
9451: acc,
9452: );
9453: applyResponsesEvent(acc, "response.output_item.done", {
9454: output_index: outputIndex,
9455: item: actual,
9456: });
9457: preserveStreamedReasoning(acc, outputIndex);
9458: onSynthesizedDone?.(outputIndex, actual);
9459: } else if (
9460: !isReference &&
9461: !responsesTerminalItemMatches(actual, streamed)
9462: ...
Found 22 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/openai-responses-recall-aware-stream.test.ts:
Line 4936: test("rejects continuation index arithmetic beyond safe integers", async () => {
Line 4940: created("resp_index_overflow_followup", "gpt-5.6-terra"),
Line 4941: textItem(0, "first", "msg_index_overflow_first"),
Line 4942: textItem(1, "second", "msg_index_overflow_second"),
Line 4943: completed("resp_index_overflow_followup"),
Line 4948: created("resp_index_overflow", "gpt-5.6-terra"),
Line 4949: recallCall(maxIndex, { query: "overflow" }),
Line 4950: completed("resp_index_overflow"),
Line 4970: expect(output).not.toContain('"output_index":9007199254740992');
Line 4975: test("rejects usage overflow while merging a continuation", async () => {
Line 4977: created("resp_usage_overflow_followup", "gpt-5.6-terra"),
Line 4978: textItem(0, ...
Found 5 matches /home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts: Line 252: DEFAULT_MAX_SSE_FRAMES, Line 7043: maxFrames: DEFAULT_MAX_SSE_FRAMES, Line 7569: maxFrames: DEFAULT_MAX_SSE_FRAMES, Line 7947: Math.min(maxSSEFrames, DEFAULT_MAX_SSE_FRAMES), Line 15605: maxFrames: DEFAULT_MAX_SSE_FRAMES,
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
7900: valueDone: boolean;
7901: finalValue?: string;
7902: partAdded: boolean;
7903: partDone: boolean;
7904: partFinalValue?: string;
7905: };
7906: type OutputLifecycle = {
7907: argumentDeltaSeen: boolean;
7908: argumentDeltas: string;
7909: argumentsDone: boolean;
7910: outputDone: boolean;
7911: reasoning: Map<number, TextPartLifecycle>;
7912: content: Map<number, TextPartLifecycle>;
7913: };
7914: const outputLifecycles = new WeakMap<
7915: ResponsesAccState,
7916: Map<number, OutputLifecycle>
7917: >();
7918: const lifecyclesFor = (
7919: acc: ResponsesAccState,
7920: ): Map<number, OutputLifecycle> => {
7921: let lifecycles = outputLifecycles.get(acc);
7922: if (!lifecycles) {
7923: lifecycles = new Map();
7924: outputLifecycles.set(acc, lifecycles);
7925: ...
Found 18 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts:
Line 8018: state.id = transactionBaseline.id;
Line 8061: event === "response.created" ||
Line 9167: const validateResponseLifecycle = (
Line 9176: if (event === "response.created") {
Line 9177: if (lifecycle.created) throw new Error("duplicate response.created");
Line 9180: throw new Error("response.created missing response identity");
Line 9187: throw new Error("response.created has invalid status");
Line 9193: throw new Error("response.created must start with empty output");
Line 9199: throw new Error(`Responses event before response.created: ${event}`);
Line 9239: const createdAt = response.created_at;
Line 9770: itemId = `msg_${state.id || "lore"}_${outputIndex}`,
Line 9885: id: state.id,
Line 10808: const syntheticId = `msg_${state.id || ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
9140: parsed: Record<string, unknown>,
9141: ): void => {
9142: if (
9143: !normalizationState ||
9144: event === "response.output_item.added" ||
9145: event === "response.output_item.done"
9146: ) {
9147: return;
9148: }
9149: const outputIndex = parsed.output_index;
9150: if (!Number.isSafeInteger(outputIndex) || (outputIndex as number) < 0)
9151: return;
9152: const index = outputIndex as number;
9153: if (acc.rawItems.has(index)) return;
9154: const normalizedRaw = normalizationState.rawItems.get(index);
9155: if (!normalizedRaw) return;
9156: const seedItem = { ...normalizedRaw };
9157: outputIndexForEvent(
9158: "response.output_item.added",
9159: { output_index: index, item: seedItem },
9160: acc,
9161: );
9162: applyResponsesEvent(acc, ...
Found 12 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/openai-responses-recall-aware-stream.test.ts:
Line 8224: "never exposes non-semantic %s frames after recall interception",
Line 8315: "rejects a %s continuation created_at before rebuilding the terminal",
Line 8317: const responseJSON = `{"type":"response.completed","response":{"id":"resp_created_at_followup","model":"gpt-5.6-terra","created_at":${createdAt},"status":"completed","output":[{"type":"message","id":"msg_created_at_answer","role":"assistant","status":"completed","content":[{"type":"output_text","text":"safe answer"}]}],"usage":{"input_tokens":11,"output_tokens":3}}}`;
Line 8319: created("resp_created_at_followup", "gpt-5.6-terra"),
Line 8320: textItem(0, "safe answer", "msg_created_at_answer"),
Line 8325: created("resp_created_at_principal", "gpt-5.6-terra"),
Line 8327: ...
Found 17 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/openai-responses-recall-aware-stream.test.ts:
Line 115: sseEvent("response.created", { response: { id, model } });
Line 801: sseEvent("response.created", {
Line 802: type: "response.in_progress",
Line 1183: test("rejects response.in_progress changing the created response identity", async () => {
Line 1187: sseEvent("response.in_progress", {
Line 1680: sseEvent("response.created", {
Line 4667: test.each(["response.created", "response.in_progress"])(
Line 4688: event === "response.created"
Line 4709: test.each(["response.created", "response.in_progress"])(
Line 4721: event === "response.created"
Line 5773: // (response.created, response.in_progress, response.completed). These must
Line 5775: // response.created and we rebuild response.completed ourselves. ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/openai-responses-recall-aware-stream.test.ts</path>
<type>file</type>
<content>
5740: let recalls = 0;
5741: const client = streamResponsesRecallAware(
5742: streamFrom([
5743: created("resp_depth_exhausted_principal", "gpt-5.6-terra"),
5744: recallCall(
5745: 0,
5746: { query: "architecture" },
5747: "fc_principal",
5748: "call_principal",
5749: ),
5750: completed("resp_depth_exhausted_principal"),
5751: ]),
5752: {
5753: maxRecallDepth: 1,
5754: onComplete: () => {},
5755: onRecall: async ({ query }) => {
5756: recalls++;
5757: return { anchorText: buildAnchor(query), resultText: "results" };
5758: },
5759: runFollowUp: async () => ({ reader: followUp.body!.getReader() }),
5760: },
5761: );
5762:
5763: const out = await ...
The working copy has no changes. Working copy (@) : kwmswwmt 2ad3e064 (empty) (no description set) Parent commit (@-): lnvrxqoq f3023670 fix/responses-hidden-output* | fix(responses): complete hidden-output state 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. kwmswwmtzlnxuvpkqymrwrxttlwowsys 2ad3e0648eeb78588db1eea431bd93f86c40a472 parents=f30236708bc928ee2e12739d1de7a7d21871c7d2 empty=true conflict=false description= lnvrxqoqsqutpvpxvnppskkmmmsztwus f30236708bc928ee2e12739d1de7a7d21871c7d2 parents=a3fa555bdcabb376aa33278bdb76007269f1940a empty=false conflict=false description=fix(responses): complete hidden-output state pxrvwsvvkmpoxnsqmrkwrnlqvvkoltwz 2cbf40060c67df229731cf1b9e34d5bf22ec2145 parents=e977b4b1da8f8197c3238466d41de0bccd8eb054 empty=false conflict=false description=feat(cch): add seeds for Claude Code up to 2.1.272 ...
Found 5 matches /home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/stream/openai-responses.ts: Line 2628: created_at: Math.floor(Date.now() / 1000), Line 2858: created_at: created, Line 2876: created_at: created, Line 3201: created_at: created, Line 3248: created_at: created,
<path>/home/byk/Code/opencode-lore-responses-projection-security/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. ...
b7df735637f9d033c895867ebe157cb05f8d390bea78842d58d14fd8091fd3e1 -
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
9280: lifecycle.terminal = true;
9281: }
9282: };
9283: const assertOutputLifecyclesComplete = (
9284: acc: ResponsesAccState,
9285: allowedIncompleteIndices: ReadonlySet<number> = new Set(),
9286: ): void => {
9287: const lifecycles = lifecyclesFor(acc);
9288: for (const index of acc.rawItems.keys()) {
9289: if (lifecycles.get(index)?.outputDone) continue;
9290: if (allowedIncompleteIndices.has(index)) continue;
9291: if (opts.validation !== "codex") {
9292: throw new Error(
9293: `Responses stream ended before output_item.done for index ${index}`,
9294: );
9295: }
9296: const item = acc.rawItems.get(index);
9297: if (
9298: item?.type === "reasoning" &&
9299: typeof item.encrypted_content === "string"
9300: ) {
9301: throw new ...
diff --git a/packages/gateway/src/pipeline.ts b/packages/gateway/src/pipeline.ts
index 9aa7944751..13cd19fdd3 100644
--- a/packages/gateway/src/pipeline.ts
+++ b/packages/gateway/src/pipeline.ts
@@ -8066,12 +8066,20 @@
event === "response.failed" ||
event === "response.output_item.added" ||
event === "response.output_item.done" ||
- event.startsWith("response.output_text.") ||
- event.startsWith("response.refusal.") ||
- event.startsWith("response.function_call_arguments.") ||
- event.startsWith("response.content_part.") ||
- event.startsWith("response.reasoning_summary_") ||
- event.startsWith("response.reasoning_text.");
+ event === "response.output_text.delta" ||
+ event === "response.output_text.done" ||
+ event === "response.refusal.delta" ||
+ event === "response.refusal.done" ||
+ event === "response.function_call_arguments.delta" ||
+ event === "response.function_call_arguments.done" ||
+ event === ...
Found 38 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/openai-responses-recall-aware-stream.test.ts:
Line 364: output: [],
Line 387: textItem(0, "omitted from terminal", "msg_omitted"),
Line 1346: output: [],
Line 1634: output: [],
Line 1685: output: [],
Line 2559: test("preserves principal finalized text when the Codex terminal item omits content", async () => {
Line 2563: created("resp_omitted_message_content", "gpt-5.6-terra"),
Line 2567: id: "msg_omitted_message_content",
Line 2572: item_id: "msg_omitted_message_content",
Line 2578: id: "resp_omitted_message_content",
Line 2583: id: "msg_omitted_message_content",
Line 2830: ).toMatchObject({ status: "failed", output: [] });
Line 3113: test("redacts a sparse call omitted from the terminal output", async () => {
Line 3117: ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/openai-responses-recall-aware-stream.test.ts</path>
<type>file</type>
<content>
330: sseEvent("response.failed", {
331: response: {
332: id: "resp_failed",
333: model: "gpt-5.6-terra",
334: status: "failed",
335: error: { message: "provider failed" },
336: },
337: }),
338: ]),
339: {
340: onComplete: () => {},
341: onRecall: async () => ({ anchorText: "", resultText: "" }),
342: runFollowUp: async () => {
343: throw new Error("should not be called");
344: },
345: },
346: );
347:
348: const out = await drain(client);
349: expect(out.match(/^event: response\.failed$/gm)).toHaveLength(1);
350: expect(out).toContain("provider failed");
351: expect(out).not.toContain("ended without a terminal event");
352: });
353:
354: test("accepts an ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/openai-responses-recall-aware-stream.test.ts</path>
<type>file</type>
<content>
3060: name: "",
3061: arguments: "",
3062: status: "in_progress",
3063: },
3064: }),
3065: sseEvent("response.function_call_arguments.delta", {
3066: output_index: 0,
3067: item_id: "fc_terminal_sparse_changed_type",
3068: delta: privateArguments,
3069: }),
3070: sseEvent("response.completed", {
3071: response: {
3072: id: "resp_terminal_sparse_changed_type",
3073: model: "gpt-5.6-terra",
3074: status: "completed",
3075: output: [
3076: {
3077: type: "message",
3078: id: "fc_terminal_sparse_changed_type",
3079: role: "assistant",
3080: status: "completed",
3081: ...
Found 6 matches /home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/stream/openai-responses.ts: Line 67: nextOutputIndex: number; Line 567: nextOutputIndex: 0, Line 620: state.nextOutputIndex = Math.max(state.nextOutputIndex, outputIndex + 1); Line 1228: let index = state.nextOutputIndex; Line 1231: state.nextOutputIndex = index + 1; Line 1750: export function normalizeCodexResponsesEvent(
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/stream/openai-responses.ts</path>
<type>file</type>
<content>
1200: );
1201: }
1202: }
1203: if (
1204: event === "response.output_text.delta" ||
1205: event === "response.output_text.done" ||
1206: event === "response.refusal.delta" ||
1207: event === "response.refusal.done" ||
1208: event === "response.function_call_arguments.delta" ||
1209: event === "response.function_call_arguments.done"
1210: ) {
1211: return [parsed.delta, parsed.text, parsed.refusal, parsed.arguments].some(
1212: (value) => typeof value === "string" && value.length > 0,
1213: );
1214: }
1215: if (event.startsWith("response.reasoning")) {
1216: const part = isRecord(parsed.part) ? parsed.part : undefined;
1217: return [parsed.delta, parsed.text, parsed.summary_text, part?.text].some(
1218: (value) => typeof value === "string" && value.length > 0,
1219: ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/stream/openai-responses.ts</path> <type>file</type> <content> 1730: case "response.refusal.done": 1731: if (typeof parsed.refusal !== "string") malformedResponsesEvent(); 1732: normalizeCodexDataEvent(state, event, parsed, maxSparseIndex); 1733: break; 1734: case "response.function_call_arguments.delta": 1735: if (typeof parsed.delta !== "string") malformedResponsesEvent(); 1736: normalizeCodexDataEvent(state, event, parsed, maxSparseIndex); 1737: break; 1738: case "response.function_call_arguments.done": 1739: if (typeof parsed.arguments !== "string") malformedResponsesEvent(); 1740: normalizeCodexDataEvent(state, event, parsed, maxSparseIndex); 1741: break; 1742: } 1743: } 1744: 1745: /** 1746: * Normalize one sparse Codex event and advance an independent normalization 1747: * state. ...
Found 75 matches /home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/stream/openai-responses.ts: Line 75: /** Accumulating output items indexed by output_index. */ Line 616: const outputIndex = parsed.output_index as number; Line 645: const outputIndex = parsed.output_index as number; Line 660: const outputIndex = parsed.output_index as number; Line 672: const outputIndex = parsed.output_index as number; Line 685: const outputIndex = parsed.output_index as number; Line 695: const outputIndex = parsed.output_index as number; Line 705: const outputIndex = parsed.output_index as number; Line 717: const outputIndex = parsed.output_index as number; Line 911: maxSparseIndex: number, Line 913: const outputIndex = parsed.output_index; Line 917: (outputIndex as number) < maxSparseIndex; Line 988: (parsed.content_index as number) >= maxSparseIndex) Line 1094: ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/stream/openai-responses.ts</path>
<type>file</type>
<content>
900: };
901: }
902:
903: // ---------------------------------------------------------------------------
904: // Stream accumulator (buffered)
905: // ---------------------------------------------------------------------------
906:
907: function validatePublicResponsesEvent(
908: state: ResponsesAccState,
909: event: string,
910: parsed: Record<string, unknown>,
911: maxSparseIndex: number,
912: ): void {
913: const outputIndex = parsed.output_index;
914: const validOutputIndex =
915: Number.isSafeInteger(outputIndex) &&
916: (outputIndex as number) >= 0 &&
917: (outputIndex as number) < maxSparseIndex;
918: const item = validOutputIndex
919: ? state.items.get(outputIndex as number)
920: : undefined;
921: const malformed = (): never => {
922: throw new Error("malformed Responses stream ...
[lore]sqlite-vec: native vector search enabled (v0.1.9, /tmp/lore-native/pid-745606/vec0.so) ## Recall Results Found 90 results, showing top 15 (score range: 0.082–0.053). ### Strong Matches #### Knowledge - **Fail-first regression proof** (1h ago): For security- or correctness-sensitive pipeline changes, add deterministic regression tests that exercise the real precondition and prove each guard independently. Confirm the test fails on the unfixed code or when the specific guard is removed, then restore the implementation and confirm focused tests pass. Treat skip, early-return, projection, validation, rollback, and redaction guards as high-risk; tests must detect leaked private data, incorrect indices, malformed provider values, or improper failure envelopes. After focused mutation proofs, run the full affected suite, typecheck, lint, formatting, and other repository gates. ...
Found 1 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts:
Line 9245: throw new Error("Responses terminal event has invalid created_at");
Found 1 matches /home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/stream/openai-responses.ts: Line 1625: function validateCodexResponsesEvent(
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/stream/openai-responses.ts</path>
<type>file</type>
<content>
1620: }
1621: }
1622: parsed.output_index = outputIndex;
1623: }
1624:
1625: function validateCodexResponsesEvent(
1626: state: ResponsesAccState,
1627: event: string,
1628: parsed: Record<string, unknown>,
1629: maxSparseIndex: number,
1630: ): void {
1631: if (parsed.type !== undefined && parsed.type !== event) {
1632: malformedResponsesEvent();
1633: }
1634: if (
1635: parsed.output_index !== undefined &&
1636: (!Number.isSafeInteger(parsed.output_index) ||
1637: (parsed.output_index as number) < 0 ||
1638: (parsed.output_index as number) >= maxSparseIndex)
1639: ) {
1640: malformedResponsesEvent();
1641: }
1642: if (
1643: parsed.content_index !== undefined &&
1644: (!Number.isSafeInteger(parsed.content_index) ||
1645: (parsed.content_index as number) < 0 ||
1646: ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/openai-responses-recall-aware-stream.test.ts</path>
<type>file</type>
<content>
8298: "strips extension fields from allowlisted %s frames after recall interception",
8299: async (source) => {
8300: const privateEventExtension = "private allowlisted event extension";
8301: const privateItemExtension = "private allowlisted item extension";
8302: const answerEvents = [
8303: sseEvent("response.output_item.added", {
8304: output_index: source === "principal" ? 1 : 0,
8305: item: {
8306: type: "message",
8307: id: `msg_allowlisted_${source}`,
8308: role: "assistant",
8309: status: "in_progress",
8310: content: [],
8311: },
8312: }),
8313: sseEvent("response.output_text.delta", {
8314: output_index: source === "principal" ? ...
Working copy changes: M packages/gateway/test/openai-responses-recall-aware-stream.test.ts Working copy (@) : kwmswwmt 42e8b8b5 fix(responses): sanitize projected output Parent commit (@-): lnvrxqoq f3023670 fix/responses-hidden-output* | fix(responses): complete hidden-output state 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. kwmswwmtzlnxuvpkqymrwrxttlwowsys 42e8b8b5cf649348d6cd79e94cc47f9d01c5f88a parents=f30236708bc928ee2e12739d1de7a7d21871c7d2 empty=false conflict=false description=fix(responses): sanitize projected output lnvrxqoqsqutpvpxvnppskkmmmsztwus f30236708bc928ee2e12739d1de7a7d21871c7d2 parents=a3fa555bdcabb376aa33278bdb76007269f1940a empty=false conflict=false description=fix(responses): complete hidden-output state b7df735637f9d033c895867ebe157cb05f8d390bea78842d58d14fd8091fd3e1 -
Found 5 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts:
Line 10033: JSON.stringify({ ...parsed, output_index: visibleIndex }),
Line 10379: await enqueuePrincipal(chunk, otherToolSeen);
Line 11059: applyResponsesEvent(contState, ce, cparsed);
Line 11135: applyResponsesEvent(contState, ce, cparsed);
Line 11335: } else queueTransactional(shifted);
Found 11 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts:
Line 5532: const sanitized = match[1].replace(/[\x00-\x1f\x7f]/g, "").trim();
Line 5533: if (!sanitized || sanitized.length > MAX_MARKER_PROJECT_PATH_LENGTH)
Line 5536: if (!sanitized.startsWith("/")) return undefined;
Line 5538: if (sanitized.includes("..")) return undefined;
Line 5539: return sanitized.replace(/\/+$/, "") || undefined;
Line 6181: /** Explicit, sanitized X-Lore-Provider value (not inferred signals). */
Line 10372: // Non-semantic frames are safe only before recall interception. ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
11260: if (item.name === RECALL_TOOL_NAME) {
11261: collectCompletedRecall(
11262: contState,
11263: outputIndex,
11264: contRecallInputs,
11265: contPending,
11266: );
11267: } else {
11268: contUnresolvedToolIndices.delete(
11269: outputIndex,
11270: );
11271: contUnresolvedToolBytes.delete(outputIndex);
11272: contOtherTool = true;
11273: }
11274: ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
11390: continuationFailureCategory = "follow_up_setup";
11391: follow = await settleFollowUp(
11392: continuationFollowUpInput,
11393: );
11394: continuationFailureCategory = "follow_up_protocol";
11395: continue;
11396: }
11397: const mergeContinuation = (): void => {
11398: for (const item of contState.rawItems.values()) {
11399: const itemIdentities = [item.id, item.call_id].filter(
11400: (value): value is string =>
11401: typeof value === "string" && value.length > 0,
11402: );
11403: for (const existing ...
Found 2 matches /home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/openai-responses-recall-aware-stream.test.ts: Line 8298: "strips extension fields from allowlisted %s frames after recall interception", Line 8300: const privateEventExtension = "private allowlisted event extension";
8210 onRecall: async ({ query }) => ({
8211 anchorText: buildAnchor(query),
8212 resultText: "results",
8213 }),
8214 runFollowUp: async () => ({ reader: malformed.body!.getReader() }),
8215 },
8216 );
8217
8218 const out = await drain(client);
8219 expect(out).not.toContain("must-not-leak");
8220 expect(out).toContain(PUBLIC_RECALL_ERROR);
8221 });
8222
8223 test.each(["principal", "continuation"] as const)(
8224 "never exposes non-semantic %s frames after recall interception",
8225 async (source) => {
8226 const privateDiagnostic =
8227 "private recall query, arguments, result, and identity";
8228 const followUp = streamFrom([
8229 created("resp_private_diagnostic_followup", "gpt-5.6-terra"),
8230 ...(source === "continuation"
8231 ? ...
10015 .join("\n");
10016 let parsed: Record<string, unknown>;
10017 try {
10018 parsed = JSON.parse(data) as Record<string, unknown>;
10019 } catch {
10020 output += `${frame}\n\n`;
10021 continue;
10022 }
10023 if (!Number.isSafeInteger(parsed.output_index)) {
10024 output += `${frame}\n\n`;
10025 continue;
10026 }
10027 const visibleIndex = visibleIndices.get(parsed.output_index as number);
10028 if (visibleIndex === undefined) {
10029 throw new Error("hidden Responses output item reached the client");
10030 }
10031 output += formatResponsesEvent(
10032 event,
10033 JSON.stringify({ ...parsed, output_index: visibleIndex }),
10034 );
10035 }
10036 return encoder.encode(output);
10037 }
10038
10039 let resumeDemand: (() => void) | undefined;
10040 const cleanupAbort = (): void =>
10041 ...
Working copy changes: M packages/gateway/test/openai-responses-recall-aware-stream.test.ts Working copy (@) : kwmswwmt 42e8b8b5 fix(responses): sanitize projected output Parent commit (@-): lnvrxqoq f3023670 fix/responses-hidden-output* | fix(responses): complete hidden-output state 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. kwmswwmtzlnxuvpkqymrwrxttlwowsys 42e8b8b5cf649348d6cd79e94cc47f9d01c5f88a parents=f30236708bc928ee2e12739d1de7a7d21871c7d2 empty=false conflict=false description=fix(responses): sanitize projected output lnvrxqoqsqutpvpxvnppskkmmmsztwus f30236708bc928ee2e12739d1de7a7d21871c7d2 parents=a3fa555bdcabb376aa33278bdb76007269f1940a empty=false conflict=false description=fix(responses): complete hidden-output state pxrvwsvvkmpoxnsqmrkwrnlqvvkoltwz 2cbf40060c67df229731cf1b9e34d5bf22ec2145 parents=e977b4b1da8f8197c3238466d41de0bccd8eb054 ...
Found 8 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/test/openai-responses-recall-aware-stream.test.ts:
Line 2677: test("allows a terminal-discovered recall that preserves sparse visible output positions", async () => {
Line 2760: test("fails closed when a terminal-discovered recall would reindex visible output", async () => {
Line 2836: test("redacts a sparse terminal-discovered recall before status validation", async () => {
Line 4936: test("rejects continuation index arithmetic beyond safe integers", async () => {
Line 5869: test("allows a late recall that preserves sparse visible output positions", async () => {
Line 5910: test("fails closed when later visible output changes an emitted sparse position", async () => {
Line 5958: test("fails closed when a lower-index recall follows visible output", async () => {
Line 5997: test("allows deferred sparse output before a higher-index recall", async () => {
9920 if (rawItem && rawItem.type !== "item_reference") {
9921 finalOutput.push({ index, item: rawItem });
9922 }
9923 continue;
9924 }
9925 if (item.type === "text") {
9926 if (item.content) {
9927 const raw = state.rawItems.get(index);
9928 finalOutput.push({
9929 index,
9930 item: {
9931 ...(raw ?? {
9932 type: "message",
9933 id: item.id,
9934 role: "assistant",
9935 status: "completed",
9936 }),
9937 content: Array.isArray(raw?.content) ? raw.content : item.content,
9938 },
9939 });
9940 continue;
9941 }
9942 if (item.refusal !== undefined) {
9943 finalOutput.push({
9944 index,
9945 item: {
9946 type: "message",
9947 ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
10165: ? ("post_tool" as const)
10166: : principalEventEmitted
10167: ? ("post_output" as const)
10168: : ("pre_output" as const);
10169: const reportContinuationFailure = (
10170: category: RecallContinuationFailureCategory,
10171: ): void => {
10172: if (continuationFailureReported) return;
10173: continuationFailureReported = true;
10174: reportRecallContinuationFailure(category);
10175: };
10176: // Recall items are gateway-internal and must stay hidden on every exit,
10177: // including failures raised before marker replacement. ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
10380: }
10381: continue;
10382: }
10383: if (parsed.type !== event) {
10384: throw new Error(`Responses payload type does not match ${event}`);
10385: }
10386: if (!isSemanticResponsesEvent(event)) {
10387: // Always accumulate into the internal state for postResponse.
10388: // The accumulator retains only reviewed metadata projections.
10389: applyResponsesEvent(state, event, parsed);
10390: if (
10391: recallIndices.size === 0 &&
10392: unresolvedToolIndices.size === 0
10393: ) {
10394: await enqueuePrincipal(
10395: encoder.encode(formatResponsesEvent(event, data)),
10396: otherToolSeen,
10397: ...
<path>/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts</path>
<type>file</type>
<content>
10870: }
10871: unresolvedToolIndices.delete(outputIndex);
10872: discardDeferredCandidate(outputIndex);
10873: promoteDeferredCandidate(outputIndex);
10874: },
10875: (outputIndex, item) => {
10876: if (item.type !== "function_call") return;
10877: if (item.name === RECALL_TOOL_NAME) {
10878: collectCompletedRecall(
10879: state,
10880: outputIndex,
10881: parsedRecallInputs,
10882: pendingRecalls,
10883: );
10884: } else {
10885: unresolvedToolIndices.delete(outputIndex);
10886: ...
10176 // Recall items are gateway-internal and must stay hidden on every exit,
10177 // including failures raised before marker replacement.
10178 const recallIndices = new Set<number>();
10179 const forwardedVisibleOutputIndices = new Map<number, number>();
10180 const visibleOutputIndices = new Map<number, number>();
10181 const visibleOutputSources: number[] = [];
10182 const unresolvedToolIndices = new Set<number>();
10183 const referenceIndices = new Map<number, ReferenceLifecycle>();
10184 const visibleSourcePosition = (sourceIndex: number): number => {
10185 let low = 0;
10186 let high = visibleOutputSources.length;
10187 while (low < high) {
10188 const middle = low + Math.floor((high - low) / 2);
10189 if ((visibleOutputSources[middle] ?? ...
Found 45 matches
/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/ui.ts:
Line 183: created_at: number;
/home/byk/Code/opencode-lore-responses-projection-security/packages/opencode/eval/extract_session.ts:
Line 71: created_at: number;
/home/byk/Code/opencode-lore-responses-projection-security/packages/opencode/eval/coding_eval.ts:
Line 39: created_at: number;
Line 50: created_at: number;
Line 58: ): Array<{ observations: string; created_at: number }> {
Line 75: created_at: number;
Line 332: msgs: Array<{ role: string; content: string; created_at: number }>,
Line 376: msgs: Array<{ role: string; content: string; created_at: number }>,
Line 447: created_at: number;
Line 551: created_at: number;
/home/byk/Code/opencode-lore-responses-projection-security/packages/opencode/eval/backfill.ts:
Line 242: created_at: ...
The candidate filters event names but does not project allowlisted event payloads:
pipeline.ts:10031-10034 spreads every parsed field into principal frames.pipeline.ts:11318-11328 does the same for continuation frames.pipeline.ts:11669-11673 forwards those reconstructed frames.pipeline.ts:9928-9938 and pipeline.ts:9968-9978 preserve arbitrary raw item fields in the rebuilt terminal output.After recall interception, an allowlisted event such as response.output_text.delta can carry an arbitrary private_extension; that field reaches client SSE unchanged. Item-level extensions can also enter rebuilt response.completed.output.
The candidate tests only cover:
openai-responses-recall-aware-stream.test.ts:8223-8264:8266-8305:8413-8454They never put an extension field inside a valid semantic event or output item. Those tests therefore cannot detect this path. Fix this with event-specific semantic reconstruction rather than { ...parsed }, and rebuild output items from allowlisted fields.
created_at validation accepts invalid timestampspipeline.ts:9238-9245 accepts any finite, non-negative number, including fractional and unsafe values. pipeline.ts:9887-9888 then emits that value in the rebuilt terminal.
The invalid-value matrix at openai-responses-recall-aware-stream.test.ts:8307-8349 covers objects, arrays, strings, negatives, null, and infinity, but not fractional or unsafe positive values. The Unix-seconds field should use an integer bound, preferably Number.isSafeInteger.
The candidate correctly:
pipeline.ts:10178-10250.:10251-10275. ...Date: Sep 16, 2026 * 🔴 (22:47) User provided a further `packages/gateway/src/pipeline.ts` segment covering approximately lines `10131-11235`, including principal-failure categorization, visible-output index tracking, recall interception, hidden-recall byte accounting, continuation execution, rollback, and streamed-reasoning preservation. * 🔴 (22:47) User directed that stream events must always …
Date: Sep 16, 2026 * 🔴 (22:46) User provided additional code from `packages/gateway/src/pipeline.ts`, covering approximately lines `8932-10086` and Responses streaming validation, item-reference lifecycle checks, recall handling, keepalives, output-index management, terminal output assembly, SSE framing, and cancellation. * 🔴 (22:46) `packages/gateway/src/pipeline.ts:9479` defines `ReferenceLif…
Date: Sep 16, 2026 * 🟡 (22:44) Search found `91` matches in `/home/byk/Code/opencode-lore-responses-projection-security/packages/gateway/src/pipeline.ts` for response-event application, rollback/transaction handling, output-index shifting, reference lifecycles, and queueing; notable symbols include `applyResponsesEvent`, `rollbackTransaction`, `ReferenceLifecycle`, `assertReferenceLifecyclesComp…
Date: Sep 16, 2026 * 🔴 (22:38) Root `package.json` identifies the project as private ESM package `lore-monorepo`, licensed `FSL-1.1-Apache-2.0`, described as “Monorepo root for Lore — three-tier memory architecture,” with entry/export `./packages/opencode/src/index.ts`, repository `git+https://github.com/BYK/loreai.git`, author `BYK`, and workspace pattern `packages/*`. * 🔴 (22:38) Root tooling…
Date: Sep 16, 2026 * 🔴 [requested-review] (22:33) User requested an independent, read-only, adversarial correctness review of immutable projection candidate `/home/byk/Code/opencode-lore-responses-projection-security`, stable change `lnvrxqoqsqut`, commit `f30236708bc9`, based on `main@origin` commit `2cbf40060c67`. * 🔴 (22:33) User stated the expected cumulative plain diff SHA is `b7df735637f9…