Repository navigation
Conversation
hidb4ai
left a comment
There was a problem hiding this comment.
Reviewed 504179c. The provider-scoped header and documented fallback are reasonable; no new database tables. Focused tests, plugin HTTP acceptance, and a real DSH 0.2.2-rc.5 → current Gateway → OceanBase/real-provider run passed, with workspace Scope routing and capture isolated from the default Scope. The real run used disabled protection and did not exercise compaction, auto-review, or a successful MCP tool call. Merge score: 80/100.
|
The affected modules are Gateway. @frf12, please coordinate follow-up. Gateway: @frf12 @happy-v587 @NeverENG. Please coordinate the review of the affected changes. |
| // A request without a session ID cannot be matched to a prompt's resolution. | ||
| if (!sessionId) return { scopeId: undefined, attempt: 0 } | ||
| const key = keyFor(sessionId, undefined) | ||
| return { scopeId: cache.get(key)?.scopeId, attempt: attempts.get(key) ?? 0 } |
There was a problem hiding this comment.
[P2] Keep the gateway Scope fixed to the prompt resolution
If pre-step Scope resolution fails but a later MCP tool retry succeeds, forTool repopulates this cache and subsequent gateway requests for the same prompt switch from PC_GATEWAY_DEFAULT_SCOPE to the workspace Scope. Snapshot the pre-step result separately so tool retries cannot change the Scope used for that prompt's preparation, checks, and capture.
There was a problem hiding this comment.
Re-review of 504179c2cbb974fe8e7379e2d5f4ed38197ba301: this P2 remains in the current source and published bundle. The concrete state transition is:
forPreStepincrements the prompt attempt, deletes the cache entry, and fails to resolve a Scope.forGatewaythen returns no Scope, so the first model request uses the gateway default.registerMcpPolicylater callsforToolfor the same session. A successful retry writes the workspace Scope into that same cache without starting a new prompt attempt.forGatewayat lines 126–130 now returns the workspace Scope, so the next model request of the same prompt selects a different Scope.
This splits recall replay, admission checks, and turn capture across Scopes within one tool loop. Please retain an independent pre-step snapshot for gateway routing, including an unresolved result, and add a regression covering failed pre-step resolution followed by successful MCP resolution. The tool's recovery must not mutate the prompt's gateway snapshot. This is a source-level execution trace; I did not rerun a host reproduction in this re-review.
NeverENG
left a comment
There was a problem hiding this comment.
Re-review report — host integration
Reviewed head: 504179c2cbb974fe8e7379e2d5f4ed38197ba301.
Result: one P2 finding remains; fix and re-review recommended.
Gateway routing still reads the same mutable Scope cache that MCP tool recovery populates. If pre-step resolution fails, the first model request uses the gateway default Scope; a successful MCP resolution can then move subsequent requests of that prompt to the workspace Scope. Preserve a separate pre-step routing snapshot, including failure. Details and the exact execution trace are in the existing finding thread.
Reviewed configuration, Scope resolution and MCP callers, provider header filtering, published bundle, documentation, and relevant tests. Existing CI for this head passed 1,223 package tests and runtime/package checks. Those checks do not establish a real DSH-to-Gateway acceptance for the newly added Scope header.
Validation scope: I inspected the current source, complete PR diff, existing review threads, and CI logs for this head. No new local test run was performed in this re-review. The cited CI ran a test merge with its then-current base; it is not proof of a merge with the latest master. This is a comment-only report, not an approval or an unconditional merge recommendation.
Which issue or RFC does this PR close?
Part of #2250.
Follows #2873 (merged), which lets DeepSeek Harness (DSH) leave prompt-time context to the PowerContext gateway.
Rationale for this change
Behind the gateway, DSH's turns are prepared, checked, and captured in the one Scope set by
PC_GATEWAY_DEFAULT_SCOPE, while the plugin already resolves a Scope for each workspace and uses it for prompt capture and MCP tools. Sending that Scope asX-PowerContext-Scope-IDlets the gateway work in the same Scope as the rest of the plugin, so one gateway serves several workspaces. This follows Pi (#2893,POWERCONTEXT_PI_GATEWAY_PROVIDER) and OpenCode (#2903).What changes are included in this PR?
llm-pi-aiprovider that routes through the gateway: the patch settinggatewayProvider(a string), orPOWERCONTEXT_DSH_GATEWAY_PROVIDER, which takes precedence. Only requests whoseproviderequals it get the Scope header, so a provider that DSH calls directly never receives one.llm-pi-ai/request-headershook that sends the conversation and internal-turn headers. With recall on, the hook is not registered, as before.agent/pre-step. The request hook is synchronous and makes no network call; every request of a prompt reuses that prompt's resolution.X-PowerContext-Turn: internaland no conversation header.PC_GATEWAY_DEFAULT_SCOPE. The gateway accepts one ID of 1–256 visible ASCII characters without a comma and answers HTTP 400invalid_scope_idotherwise, while Scopes from early releases can have other IDs; a non-Latin-1 ID would also makeHeaders.setthrow inside the hook. This follows_scope_headersin the prefixed extraction (feat(gateway): bind model requests to an explicit Scope #2810). A prompt that resolved none does not reuse an earlier prompt's Scope. The plugin logs one content-freegateway_scopediagnostic (outcome: skipped,reason: scope_unresolvedorscope_id_unsupported, never the ID) per such prompt, not one per request. Scope resolution, prompt capture,/pcand MCP tools still use the resolved Scope.scope.contributoron each workspace Scope the plugin sends, in the grant list the guide already gives forPC_GATEWAY_DEFAULT_SCOPEand every Scope a request selects;lib/index.jsandlib/index.d.tsare rebuilt.Are there any user-facing changes?
Yes.
POWERCONTEXT_DSH_GATEWAY_PROVIDER/gatewayProvideris new and unset by default. While it is unset, DSH sends no Scope header, as before. Once it is set and prompt recall is off, the gateway prepares, checks, and captures in each workspace's Scope, so when Core enforces authentication the gateway's Core credential needsscope.contributoron every such Scope as well as onPC_GATEWAY_DEFAULT_SCOPE. No breaking changes.How was this change tested?
New behavior tests in
integrations/dsh/plugins/powercontext/tests/automatic-path.spec.tscover:gateway_scopediagnostic per prompt, with no prompt text in it.scope_id_unsupporteddiagnostic per prompt without the ID. IDs at the edges of the accepted syntax (!,~, 256 characters) are still sent.gatewayProvideris rejected.Commands run on
504179c2c(this commit on master818467a50), offline, macOS:These tests drive the plugin's DSH hooks with fixtures.
tests/e2ehas no test of DSH behind the gateway.Real-host run on
504179c2c: DSH 0.2.2-rc.5 (--profile headless,@deepseek-ai/dsh-llm-pi-ai0.2.2-rc.5) with the plugin'slib/built at that commit, through a Server and apc-gatewaybuilt from it (cargo build --locked --offline), to a local stub Responses upstream. No model provider was called.enforced, protectionenforcing, one target.PC_GATEWAY_UPSTREAM_URL_RESPONSESat the stub,PC_GATEWAY_UPSTREAM_PROFILEnaming the target,PC_GATEWAY_SEDIMENT=on, andPC_GATEWAY_DEFAULT_SCOPE.PC_GATEWAY_CORE_TOKENwas the Server's bootstrap token.PC_GATEWAY_DEFAULT_SCOPEwere different Scopes, each holding a distinct synthetic fact.POWERCONTEXT_DSH_PROMPT_RECALL=false,POWERCONTEXT_DSH_CAPTURE_PROMPTS=falseandPOWERCONTEXT_DSH_GATEWAY_PROVIDER=powercontext-gateway, using the guide'spowercontext-gatewayprovider entry.Three prompts went to
powercontext-gatewayin one session: a new session, a follow-up, and a prompt that the stub answered with anmcp__powercontext__search_memorycall whosescope_idit copied from the Scope routing in DSH's runtime context. A recording proxy in front of the gateway showed:X-PowerContext-Scope-IDwith the workspace Scope that the plugin's binding resolution returned, the same Scope that the routing names. So in rc.5,request.providerinllm-pi-ai/request-headersis the provider's key underproviders.X-PowerContext-Conversation-ID.X-PowerContext-Turn: internaland no conversation header.scope_idreturned the workspace fact.gateway_scopediagnostic.X-PowerContext-*header. As the guide describes, Core rejected the agent-loop requests, which carry the plugin's prepared-context block, and the gateway returned HTTP 503. The session-title request, the only one that reached the upstream, was captured inPC_GATEWAY_DEFAULT_SCOPE.Not covered by a real run:
dsh web) and a real model provider.AI usage statement
Claude Code (Claude Opus 5.5) wrote the change, ran the checks listed above, and wrote this description. It reviewed the diff twice, once for the implementation and once for users and the documented contract, and checked each claim in this description against the diff, the tests, and the run's recorded requests. After #2920 reverted #2630, it moved the guide's grant and trust text to master's gateway setup. After #2873 merged, it rebased the change onto master and reran the checks and the real-host run above on the rebased commit. Another Claude Code session (Claude Opus 5.5) reviewed the change, the rebase and this description before the PR was opened, without rerunning the checks.