Skip to content

fix(openclaw): apply the shared prompt-privacy rule to automatic recall and capture - #2636

Merged
hidb4ai merged 2 commits into
oceanbase:masterfrom
Fengzdadi:fix/openclaw-prompt-privacy
Nov 17, 2026
Merged

hidb4ai merged 2 commits into
oceanbase:masterfrom
Fengzdadi:fix/openclaw-prompt-privacy

Conversation

@Fengzdadi

Copy link
Copy Markdown
Collaborator

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:

  • the recall query must not carry a recognized credential;
  • a prompt that contains one is not captured.

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/prepare verbatim and was stored as a Source by agent_end and before_compaction.

What changes are included in this PR?

What reaches the Server and what is stored, before and after

Path Before After
before_prompt_build → POST /v1/context/prepare query Latest user text (or prompt fallback), first 8192 UTF-8 bytes, credentials verbatim Recognized credentials, including the trimmed token in the configured tokenEnv variable, replaced by [REDACTED], then the same 8192-byte bound
agent_end / before_compaction → POST /v1/sources/content User: + latest user text, truncated to captureMaxChars, stored as a Source Not sent when the whole latest user text, before truncation, contains a recognized credential. Otherwise the same content and Source ID as before
Explicit tools, flushes Unchanged Unchanged

Code

  • src/secrets.ts is the shared rule, byte-identical to the Pi plugin's src/secrets.ts.
  • src/lifecycle.ts scrubs the recall query before truncateUtf8. It trims the token from tokenEnv, because fetch trims the Authorization header value the Server receives.
  • The capture path checks the untruncated latest user text before building the Source. Truncation can shorten a credential below a shape the rule recognizes, so the check runs on the full text.

Source identity

  • deterministicSourceId still hashes the content that is sent, and that content is unchanged for every turn that is still captured.
  • A turn replayed across the upgrade without a credential keeps its Source ID. The check does not change Scope resolution, so a replayed agent_end still 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.
  • A turn with a credential that was captured before the upgrade stays stored on the Server; this PR does not delete Sources. When it is replayed after the upgrade, nothing is sent.

Tests

  • src/prompt-privacy.test.ts reads automatic_prompt_privacy.json and checks two things:
    • the rule itself;
    • the registered before_prompt_build and agent_end hooks. 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.
  • The known-Server-token case sets the tokenEnv variable. Two more tests cover:
    • a token with surrounding whitespace;
    • a before_compaction capture whose credential lies past the captureMaxChars truncation.
  • Without the lifecycle.ts change, the 19 sensitive cases fail.
  • integrations/capabilities.toml lists the test as OpenClaw evidence.

Docs

  • docs/{en,zh}/docs/integrations/openclaw.md describe 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.md add OpenClaw to the "Automatic prompt privacy" table, with autoCapture=false to disable capture.

Not included:

  • Query bound. The head-versus-tail recall query bound (truncateUtf8(query, 8192) keeps the first bytes, while tests/fixtures/recall_query_bound.json keeps the end) is a separate behavior PR.
  • Diagnostic for skipped captures. A skipped capture is silent, like the existing autoCapture=false and ineligible-session skips; OpenClaw has no capture status surface.
  • Drift check for 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:

  • Recognized credentials no longer reach the Server in recall queries.
  • Turns that contain one are no longer captured.

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, and git 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).
  • No real OpenClaw host was run.
  • Self-review against REVIEW.md, plus an independent review pass, found nothing blocking.
    • Fixed: a tokenEnv value with surrounding whitespace is recognized as the trimmed token the Server receives.
    • Checked:
    • Left as a design note: a short configured token is redacted wherever it occurs, which matches Pi and OpenCode.

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.

…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 hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 hireview001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 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 hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 hireview001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* limitations under the License.
*/

const SECRET_PATTERNS = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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)。问题不在规则本身,而在副本的登记方式。

证据:

影响: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 因打包或加载方式必须保留独立文件名,请在生成器注释中写明这条例外,使后续改动有据可循。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@AlexStocks AlexStocks added the 1.6.0 v1.6.0 release tracking label Nov 17, 2026
@hidb4ai
hidb4ai merged commit 8481434 into oceanbase:master Nov 17, 2026
161 of 171 checks passed
hidb4ai pushed a commit that referenced this pull request Nov 18, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.6.0 v1.6.0 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants