Skip to content

fix(openai): preserve Codex standalone context on Responses - #8680

Closed
Hato626 wants to merge 3 commits into
Wei-Shaw:mainfrom
Hato626:fix/codex-browser-tabs-context
Closed

Hato626 wants to merge 3 commits into
Wei-Shaw:mainfrom
Hato626:fix/codex-browser-tabs-context

Conversation

@Hato626

@Hato626 Hato626 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex injects browser state, page snapshots and other context as named function_call_output items without a model-issued call_id. HTTP Responses rejects these legitimate inputs, while recognized page snapshots are rewritten as user messages. The Codex OAuth upstream accepts the original items, so preserve their native representation.

Exclude recognized context only from call/result association checks using a separate validation copy. Forward the original items with their type, ID, name, namespace, output and ordering intact. Remove the page, automation and delegation conversions to user messages, including when these inputs are mixed together. Preserve namespaces in the API-key path and prevent the OAuth transform from synthesizing a call_id from a standalone item's id, which would cause orphan-result cleanup to drop the context.

The allowlist retains page-snapshot checks, adds the complete ambient browser-state envelope, and covers these producers in openai/codex at e58bf8f5233b:

  • agent.goal_objective: ext/goal/src/steering.rs.
  • agent.proposed_plan: core/src/session/approved_plan.rs.
  • agent.untrusted_content: fallback name in context-fragments/src/additional_context.rs.
  • guardian.guardian_housekeeper_input, guardian.guardian_channel_selection_input, guardian.guardian_original_evidence: ext/guardian-v3/src/sampling.rs and delivery.rs.
  • cloud_threads.send_message: delegation delivery recognized in core/src/agent/control/sender_context.rs, including optional source_orbit_id.
  • Existing codex_app.automation_update bootstrap/heartbeat envelopes and codex_app/codex_tui create_thread/send_message_to_thread envelopes now use the same native path. Their existing envelope validation remains; explicit empty/whitespace call IDs are not treated as missing IDs.

Matching requires the exact namespace/name, a missing call_id, and the expected text/JSON/envelope shape. Explicit call IDs, malformed entries and unknown names retain normal validation. Dynamic names supplied through Codex additional context are not wildcard-allowlisted.

Regression coverage verifies non-mutating validation, history, mixed bootstrap inputs, multipart snapshots, CRLF, malformed and unrelated outputs, plus captured OAuth/API-key outbound requests and WebSocket compatibility processing.

Validation:

  • Focused context/forwarding/namespace regression tests pass on this PR branch. Both complete handler/service suites pass on the deployment branch.
  • go test -tags=unit ./internal/handler ./internal/service -count=1 -timeout=300s on this PR branch: handler passes; service has one failure in the unchanged TestOllamaProbeCallback_StaleLongDoesNotOverrideNewShort on Windows. The failure also reproduces when that test runs alone with -count=20 (the two time.Now().Add(5*time.Second) cooldown generations can compare equal). No Ollama code or tests are changed here.
  • golangci-lint run --new-from-rev=upstream/main --timeout=5m ./internal/handler/... ./internal/service/...: 0 issues.
  • Direct Codex OAuth checks on two models: baseline, browser/page context, real tool history, each of the seven additional names and their combined input all returned HTTP 200 and completed text (26 requests). No context was converted to user messages.
  • Automation, heartbeat and all four app/TUI delegation combinations also completed as standalone first inputs on both models, plus mixed bootstrap/browser/page/tool-history cases (14 additional requests).
  • GitHub's backend-security job reports GO-2026-6859 in its Go 1.27.3 standard library, fixed in Go 1.27.4. This PR does not change the toolchain or dependencies.

Follow-up to #8622. Refs #8609, #8635.

Copilot AI balanced review requested due to automatic review settings November 11, 2026 12:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Hato626 Hato626 changed the title fix(openai): normalize Codex ambient browser context fix(openai): preserve Codex standalone context on Responses Nov 11, 2026
@Hato626

Hato626 commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

CI investigation: the only failing check is backend-security, reporting GO-2026-6859 in net/http@go1.27.3 (fixed in Go 1.27.4). The functional test and golangci-lint checks passed.

This is the same existing toolchain issue affecting #8735 and other PRs, not a failure of the standalone-context change. It is already addressed by #8670, whose backend-security and other CI checks have passed. Keeping the context fix scoped: no duplicate toolchain upgrade or unrelated code changes are added here. Once #8670 lands, this branch can be updated and the security scan rerun.

riofutab added a commit to riofutab/sub2api that referenced this pull request Nov 13, 2026
riofutab added a commit to riofutab/sub2api that referenced this pull request Nov 13, 2026
- Claude 链路:令牌轮换后 401 同账号重试,per-turn beta 保留轮次输出配置,Stainless 版本头与抬升后的 UA 对齐(Wei-Shaw#8737 Wei-Shaw#8742 Wei-Shaw#8731 Wei-Shaw#8726 Wei-Shaw#8724 Wei-Shaw#8698)。
- Codex/OpenAI 链路:Desktop 独立上下文原样转发并删除 fork 的 bootstrap 扫描器,分叉会话沿用父会话缓存键,刷新后的令牌在补充信息超时时仍保存(Wei-Shaw#8680 Wei-Shaw#8664 Wei-Shaw#8671 Wei-Shaw#8735 Wei-Shaw#8682 Wei-Shaw#8703)。
- 构建:Go 升到 1.27.4 修复 GO-2026-6859(Wei-Shaw#8670);前端 Gemini 用量条刷新不再跳动(Wei-Shaw#8740)。
- fork 带的 Wei-Shaw#8034 测试改为断言轮换后的凭据被保存,并为测试桩补齐 CAS 方法。
- 后端全量 unit、golangci-lint、前端 lint/typecheck/账号组件测试通过;repository 集成测试未跑。
@Wei-Shaw

Copy link
Copy Markdown
Owner

感谢贡献!本 PR 与已合并的 #8769 方向相反:#8769 延续了 #8622 的做法,把 Codex 独立上下文归一化为 user 文本;本 PR 删除了这套归一化,改为原样转发。两者只能二选一,维护者选择了 #8769。

审计中还发现一个回归:归一化位于 handler 入口,对所有 OpenAI 平台账号生效。删除后,upstream_protocol=anthropic 的账号会在 ResponsesToAnthropicRequest 里把这类无 call_id 的 function_call_output 当作孤儿 tool_result 静默丢弃;走 Chat 回退时会产出缺 tool_call_id 的 tool 消息。

如果 #8769 白名单里还缺 untrusted_content 等名字,欢迎基于 main 另开一个小 PR 补充。

Thanks! This conflicts by design with the merged #8769 (normalize-to-user-text, as in #8622), so we're closing it. Removing the normalization also regresses OpenAI accounts on Anthropic/Chat protocol conversion: standalone context gets dropped there, or becomes a tool message without tool_call_id. A follow-up PR adding missing names such as untrusted_content to #8769's allowlist is welcome.

@Wei-Shaw Wei-Shaw closed this Nov 16, 2026
riofutab added a commit to riofutab/sub2api that referenced this pull request Nov 17, 2026
- 撤销 Wei-Shaw#8680 后 agent 的 proposed_plan、untrusted_content,guardian 的三类输入与 cloud_threads/send_message 委派信封会在本地被拒(400)
- 归一化扩展到这三个命名空间:agent 与 guardian 包成 external 标签,云端委派信封原文作为 user 文本,与 codex_app 委派一致
- 预检标记同步补充,新增覆盖补回名字与不合规输入的单测

测试:handler 包 Codex 上下文相关单测与 golangci-lint 通过
riofutab added a commit to riofutab/sub2api that referenced this pull request Nov 17, 2026
- 带入上游 11-16 已合的 55 个 PR,同步基准更新为 9cd1a1e;用量汇总改为非阻塞建表(Wei-Shaw#8693),被动用量换窗清理与 Fable 限额恢复采用上游实现(Wei-Shaw#8723 Wei-Shaw#8779)。
- Codex 独立上下文改用上游 Wei-Shaw#8769 的 user 文本归一化,撤回 fork 的 Wei-Shaw#8680 并补回 proposed_plan、guardian、cloud_threads 等类型;Gemini 思考等级改用 Wei-Shaw#8673,撤回 fork 的 Wei-Shaw#8619。
- 合入 24 个开放 PR,Wei-Shaw#8781 与 Wei-Shaw#8705 部分合入;Wei-Shaw#8856、Wei-Shaw#8858 与已有实现重复,未合入。
- 修复转义的 1h TTL 被快速路径漏判,并按 fork 的构造参数与模型目录调整上游测试。
- 后端全量 unit、golangci-lint、前端 vitest、迁移空库回放与 CI 集成测试通过;go.sum 未整理。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants