Repository navigation
feat(bub): let the gateway own prompt-time recall - #2836
Merged
Merged
Conversation
Add a prompt_recall setting (POWERCONTEXT_BUB_PROMPT_RECALL, default true). With false, the plugin sends no preparation request and adds no context before a model call, and it does not offer powercontext.context. Bub keeps a tool result on the session's tape and replays it with every later model call. The gateway does not strip the plugin's plain prepared text from a tool result, so Core would reject every later gateway request of that session. Capture, the other tools and flushes are unchanged; with capture off as well, the hook sends no request at all. The plugin now provides its tools through Bub's provide_tools hook instead of relying on @tool collection, which Bub 0.6.1 deprecates and which cannot leave a tool out. Document the gateway setup for Bub 0.6.1 in the plugin README: the Responses route of the openai provider and how the gateway treats streamed Chat Completions, the Core target and the store: false that an enforcing Core requires (sent through BUB_COMPLETION_ARGS extra_body), one shared Scope for the plugin and the gateway, scheduled extraction for the turns the gateway captures, the conversation a combined deployment infers from Bub's opening system and user messages, since Bub sends no per-session header (a standalone gateway still needs PC_GATEWAY_INJECTION=on), and that only a session that called the prepare tool needs a fresh tape. Part of oceanbase#2250.
16 of 17 tasks
hidb4ai
approved these changes
Nov 26, 2026
hireview001
approved these changes
Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue or RFC does this PR close?
Part of #2250. This is step 5 for Bub, alongside #2754 (OpenCode), #2755 (Pi), and #2829 (Hermes).
Rationale for this change
Behind the PowerContext gateway, Core rejects every request that carries a prepared-context block the gateway did not inject, in every privacy mode. Core answers HTTP 422, and the gateway returns HTTP 503
gate_paused.The Bub plugin produces such blocks in two ways:
before_llm_callprepends a system message with the prepared context. Bub does not write this message to the session's tape, so it affects only the model call it was added to.powercontext.contexttool. Bub keeps a tool result on the session's tape and replays it with every later model call. Bub renders the tool's string result as-is, so the tool message carries the prepared text itself. fix(gateway): strip replayed plugin context before model admission #2809 strips only a JSON tool output shaped{"ok": true, "data": {"schema": "powercontext.prepared-context.v1", ...}}and a Responses developer message whose content is exactly the envelope. Neither matches a Bub tool message, so once the tool runs, Core rejects every later gateway request of that session.Bub therefore needs a switch that hands prompt-time context to the gateway and withholds the tool.
What changes are included in this PR?
Setting:
prompt_recall(POWERCONTEXT_BUB_PROMPT_RECALL, orprompt_recallin thepowercontextsection of Bub's configuration file), defaulttrue. The default keeps today's behavior.With
prompt_recall: false:powercontext.context. When a model calls it anyway, Bub's builtin unknown-tool handling answers that the tool does not exist;powercontext.search,powercontext.remember, event capture, and flushes are unchanged;capture_eventsalso off, the hook sends no request at all, not even the Scope resolution it would only have needed for recall.Tool registration: the plugin now provides its tools through Bub's
provide_toolshook, which can leave a tool out. Before, the tools were collected from@toolwhile Bub loaded the entry point. Bub 0.6.1 deprecates that path: it warnsrelies on @tool registering its tools, and it cannot exclude a tool. Loading through the entry point offers the same three tools by default, without that warning.Docs: a new "Leave prompt-time context to the gateway" section in
integrations/bub/README.md, modeled on the Hermes guide in #2829. Bub has no docs page. The section covers:POWERCONTEXT_SERVER_RUNTIME_SCHEDULE_SECONDS(neither set by default);powercontext.contextneeds one, because the per-call context is never on the tape. A new--session-idor Bub'stape.resetboth work;/gateway/v1. Theopenaiprovider uses the Responses route, and Bub streams every call. On that route the gateway calls the model without streaming and replays the checked response."api_format": "chat"or theopenai-compatibleprovider would use streamed Chat Completions, which an enforcing Core withholds (HTTP 400). A non-enforcing Core releases the stream, and withPC_GATEWAY_SEDIMENT=onthe gateway also captures it;store, so an enforcing Core withholds every request withprovider_state_unsupportedand the gateway returns HTTP 400.BUB_COMPLETION_ARGS='{"extra_body": {"store": false}}'adds"store": false; Bub passes completion arguments to every model call, and republic mergesextra_bodyinto the body rather than sending it as a field. Bub always sendsmax_output_tokens(BUB_MAX_TOKENS, 16384 by default) and neverprompt_cache_key, so it has no cache-retention requirement;POWERCONTEXT_BUB_SCOPE_IDandPC_GATEWAY_DEFAULT_SCOPEset to the same Scope, so the tools use the Scope the gateway fills;BUB_CLIENT_ARGSheaders are the same for every session, so the gateway infers the conversation from the request. Bub's input qualifies: it sends noprevious_response_idorconversation, and it opens with the system prompt as asystemmessage followed by the first user message of the tape since the last anchor, both unchanged across the turn's tool-loop steps. The limits are stated: the inferred ID is local to the gateway process and serves only the replay; sessions that open with the same system prompt and first message share one; without a header, capture has no conversation identity that survives a gateway restart and prefix extraction is unavailable; aftertape.handoffortape.resetthe gateway infers a new conversation. A standalone gateway still needsPC_GATEWAY_INJECTION=on, and a fixedX-PowerContext-Conversation-IDinBUB_CLIENT_ARGSwould make every session one conversation.The intro and the settings table link to this section.
Are there any user-facing changes?
Yes, one new opt-out setting,
POWERCONTEXT_BUB_PROMPT_RECALL=false. The default is unchanged. There are no API or persisted-format changes.How was this change tested?
New
e2e/bub/tests/test_bub_prompt_recall.pydrives one Bub turn throughBubFramework.process_inbound, using Bub's builtin hooks, a stub Chat Completions model that can call tools, and a recording PowerContext client:user_promptandllm_resultcaptured; one flush;powercontext_contextandpowercontext_search: the first is not offered and is answered as an unknown tool; no prepare request is sent; the search still runs;tests/e2e/test_bub_service_chain.pygains a case that runsbub runwithPOWERCONTEXT_BUB_PROMPT_RECALL=falseand capture on, against a real in-process Server. It checks:/v1/context/preparerequest, and no plugin context orpowercontext_contexttool in any model request;powercontext_searchstill reaches the Server;Against the plugin source on 4f829cb (#2820), the 3 new harness tests and the new service-chain case fail; the other 5 service-chain cases pass.
Commands, offline, on 1516580, based on master 4f829cb. Bub tests used an existing harness venv with bub 0.6.1 and republic 0.6.1, matching
e2e/bub/uv.lock. It was pointed at this checkout withPYTHONPATH, and module paths were verified first.python -m pytest e2e/bub/tests: 417 passed.POWERCONTEXT_TEST_BUB_HOST=1 pytest tests/e2e/test_bub_service_chain.py(thebub-hostjob's command): 6 passed.openaiprovider against a Responses stub: the request goes to/responseswithmodel,input,tools,max_output_tokens: 16384, andstream: trueand nostore; withBUB_COMPLETION_ARGS='{"extra_body": {"store": false}}'it also carries"store": false, and noextra_bodykey.systemitem and a non-empty user message, carries noprevious_response_id,conversation, orinstructions, and its opening items are byte-identical across the model calls of one turn and across later turns of the session.BubFramework.load_hooks(), withDeprecationWarningas an error):powercontext.context,powercontext.remember, andpowercontext.searchby default, and only the last two withPOWERCONTEXT_BUB_PROMPT_RECALL=false.pytest tests/test_automatic_prompt_privacy.py tests/test_integration_manifest.py: 672 passed.ruff checkandruff format --checkone2e/bubandintegrations/bub: passed.ty check --project e2e/bub --python-version 3.12 --extra-search-path src e2e/bub/src integrations/bub/src, and the project'sty check: passed.generate_integration_lifecycle.py --checkandgenerate_integration_manifest_docs.py --check: passed.prek run --files <changed files>: every hook passed exceptty-check, which was skipped because it needs a synced environment.tywas run directly instead.Not run:
make docs-test. The README is not part of the website.AI usage statement
This PR was written with Claude Code (Claude Opus 5.5), which read the code and Bub's installed source, implemented the change, wrote the tests and docs, and ran the checks above. A second Claude Code session reviewed the change against the code and the Bub 0.6.1 source, and reran the e2e/bub tests and the check against the previous plugin source.