Skip to content

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

Merged
hidb4ai merged 1 commit into
oceanbase:masterfrom
Fengzdadi:fix/dsh-prompt-privacy
Nov 13, 2026
Merged

hidb4ai merged 1 commit into
oceanbase:masterfrom
Fengzdadi:fix/dsh-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.

Claude Code, Codex, WorkBuddy, Kimi Code, ZCode, OpenCode, and Pi test against that fixture. DSH did not, and it diverged in two ways:

  • Recall query. It sent the query to POST /v1/context/prepare without removing credentials.
  • Capture. It decided whether to capture a prompt with three substring markers (sk-, api_key, BEGIN PRIVATE). These miss most credential shapes the other hosts recognize, such as Authorization and Cookie headers, password= and access_token= assignments, bearer and GitHub tokens, and the configured Server token. They also skip ordinary prompts that merely contain a marker, such as "Fix the task-runner timeout".

What changes are included in this PR?

What reaches the Server, before and after

Path Before After
Automatic POST /v1/context/prepare query Conversation text with credentials verbatim The same text with recognized credentials replaced by [REDACTED], then bounded as before
Automatic POST /v1/sources/content Sent and stored unless the prompt contains sk-, api_key, or BEGIN PRIVATE Sent and stored unless the prompt contains a credential the shared rule recognizes. Otherwise skipped with status sensitive_content, as before
Explicit tool writes (secret_rejected) Substring markers Unchanged

Code

  • src/secrets.ts adds scrubSecrets and the shared containsSecret(text, authorization), with the same patterns as the Pi and OpenCode plugins.
  • The explicit-write check keeps its markers under a private name.
  • src/recall.ts scrubs the query with the configured authorization before boundedRecallQuery.
  • src/capture.ts uses the shared rule.
  • lib/index.js is rebuilt; it changes only in these functions.

Tests and fixture

  • tests/prompt-privacy.spec.ts reads automatic_prompt_privacy.json and checks two things:
    • the rule itself;
    • runRecallPreStep end to end. 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 capture are unchanged when it is not.
  • Without the source change, the 19 sensitive cases fail.
  • The containsSecret assertions in tests/invoke.spec.ts moved into the new spec. Explicit-write rejection stays covered by invoke.spec.ts and mcp.spec.ts; invoke.spec.ts gains a private-key case, because the removed assertions were the only ones pinning the BEGIN PRIVATE marker.
  • The shared fixture gains a marker-inside-word case ("Fix the task-runner timeout before the release.", not sensitive). Every host that reads the fixture passes it, because they already share the rule.
  • integrations/capabilities.toml lists the new spec as DSH evidence, as OpenCode and Pi do.

Docs

  • docs/{en,zh}/docs/integrations/dsh.md describe the rule under "Understand what the plugin does" and link to the policy section.
  • docs/{en,zh}/docs/integrations/index.md add DSH to the "Automatic prompt privacy" table, with POWERCONTEXT_DSH_CAPTURE_PROMPTS=false to disable capture.

Not included, as follow-ups:

  • Explicit-write rejection. DSH's explicit writes still use the substring markers, so a write containing "task-runner" is still rejected and a password= value is not. Aligning them with the shared rule changes which explicit writes are rejected, so it gets its own PR.
  • OpenClaw. It has the same automatic-path gap, fixed in a separate PR.

Are there any user-facing changes?

Yes, for DSH's automatic path only:

  • Recognized credentials no longer reach the Server in recall queries.
  • Prompts with credential shapes the old markers missed are no longer captured.
  • Prompts that only contain a marker inside a word are now captured.

Explicit tools are unchanged. Sources already stored are not changed.

How was this change tested?

  • make js-test: 575 unit tests, build with lib/ freshness, and 8 e2e tests.

  • make check, and git diff --check.

  • uv run pytest tests/test_automatic_prompt_privacy.py (99 passed), and tests/test_integration_manifest.py, tests/test_ci_changes.py, and tests/test_dsh*.py.

  • The fixture's other readers pass with the new case:

    • Pi and OpenCode prompt-privacy.spec.ts;
    • ZCode tests/plugin.test.mjs;
    • Kimi Code tests/plugin.test.mjs. One loopback-alias test there fails on macOS because the host has no 127.0.0.2; it is unrelated.
  • No real DSH host was run. make dsh-runtime-test downloads the pinned host and was not run locally.

  • Self-review against REVIEW.md, plus an independent review pass, found nothing blocking. Fixed:

    • the docs and commit message said every host plugin shares the rule, but Hermes does not. They now link to the policy section, and DSH joins its table;
    • the docs now say the rule recognizes common shapes, not every secret;
    • the explicit-write private-key marker regained a test (it fails when the marker is removed).

    Confirmed by execution:

    • every automatic path that sends prompt text is covered: the recall query, built from all non-snapshot messages, is scrubbed as a whole, and capture checks the exact text it sends;
    • explicit-write rejection is unchanged;
    • the committed lib/ matches a rebuild;
    • the branch merges cleanly with the OpenClaw privacy branch.

    Left as a design note: a short configured Server 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, tests, and this description, and ran the checks above. I reviewed the result.

…d capture

DSH sent the prompt to /v1/context/prepare without removing credentials,
and decided whether to capture a prompt by substring markers ('sk-',
'api_key', 'BEGIN PRIVATE'). The markers missed most credential shapes the
other prompt adapters recognize (Authorization and Cookie headers, password
and token assignments, bearer and GitHub tokens, the configured Server
token) and skipped ordinary prompts such as "Fix the task-runner timeout".

The automatic path now uses the rule from "Automatic prompt privacy" in the
integrations guide (tests/fixtures/automatic_prompt_privacy.json): the
recall query is scrubbed before it is bounded, and a prompt that contains a
recognized credential is not captured. The guide lists DSH in the policy
table. Explicit tool writes keep their existing secret_rejected markers.
Copilot AI balanced review requested due to automatic review settings November 13, 2026 08:02

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@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 a65b25e; no blocking findings. The automatic recall/capture path applies the shared credential policy before dispatch, preserves explicit-write behavior, and adds no database tables or public interfaces.

Verified the built plugin in real DSH 0.1.2-rc.1 against a local PowerContext Server with a scripted model, including capture enabled/disabled and the configured Server token. Full CI is still pending.

@hidb4ai
hidb4ai merged commit 9fb154d into oceanbase:master Nov 13, 2026
13 checks passed
lizining1231 added a commit to lizining1231/powercontext that referenced this pull request Nov 13, 2026
lizining1231 added a commit to lizining1231/powercontext that referenced this pull request Nov 13, 2026
hidb4ai pushed a commit that referenced this pull request Nov 14, 2026
… peak memory and recall cost (#2449)

* perf(atomic-memory): bound related recall candidates in SQL

Bound related recall with a max_candidates limit pushed into eligibility,
over-fetch one RRF window per channel, and trim fused hits and heads to
the cap. SQLite and OceanBase enforce the cap in SQL; OceanBase uses one
snapshot with a readiness CTE and an explicit sentinel row. Runtime
configuration defaults to 100 candidates, and explicit null keeps complete
enumeration.

Closes: #2448

* test(atomic-memory): cover bounded related recall

Cover SQLite channel caps, filter-before-limit ordering, the hybrid
over-fetch window, OceanBase bindings and UNION widths, sentinel handling,
runtime configuration validation, and the flush-to-reconciler chain.

Closes: #2448

* docs(atomic-memory): document the default related candidate limit

Document that related recall is bounded to 100 candidates by default in
both locales.

Closes: #2448

* perf(atomic-memory): enumerate complete related recall in pages

Closes: #2448

* style(atomic-memory): format related pagination tests

Closes: #2448

* fix(atomic-memory): freeze the related ranking across pages

Take one complete lightweight ranking per related enumeration and slice it by
offset, so corpus changes in another Scope can no longer reorder or truncate
later pages. A ranked memory that leaves the index before its page is read
reports stale recall instead of raising a bare KeyError.

* fix(atomic-memory): keep compared reads until the window commits

Release only page-local bodies from a workset and retain every compared read,
so an artifact revision published mid-window conflicts and retries instead of
committing against stale evidence.

* docs(atomic-memory): describe related recall paging and commit checks

Document the frozen lightweight ranking, what the page size bounds, and that a
revision published after ranking conflicts and retries the window.

* perf(atomic-memory): raise the default related page size to 250

The inherited 100 came from the retired candidate cap, where it bounded the
result set. Paging only batches bodies and authorization, so the same number
now multiplies a fixed per-page cost across a complete enumeration.

At 50k rows, 250 turns 500 page transactions into 200: Sys 3.77s -> 0.69s,
User 8.63s -> 5.15s, Wall 10.48s -> 4.81s, with the peak delta unchanged at
159.7 MB. 250 is where the gains stop (250/500/1000 stay within noise) and it
leaves headroom below the 1000 validation limit.

* fix(atomic-memory): skip impossible lexical admission in related paging

Related recall pages no longer issue a rank query when the admission floor
exceeds the query's distinct terms; whole-word coverage can never reach it.
Refresh the persistence review digest for the resulting tree.

* fix(atomic-memory): batch SQLite page bodies within the bind limit

One page can hold up to 1000 identities, and expanding body_ids bound one
variable per identity plus scope_id, past SQLite's legacy 999-variable
limit. Read bodies in 900-identity batches and assemble the page from the
combined rows.

Refs #2449

* fix(atomic-memory): keep native FTS for related recall

Related-page ranking built the legacy LOCATE/MATCH ... AGAINST query even
when the tenant supports native MATCH, so one recall emitted both paths.
Select the channel from _supports_native_fts() and keep the coverage query
as the fallback for unsupported queries.

Refs #2449

* fix(atomic-memory): compare each recalled identity once per window

A paginated recall can return a published origin that an earlier
comparison already revised. workset.add() resolves it to the same
working item, and the empty related list still invoked the reconciler,
letting a later create response rewrite the decided revision.

Drop pending identities that resolve to the current proposal or to an
already compared item, and re-resolve them after every batch because a
noop target can turn a remaining candidate into the current proposal.

Refs #2449

* test(atomic-memory): satisfy lint and typing in the batching regression

The fake connection indexed a nullable parameter map and the file needed
ruff formatting, which failed the quality gate.

Refs #2449

* test(dsh): surface setup CLI output when the runtime fixture fails

The include-tree test only reports `exit code 1` because `powercontext
setup dsh --json` writes the failure detail to stdout and the fixture
discards it. Print both streams so the next CI run identifies the step
that fails.

This is temporary diagnostic scaffolding and will be reverted.

* chore(build): regenerate plugin artifacts left stale by #2625

* chore(release): refresh the persistence review digest
hidb4ai pushed a commit that referenced this pull request Nov 14, 2026
… sources (#2637)

Three pull requests merged on 11-13 within four minutes. #2608 added the
committed DSH pet bundle. #2516 added the `X-PowerContext-Resolve-Target`
header parameter to `check_context` in the generated operation table.
#2625 changed `containsSecret` in the DSH plugin's `src/secrets.ts`. The
Cindy worker and the DSH pet bundle include those modules, and neither
committed bundle was rebuilt for the combination. So `make cindy-test`
and `make js-test` fail their freshness checks on master and on every
pull request that selects those suites.

Only the two bundles are regenerated, with the existing builds. Their
credential checks now follow the shared prompt-privacy rule, as their
sources have since #2625. The pet does not call `check_context`.
@hidb4ai hidb4ai added the 1.5.2 v1.5.2 release tracking label Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.5.2 v1.5.2 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants