Skip to content

docs(rfc): propose a PowerContext gateway model route for DSH - #3003

Open
jasper-yl wants to merge 13 commits into
oceanbase:masterfrom
jasper-yl:rfc/dsh-gateway-model-route
Open

jasper-yl wants to merge 13 commits into
oceanbase:masterfrom
jasper-yl:rfc/dsh-gateway-model-route

Conversation

@jasper-yl

@jasper-yl jasper-yl commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Which issue or RFC does this PR close?

This PR adds a new RFC and closes no issue. Related: #2040.

Modules and coordination

Primary coordinator: @frf12.

Affected module What this RFC asks of it Owners
Gateway (module:gateway) npm platform packages for pc-gateway; a service definition that covers the gateway @frf12 @happy-v587 @NeverENG
Core (module:core) powercontext service extended to the gateway; publication of the Core runtime archive @hidb4ai @frf12 @Fengzdadi @beatenevo
DSH integration (integrations/dsh/, module:other) The model route, per-session switching and the configuration page in the plugin @knqiufan @hidb4ai

The runtime archive reuses the managed resource producer that Desktop uses, so @PsiACE may want to look at section 5. I cannot set labels on this repository; please add the module labels.

Rationale for this change

DSH users have two ways to use PowerContext today, and each has a gap:

  • The plugin captures only the user prompt. In a real run on DSH 0.2.2-rc.5, a decision the assistant made after a tool call was not stored and a new session could not recall it. Through the gateway the same decision was recalled, because the gateway captures the whole turn.
  • The plugin registers all 63 MCP tools: the first request is 34,432 input tokens against 4,389 without the plugin (Token and latency costs along the Hook → capture → flush → recall chain: measurements and proposed changes #2040 measured the same kind of cost on other hosts).
  • The gateway path needs Core, the gateway, a hand-written DSH provider patch, Core's upstream target and several environment variables, started in three terminals. DSH's own plugin installation takes one package name, and powercontext-dsh is not on npm yet, so the documented installation returns 404.

What changes are included in this PR?

One RFC, in English and Chinese (docs/{en,zh}/rfcs/3003-dsh-gateway-model-route.md). It proposes:

  • The DSH plugin registers a powercontext-gateway model route through DSH's built-in llm-pi-ai adapter. A session on that route leaves recall, injection and capture to the gateway; the plugin turns its own recall, capture, MCP tools and guidance off for that session. Sessions on other models keep the current behavior.
  • Installation the standard DSH way (powercontext-dsh from npm), the gateway executable as npm platform packages, the Core runtime archive downloaded on first use.
  • Core and the gateway run as the user's persistent service under powercontext service, extended to cover the gateway. The plugin only makes sure the service is running and keeps an explicit stop.
  • A model configuration page in the plugin panel. The design targets individual users under the default disabled protection mode.
  • A six-step delivery order in which each step is usable on its own, starting with the first npm publication of powercontext-dsh.

The RFC has a section with the evidence gathered so far and a list of what is not verified (Windows/WSL2, macOS, DSH Desktop, a mid-session model change, DeepSeek's official endpoint, a real npm optional-dependency installation).

Are there any user-facing changes?

No. This PR adds design documents only.

How was this change tested?

  • make docs-test passed with both files in place (lint 0 warnings and 0 errors, site tests, static build of 1,432 pages including the two RFC pages).
  • The evidence in the RFC comes from real runs on one Linux x86_64 host with DSH 0.2.2-rc.5, master 9e40f8996 and gpt-4.1-mini on api.openai.com: plugin path versus gateway path recall, token counts, route registration through the DSH settings service, per-session switching in a prototype of the plugin change, the managed runtime produced and smoke-tested for linux-x86_64, and powercontext service install/start/stop/crash recovery. The prototype is not part of this PR.

AI usage statement

Written with Claude Code (Claude). The measurements were run by the tool on a test machine and reviewed by the author.


中文摘要:本 PR 新增一份 RFC(中英文)。提案让 DSH 插件在模型选择器中登记 powercontext-gateway 路由:选中它的会话由 gateway 负责召回和完整回合采集,插件关闭自己的召回、采集、MCP 工具和使用指引;其他模型保持现有行为。安装按 DSH 标准方式进行,gateway 以 npm 平台包分发,Core 运行环境首次使用时下载,两者由扩展后的 powercontext service 统一管理,插件只确保服务在运行。RFC 中列出了已有的实测证据和尚未验证的部分。

🤖 Generated with Claude Code

jasper-yl and others added 4 commits December 2, 2026 23:01
Co-Authored-By: Claude <noreply@anthropic.com>
…f the DSH gateway route

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…posal

Co-Authored-By: Claude <noreply@anthropic.com>
jasper-yl and others added 3 commits December 3, 2026 00:47
Co-Authored-By: Claude <noreply@anthropic.com>
…ail on Responses

Co-Authored-By: Claude <noreply@anthropic.com>
…eclare strict mode on the route

Co-Authored-By: Claude <noreply@anthropic.com>
@jasper-yl

Copy link
Copy Markdown
Contributor Author

@frf12 A commitment on timing: once you, as primary coordinator, agree with the direction of this RFC, we will open the first implementation PR within 24 hours. We will not wait for this PR to be merged.

That first PR covers step 2 of the delivery order in section 9: the DSH plugin registers the powercontext-gateway model route and switches its own recall, capture and MCP tools per session, working with a gateway the user runs. A prototype of this step already ran on DSH 0.2.2-rc.5. The later steps (Scope header, gateway platform packages and service coverage, the Core runtime archive, the configuration page) follow as separate PRs.


关于时间的承诺:主责协调人同意本 RFC 的方向后,我们会在 24 小时内提交第一个实现 PR,不等本 PR 合并。第一个 PR 对应第 9 节交付顺序的第 2 步:插件登记 powercontext-gateway 模型路由,并按会话切换自身的召回、采集和 MCP 工具(配合用户自行运行的 gateway);这一步的原型已在 DSH 0.2.2-rc.5 上运行过。其余步骤各自单独提交。

@hidb4ai hidb4ai 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.

Reviewed 936ec20 as a design-only change. The bilingual proposal separates the model route, per-session behavior, managed service ownership, distribution, and unverified host acceptance. Both RFC pages compile as MDX and their relative references resolve. There are no implemented table or interface additions. Prototype measurements remain author-supplied evidence, not acceptance of an implementation in this PR. CI still needs to recover from the workflow-actions-check lockfile failure and run the selected checks before merge.

@jasper-yl

Copy link
Copy Markdown
Contributor Author

@hidb4ai Thanks for the review. The preflight failure was the uv.lock drift on the old base, fixed on master by #3005. I merged current master into this branch (head df23b7a46, no RFC content changed) and CI now passes.

感谢审阅。preflight 失败来自旧基线上的 uv.lock 不一致,master 已由 #3005 修复。我已把最新 master 合入本分支(head df23b7a46,RFC 内容没有变化),CI 现已通过。

@knqiufan knqiufan added module:gateway Primary module: model gateway, protocols and context injection module:core Core: PR changes under src/ module:other Other: changes without an applicable Knowledge base, Gateway, Core, Desktop or pc-mate label labels Dec 3, 2026

@knqiufan knqiufan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Overall the direction makes a lot of sense: bringing gateway-grade whole-turn capture and low token overhead into a single-plugin DSH install experience directly solves the biggest usability gap today.

Before moving into implementation, there are a few alignment and UX points against the current codebase that I'd recommend clarifying in the RFC:

  1. Contradiction on where the upstream API key is stored

    • Guide Step 3 says the upstream model key is stored in DSH's credential store and not written to a config file, while Section 6 says it is written to the service's 0600 env file (and Section 2 puts POWERCONTEXT_DSH_GATEWAY_KEY in DSH's credential store).
    • Please align both sections to clearly distinguish the DSH → local gateway key (DSH credential store) from the gateway/Core → upstream API key (0600 service env file).
  2. Alignment with existing powercontext service constraints & Desktop coexistence

    • Env file identity pinning: powercontext service binds the exact EnvironmentFileIdentity (inode/size/mtime) into the service definition. Editing models or rotating keys in the panel will invalidate the registered service unless it re-installs/reconciles and restarts the service — and it should merge rather than overwrite existing user env vars.
    • UDS vs. loopback HTTP: service/launcher.py currently rejects UDS for personal services. If loopback HTTP is used instead, PC_GATEWAY_INJECTION=on and PC_GATEWAY_SEDIMENT=on need to be explicitly enabled.
    • Coexistence with PowerContext Desktop: Desktop also manages the user's powercontext service with its own runtime path. Please clarify ownership and upgrade behavior when both Desktop and the DSH plugin are installed.
  3. DSH Web ownerLocal gate & panel write-operation security boundary

    • On dsh web, status-bridge.ts currently returns 403 owner_local_unverified unless ownerLocal: true or POWERCONTEXT_DSH_OWNER_LOCAL=true is configured. A user following Guide Step 1 on dsh web will be blocked at Step 2 before they can click Prepare or open Models.
    • At the same time, the panel is expanding from read-only status into privileged writes (downloading/unpacking runtimes, registering a login service, writing 0600 key files, modifying DSH profile providers). The RFC should specify the onboarding flow and authorization/confirmation boundary for dsh web vs. DSH Desktop.
  4. Per-session switching edge cases & UI uninstall cleanup

    • In integrations/dsh/plugins/powercontext/src/index.ts, companion-memory (dsh-pet) injects prepared-context blocks that the gateway rejects and is currently gated only by global promptRecall; it should be covered by per-session switching.
    • Please also confirm whether DSH supports per-session disabling for guidance and skills (not just process-wide registration), and whether uninstalling via DSH UI invokes a plugin hook to remove the powercontext-gateway provider from the user's profile (otherwise a broken orphan model stays in the selector).
  5. UX regression: buffered SSE replay instead of live token streaming

    • pc-gateway buffers the full upstream response for before_release before replaying SSE. On the gateway route, users will see no streaming tokens until the entire turn finishes — which feels like a hang on reasoning models (e.g. DeepSeek) or long code replies, and can hit client timeouts or response_buffer_limit_exceeded.
    • This should at least be called out in Drawbacks, and it's worth evaluating whether disabled protection mode can support live streaming passthrough.
  6. Failure UX & first-run onboarding friction

    • Fail-closed when stopped: Unlike the fail-open plugin path, a stopped service or unreachable Core breaks model calls on the gateway route. Please clarify whether PC_GATEWAY_DEGRADE=passthrough is enabled in disabled mode, and define clear error recovery prompts (start service / switch model).
    • First-run usability: Asking users to manually choose Responses vs. Chat Completions and enter raw URLs is error-prone; provider presets (DeepSeek, OpenAI, Custom) plus a Test connection button would significantly reduce setup failures. It would also help to clarify which model Core uses for background extraction when multiple models are configured, and to treat deduplication + China-accessible download mirrors for the ~205 MB runtime archive as a prerequisite for Step 5 rather than an open question.

整体方向非常认可:把 gateway 的完整回合采集和低 Token 开销整合进 DSH 单插件的安装体验里,切中了目前最大的易用性痛点。

在进入实现前,结合当前仓库实现和用户体验,有 6 点建议在 RFC 中先明确或对齐:

  1. 上游 API Key 存储位置描述前后不一致

    • Guide 第 3 步写上游模型密钥进入 DSH 凭据存储、不写配置文件,但第 6 节写上游密钥通过 0600 服务环境文件传给服务(第 2 节进 DSH 凭据存储的是 POWERCONTEXT_DSH_GATEWAY_KEY)。
    • 建议统一表述,明确区分 DSH → 本地 gateway 的鉴权密钥(DSH 凭据存储)与 gateway/Core → 上游模型的 API Key(0600 服务环境文件)。
  2. 与现有 powercontext service 约束及 Desktop 的共存问题

    • 环境文件指纹绑定:powercontext service 将 EnvironmentFileIdentity(inode/size/mtime)严格绑定在服务定义中。用户在面板修改模型或密钥后,服务定义会失效,必须触发重新 install/reconcile 并重启服务;同时写入环境文件时需合并保留用户已有变量,避免覆盖。
    • UDS 与回环 HTTP:service/launcher.py 目前禁止个人服务使用 UDS;如果采用回环 HTTP 模式,需要显式开启 PC_GATEWAY_INJECTION=on 和 PC_GATEWAY_SEDIMENT=on。
    • 与 PowerContext Desktop 共存:Desktop 同样管理本机 powercontext service 并绑定自身运行时路径,建议明确两者同时安装时的服务所有权与升级策略。
  3. DSH Web 的 ownerLocal 门禁与面板写操作安全边界

    • 在 dsh web 上,status-bridge.ts 默认在未配置 ownerLocal: true(或环境变量)时返回 403 owner_local_unverified,这会导致按 Guide 第 1 步装完插件的 Web 用户在第 2 步直接被拦住,无法点“准备”或配置模型。
    • 同时,面板从“只读状态展示”扩展为“高权限写操作”(下载解包运行环境、注册系统登录自启服务、写入含密钥的 0600 文件、修改 DSH profile 配置),建议明确 dsh web 与 DSH Desktop 两种宿主下的引导方式和鉴权/确认边界。
  4. 按会话切换的遗漏项与 UI 卸载清理机制

    • 现有 integrations/dsh/plugins/powercontext/src/index.ts 中,companion-memory(dsh-pet)会注入被 gateway 拒绝的 prepared-context 块,目前仅受全局 promptRecall 控制,改为按会话切换时需一并处理。
    • 建议确认 DSH 的 guidance 和 skills 是否支持按会话关闭(而非进程级全局注册),以及用户在 DSH UI 卸载插件时是否存在可用的卸载钩子来清理 profile 中的 powercontext-gateway 路由,避免模型选择器里残留不可用的孤儿项。
  5. 流式输出退化为“整轮缓冲回放”的用户体验落差

    • pc-gateway 因 before_release 机制会先完整缓冲上游响应再回放 SSE,用户在 gateway 路由下会失去实时逐字流式输出——在思考模型(如 DeepSeek)或长代码生成场景下会表现为长时间卡住无响应,甚至触发客户端超时或 response_buffer_limit_exceeded。
    • 建议至少在 Drawbacks 中明确说明这一体验代价,并评估在 disabled 保护模式下是否支持实时流式透传。
  6. 故障降级体验与首次配置门槛

    • 停机/异常体验:与插件路径 fail-open 不同,gateway 路由在用户手动停止服务或 Core 不可达时会直接阻断对话。建议明确 disabled 模式下是否开启 PC_GATEWAY_DEGRADE=passthrough,并在报错时给出清晰的恢复引导(启动服务 / 切回直连模型)。
    • 首次配置易用性:让普通用户自行判断 Responses 还是 Chat Completions 并手填完整地址容易出错,建议模型页提供常见供应商预设(DeepSeek、OpenAI、自定义)与 测试连接 按钮;同时说明多模型配置下 Core 后台抽取具体复用哪个模型及费用预期;并把 ~205 MB 运行时归档的去重与国内可达下载镜像作为第 5 步交付的前置条件,而非留作未决问题。

@frf12 frf12 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One clarification on the Scope-resolution fallback in section 4; the scenario and the existing behavior are described inline.


## 4. Scope

The plugin sends the Scope it resolves for the current working directory to the gateway in `X-PowerContext-Scope-ID`, so the gateway's recall and capture land in the same Scope as the `/pc` commands. Without a resolved Scope the header is not sent and the gateway uses its default Scope. The gateway's default Scope is set to the Server's default Scope.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we clarify whether “without a resolved Scope” includes a failed or timed-out resolution request?

The existing DSH resolver already asks Core to resolve the workspace binding with the Server-default fallback enabled. When resolution fails or returns no usable Scope, the current plugin skips recall and capture; it does not select another Scope itself.

For example:

  1. The current workspace is bound to Scope A.
  2. Its Scope-resolution request fails or times out.
  3. If the plugin follows this fallback by omitting X-PowerContext-Scope-ID, the gateway uses its instance default, Scope D.
  4. Recall and capture then run in D rather than A, even though the workspace binding has not changed.

A successful resolution to the Server's default Scope and a failure to resolve the intended Scope are different outcomes. As written, this sentence could turn a resolution failure into recall from, or a write to, another Scope. Could you clarify the intended failure behavior here so it preserves the existing Scope boundary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are right, and the sentence was wrong as written: it would have turned a resolution failure into recall from, and writes to, the gateway instance default. That was not intended. Fixed in 462971c9d (both languages):

  • Resolution keeps using the existing resolver (workspace binding, Server-default fallback allowed). When it succeeds, the plugin always sends the resolved Scope explicitly in X-PowerContext-Scope-ID, including when the result is the Server default.
  • When the request fails, times out, or returns no usable Scope, the plugin sends X-PowerContext-Turn: internal for that request. The gateway already treats such a request as a non-turn: it forwards it without preparing, injecting, or capturing. This keeps the current plugin behavior (skip recall and capture) and the model call still works.
  • So a request from the plugin never reaches the gateway instance default Scope. In your example the turn in the workspace bound to A is forwarded without memory; nothing is read from or written to D.

I also changed the delivery list so the Scope header ships in the same change as the route registration (items 2 and 3 together). Otherwise there would be a window in which the route exists without the header.

Not verified yet: I read the internal handling in ingress.rs / executor.rs but have not run this failure path through DSH. The implementation PR will cover it with a test.


你说得对,原句有误:按原文,解析失败会变成从 gateway 实例默认 Scope 召回并向它写入,这不是本意。已在 462971c9d 修正(中英同步):解析成功时始终显式发送解析出的 Scope(包括结果是 Server 默认 Scope 的情况);解析失败、超时或无可用 Scope 时,插件为该请求发送 X-PowerContext-Turn: internal,gateway 只转发,不召回、不注入、不采集,与插件现有行为一致。交付顺序也改为 Scope 请求头与路由登记在同一个改动中交付。该失败路径目前只读过 gateway 代码,尚未经 DSH 实际运行,会在实现 PR 中用测试覆盖。

… gateway route

Co-Authored-By: Claude <noreply@anthropic.com>
@frf12

frf12 commented Dec 3, 2026

Copy link
Copy Markdown
Member

@jasper-yl Thanks for the RFC, the real-host measurements, and the quick fix on the Scope fallback (462971c9d). I agree with the overall direction — feel free to go ahead and open the Step 2 implementation PR.

@knqiufan Regarding your point 2 on service env/config ownership, EnvironmentFileIdentity pinning, and Desktop/CLI/DSH coexistence: I plan to put together a dedicated configuration management design to unify how multiple clients manage shared powercontext service settings without stepping on each other. So we don't need to solve the full multi-client config ownership problem inside this RFC or block Step 2 on it — Step 6 (panel configuration) will align with that design once it lands.

For Step 4 (powercontext service covering the gateway and distribution), there are three design points I'd like to align on with @jasper-yl (non-blocking for Step 2):

  1. Gateway key ownership & multi-host sharing (Section 2 vs Section 6)
    Alongside @knqiufan's point 1 on separating the gateway key from the upstream API key: multiple DSH instances and other hosts (e.g., Codex, OpenCode) share the same persistent powercontext service.

    • If PC_GATEWAY_API_KEY is enabled on the service, having the DSH plugin generate its own key (POWERCONTEXT_DSH_GATEWAY_KEY) will either mismatch the running gateway (401) or overwrite the shared key and break other hosts.
    • If PC_GATEWAY_API_KEY is intentionally unset on loopback, then POWERCONTEXT_DSH_GATEWAY_KEY is just a client-side placeholder for llm-pi-ai rather than an auth credential.
      Could you propose how key ownership/sync should work across shared hosts (for example, having PowerContext / powercontext service allocate and persist it in a shared location)?
  2. Decoupling the gateway binary from DSH's node_modules (Section 5 vs Section 6)
    The gateway binary ships as npm optionalDependencies under powercontext-dsh, whereas powercontext service is a shared user-level service bound to an absolute executable path. Uninstalling or upgrading powercontext-dsh could remove or move the binary inside DSH's plugin directory and break the shared service for other Agents.
    Suggestion: during preparation/installation, copy or stage the gateway binary into the PowerContext data directory (managed alongside the Core runtime archive) so powercontext service does not depend on DSH's node_modules. What do you think?

  3. Combined UDS vs loopback HTTP (Unresolved Questions update README.md #4)
    I lean toward combined UDS deployment. Having Core unreachable when the gateway is down is an acceptable trade-off here — if the gateway fails, we should fix/recover the gateway anyway — and UDS gives us a single external port with recall injection enabled by default (with PC_GATEWAY_SEDIMENT=on still set explicitly). As @knqiufan noted, service/launcher.py currently rejects UDS for personal services, so Step 4 would lift that restriction and align on the single listening port (e.g., keeping 8000 for compatibility with existing /pc, Dashboard, CLI, and Desktop clients and updating baseURL in Section 2 accordingly).


中文摘要:感谢 RFC、实测数据以及对 Scope fallback 的快速修正(462971c9d)。同意整体方向,可以先按计划提 Step 2 的实现 PR。

关于 @knqiufan 提到的第 2 点(powercontext service 环境文件/配置归属、EnvironmentFileIdentity 绑定以及与 Desktop/CLI 共存时的覆盖问题):我后面会专门出一份统一配置管理设计,系统解决多端共用 powercontext service 的配置归属与防覆盖问题,不需要在本 RFC 里一次解决,也不用因此阻塞 Step 2;后续 Step 6(面板配置页)直接对齐那份设计即可。

另外在进入 Step 4 之前,有三个不阻塞 Step 2 的设计点希望和 @jasper-yl 提前对齐:

  1. 网关密钥归属与多宿主共享(第 2 节 vs 第 6 节):多个 DSH 和其他宿主共用同一份 powercontext service,由 DSH 插件自行生成密钥容易与服务侧的 PC_GATEWAY_API_KEY 不一致或覆盖破坏其他宿主;如果本机回环实际不设 PC_GATEWAY_API_KEY,则应明确它只是 llm-pi-ai 占位符。希望你给一个面向多宿主共享的方案(例如由 PC 服务统一分配和存放)。
  2. gateway 二进制与 DSH node_modules 解耦(第 5 节 vs 第 6 节):如果 powercontext service 直接绑定 DSH 插件目录里的可执行文件,卸载或升级 powercontext-dsh 会影响其他 Agent 共用的常驻服务。建议在准备/安装阶段把 gateway 二进制拷贝到 PowerContext 数据目录(与 Core 运行环境统一托管),想听听你的看法。
  3. UDS 组合部署 vs 回环 HTTP(未决问题 update README.md #4):我倾向于采用 UDS 组合部署。Gateway 挂了导致 Core 一起不可达可以接受(此时本来就应优先修复/拉起 Gateway),而且单端口更简洁、注入默认开启(显式配置 PC_GATEWAY_SEDIMENT=on 即可)。正如 @knqiufan 所指出的,service/launcher.py 目前对个人服务禁用了 UDS,Step 4 放开这一限制并统一对外端口(例如复用 8000 以兼容现有 /pc、Dashboard、CLI 和 Desktop,同时调整第 2 节的 baseURL)即可。

@jasper-yl

Copy link
Copy Markdown
Contributor Author

@frf12 Thanks. Starting now; the Step 2 implementation PR will be open by 2026-12-04 18:28 UTC (24 hours from your comment). It will include the Scope header with the failure behavior from 462971c9d, and per-session handling of companion-memory (@knqiufan's point 4).

I will answer your three Step 4 points and @knqiufan's remaining points in a separate comment, with the matching RFC changes.


收到,现在开始。Step 2 的实现 PR 会在 2026-12-04 18:28 UTC 前提交(自你的评论起 24 小时),其中包含 Scope 请求头(失败行为按 462971c9d)以及 companion-memory 的按会话处理(@knqiufan 的第 4 点)。Step 4 的三个设计点和 @knqiufan 其余几点,我会另行回复并同步修改 RFC。

@hireview001 hireview001 removed module:core Core: PR changes under src/ module:other Other: changes without an applicable Knowledge base, Gateway, Core, Desktop or pc-mate label labels Dec 3, 2026
@hireview001
hireview001 requested a review from frf12 December 3, 2026 18:34
…t, streaming, and failure behavior

Co-Authored-By: Claude <noreply@anthropic.com>
@jasper-yl

Copy link
Copy Markdown
Contributor Author

@frf12 @knqiufan Thanks both. The RFC is updated in 0223776d4 (both languages). What changed, by point:

@frf12's three points for Step 4 — all three adopted.

  1. Gateway key ownership. The plugin no longer generates a key. powercontext service allocates the gateway access key and keeps it in the PowerContext data directory; every host sharing the service reads it. The plugin only hands the value it read to llm-pi-ai. Section 6 now has a table that separates this key from the upstream API key.
  2. Gateway binary. The npm platform packages are a download channel only. Preparation copies the executable into the PowerContext data directory next to the Core runtime, and the service definition refers to that copy, not to DSH's node_modules.
  3. Combined UDS. Agreed: combined deployment, one external loopback port, kept at 8000. Section 2's baseURL is updated, and Step 4 includes lifting the UDS restriction in service/launcher.py.

@knqiufan's points

  1. Key storage contradiction. Fixed; it was an error in the guide text. The upstream key lives in the service's protected configuration, never in DSH's profile or credential store.
  2. Service constraints and Desktop. The RFC now defers configuration ownership, merging, and re-registration after the env file identity changes to the separate configuration management design, and Step 6 aligns with it. It also says the plugin reuses an existing service (for example Desktop's) without registering it again.
  3. ownerLocal gate. Not loosened. Desktop is the primary path and the panel writes there with a confirmation per operation; dsh web with ownerLocal behaves the same; dsh web without a confirmed owner gets no write operation, only the state and the equivalent terminal commands.
  4. Per-session switching and removal.
    • powercontextCompanionMemory is unavailable for sessions on the gateway route (in the Step 2 implementation).
    • Guidance can be switched per step, because DSH assembles the system prompt per step with the model selection. A Skill cannot: registration is global and I found no per-session interface. It stays visible; listed under Drawbacks.
    • I found no removal hook in DSH's plugin management. The route is removed by powercontext setup dsh --remove and a new /pc route remove command; removing only through the DSH interface leaves the route. Also under Drawbacks. If there is a hook I missed, I would much prefer to use it.
  5. Buffered replay. You are right, and my verification missed it: I checked that the result was correct, not when the output appeared. It is now the first item in Drawbacks. I also read check_context: outside enforcing mode the release check does not inspect the response, so in disabled mode the wait protects nothing. The RFC adds delivery item 7, live forwarding of streamed output in disabled mode, and says the route is not presented as the default recommendation before that lands. @frf12 this changes gateway behavior, so it needs your view; the open design questions are listed under Unresolved questions.
  6. Failure UX and onboarding.
    • The managed service runs with PC_GATEWAY_DEGRADE=passthrough, on the condition that the user can see memory is off. The plugin can show this itself: it resolves the Scope through Core before every step, and a failure already marks the request internal (section 4). A stopped service cannot degrade; the error message offers "start the service" or "switch to a direct model".
    • Provider presets (DeepSeek, OpenAI, Custom) and Test connection are in.
    • Extraction model: configured on the Models page, default "automatic" — prefix extraction with the turn's own model and cache, falling back to Core's generation model (default: the first configured model).
    • Archive deduplication and a mirror reachable from mainland China are now prerequisites of Step 5. Who provides the mirror is still open.

Not verified, and stated as such in the RFC: the Scope failure path on a real host, requests from other plugins such as dsh-pet through the route, and first-output delay on the route.


中文摘要:RFC 已在 0223776d4 更新(中英同步)。@frf12 的三点全部采纳:gateway 访问密钥由 powercontext service 分配并存放在 PowerContext 数据目录,插件不再生成;npm 平台包只作下载渠道,可执行文件复制到数据目录;采用 UDS 组合部署,对外端口沿用 8000。@knqiufan 的各点:密钥存放的矛盾已修正;配置归属交给独立的配置管理设计;ownerLocal 门禁不放宽,Desktop 为主路径;powercontextCompanionMemory 在 gateway 路由的会话上不可用,guidance 可按步省略,Skill 无法按会话隐藏,卸载没有找到钩子,改为提供 /pc route remove;整轮缓冲写入 Drawbacks,并新增第 7 项交付(disabled 模式下实时转发流式输出),需要 @frf12 的意见;受管服务默认 passthrough,前提是插件显示“本回合未使用记忆”;加入供应商预设、测试连接、抽取模型(默认自动);归档去重和国内镜像改为第 5 项的前置条件。

… DSH gateway route

Co-Authored-By: Claude <noreply@anthropic.com>
@jasper-yl

Copy link
Copy Markdown
Contributor Author

The Step 2 implementation PR is open: #3020. It covers delivery items 2 and 3 (route registration, per-session switching including powercontextCompanionMemory, the Scope header with the failure behavior from the review thread, and /pc route remove).

Two items I listed as unverified in my previous comment are now measured on a real DSH host and recorded in the RFC (d74ac562f):

  • Scope failure path. With resolution forced to fail, the turn completed, the gateway recorded the requests as internal, and no Source was added in any Scope. With resolution succeeding, the Source landed in the Scope the plugin resolved and not in the gateway's default Scope.
  • Streaming. With Core in disabled mode, a streamed request through the gateway got its first delta only when the whole reply ended, on both the Chat Completions and the Responses route (two runs each, 11–17 s replies). So the drawback applies to both routes, not only Responses.

Step 2 的实现 PR 已提交:#3020,覆盖第 2、3 项交付。上一条评论中标为未验证的两项已在真实 DSH 宿主上测量并写入 RFC(d74ac562f):Scope 解析失败时回合正常完成、请求被记为 internal、任何 Scope 都没有新增 Source;disabled 模式下经 gateway 的流式请求在 Chat Completions 和 Responses 两条路由上都是整轮结束才收到首个增量。

…patch

Co-Authored-By: Claude <noreply@anthropic.com>
@frf12

frf12 commented Dec 3, 2026

Copy link
Copy Markdown
Member

@jasper-yl Agreed on delivery item 7 (live streaming forwarding in disabled protection mode) — go ahead with it.


中文摘要:同意第 7 项交付(disabled 保护模式下的实时流式转发),按这个方向做就行。

@jasper-yl

Copy link
Copy Markdown
Contributor Author

@frf12 Thanks. Before writing item 7 properly I built a throwaway prototype to get numbers and find the hard parts. It is not pushed anywhere.

What the prototype does. Chat Completions route only, behind an environment switch: the transport hands each upstream chunk to the client as it arrives, the executor still accumulates the full body, and the release check and capture run on it after the stream ends.

Measured (gateway from master 718cf0a91 plus the prototype, Core in disabled mode, gpt-4.1-mini, a reply of about 10 s, three runs each, injection off because my Core install is older than the gateway):

First body bytes Whole reply Turn captured
Current behavior 10.7–14.2 s 10.7–14.2 s 3 of 3
Prototype, client reads to the end 0.45–0.75 s 11.0–12.5 s 3 of 3
Prototype, client closes at [DONE] 0.34–0.54 s 10.5–11.4 s 0 of 3

The third row is the real problem. Once the client closes, the call's lifecycle stops with request_cancelled right after response_received, before the release check and capture. Today that cannot happen, because the response is only written after both are done. Keeping the body open until capture finishes fixes the first client and not the second.

Two design points I would like your view on before I implement:

  1. Finishing after the client has gone. For a reply that was already delivered in full, I think the release record and capture should complete even if the client disconnects, with a bounded grace period so shutdown and admission accounting stay correct. A disconnect before the upstream reply ends would stay a cancellation as it is now. Is that the lifecycle rule you want?
  2. How the gateway knows it may forward early. The gateway does not know Core's protection mode; Core decides at check time. I see two options: the before_send result says that the release phase will not inspect the response, or the gateway reads it once from capabilities at startup, as it already does for degradation. The first is per request and exact; the second needs no contract change on the check path. I lean to the first.

Not covered by the prototype: the Responses route (the upstream request is non-streaming there today, so it needs the streamed send and SSE handling first), subscription channels, retries, and error replies after the first byte.


中文摘要:在正式做第 7 项之前,我做了一个不提交的原型来取数。Chat Completions 路由上,首个输出从 10.7–14.2 秒降到 0.45–0.75 秒,客户端读到流结束时回合照常被采集(3/3);但客户端在 [DONE] 后立即断开时,调用以 request_cancelled 终止,采集丢失(0/3)。想先确认两点:一是回复已完整送达后,即使客户端断开也应在限定的宽限期内完成释放记录和采集;二是 gateway 如何得知可以提前转发,是由 before_send 的结果声明,还是启动时从 capabilities 读取,我倾向前者。原型未覆盖 Responses 路由、订阅通道、重试和首字节之后的错误。

@frf12

frf12 commented Dec 4, 2026

Copy link
Copy Markdown
Member

@jasper-yl Thanks for the prototype and measurements. Agreed on both design points:

  1. Bounded finalization after the response completes. Once the upstream reply has reached its valid protocol end, a client closing at the terminal marker (such as [DONE]) should not cancel the remaining release record and capture. Let that work finish within a bounded grace period, preserving admission accounting and shutdown limits. A disconnect before the upstream reply completes should remain a cancellation.

  2. Per-request permission in before_send. I agree with your preferred option: use the existing before_send result to explicitly authorize early streaming for that request in disabled mode. Core derives this from the user's configured protection mode, and the gateway follows that decision. This reuses the existing check without another round trip. It should express permission to forward early, rather than only saying that the response body will not be inspected, since the current release phase also validates the request binding. The permission is established before forwarding starts; it is not a mechanism for Core to decide when to interrupt an already-released stream.

Please go ahead with item 7 on this basis.

@jasper-yl

Copy link
Copy Markdown
Contributor Author

@frf12 Thanks. The Chat Completions part of item 7 is in #3035, built on those two points:

  • Core returns early_release: true on an allowed before_send while protection is disabled; the gateway forwards only with that permission, and ignores it when it discovered an enforcing Core at startup.
  • A client that closes once it has data: [DONE] (or the whole body) no longer cancels the call. The release record and capture get up to 20 seconds after the connection ends, within the 180-second deadline and the drain limit, with the model permit held. A disconnect before the reply ends is still a cancellation.

Against api.openai.com the first body byte arrived after 0.41–1.62 s instead of at the end of the reply, and the three runs that closed at [DONE] were all captured. Details and limits are in the PR.

One point needs your view before I do the Responses route. The gateway sends Responses upstream without streaming, and the binding covers the exact payload, so stream: true has to be chosen when the request is rendered, before before_send returns the permission. I suggest an optional early_release hint in ContextProtectionCapabilities, read at startup like enforcing: with the hint the gateway renders streamed Responses requests for streaming clients, and the per-request permission still decides whether anything is forwarded early. A streamed reply without the permission would be buffered, converted to the terminal response and replayed as today. The alternative without a contract change is a second before_send after the first one returns the permission, which costs a round trip on every streamed turn. Which do you prefer?

I also updated the RFC text: item 7 now states the agreed design, the evidence table has the new measurements, and the response buffer limit is corrected to 1 MiB (I had written 16 MB, which is the request body limit).


中文摘要:第 7 项的 Chat Completions 部分已提交为 #3035,按上面两点实现:Core 在 disabled 模式的 before_send 准许结果里返回 early_release: true;客户端拿到 data: [DONE] 后断开不再取消调用,收尾工作在连接结束后最多 20 秒内完成。实测首个正文字节 0.41–1.62 秒到达,在 [DONE] 处断开的 3 次全部完成采集。Responses 路由需要在渲染请求时(before_send 之前)就决定向上游请求流式,我建议在 ContextProtectionCapabilities 里加一项启动时读取的 early_release 提示,逐请求的许可仍然是最终依据;不改契约的替代做法是拿到许可后再做一次 before_send,每个流式回合多一次往返。想听你的意见。RFC 正文已同步,并把响应缓冲上限更正为 1 MiB。

@hireview001 hireview001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@hidb4ai hidb4ai 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.

Re-reviewed 0923f5d as a documentation-only RFC. The updated text separates service and upstream credentials, requires an explicit resolved Scope or an internal turn, preserves shared-service ownership and manual stop, and documents uninstall, host, and streaming limits. The six earlier design concerns are now addressed or explicitly made prerequisites for implementation. Both language versions compile with MDX 3.1.1, their nine links agree and relative references resolve, and the current master d9c467a merges cleanly (tree e0b60f019b351b8b0123d9ce9d28e2602a49c8e3). Current checks: 7 success, 39 skipped. No runtime, table, migration, or implemented API changes. Merge score: 82/100. This approves the RFC, not the author-reported prototype measurements or future early-release implementation; real-host, official DeepSeek, and Responses streaming acceptance remain implementation gates. Other reviewers retain ownership of their outstanding review states.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:gateway Primary module: model gateway, protocols and context injection

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants