Repository navigation
fix(integrations): keep recognized credentials out of automatic recall and capture in in-process adapters - #2703
Conversation
…l and capture in in-process adapters Hermes, LangChain, LangGraph, and Pydantic AI sent the user's prompt unchanged as the automatic recall query, which the Server may embed, and Hermes and LangChain stored it in completed-turn Sources. A credential typed into a prompt could therefore leave the host and be persisted. These adapters now apply the automatic prompt privacy rule the hook hosts share (powercontext_integration_lifecycle.prompt_privacy), with the same handling: - The automatic recall query replaces recognized credentials, including the configured Server credential, with [REDACTED] before it is bounded. Recall still runs. - An automatic capture whose user text contains one is skipped as a whole: the Hermes and LangChain completed turn, and the Pydantic AI user_prompt event. A redacted copy is never stored under the original event's identity. The skip is logged at debug level as sensitive_content. Only the user text is checked; assistant text is not. Pydantic AI model-response and tool events keep their key-based and known-credential redaction. Hermes evaluation traces apply the shared rule on top of the plugin's own patterns; pre-compression capture keeps its own redaction, because skipping a recognized message there would change what a checkpoint commits. Each adapter ships a generated copy of the rule, like the recall bound. The shared privacy fixture now also drives one real turn through each adapter against a recording Server. The integration docs list the four adapters in the automatic prompt privacy policy, and the Hermes data flow table no longer says recall and completed-turn capture are unscrubbed.
| scope_id = self._scope_id | ||
| client = self._client | ||
| recall_query = _automatic_recall_query(query) | ||
| recall_query = _automatic_recall_query(query, getattr(client, "authorization", None)) |
There was a problem hiding this comment.
[P2] The recall query keeps credentials that the local trace redacts
The query built here is scrubbed only with the shared rule (_automatic_recall_query → _scrub_secrets). The evaluation trace a few lines below additionally applies _redact_secrets, which recognizes forms the shared rule does not.
The new test_evaluation_trace_keeps_the_plugin_redaction_for_hyphenated_keys is the evidence that the two differ: db-password=… and X-Api-Key: … both bypass the shared rule and are asserted absent from the trace. Measured on 578b118, driving this flow through the recording server in tests/inprocess_adapter_turns:
- prompt
please rotate db-password=hunter2-value now→turn.queries == ["please rotate db-password=hunter2-value now"], and the same value is accepted as Source content; scrub_secrets("X-Api-Key: synthetic-header-2084")andscrub_secrets("db-password=synthetic-hunter-2084")return their input unchanged, whileredact_secretsredacts both.
The cause is (?<![\w-]) in the shared pattern: a key name that follows _ or - is rejected, so the common env-file spellings are never recognized. DB_PASSWORD=hunter2-value behaves identically for all four adapters in this PR, and LangChain, LangGraph and Pydantic AI have no second rule at all.
Impact: the trace shows [REDACTED] for an input the Server still receives and stores, so an operator auditing the trace cannot tell what left the host. The gap itself originates in the shared rule, which the hooks already used, so treat the scope as yours to set.
Suggested: pass the query through _redact_secrets as well, the same composition the trace uses (_scrub_secrets(_redact_secrets(query), …)), or widen the shared pattern to accept a prefixed key name and add DB_PASSWORD=/db-password= to tests/fixtures/automatic_prompt_privacy.json so every adapter is covered by the fixture set.
There was a problem hiding this comment.
We took the second option. #2712 widens the shared rule so that a key name may carry any [\w-] prefix, as long as it ends with the marker, and adds separated-prefix, environment-password and api-key-header to the fixture. All three spellings from this comment are then recognized: please rotate db-password=hunter2-value now is sent as please rotate [REDACTED] now, X-Api-Key: … and DB_PASSWORD=… are redacted too, and the prompt stays out of capture because the capture check uses the same rule as the query. The in-process test here runs every fixture case through all four adapters, and whichever of #2703 and #2712 merges later regenerates the adapters' copies of the rule.
Passing the query through _redact_secrets would not close the gap: the capture check would still accept the prompt as Source content, and _redact_secrets misses DB_PASSWORD= as well. Composing the capture check too would make Hermes alone skip prompts that #2712's fixture lists as ordinary settings, such as skip-authorization: false and API_KEY: ${API_KEY}.
Checking the trace against the fixture found a gap in the other direction, fixed in b07d275. The trace ran _redact_secrets first. Its assignment pattern takes the scheme word, or the start of a PEM block, as the value (Authorization: Bearer … became [REDACTED] …), and the shared rule then no longer recognized the rest. Four sensitive fixture cases kept their value in the trace while the query redacted it: authorization-header, proxy-authorization-header, folded-authorization-header and pem-authorization-header; #2712's fixture adds four more. Both trace fields now apply the shared rule first and _redact_secrets after it, so the trace never shows a credential that the query redacted. test_evaluation_trace_redacts_every_credential_the_recall_query_redacts runs every sensitive fixture case through prefetch, with recalled content that repeats the prompt.
The trace keeps the _redact_secrets pass, as on master, so it can still hide text that the query sends where #2712 deliberately narrows the shared rule: a value on the next unindented line, such as Password: with the value below it, and settings or placeholders such as password=true and API_KEY: ${API_KEY}. The hyphenated-key test is now test_evaluation_trace_keeps_the_plugin_redaction. Its input, X-Api-Key: with the value on the next line, is recognized only by _redact_secrets under both the current shared rule and #2712's, so the test and its comment hold whichever PR merges first.
There was a problem hiding this comment.
在 head 83aa8fab 上复核:本 PR 内的 trace 与 query 仍不一致,b07d2754 只调整了 trace 内部的规则顺序,没有改变两条规则的识别面差异。
代码位置:
- query 只过共享规则:
provider.py:138→_recall_query_tail(_scrub_secrets(prompt, authorization)); - trace 过两条规则:
provider.py:162→_redact_secrets(_scrub_secrets(text, authorization)); - 共享规则的前缀排除仍在:
prompt_privacy.py:32-34的三处(?<![\w-]),src/powercontext_integration_lifecycle/prompt_privacy.py同源同形。
实测(直接调用这两个函数,输入为原评论里的样本):
scrub_secrets('please rotate db-password=hunter2-value now') -> 'please rotate db-password=hunter2-value now' # 未脱敏
redact_secrets(同上) -> 'please rotate db-[REDACTED] now'
scrub_secrets('X-Api-Key: synthetic-header-2084') -> 'X-Api-Key: synthetic-header-2084' # 未脱敏
redact_secrets(同上) -> 'X-[REDACTED]'
即 prefetch 发出的 query 仍带着 trace 显示为已遮蔽的值。这条差异由 #2712 放宽共享规则后才会消失,而 #2712 仍是 open(head 5bd91d27)。
因此这不只是「Not included」的范围说明,而是合入顺序依赖:#2703 先于 #2712 合入时,POWERCONTEXT_HERMES_EVALUATION_TRACE 的遮蔽结果仍会误导审计(trace 显示 [REDACTED],Server 收到原文)。请把「#2712 未合入前 trace 遮蔽不覆盖 query 的发送内容」写成合并条件,而不是仅在同段落里提一句 #2712 放宽规则。
若要在此 PR 内自洽,最小改法仍是让 query 复用与 trace 相同的两次调用;作者在回复里给出的反对理由(会让 Hermes 单独跳过 skip-authorization: false 这类设置行)成立,那就需要上面的顺序约束,二者取一。
There was a problem hiding this comment.
Agreed. The PR body now makes it a merge condition: #2712 merges first, then master is merged into this branch and the in-process copies are regenerated, and only then does this PR merge. Until that point the shared rule misses prefixed key names, so the evaluation trace can show [REDACTED] for a value that the recall query sent.
The query stays on the shared rule alone, for the reason in the reply above. The body now also lists what the trace still masks after #2712: a value on the next unindented line, and settings or placeholders that #2712 treats as ordinary.
There was a problem hiding this comment.
#2712 has merged, and 9121f20 merges master into this branch with the four in-process copies regenerated. The recall query now redacts credentials under prefixed key names such as db-password=, X-Api-Key: … and DB_PASSWORD=, the same as the Hermes evaluation trace. 256e464 makes the in-process and trace tests check all three fixture value markers: #2712's new stripe-token case carries only SyntheticValue2084, so the two-marker checks asserted nothing for it.
As noted earlier, the trace still masks two kinds of text that the query sends, by design. The first is a value on the unindented line after a bare key name. The second is settings or placeholders that the shared rule treats as ordinary, such as the boolean-header-settings, inline-header-settings and placeholder-settings fixture cases. test_evaluation_trace_keeps_the_plugin_redaction covers the first case under the new rule.
hidb4ai
left a comment
There was a problem hiding this comment.
Reviewed 578b118. No new blocking correctness defect found in the scoped adapter changes. Scrubbing before bounding and skipping sensitive captures as whole events preserve the existing identity semantics. No new database tables or public interfaces.
The prefixed-key recognition limitation discussed in the existing thread is inherited from the shared rule and explicitly deferred; I consider it a non-blocking follow-up for this scoped change. Validation used framework adapters and recording HTTP endpoints, not real-provider/host acceptance.
The failing dsh-package / CI result checks still need to be resolved before merge; this approval does not waive those gates.
AlexStocks
left a comment
There was a problem hiding this comment.
审查了 578b1184 的增量。先说验证结果:4 份新增的 prompt_privacy.py(hermes / langchain / langgraph / pydantic-ai)逐字节相同(各 2281 字节),且 scripts/generate_integration_lifecycle.py 的 COPIES["prompt_privacy.py"] 已经把 5 个目标都覆盖,PACKAGE_COPIES 负责 claude-code / codex——所以这 5 份是生成物而不是手工维护的副本,漂移风险有界。这一点做对了。
下面一条是新增守卫本身的覆盖面问题。另外一条协作信息(不是缺陷):共享规则里 (?<![\w-]) 不认 DB_PASSWORD= 这类带前缀键名的问题,已经被 #2712 在同一条规则上修掉了;本 PR 的 test_evaluation_trace_keeps_the_plugin_redaction_for_hyphenated_keys 把这个缺口写成了断言(靠插件自己的第二条规则兜住 trace),两个 PR 合并后该用例仍会通过,只是注释里「共享规则不认连字符前缀」这句会过期,建议合并时顺手更新措辞。
| assistant_content = _message_text(assistant_content) | ||
| if not user_content and not assistant_content: | ||
| return | ||
| if _scrub_secrets(user_content, getattr(self._client, "authorization", None)) != user_content: |
There was a problem hiding this comment.
[P2] 守卫只扫 user 侧,assistant 侧单独带凭据时仍会被捕获
这里判的是 _scrub_secrets(user_content, ...) != user_content,但被写进 Source 的是 projected = f"[user]\n{user_content}\n\n[assistant]\n{assistant_content}"(下面第 970 行左右),assistant_content 全程没有经过判定。
触发路径很具体:用户在 prompt 里不放凭据,但 assistant 读取了 .env / 配置文件后把凭据原样回显(或贴出带 key 的 curl 命令)。此时 user_content 干净 → 守卫放行 → 整个 turn(含 assistant 段的凭据)作为一条 Source 落库。「跳过整轮而不是存脱敏副本」这个设计是对的,只是判定面少了一半。
integrations/langchain/src/powercontext_langchain/middleware.py:182 的守卫形状一样(只判 user_text,而 _source_content(user_text, assistant_text) 两者都打包)。pydantic-ai 侧没有这个问题——它只捕获 user_prompt 事件,不捕获 assistant 文本。
最小修法:判 _scrub_secrets(projected, ...) != projected,或对 assistant_content 再判一次(后者日志能区分是哪一半触发的)。测试目前只覆盖 prompt 侧带凭据的场景,建议在 tests/inprocess_adapter_turns.py 的用例里加一条「凭据只在 assistant 侧」的 case。
There was a problem hiding this comment.
Confirmed and fixed in 83aa8fa.
Hermes sync_turn and LangChain _capture now check both halves of the completed turn. A recognized credential in either the user text or the assistant reply skips the whole turn, and the debug log names the side, for example sensitive_content in the assistant text. The check runs on the full texts before the Source is bounded, so it also covers a credential past the length bound. Pydantic AI captures only the user_prompt event under this policy, as you noted, and LangGraph has no automatic capture.
This matches the hooks. Claude Code, Codex, Kimi Code, ZCode, Pi, OpenCode, WorkBuddy, OpenClaw and the DSH plugin capture only user text, which they already check. The DSH pet adapter is the one host that captures replies, and it skips a turn when either side contains a credential.
tests/test_automatic_prompt_privacy.py::test_inprocess_turn_capture_skips_a_credential_only_in_the_assistant_reply adds the case you suggested. It runs a clean prompt whose model reply is each sensitive case from tests/fixtures/automatic_prompt_privacy.json, through Hermes and LangChain, and checks that recall still runs, nothing is captured, no request carries the value, and the skip is logged with the assistant side. With the user-only check from 578b118, all 38 cases fail.
The integrations, Hermes and LangChain guides now say that both sides are checked, in both locales.
…pters-prompt-privacy
…in evaluation traces The plugin's assignment pattern consumes a scheme word or the start of a private-key block, so running it first left values such as the token in `Authorization: Bearer <value>` that the shared rule no longer recognized. The trace now applies the shared rule first, then the plugin rule, to both the query and the injected text.
…ply contains a credential The completed-turn Source stores the user text and the assistant reply, but only the user text was checked, so a reply that echoed a configuration file was captured with its credential. Both sides are now checked, and the debug log names the side that contained the credential.
|
|
hidb4ai
left a comment
There was a problem hiding this comment.
Re-reviewed 83aa8fa. The shared-first Hermes trace redaction and the user/assistant capture checks address the updated scenarios. Long assistant-only credentials also skip capture through Hermes prefetch/queue_prefetch and LangChain invoke/ainvoke while preserving recall. No new blocking defect, database table, or public interface found. Validation uses recording endpoints, not real-provider acceptance.
The existing prefixed-key limitation remains a separate #2712 follow-up. CI still needs a successful run: openclaw-package failed downloading openclaw-2026.8.1-beta.2.tgz with a timeout, and several jobs were cancelled. This approval does not waive CI or other merge requirements.
…pters-prompt-privacy # Conflicts: # docs/zh/docs/integrations/index.md
hireview001
left a comment
There was a problem hiding this comment.
- Resolve merge conflicts with the target branch.
…s privacy tests The fixture's stripe-token case carries only the SyntheticValue2084 marker, so the in-process and Hermes trace value checks, which looked for two markers, asserted nothing for it. The plugin-redaction trace test's comment now names the one difference left between the two rules: a value on the unindented next line.
|
@Fengzdadi plz fix the ci failures. |
|
@AlexStocks The failures at 256e464 do not come from this change. None of the 16 failing tests in tests (3.13, e2e) failed on what it checks:
Fail-fast then cancelled the other test jobs, and Upgrade release gate failed because the selected upgrade acceptance was skipped. A new run on current master also fails |
…pters-prompt-privacy
…pters-prompt-privacy
|
CI on 1d86a5e fails on one test that this PR does not touch: |
…pters-prompt-privacy
…ture (#2820) * fix(bub): keep recognized credentials out of automatic recall and capture Bub was the last in-process adapter with automatic recall and capture that did not apply the shared prompt-privacy rule. The plugin now ships a generated copy of src/powercontext_integration_lifecycle/prompt_privacy.py and, like Pydantic AI after #2703: - scrubs recognized credentials from the recall query before bounding it, so recall still runs with [REDACTED] in place of each value; - skips the user_prompt event when the initial task contains a recognized credential, and records the skip in the capture log with the reason sensitive_content and without the text; - leaves llm_result and tool_result events to their existing key-based and known-credential redaction. The configured API token counts as a known credential. A new harness test drives a Bub turn for every case in automatic_prompt_privacy.json. * test(bub): expect the skipped user_prompt in host acceptance The Bub service-chain case still expected a redacted user_prompt Source for a prompt that carries Bub's own provider key. That prompt now holds a recognized credential, so the plugin skips the event. The case now asserts that no user_prompt Source is sent and that the capture log records the skip without the prompt text. It keeps the checks that the model receives the prompt as written, that no captured Source, stored Source, generation request or log line carries the credential, and that the turn flushes. The replay harness reads the same capture log into CaptureRecord, which forbids unknown fields and rejected the skip record's reason. It now accepts the field, and the plugin privacy test validates every record against it.
Since oceanbase#2703, the Hermes provider skips a turn whose user or assistant text still contains a recognized credential. The real-manager scenario sent `api_key=<sample>` through MemoryManager.sync_all and expected it to be captured. Hermes masks the value to `api_key=***`, and the remaining assignment is still recognized, so the turn was skipped and the scenario failed with behavior_mismatch. The scenario now sends that turn first and asserts that no capture request reaches the Server, then captures a turn without a credential end to end. The request log is also checked for the sample's prefix and suffix, so a masking scheme that keeps part of the key would fail. Accepted Source counts and the other privacy assertions are unchanged.
…es (#2719) * ci(hermes): run the real-manager conformance test against pinned Hermes Add a hermes-host job that checks out NousResearch/hermes-agent at 4131fd95, prepares the Python 3.14 environment with Hermes' YAML pins, and runs tests/integration_conformance/hermes/test_real_manager.py with POWERCONTEXT_TEST_HERMES_CHECKOUT set. The step fails unless the conformance JSON reports a pass on Python 3.14, and uploads that content-safe JSON. Route tests/e2e/dream_support.py to the hermes suite, add the job to the hermes checks and the CI result gate, and list the test as Hermes evidence. * ci(hermes): budget cold setup and cache publication for the real-host job The first hermes-host run passed the conformance test in 48 seconds, but checking out this repository, preparing the Python 3.14 environment, and fetching Hermes used most of the 15-minute limit, and the job was cancelled while saving its cache. The job is often cold. It keeps its own dependency cache, because it installs the Hermes YAML pins after the locked dependencies and cannot share the root cache, and it checks out a fresh copy of Hermes on every run. Thirty minutes matches the cold-start budget master gives docs-tests. * test(hermes): expect the real manager to drop a credential-bearing turn Since #2703, the Hermes provider skips a turn whose user or assistant text still contains a recognized credential. The real-manager scenario sent `api_key=<sample>` through MemoryManager.sync_all and expected it to be captured. Hermes masks the value to `api_key=***`, and the remaining assignment is still recognized, so the turn was skipped and the scenario failed with behavior_mismatch. The scenario now sends that turn first and asserts that no capture request reaches the Server, then captures a turn without a credential end to end. The request log is also checked for the sample's prefix and suffix, so a masking scheme that keeps part of the key would fail. Accepted Source counts and the other privacy assertions are unchanged.
Which issue or RFC does this PR close?
Part of #2250: the in-process Python adapters follow the automatic prompt privacy policy. Follows #2647, which added the shared adapter test harness and the recall bound.
Builds on #2712. #2712 widened the shared rule to prefixed key names. This branch includes it, and its in-process copies are regenerated (
make integration-lifecycle), so the recall query and the Hermes evaluation trace both redact credentials under prefixed key names such asdb-password=,X-Api-Key: …andDB_PASSWORD=.Rationale for this change
The hook hosts follow the automatic prompt privacy policy in the integrations guide (#2174,
tests/fixtures/automatic_prompt_privacy.json). Under it, the automatic recall query must not carry a recognized credential, and a prompt that contains one is not captured. The TypeScript hosts share the same rule throughintegrations/lifecycle/prompt-privacy.ts(#2644, #2636).Hermes, LangChain, LangGraph, and Pydantic AI applied neither rule. The recall query, which the Server may send to its embedding backend, carried the prompt verbatim, and Hermes and LangChain stored it in completed-turn Sources. The Hermes guide said so: "Recall requests and completed-turn Sources do not scrub credentials."
What changes are included in this PR?
What reaches the Server, before and after
prefetchquery (queue_prefetchis a no-op since #2781)[REDACTED], then boundedsync_turncompleted-turn Source (capture_turns, on by default)after_agentcompleted-turn Source (auto_capture=True)PowerContextRecallqueryuser_promptcapture event (CAPTURE_EVENTS=true)These are the hooks' semantics. The read-only query is scrubbed before it is bounded, so a cut can never leave a bare credential behind. A capture is skipped as a whole rather than stored as a redacted copy under the original event's identity. Recall still runs when a credential is found, and a query with no UTF-8 form still skips recall, as in #2647. A skip is logged at debug level with the reason
sensitive_contentand without the text; a completed-turn skip also names the side that contained the credential. Pydantic AI model-response and tool events (which keep their existing redaction) and explicit tools are not checked.Code
scrub_secretsinsrc/powercontext_integration_lifecycle/prompt_privacy.py. Each adapter ships a generated copy beside the recall-bound copy from fix(integrations): recall with the end of a long prompt in Hermes, LangChain, LangGraph, and Pydantic AI #2647: Hermesprompt_privacy.py, SDK adapters_prompt_privacy.py. The SDK adapters use a copy for the same reason as fix(integrations): recall with the end of a long prompt in Hermes, LangChain, LangGraph, and Pydantic AI #2647: they support released cores that predatepowercontext_integration_lifecycle.scripts/generate_integration_lifecycle.pylists the four copies, andpyproject.tomllints them as Python 3.9.helpers.redact_secrets, so the trace never shows a credential that the recall query redacted. The order matters: the plugin rule consumes a scheme word or the start of a private-key block, so running it first left values such as the token inAuthorization: Bearer <value>. The trace query redacts the whole prompt before it is bounded. Because of that second pass, the trace can mask text that the query sends: a value on the unindented line after a bare key name, and settings or placeholders that the shared rule treats as ordinary.hermes.mdnow states that its rules recognize fewer formats, so a turn that completed-turn capture skips can still reach the Server, redacted, in a pre-compression window.integrations/capabilities.tomlliststests/test_automatic_prompt_privacy.pyas evidence for the four adapters.Tests
tests/test_automatic_prompt_privacy.pydrives one turn with capture enabled through each adapter (the harness from fix(integrations): recall with the end of a long prompt in Hermes, LangChain, LangGraph, and Pydantic AI #2647) for each of the 66 fixture cases (53 sensitive, 13 ordinary). It sets the configured token for the known-Server-token case.user_promptevent;tests/integrations/test_hermes_provider.py:prefetchwith the evaluation trace on, with recalled content that repeats the prompt, and checks that the value appears nowhere in the trace.Docs
docs/{en,zh}/docs/integrations/index.mdadds the four adapters to "Automatic prompt privacy", with their input boundary, checked capture, and capture default, and states what is not checked.hermes.md:langchain.md,langgraph.md, andpydantic-ai.mddescribe the query scrubbing and the capture skip.Not included
commands.py, LangGraphtools.py), and Hermes pre-compression capture (see above).Are there any user-facing changes?
Yes, for the automatic paths of these four adapters:
user_promptevent whose prompt contains one, is no longer captured.Capture defaults are unchanged. Detection is best effort; see the policy section. Sources already stored are not changed. No API or persisted format changes.
How was this change tested?
uv run pytest tests/test_automatic_prompt_privacy.py -k inprocess: 370 passed (66 cases × 4 adapters, plus 53 sensitive replies × 2 adapters). With the four adapter sources frommaster, all 318 sensitive runs fail and the 52 ordinary runs pass.uv run pytest tests/langchain_middleware tests/langgraph_adapter tests/pydantic_ai_adapter tests/integrations/test_hermes_provider.py tests/test_hermes_cli.py tests/integration_conformance tests/test_recall_query_bound.py tests/test_automatic_prompt_privacy.py tests/test_integration_lifecycle.py tests/test_integration_manifest.py: 1,050 passed, 2 skipped.make integration-lifecycle-checkandmake checkpass.make unit-teston 578b118, the branch's first version (not rerun after the latermastermerges and fixes): 9,248 passed, 13 failed. Twelve fail the same way on unmodifiedmaster437aa06: 4 intest_ci_installation_rolesand 8 intest_jev_rerank_comparison. The thirteenth,tests/builtin/runtime/test_model_usage_recorder.py::test_native_sqlite_deadline_stops_vm_work_and_preserves_in_memory_database, asserts a 0.5 s deadline; it failed under the full parallel run and passed 3 of 3 times when rerun on its own.Self-review: the diff was reviewed against
REVIEW.md, and an independent Claude Opus review checked the same change. Both confirmed that:prefetchquery (the only Hermes path that sends one), the LangChain Langfuse recall observation, and repeated Pydantic AI model steps;prompt_capturedconsistent;capabilities.toml, and the code agree, in both locales.Non-blocking: a very short configured token over-matches through a plain substring replace, the same as in the hook hosts.
AI usage statement
Claude Code (Claude Opus 5.5) wrote the change, the tests, and this description, ran the checks above, and did the self-review and the independent review.