Skip to content

fix(bub): keep recognized credentials out of automatic recall and capture - #2820

Merged
PsiACE merged 2 commits into
oceanbase:masterfrom
Fengzdadi:fix/bub-prompt-privacy
Nov 26, 2026
Merged

PsiACE merged 2 commits into
oceanbase:masterfrom
Fengzdadi:fix/bub-prompt-privacy

Conversation

@Fengzdadi

@Fengzdadi Fengzdadi commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Which issue or RFC does this PR close?

Part of #2250. #2703 applied the shared prompt-privacy rule to Hermes, LangChain, LangGraph, and Pydantic AI. This PR applies it to Bub, the last in-process adapter with automatic recall and capture.

Rationale for this change

The integrations guide's automatic prompt privacy policy (#2174, tests/fixtures/automatic_prompt_privacy.json) says that an automatic recall query must not carry a recognized credential, and that a prompt containing one is not captured. Every hook host and, since #2703, every Python SDK adapter follows it.

On master, the Bub plugin applies neither half of the rule:

  • it sends the user's text verbatim (then bounded) as the prepare_context query;
  • with capture_events on, it stores the initial task as a user_prompt Source with only the key-based and known-environment redaction of render_capture_event.

Bub's SecretStr protects only the plugin's own API token in its settings.

Bub is the evaluation harness, not a supported Agent framework. Its runs still send prompts to a real Server, and harness tasks and paired evaluations can contain configuration text.

What changes are included in this PR?

What reaches the Server, before and after

Path Before After
before_llm_call recall query user's text verbatim, then bounded recognized credentials, including the configured api_token, replaced by [REDACTED], then bounded
user_prompt capture event (capture_events=true) initial task with key-based / known-environment redaction not sent when the initial task contains a recognized credential; otherwise unchanged
llm_result / tool_result events key-based / known-environment redaction unchanged

The behavior follows #2703's Pydantic AI treatment:

  • the query is scrubbed before it is bounded, so a cut cannot leave a bare credential;
  • recall still runs when a credential is found;
  • a capture is skipped as a whole rather than stored as a redacted copy.

prompt_captured is still set when the event is skipped, so later model calls in the same turn do not retry it. A query with no UTF-8 form still skips recall, as in #2666.

Code

  • integrations/bub/src/powercontext_bub/_prompt_privacy.py: a generated copy of src/powercontext_integration_lifecycle/prompt_privacy.py. It is registered in scripts/generate_integration_lifecycle.py, with a py39 per-file target in pyproject.toml like the other copies. Bub keeps a private copy for the same reason as the SDK adapters: it also supports released cores, as its ContextAssembly import fallback shows.
  • plugin.py: applies scrub_secrets to the recall query in _prepare_context and to the user_prompt check in before_llm_call. The authorization value is Bearer <api_token> when a token is set.
  • e2e/bub/src/powercontext_e2e/models.py: the replay harness's CaptureRecord accepts the skip record's reason. The model forbids unknown fields, so without it a harness task whose initial task carries a recognized credential would lose its capture evidence.

Where Bub differs from #2703, and why

  • Skip evidence. The skip is recorded in the plugin's capture log (POWERCONTEXT_BUB_CAPTURE_LOG) as {"event": "user_prompt", "status": "skipped", "reason": "sensitive_content"}, without the text. The plugin logs nothing through logging and reports its other skips and failures only in that log, so this adds no logger.
  • Test location. The tests live in e2e/bub/tests, not in tests/inprocess_adapter_turns.py. Bub and republic install only in the harness environment (e2e/bub, Python 3.12+), which the root test environment cannot import.
  • Docs location. The rule is documented in the Bub README and in integrations/evaluation.md, not in integrations/index.md, which lists only the supported hosts and framework adapters.
  • Bounding. Bub keeps its own _bounded_recall_query instead of a generated prepared_context copy; this PR does not change it.

Docs

  • integrations/bub/README.md: describes the recall query, the skipped user_prompt event, and the capture-log record, and links to the automatic prompt privacy policy.
  • docs/en/docs/integrations/evaluation.md and docs/zh/docs/integrations/evaluation.md: one paragraph each with the same rule.
  • integrations/capabilities.toml: Bub's test evidence now lists e2e/bub/tests/test_bub_prompt_privacy.py.

CI path selection needs no change:

  • integrations/bub/** selects tests, bub, and harness, and e2e/bub/tests/** selects harness. Checked with ci_changes.select_suites against .github/ci-paths.toml.
  • A change to the shared source under src/** selects bub and harness.
  • A generator-only change does not select them, but any Bub copy it rewrites lands under integrations/bub/**, which does.

Are there any user-facing changes?

Yes, for Bub runs:

  • A recall query no longer carries recognized credentials.
  • With capture_events on, an initial task that contains one is no longer stored as a user_prompt Source; the model's reply and tool events are still captured.

Recognition is best effort; see the automatic prompt privacy section of the integrations guide. There are no API, settings, or persisted-format changes. Existing Sources are not rewritten.

How was this change tested?

New e2e/bub/tests/test_bub_prompt_privacy.py drives one Bub turn through BubFramework.process_inbound for every case in automatic_prompt_privacy.json (66 cases, 53 sensitive). The turn uses Bub's builtin hooks, a stub model over a mock transport, and a recording PowerContext client, with capture_events=true and the case's token as api_token. For each case it checks:

  • every case: exactly one prepare request, and every capture-log record validates as the replay harness's CaptureRecord;
  • sensitive cases: no synthetic credential value in the query, in any captured Source, or in the capture log; only llm_result captured; the skip record present;
  • other cases: the query equals the trimmed prompt, and user_prompt and llm_result are both captured.

Before the source change, the new test failed for all 53 sensitive cases (53 failed, 13 passed). Making _authorization return None fails the known-server-token case. The harness's CaptureRecord forbids unknown fields and rejected the skip record's reason (53 extra_forbidden failures), which would have dropped a task's capture evidence in a harness run; it now accepts reason.

tests/e2e/test_bub_service_chain.py::test_bub_capture_removes_known_credential_values runs bub run with the plugin against a real in-process Server. Its prompt carries Bub's own provider key, which the rule recognizes, so the case now expects the skip:

  • no user_prompt Source is sent, and the turn's other events still are;
  • the capture log has one user_prompt record with status skipped and reason sensitive_content, and none of the prompt text;
  • the log's captured events match the Sources sent.

It keeps the earlier checks: Bub's model receives the prompt as written; no captured Source, stored Source, Server generation request, or capture-log line carries the credential; and the turn flushes. The other Bub service-chain cases that capture user_prompt use prompts without a recognized credential, and none of the replay harness's committed workload and scenario text contains one.

Commands, run on f08ad37 (on master eb695a1), offline. Bub ran from an existing harness venv with bub 0.6.1, republic 0.6.1, and pytest 9.1.1, matching e2e/bub/uv.lock. It was pointed at this checkout with PYTHONPATH, and module paths were verified first.

  • POWERCONTEXT_TEST_BUB_HOST=1 pytest tests/e2e/test_bub_service_chain.py (the bub-host job's command): 5 passed. Before the test update, on 9c55119, it failed as in CI (assert 0 == 1 at the user_prompt count; 1 failed, 4 passed).
  • python -m pytest e2e/bub/tests (the make harness-test suite): 414 passed, including the 66 new cases.
  • ruff check and ruff format --check on e2e/bub, integrations/bub, the generator, and the service-chain test: passed.
  • ty check --project e2e/bub --python-version 3.12 --extra-search-path src e2e/bub/src integrations/bub/src: passed.
  • python -m powercontext_e2e --help: passed.
  • python scripts/generate_integration_lifecycle.py --check (make integration-lifecycle-check): passed; it failed with "is missing" before the copy was generated.
  • pytest tests/test_integration_lifecycle.py tests/test_integration_shared_files.py tests/test_automatic_prompt_privacy.py tests/test_recall_query_bound.py tests/test_ci_changes.py tests/test_integration_manifest.py: 926 passed (on 9c55119; the follow-up commit changes none of their inputs).
  • generate_integration_manifest_docs.py --check (make integration-manifest-check): passed.
  • prek run --files <changed files>: every hook passed except ty-check, which was skipped because it needs a synced environment. Run directly, ty check: passed.

Not run:

  • a Bub turn against a live model;
  • the Docker harness (make harness-acceptance);
  • make docs-test (website build);
  • the full make check.

AI usage statement

This PR was written with Claude Code (Claude Opus 5.5), which read the code, implemented the change, wrote the tests and docs, and ran the checks above. No human has reviewed the change yet.

…ture

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 oceanbase#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.

@NeverENG NeverENG 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.

Reviewed 9c55119. The sensitive-prompt skip behavior conflicts with the existing Bub service-chain acceptance test, which fails the required bub-host job. Please align that case with the new behavior while retaining its credential-leak and flush assertions; details inline.

@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.

Confirmed the existing service-chain finding against the code and the bub-host CI log: test_bub_capture_removes_known_credential_values still expects one user_prompt Source, while this change correctly skips it (0 == 1). Please update that acceptance case to the skip contract while preserving the original-model-input, credential-exclusion, and flush checks, then rerun bub-host. The shared scrubber and scrub-before-bounding approach are reasonable; the failing acceptance gate prevents approval.

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.
@hidb4ai
hidb4ai dismissed their stale review November 26, 2026 00:23

Re-reviewed f08ad37. The previously reported service-chain assertion is corrected while retaining credential-exclusion and flush checks; bub-host and CI result now pass. CaptureRecord also accepts the new skip reason. Withdrawing my obsolete change request. This is not an approval: the PR extends the capture-log/evidence contract with reason=sensitive_content, which falls outside the requested no-new-interface automatic-approval condition.

@Fengzdadi
Fengzdadi requested a review from NeverENG November 26, 2026 01:37
@PsiACE
PsiACE dismissed NeverENG’s stale review November 26, 2026 03:17

Addressed in f08ad37; the service-chain acceptance test now follows the skip contract and bub-host CI passes.

@PsiACE
PsiACE merged commit 4f829cb into oceanbase:master Nov 26, 2026
93 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants