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.
There was a problem hiding this comment.
Executed this at 504179c. A regression through the registered pre-step, MCP policy, and request-header hooks fails: failed pre-step resolution produces no Scope header; successful MCP recovery then changes the header to the workspace Scope without another pre-step. I sent those emitted headers through the gateway built from this head, authenticated real Core/SQLite, and a real model provider using a service principal granted only the two test Scopes. Both requests returned 200, but Core before_send/before_release used the default Scope for the first and the workspace Scope for the second. An ungranted Scope was rejected by Core (403; gateway 503). Please keep the gateway snapshot separate from the tool-resolution cache. Hook scheduling was driven by a test fixture; this is not a full native DSH-host reproduction, and injection/capture were disabled for this focused authorization check.
There was a problem hiding this comment.
Thanks for the trace and for the reproduction through the registered hooks. Fixed in 5f7e68b. The fallback for an unresolved prompt also changes, in its own commit dc99036, so you can take the fix without it. Both commits sit on a merge of master (fd1aef2).
5f7e68b: snapshot fix
- Gateway routing no longer reads the resolution cache that MCP tool calls write. It keeps its own snapshot per session.
- Only the pre-step's resolution writes it. That resolution runs on the step that brings the prompt's messages, resets the snapshot, and records its result, an unresolved result included.
- MCP tool resolutions never touch it. Neither do later steps of the same prompt: DSH runs the pre-step before every step, and a tool continuation brings no new messages, so it resolves nothing.
Regressions in tests/automatic-path.spec.ts drive the registered agent/pre-step, MCP tools/pre-execute, and llm-pi-ai/request-headers hooks:
- a failed pre-step followed by a successful MCP resolution, which is the case you reproduced;
- a successful pre-step followed by an MCP resolution from another cwd that returns another Scope;
- a successful pre-step followed by an MCP resolution from another cwd that fails.
All three fail against the source of 504179c and pass now.
A fourth test covers a pre-step with no new messages, such as the step that continues after a tool call. It resolves nothing and leaves the snapshot as it is.
dc99036: fallback
A prompt with no usable Scope no longer falls back to the gateway's default Scope. That covers an unresolved prompt, an ID the header cannot carry, and a request that cannot be matched to a prompt. Such a request to the gateway provider now carries X-PowerContext-Turn: internal and no Scope or conversation header. Every gateway request therefore either carries the prompt's Scope or is internal.
This follows frf12's point on #3003 (r4789222611): a failed or timed-out resolution is not a resolution to the default Scope, and omitting the header lets the gateway recall and capture there.
What the gateway does with an internal request without a Scope header, from the source and a run against this branch's gateway and an enforced Core:
- it does not prepare, inject, replay, steer, or capture;
- Core still runs
check_contexttwice (before_sendandbefore_release) inPC_GATEWAY_DEFAULT_SCOPE; - with a default Scope ID that names no Scope, Core's check fails and the gateway answers 503.
The DSH guide (en and zh) and the plugin README describe this. The gateway_scope diagnostic is unchanged.
What ran
Offline on dc99036:
- the plugin's tests (1228) and
test:e2e(9); - bundle rebuild with no diff;
- dsh-pet and Cindy tests;
- lifecycle
--check; - the Python tests that read the DSH guide (307 passed, 1 skipped);
prek, includingty check.
Real DSH 0.2.2-rc.5 run with the plugin's lib/ as committed in dc99036, through a Server and gateway built from this branch to a stub upstream (no model provider), with the bootstrap token:
- three prompts, including an MCP call and its tool continuation: all five model requests carried the workspace Scope, and prepare, checks, and capture all ran in it;
- a prompt whose Scope resolution failed (401 from an invalid plugin credential): both of its requests were internal, with checks in the default Scope and nothing prepared or captured.
Not run
- a Core credential restricted to the listed Scopes;
- compaction and auto-review behind the gateway;
- an unsupported Scope ID on a real host;
- a real model provider.
hidb4ai's run with a service principal limited to two Scopes remains the only restricted-credential evidence.
There was a problem hiding this comment.
Verified fixed at dc99036 and in its merge with master eb0a354. The registered-hook regression now keeps identical internal headers before and after successful MCP recovery; only the next prompt selects the resolved workspace Scope. I ran those emitted headers through a real authenticated Core/SQLite, the compiled Gateway, and a real Qwen provider with injection and capture enabled: both internal requests returned 200 but created no Source in either Scope; the next prompt returned 200 and created one Source in the workspace while the default Scope remained empty. An ungranted Scope returned Core 403 / Gateway 503 with no model choices. Both runs stopped their child processes. Host hook scheduling was fixture-driven; this is not a native DSH-host acceptance claim.
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.
hidb4ai
left a comment
There was a problem hiding this comment.
The existing Scope-snapshot defect is reproduced at this head; the thread now includes registered-hook reproduction and real Gateway/Core/model evidence. Tool recovery can switch the Scope used by later requests of the same prompt. Holding approval until gateway routing retains its own pre-step snapshot. A separate local companion-memory cancellation test timed out on this head while passing on the base; its test and implementation are unchanged, so I have not attributed that failure to this change.
The gateway Scope header read the session's resolution cache, which MCP tool calls also write. After a failed pre-step, a later successful tool resolution moved the rest of the prompt's model requests from the gateway's default Scope to the workspace Scope, splitting recall replay, Core's checks and capture across Scopes within one tool loop. A tool resolution for another cwd, or a failed tool refresh, could likewise change or drop the prompt's Scope. Gateway routing now keeps its own snapshot per session. The pre-step's Scope resolution, which runs on the step that brings the prompt's messages, starts it as unresolved and fills it; later steps of the prompt and tool resolutions leave it unchanged.
…le Scope Without a Scope header the gateway prepares, injects and captures a turn in its default Scope, not the workspace's. A failed, timed-out or empty Scope resolution is not a resolution to that Scope, so a prompt that resolved no Scope, or one whose ID the header cannot carry, now sends its requests to the gateway provider with X-PowerContext-Turn: internal and no Scope or conversation header. A request that cannot be matched to a prompt is treated the same way. Every gateway request then either carries the prompt's Scope or is internal; Core still checks internal requests, in the gateway's default Scope. Requests to other providers are unchanged. The gateway_scope diagnostic keeps its event, outcome and reasons. The DSH guide (en and zh) and the plugin README describe the fallback.
hidb4ai
left a comment
There was a problem hiding this comment.
Re-reviewed dc99036. The independent prompt snapshot fixes the reported Scope drift, including failed resolutions; marking unresolved requests internal prevents default-Scope preparation/capture. Provider-specific routing and the documented default-Scope authorization checks are reasonable. Real Core/SQLite -> Gateway -> Qwen verification passed on both this head and the current master merge with injection/capture enabled: internal requests create no Sources, the next resolved prompt captures in the workspace, and an ungranted Scope is denied. The merged automatic-path suite passes all 71 tests. Full plugin run: 1224 passed, 2 skipped, 2 timeouts; both timeout cases also fail on the declared base, so they are not attributed to this change. Plugin rebuild matches checked-in output; Rust 1.95.0 locked build passes. Current CI: 14 success, 35 skipped. Merge with master eb0a354 is clean (tree adc8a10fd34a6f98571eb37f656a7847370c6f78). No new table or migration; the new configuration option is acceptable. Merge score: 82/100. Native DSH host scheduling, non-SQLite backend acceptance, and actual recalled-context quality were not established by these focused tests.
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).Recall replay, Core's checks, and capture all follow the Scope header, so every model request of a prompt must select the same Scope. The header therefore comes from the prompt's own Scope resolution and nothing else.
A failed, timed-out, or empty resolution is not a resolution to the gateway's default Scope. Omitting the header in that case would let the gateway recall from and capture into
PC_GATEWAY_DEFAULT_SCOPEinstead of the workspace's Scope, as noted on RFC #3003 (review comment). Without a usable Scope the plugin therefore marks the request internal, which matches its own path: it skips recall and capture when nothing resolves.What changes are included in this PR?
Setting. A new setting names the
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 headers below, so a provider that DSH calls directly never receives them.When the header is sent. Only while prompt recall is off, through the same
llm-pi-ai/request-headershook that sends the conversation and internal-turn headers. With recall on, the hook is not registered, as before.Which Scope. The header carries the Scope that the prompt's pre-step resolved.
agent/pre-stepbefore every step of the agent loop, but only the step that brings the prompt's messages resolves the Scope. That resolution resets the snapshot and records its result, an unresolved result included.Internal requests. Compaction, session-title, and auto-review requests also carry the Scope header, as in Pi, so Core checks them in the same Scope as the session's turns. They still carry
X-PowerContext-Turn: internaland no conversation header.Fallback. A request to the gateway provider carries
X-PowerContext-Turn: internaland no Scope or conversation header in these cases:Every request to the gateway provider therefore either carries the prompt's Scope or is internal.
before_sendandbefore_release, inPC_GATEWAY_DEFAULT_SCOPE.invalid_scope_idotherwise. Scopes from early releases can have other IDs, and 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).gateway_scopediagnostic per such prompt, not one per request:outcome: skipped,reason: scope_unresolvedorscope_id_unsupported, never the ID./pc, and MCP tools still use the resolved Scope.Other providers. Requests to other providers are unchanged. The conversation header and the internal marker work as before.
Docs. The DSH guide (en and zh) and the plugin README document:
scope.contributoron each workspace Scope the plugin sends. This is in the grant list the guide already gives forPC_GATEWAY_DEFAULT_SCOPEand every Scope a request selects;Bundle.
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. When Core enforces authentication, the gateway's Core credential therefore needs
scope.contributoron every such Scope as well as onPC_GATEWAY_DEFAULT_SCOPE.A prompt without a usable Scope gets no recall from the gateway and is not captured by it. Core still checks its requests in
PC_GATEWAY_DEFAULT_SCOPE.No breaking changes.
How was this change tested?
The plugin has two kinds of evidence: behavior tests that drive its registered DSH hooks with fixtures, and real-host runs.
Behavior tests
New behavior tests in
integrations/dsh/plugins/powercontext/tests/automatic-path.spec.tsdrive the registeredagent/pre-step, MCPtools/pre-execute, andllm-pi-ai/request-headershooks.Named provider. With recall off, requests to the named provider carry the Scope, internal requests included. The setting works from both the patch and the environment, and the environment overrides the patch.
Other providers. Requests to any other provider carry no Scope header, and the prompt makes only Scope resolution and capture requests.
Unnamed or recall on. Without a named provider, or with recall on, no request carries the Scope header.
Snapshot. The gateway Scope stays the pre-step's for the rest of the prompt in each of these cases:
The next prompt takes what its own pre-step resolves. The first and the last two cases fail against the plugin source before this fix.
Unresolved prompt. Its gateway requests, session-title included, carry
X-PowerContext-Turn: internaland nothing else from the plugin. A direct provider still gets the conversation header. The plugin logs exactly onegateway_scopediagnostic per prompt, with no prompt text in it.Unmatched request. A gateway request before any prompt resolved, or without a session ID, is internal and reported.
Unsupported IDs. A Scope ID with a comma, a space, non-ASCII Latin-1 text, non-Latin-1 text, or more than 256 characters marks the gateway requests internal and raises no exception. The plugin's capture still uses the Scope, and the plugin logs one
scope_id_unsupporteddiagnostic per prompt without the ID. IDs at the edges of the accepted syntax (!,~, 256 characters) are still sent.Failed resolution. A later prompt whose resolution fails drops the previous prompt's Scope.
Config. A non-string
gatewayProvideris rejected.Commands
Commands run on
dc990368a, offline, macOS:tests/companion-memory.spec.tspassed in each of five separate runs on this commit.The plugin has no typecheck target.
tsc --noEmitover itstsconfig.jsonreports only errors that exist on master, none on the lines this PR adds.tests/e2ehas no test of DSH behind the gateway.Gateway handling of the fallback headers
Setup:
pc-gatewaybuilt from this branch (cargo build --locked --offline). The two plugin commits do not touchgateway/.enforced, protectionenforcing.PC_GATEWAY_SEDIMENT=on, andPC_GATEWAY_DEFAULT_SCOPEset to a Scope other than the workspace Scope, each Scope holding a distinct synthetic fact.Responses requests sent with
curl, with the Server's log of each Core operation and its Scope:X-PowerContext-Turn: internalonly (the plugin's fallback)check_contextcalls in the default Scope; no prepare, no captureX-PowerContext-*headerinternaland the workspace ScopeA second gateway was set up with
PC_GATEWAY_DEFAULT_SCOPEset to a valid ID that names no Scope:internalalone: Core'scheck_contextfailed withScopeNotFoundErrorfor that ID, and the gateway answered 503gate_paused(gate rejected: HTTP 404).internalwith the workspace Scope: 200.The gateway source agrees.
request_scopefalls back toPC_GATEWAY_DEFAULT_SCOPE.internalturns off steering, injection, replay, prefix capture, and sediment, but not the checks. Core'scheck_contextauthorizesscope.readon the request's Scope when access is enforced, and authorizes nothing when access control is off.Real-host run
Real-host run with the plugin's
lib/as committed indc990368a. The client was DSH 0.2.2-rc.5 (--profile headless,@deepseek-ai/dsh-llm-pi-ai0.2.2-rc.5). It went through the Server and gateway above, set up as the guide shows (PC_GATEWAY_UPSTREAM_URL_RESPONSESat the stub,PC_GATEWAY_UPSTREAM_PROFILEnaming the target), to the stub upstream. No model provider was called.PC_GATEWAY_CORE_TOKENwas the Server's bootstrap token.POWERCONTEXT_DSH_PROMPT_RECALL=false,POWERCONTEXT_DSH_CAPTURE_PROMPTS=false, andPOWERCONTEXT_DSH_GATEWAY_PROVIDER=powercontext-gateway, using the guide's provider 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. The call'sscope_idwas 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 binding resolution returned. That includes the request that continued after the tool call, whose pre-step resolved nothing. In rc.5,request.providerinllm-pi-ai/request-headersis the provider's key underproviders.X-PowerContext-Conversation-ID. The session-title request carriedX-PowerContext-Turn: internaland no conversation header.One more prompt ran in a new session with the plugin's Server credential replaced by an invalid one, so that its Scope resolution failed:
X-PowerContext-Turn: internal;PC_GATEWAY_DEFAULT_SCOPE;Not covered by a real run
gateway_scopediagnostic is covered only by the tests; DSH's headless output does not show plugin diagnostics.dsh web), and a real model provider.AI usage statement
Claude Code (Claude Opus 5.5) wrote the change, ran the checks and runs 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, the gateway and Server source, and the runs' recorded requests and Server logs. Another Claude Code session (Claude Opus 5.5) reviewed the change and this description, checked the gateway claims against
ingress.rs, and reran the plugin's tests (1228 passed), the bundle rebuild (no diff tolib/), and the new tests against the source before the fix and after the first commit.