Repository navigation
feat(gateway): bind model requests to an explicit Scope - #2810
Conversation
Signed-off-by: wangshun <96341168+xixi-box@users.noreply.github.com>
NeverENG
left a comment
There was a problem hiding this comment.
Reviewed efc2cc4. No blocking findings in explicit Scope selection or the extraction callback. Recall, send/release checks, capture, prefix lookup, and the Python callback carry the selected Scope consistently; ambiguous selections are rejected.
|
please resolve conflicts |
|
Re-reviewed commit 1502599. No new correctness issue found in the Scope-routing changes, but merge readiness is still blocked:
Please reconcile the current master conflicts and investigate/re-run the failed acceptance check on the updated commit before merging. |
Signed-off-by: wangshun <96341168+xixi-box@users.noreply.github.com>
|
Re-reviewed 5bdaeb5. The previous merge conflicts are resolved, and I found no new correctness issue in Scope routing. Live Core/Gateway checks with a real model passed for cross-Scope Chat recall/capture and for non-default-Scope Responses prefix extraction; this validation used isolated SQLite. CI is still blocking merge: SQLite acceptance and the aggregate CI result failed. The uploaded LoCoMo evidence reports |
|
CI infrastructure follow-up: #2827 is now merged into Please merge the latest |
Signed-off-by: wangshun <96341168+xixi-box@users.noreply.github.com>
Brings in oceanbase#2859/oceanbase#2846 and the Harbor shared-download CI fix (oceanbase#2827) so the next acceptance run exercises the updated install path. Signed-off-by: wangshun <96341168+xixi-box@users.noreply.github.com>
Fengzdadi
left a comment
There was a problem hiding this comment.
Reviewed d9fb44e. No blocking concerns.
What I checked:
- Scope isolation of the gateway's per-conversation state. The replay cache matches on
(scope_id, conversation_id, anchor)(replay_cache.rs:81,:89,:105),PrefixStore::getrequires the stored Scope (prefix_store.rs:116), andturn_digesthashes the Scope together with the conversation (executor.rs:1342). I also ran an uncommitted test in thegateway_behaviorsharness: a tool turn in one Scope, then the same continuation with a second Scope, then with the first again. I ran it on Chat and Responses, once with a conversation header and once with the ID that #2813 infers. The second Scope got no replayed block and its own capture digest, and the first Scope's continuation replayed its context. - Header handling. Repeated, empty, comma-separated, over-256-byte and non-UTF-8 values return 400
invalid_scope_id, and the header is not forwarded upstream. - Mixed versions. An older Server sends no Scope on the extraction callback, so a handle from a non-default Scope is not found, the gateway returns
prefix_unavailable, and extraction falls back to the normal path. An older Gateway ignores the header. Neither direction errors. - Tests.
request_scope_binds_recall_checks_and_capturefails with the baseingress.rs, and three of the newtest_prefixed_extraction.pytests fail with the base sources.
Three optional notes, all docs:
- Trust boundary (
docs/en/docs/operate/deploy-server.md:190, zh:192). "Use a Gateway with clients trusted to select the Scopes available to its Core credential" is accurate, but the consequence could be spelled out. Any client with the gateway key can now have the gateway recall from and capture into every Scope thatPC_GATEWAY_CORE_TOKENcan reach, or every Scope when Core does not enforce access. On a loopback listener withoutPC_GATEWAY_API_KEY, that client is any local process. Before this change those clients reached onlyPC_GATEWAY_DEFAULT_SCOPE, so an upgrade note would help operators who relied on that default as a boundary. - Codex guide (
docs/en/docs/integrations/codex.md:415-418, zh:360-361). ThePC_GATEWAY_DEFAULT_SCOPEbullet ends at "to print that Scope" and no longer says what to do with it, and the provider block sends no Scope header, so a Codex user still lands in the fallback Scope. Codex's[model_providers.<id>]acceptshttp_headersandenv_http_headers(both present in Codex 0.167.2), so the provider block could carryhttp_headers = { "X-PowerContext-Scope-ID" = "<scope>" }. - Mixed versions in the docs. The PR body says prefix extraction for a non-default Scope needs both the updated Server and the updated Gateway. "Memory extraction over the cached prefix" (
deploy-server.md:235) does not say so yet. One sentence would do; the fallback itself is safe.
The other gateway guides still say the gateway uses only PC_GATEWAY_DEFAULT_SCOPE: Deep Agents, LangChain, LangGraph, OpenClaw and Pydantic AI, and the Pi, Hermes and Bub guides in #2755, #2829 and #2836. I'll update them after this merges, along with the Codex example from note 2 if it isn't in this PR by then.
|
Re-reviewed d9fb44e against 69c28d4. The blockers in my previous comment are resolved: the branch is mergeable, SQLite acceptance and the aggregate CI result now pass. I found no blocking correctness issue in the Scope-routing changes. Live tests with the current Core/Gateway and a real model passed for three-Scope Chat capture/recall isolation, headerless default behavior, injection-off control, persistence and recall after restart, and non-default-Scope prefix callbacks through both Chat/per-candidate and Responses/one-pass extraction. These checks used isolated SQLite; they do not establish OceanBase or native Codex/OpenCode host acceptance. No database tables or migrations are added. This does add a request-header contract ( |
Since #2810 a request selects its Scope with X-PowerContext-Scope-ID and falls back to PC_GATEWAY_DEFAULT_SCOPE, but the LangChain, LangGraph, Deep Agents, Pydantic AI, Hermes, OpenClaw, Dify and Bub gateway guides still said the gateway works in one Scope. Each guide now says how its host or application can send the header, what requests without it use, that the gateway's Core credential needs access to every Scope requests select, and links the Gateway request Scope trust boundary. Part of #2250.
Fixes #2804
Which issue or RFC does this PR close?
Closes #2804.
Rationale for this change
The shared model ingress always assigned
PC_GATEWAY_DEFAULT_SCOPEto the managed call. On a single Gateway serving several projects, recall and captured turns therefore went to the same Scope even when the requests came from different projects.What changes are included in this PR?
Read
X-PowerContext-Scope-IDon Chat and Responses and carry the selected Scope through recall, replay, both Core checks, and capture. The Server sends the Source window's Scope on prefix extraction callbacks so the Gateway can look up the captured prefix within that Scope. Add process-level regression coverage, verify the per-candidate and one-pass callback headers, and update the English and Chinese guides.Are there any user-facing changes?
Clients or trusted proxies can select a Scope with one header on each request. Requests without the header use the configured default. Invalid or repeated Scope headers return HTTP 400. Core applies its existing access rules under the Gateway's Core credentials. Prefix extraction for explicitly selected non-default Scopes requires the updated Server and Gateway. The normal extraction fallback applies when a prefix is unavailable.
How was this change tested?
Tests:
cargo test --locked --manifest-path gateway/Cargo.toml -p pc-gateway-app --test gateway_behaviors request_scope_binds_recall_checks_and_capture -- --exact.Result: cargo test --locked --manifest-path gateway/Cargo.toml -p pc-gateway-app --test gateway_behaviors — original module passed, 13 tests.
Result: cargo test --locked --manifest-path gateway/Cargo.toml -p pc-gateway-app --test gateway_behaviors request_scope_binds_recall_checks_and_capture -- --exact — base exited 101 and reported two gateway:fallback preparations for four requests. Patched exited 0 with 1 passed.
Result: cargo test --locked --manifest-path gateway/Cargo.toml -p pc-gateway-core --test executor_semantics — 92 passed on base.
Result: cargo test --locked --manifest-path gateway/Cargo.toml --workspace -- --skip live_ — passed after the fix, including all 14 gateway_behaviors tests, 92 executor semantics tests, and both tests in real_core_rpc_recovery. Four live_context_check cases were filtered out.
Result: uv run --locked pytest tests/builtin/artifacts/atomic_memory/test_prefixed_extraction.py -q — 31 passed before and after the change.
Result: uv run --locked pytest tests/builtin/artifacts/atomic_memory/test_prefixed_extraction.py -q -k 'a_gateway_turn_is_extracted_over_its_prefix_without_resending_the_transcript or a_one_pass_window_continues_the_prefix_through_every_step' — both updated cases failed before the Python fix because callback headers were absent. Both passed afterward.
Result: uv run --locked pytest tests/test_capture_content_sources.py -q — 9 passed.
Result: cargo +1.95.0 fmt --manifest-path gateway/Cargo.toml --all --check — passed.
Result: cargo +1.95.0 clippy --locked --manifest-path gateway/Cargo.toml --all-targets -- -D warnings — passed.
Result: uv run --locked ruff check src/powercontext/builtin/artifacts/atomic_memory/{extraction,prefixed_extraction}.py src/powercontext/builtin/runtime/atomic_memory_processing.py tests/builtin/artifacts/atomic_memory/test_prefixed_extraction.py — passed.
Regression coverage:
gateway/crates/pc-gateway-app/tests/gateway_behaviors.rs.AI usage statement
OpenAI Codex (GPT-6) implemented the change, ran the local checks, and authored this PR description.