Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/en/docs/operate/deploy-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Do not route Core's own generation through automatic Gateway recall or capture w

When the gateway connects to the Core over UDS (`PC_GATEWAY_CORE_UDS`, the combined deployment), it injects prepared context by default into Chat and Responses requests that belong to a conversation. Within a conversation it prepares once per new user message and replays the exact result for the rest of that turn, such as an agent's tool loop.

The gateway identifies the conversation from the first of these request headers that is present:
The gateway identifies the conversation from the first of these request headers with a valid value:

| Header | Sent by | Conversation |
| --- | --- | --- |
Expand All @@ -196,7 +196,11 @@ The gateway identifies the conversation from the first of these request headers
| `x-opencode-session-id` | OpenCode | the session; a child session has its own ID |
| `thread-id` (Responses route only) | Codex | the thread; a subagent has its own thread ID |

Headers that a client shares between a parent and its subagents, such as Codex `session-id` and `prompt_cache_key` or OpenCode `x-opencode-session` and `x-session-affinity`, do not identify a conversation. Claude Code speaks the Anthropic Messages API, which the gateway does not serve, so its headers apply only when a proxy in front of the gateway translates its requests to the Chat or Responses route and forwards them. Set `PC_GATEWAY_INJECTION=on` to inject every request (requests without a conversation ID then prepare individually), `PC_GATEWAY_INJECTION=off` to turn injection off, or `PC_GATEWAY_INJECTION_RESPONSES=off` to keep only the Responses route uninjected. A standalone gateway (`PC_GATEWAY_CORE_BASE`) injects only with `PC_GATEWAY_INJECTION=on`. An empty or failed preparation sends the request without injection.
Headers that a client shares between a parent and its subagents, such as Codex `session-id` and `prompt_cache_key` or OpenCode `x-opencode-session` and `x-session-affinity`, do not identify a conversation. Claude Code speaks the Anthropic Messages API, which the gateway does not serve, so its headers apply only when a proxy in front of the gateway translates its requests to the Chat or Responses route and forwards them.

When none of these headers supplies an ID, the gateway can identify a full-history Chat or Responses request using the route and a hash of the model, leading instructions, and first user message. The opening must contain a user message preceded only by system or developer messages. Responses requests linked through `previous_response_id` or `conversation` need a header for reuse. An inferred ID is local to the gateway process and applies only to preparation replay. Sessions with identical openings can share an inferred ID, so send an explicit conversation header when sessions must be distinct.

The combined deployment default skips injection if no explicit or inferred ID is available and logs `context injection skipped: no conversation identity`. With `PC_GATEWAY_INJECTION=on`, requests with no ID prepare individually when they have a usable user message. `PC_GATEWAY_INJECTION=off` disables injection and `PC_GATEWAY_INJECTION_RESPONSES=off` disables it for Responses only. Standalone gateways (`PC_GATEWAY_CORE_BASE`) require `PC_GATEWAY_INJECTION=on`. An empty or failed preparation sends the request without injection.

Set `PC_GATEWAY_INJECTION_CODE=on` to include code evidence from the Scope's code index in the prepared context; it is off by default and requires a configured repository for the Scope. When a replayed value no longer passes the check because a cited source changed (for example, the agent edited a cited file), the gateway discards that conversation's replay and prepares once more for the request instead of returning the withhold.

Expand Down
8 changes: 6 additions & 2 deletions docs/zh/docs/operate/deploy-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Gemini 关闭 Gateway 上下文注入。Claude CLI 只接受新的单轮文本

网关通过 UDS 连接 Core(`PC_GATEWAY_CORE_UDS`,即同机组合部署)时,默认向属于某个会话的 Chat 和 Responses 请求注入准备好的上下文。在同一会话内,每条新的用户消息只准备一次,该回合的后续请求(例如 Agent 的工具循环)精确重放同一结果。

网关按以下顺序,取第一个出现的请求头确定会话:
网关按以下顺序,取第一个值有效的请求头确定会话:

| 请求头 | 发送方 | 会话 |
| --- | --- | --- |
Expand All @@ -198,7 +198,11 @@ Gemini 关闭 Gateway 上下文注入。Claude CLI 只接受新的单轮文本
| `x-opencode-session-id` | OpenCode | 会话;子会话有自己的 ID |
| `thread-id`(仅 Responses 入口) | Codex | 线程;子代理有自己的线程 ID |

客户端在父代理与子代理之间共享的头不用于确定会话,例如 Codex 的 `session-id` 和 `prompt_cache_key`,以及 OpenCode 的 `x-opencode-session` 和 `x-session-affinity`。Claude Code 使用 Anthropic Messages API,而网关不提供该接口,所以只有在网关前的代理把它的请求转换到 Chat 或 Responses 入口并转发这些头时,Claude Code 的头才会生效。设置 `PC_GATEWAY_INJECTION=on` 会注入所有请求(没有会话 ID 的请求各自准备),设置 `PC_GATEWAY_INJECTION=off` 关闭注入,设置 `PC_GATEWAY_INJECTION_RESPONSES=off` 只关闭 Responses 入口的注入。独立运行的网关(`PC_GATEWAY_CORE_BASE`)只有设置 `PC_GATEWAY_INJECTION=on` 时才注入。准备结果为空或准备失败时,请求照常发送,不注入内容。
客户端在父代理与子代理之间共享的头不用于确定会话,例如 Codex 的 `session-id` 和 `prompt_cache_key`,以及 OpenCode 的 `x-opencode-session` 和 `x-session-affinity`。Claude Code 使用 Anthropic Messages API,而网关不提供该接口,所以只有在网关前的代理把它的请求转换到 Chat 或 Responses 入口并转发这些头时,Claude Code 的头才会生效。

如果这些头均未提供 ID,网关可以根据入口以及模型、开头的指令和第一条用户消息的哈希,识别携带完整历史的 Chat 或 Responses 请求。历史开头必须有用户消息,且其前面只能有 system 或 developer 消息。通过 `previous_response_id` 或 `conversation` 续接的 Responses 请求需要提供请求头才能复用准备结果。推导出的 ID 仅在当前网关进程内用于重放准备结果。开头完全相同的会话可能共享推导出的 ID,需要区分时请发送显式会话头。

如果既没有显式 ID 也无法推导 ID,组合部署默认跳过注入,并记录 `context injection skipped: no conversation identity`。设置 `PC_GATEWAY_INJECTION=on` 后,没有 ID 的请求如果带有可用的用户消息,就会各自准备。设置 `PC_GATEWAY_INJECTION=off` 关闭注入,设置 `PC_GATEWAY_INJECTION_RESPONSES=off` 仅关闭 Responses 入口的注入。独立部署(`PC_GATEWAY_CORE_BASE`)必须设置 `PC_GATEWAY_INJECTION=on` 才会注入。准备结果为空或准备失败时,请求照常发送,不注入内容。

设置 `PC_GATEWAY_INJECTION_CODE=on` 后,准备的上下文同时包含 Scope 代码索引中的代码证据;该选项默认关闭,并要求 Scope 已配置代码仓库。重放的内容因被引用的来源变化(例如 Agent 修改了被引用的文件)而不再通过检查时,网关丢弃该会话的重放,为该请求重新准备一次,而不是把 withhold 返回给客户端。

Expand Down
2 changes: 1 addition & 1 deletion gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Blocked calls return HTTP 403. Withheld calls return HTTP 400 unless the executo

In a combined UDS deployment, recall injection is enabled by default for requests with a conversation ID. The Gateway prepares context once per new user message and reuses it for tool continuations in that turn. Core verifies the injected text and its binding. Empty or failed preparation leaves the request uninjected.

Use `X-PowerContext-Conversation-ID` to identify a conversation. The Gateway also recognizes client session headers from OpenCode, Codex and translated Claude Code traffic. See [context injection settings](../docs/en/docs/operate/deploy-server.md#gateway-context-injection) for header precedence and subagent handling. Standalone deployments require `PC_GATEWAY_INJECTION=on` to enable injection.
Use `X-PowerContext-Conversation-ID` to identify a conversation. The Gateway also recognizes client session headers from OpenCode, Codex and translated Claude Code traffic. Without a valid header, eligible full-history requests get a process-local identity for preparation replay from their opening messages. See [context injection settings](../docs/en/docs/operate/deploy-server.md#gateway-context-injection) for header precedence and fallback behavior. Standalone deployments require `PC_GATEWAY_INJECTION=on` to enable injection.

Set `PC_GATEWAY_SEDIMENT=on` to capture completed user turns as Sources for later extraction. Capture excludes injected context and provider reasoning ciphertext. Tool continuations remain open until the final response. Long turns are split into Sources, and Core stores all parts in one batch. With a trusted conversation ID, captures share a turn digest and include a digest of the ordered normalized Source parts in their Source IDs. Distinct terminal records are stored independently; identical normalized parts are idempotent even when provider response IDs or usage change. Existing Sources remain unchanged, and a repeated capture under the former turn-only ID creates a new Source. Capture requires a Core that supports batch capture. Capture failure does not prevent response delivery. Blocked and degraded turns are not captured.

Expand Down
Loading