Repository navigation
fix(openclaw): apply the shared prompt-privacy rule to automatic recall and capture - #2636
Conversation
…ll and capture OpenClaw sent the latest user text to /v1/context/prepare and captured it as a Source without recognizing credentials, unlike the hosts listed under "Automatic prompt privacy" in the integrations guide. The plugin now ships that rule (tests/fixtures/automatic_prompt_privacy.json) as src/secrets.ts. Automatic recall replaces recognized credentials, including the trimmed token from the configured tokenEnv variable, with [REDACTED] before the query is bounded. Automatic capture, from agent_end and before_compaction, skips a turn whose whole latest user text contains a recognized credential, including one past the captureMaxChars truncation. Other turns keep the same content and Source ID. The guide lists OpenClaw in the policy table.
hidb4ai
left a comment
There was a problem hiding this comment.
Reviewed eb82968. No blocking correctness issues found. Applying the shared privacy rule before truncation is appropriate; safe-turn Source identity and pending-flush behavior are preserved. No new database tables or public interfaces.
Plugin tests, type checking, build, related Python checks, and built-plugin HTTP probes passed. A live model-driven OpenClaw session was not exercised.
CI remains blocked by the baseline Desktop Linux clippy failure and stale DSH/Cindy generated bundles in unchanged code. This approval does not clear those failures.
hireview001
left a comment
There was a problem hiding this comment.
- CI failed: CI result (failure).
- CI failed: desktop-validation / linux (failure).
- CI failed: dsh-package (failure).
- CI failed: cindy-package (failure).
- CI failed: Main (failure). Failed steps: cindy-package / Build and test the standalone Cindy archive; dsh-package / Test DSH package; desktop-validation / linux / Run cargo clippy --locked --manifest-path src-tauri/Cargo.toml --all-targets -- -D warnings.
hidb4ai
left a comment
There was a problem hiding this comment.
Reviewed 6c90ea5 after the master merge. No blocking correctness issues found, and no new database tables or public interfaces. The privacy patch is unchanged: checks precede truncation, while safe-turn Source identity and pending flush behavior are preserved.
Plugin tests, type checking, build, generated-helper checks, integration contract tests, and built-plugin HTTP probes passed. A live model-driven OpenClaw session was not exercised.
Current CI failures also occur on base 303b32c: prepared-context budget report snapshots and native-service migration tests expecting v1_5_0_004 instead of v1_5_0_005. Approval does not clear these CI failures.
hireview001
left a comment
There was a problem hiding this comment.
- CI failed: CI result (failure).
- CI failed: native-service / windows-task-scheduler (failure).
- CI failed: native-service / linux-systemd-user (failure).
- CI failed: native-service / macos-launchagent (failure).
- CI failed: evaluation-tests (failure).
- CI failed: Main (failure).
| * limitations under the License. | ||
| */ | ||
|
|
||
| const SECRET_PATTERNS = [ |
There was a problem hiding this comment.
[P2] 自动 prompt 隐私规则在 openclaw 侧是手写副本,未进入 scripts/generate_integration_lifecycle.py 的生成链
本文件 17-33 行的规则与 integrations/lifecycle/prompt-privacy.ts(并行 PR #2644 head b91159a4)除 2 行注释外逐字节相同;用仓库自带 fixture tests/fixtures/automatic_prompt_privacy.json 实测 23 个 case 全通过(node 22.22.2 直接类型擦除执行,探针 D:\test\github\review\oceanbase-powercontext-pr-2636\probes\probe_privacy.mjs)。问题不在规则本身,而在副本的登记方式。
证据:
- 生成器的
TYPESCRIPT_COPIES已包含{_OPENCLAW}/src/transport.ts,说明 openclaw 本来就参与这条生成链; - refactor(integrations): generate the TypeScript prompt-privacy copies from one source #2644 新增的
TYPESCRIPT_COPIES["prompt-privacy.ts"]只列了_DSH/_OPENCODE/_PI,没有_OPENCLAW; - 本 PR 的文件列表里没有
scripts/generate_integration_lifecycle.py(同一作者的 refactor(integrations): generate the TypeScript prompt-privacy copies from one source #2644、fix(integrations): recall with the end of a long prompt in Hermes, LangChain, LangGraph, and Pydantic AI #2647 都登记了自己的副本)。
影响:make integration-lifecycle-check 只校验已登记的副本,于是这条规则现在有 4 份实现、只有 3 份受校验。此后修改 integrations/lifecycle/prompt-privacy.ts 时,openclaw 的 secrets.ts 漂移不会被任何门禁发现,而 docs/{en,zh}/docs/integrations/openclaw.md 已改成「自动召回和捕获遵循同一策略」,两份文档会先于代码失真。
建议:把本文件改名为 src/prompt-privacy.ts,在 TYPESCRIPT_COPIES["prompt-privacy.ts"] 追加 {_OPENCLAW}/src/prompt-privacy.ts,lifecycle.ts 改 import 路径。若 openclaw 因打包或加载方式必须保留独立文件名,请在生成器注释中写明这条例外,使后续改动有据可循。
There was a problem hiding this comment.
Agreed: this rule should be a registered copy. #2644 adds the prompt-privacy.ts entry to TYPESCRIPT_COPIES and has not merged yet, so this PR cannot register against it today. Whichever of #2636 and #2644 merges second will move this rule to src/prompt-privacy.ts, add {_OPENCLAW}/src/prompt-privacy.ts to that entry, and update the import in lifecycle.ts, so make integration-lifecycle-check covers all four copies.
…source (#2704) #2636 gave the OpenClaw plugin the automatic prompt-privacy rule as a hand-written src/secrets.ts, and #2644 made integrations/lifecycle/prompt-privacy.ts the source of the DSH, OpenCode, and Pi copies. OpenClaw's copy was the only one the generator did not write or check. scripts/generate_integration_lifecycle.py now also writes src/prompt-privacy.ts into the OpenClaw plugin, so `make check` rejects it if it drifts. src/secrets.ts is removed, and src/lifecycle.ts and its privacy test import the rule from ./prompt-privacy.js. The generated copy differs from the removed file only in comments, so behavior does not change.
Which issue or RFC does this PR close?
Part of #2250.
Rationale for this change
The prompt adapters listed under "Automatic prompt privacy" in the integrations guide follow one rule, defined by
tests/fixtures/automatic_prompt_privacy.json:OpenClaw applied no such rule. Its guide said so: "Neither automatic recall nor capture performs credential detection or scrubbing". The latest user text reached
POST /v1/context/prepareverbatim and was stored as a Source byagent_endandbefore_compaction.What changes are included in this PR?
What reaches the Server and what is stored, before and after
before_prompt_build→POST /v1/context/preparequerytokenEnvvariable, replaced by[REDACTED], then the same 8192-byte boundagent_end/before_compaction→POST /v1/sources/contentUser:+ latest user text, truncated tocaptureMaxChars, stored as a SourceCode
src/secrets.tsis the shared rule, byte-identical to the Pi plugin'ssrc/secrets.ts.src/lifecycle.tsscrubs the recall query beforetruncateUtf8. It trims the token fromtokenEnv, because fetch trims theAuthorizationheader value the Server receives.Source identity
deterministicSourceIdstill hashes the content that is sent, and that content is unchanged for every turn that is still captured.agent_endstill resolves the Scope of its run's projects (fix(openclaw): capture prompts under the run's project binding #2601), and the Server's existing idempotent acceptance applies.Tests
src/prompt-privacy.test.tsreadsautomatic_prompt_privacy.jsonand checks two things:before_prompt_buildandagent_endhooks. For each case it asserts that no request carries the synthetic credential and nothing is captured when the case is sensitive, and that query and Source content are unchanged when it is not.tokenEnvvariable. Two more tests cover:before_compactioncapture whose credential lies past thecaptureMaxCharstruncation.lifecycle.tschange, the 19 sensitive cases fail.integrations/capabilities.tomllists the test as OpenClaw evidence.Docs
docs/{en,zh}/docs/integrations/openclaw.mddescribe the rule in the data-flow table and the capture paragraph, replacing the statement that no detection happens, and link to the policy section.docs/{en,zh}/docs/integrations/index.mdadd OpenClaw to the "Automatic prompt privacy" table, withautoCapture=falseto disable capture.Not included:
truncateUtf8(query, 8192)keeps the first bytes, whiletests/fixtures/recall_query_bound.jsonkeeps the end) is a separate behavior PR.autoCapture=falseand ineligible-session skips; OpenClaw has no capture status surface.secrets.ts. No test fails yet when this copy and Pi's diverge. The copies move under the generated TypeScript module that refactor(integrations): generate the TypeScript transport copies from one source #2623 starts, in a separate PR.Are there any user-facing changes?
Yes, for the automatic paths:
Explicit tools are unchanged. Sources already stored are not changed.
How was this change tested?
make openclaw-plugin-test: 157 tests, typecheck, and build.make check, andgit diff --check.uv run pytest tests/test_automatic_prompt_privacy.py tests/test_integration_shared_files.py tests/test_integration_manifest.py tests/test_ci_changes.py tests/test_openclaw*.py(342 passed).REVIEW.md, plus an independent review pass, found nothing blocking.tokenEnvvalue with surrounding whitespace is recognized as the trimmed token the Server receives.capture()after the hook resolves the run's agent and projects, so it reads the same latest user text that is captured;src/secrets.tsis byte-identical to Pi'ssrc/secrets.ts;AI usage statement
Claude Code (Claude Opus 5.5) found the gap, wrote the change, the tests, and this description, ran the checks above, and reviewed the diff before this PR was opened.