Repository navigation
fix(bub): recall with the user's text, not Bub's channel frame - #2488
Conversation
There was a problem hiding this comment.
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.
2a22156 to
9481d4b
Compare
There was a problem hiding this comment.
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.
PsiACE
left a comment
There was a problem hiding this comment.
Thanks for the fix. Could we target bub[app] 0.6.1 and obtain recall text through standard hooks instead of reverse-parsing model prompts?
The current unwrapping also turns CLI input {"message":"report","constraint":"database migrations"} into report, dropping the constraint and missing relevant memories. For Telegram, we should expose searchable text before JSON wrapping, with a small upstream change if needed, while preserving the model-facing messages.
hidb4ai
left a comment
There was a problem hiding this comment.
Additional end-to-end evidence for @PsiACE's existing JSON-input finding, verified at 9481d4b4 with real Bub 0.5.1 CLI, a local SQLite PowerContext Server without embeddings, and a recording OpenAI-compatible model stub.
With a stored rollout-procedure memory, this CLI input recalls and injects it on base 4b50c158:
{"message":"Help","task":"Recall our canary rollout procedure: deploy database migrations before rolling out the application; notify the release team and verify health checks."}At this head, the prepare request contains only Help, and the model receives no recalled context. Changing message to "" skips prepare entirely despite the nonempty task. The ordinary question How should we deploy the migrations? does start recalling correctly, confirming both the intended fix and the JSON regression.
Please preserve user-authored JSON fields when extracting recall text; a message key alone does not establish that the content is a channel envelope.
Thanks for the reply; I’ll refactor it a bit later. |
Bub's builtin build_prompt prefixes each channel message with its context and the time, which outweighs the user's words in lexical recall. The plugin now takes the recall text from the inbound message in load_state, before that framing, and keeps the model request unchanged.
9481d4b to
ff44db7
Compare
There was a problem hiding this comment.
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.
|
Thanks, @PsiACE. Reworked along those lines:
Verified with real |
hidb4ai
left a comment
There was a problem hiding this comment.
The previous JSON-input regression is fixed. A same-session steering regression remains; reproduction is attached inline.
knqiufan
left a comment
There was a problem hiding this comment.
The existing same-session steering finding still applies: subsequent recall uses the earlier inbound text. Please address the existing thread before merging.
Bub drains steered follow-ups into a running turn through build_prompt without load_state, so the per-turn recall text went stale. The plugin now implements build_prompt at tryfirst priority, delegates to the other implementations in Bub's resolution order, and records the inbound text (ChannelMessage.text when set, else content) for each built prompt. before_llm_call recalls with the text of the latest user message.
The turn's message reaches the model through Bub's legacy prompt form, which joins text parts with newlines, so record the recall text under that form too. A plugin delegating build_prompt the same way would call back into this one without end; return None when re-entered so the delegation continues with the remaining implementations.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Verified at 80eb5941: the previous JSON-input and same-session steering issues are fixed, including the real Bub steering path against a lexical-only SQLite Server. One empty-text fallback issue remains, detailed inline.
Bub sets `text` to None when `content` is what the sender wrote (bubbuild/bub#399). Fall back to `content` only then, so an empty `text` skips recall instead of recalling the JSON envelope with its metadata and replied-to message.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Re-reviewed at 3a28a015. The empty-text fallback is fixed: explicit empty/blank text skips prepare and context injection, while absent/None text preserves the full JSON content. Verified through real Bub 0.6.1 process_inbound and steering against a lexical-only SQLite Server with a recording model stub. No remaining blocking findings; no database tables or public APIs added. Live Telegram was not exercised.
|
The code review at |
There was a problem hiding this comment.
🟡 Changes recommended
The hook loop re-enters a modifying delegator, duplicating its prefix and leaving PowerContext mapped to the inner prompt, so the final prompt loses recall metadata and recall falls back to channel-framed text.
Review effort: Balanced
| others = self._framework.plugin_manager.subset_hook_caller("build_prompt", remove_plugins=[self]) | ||
| kwargs = {"message": message, "session_id": session_id, "state": state} | ||
| for impl in reversed(others.get_hookimpls()): | ||
| result = impl.function(**{name: kwargs[name] for name in impl.argnames if name in kwargs}) |

Which issue or RFC does this PR close?
Closes #2487.
Rationale for this change
The Bub plugin builds its
POST /v1/context/preparequery from the latest user message in the model request. Bub's builtinbuild_prompthook frames every channel message as:context_stris the message context, written askey=value|.... It always includeschannelandchat_id, plus channel-specific keys such assender_id. So a plainbub run "How should we deploy the migrations?"sends this query:Lexical admission (
fts_query_requirementsinsrc/powercontext/builtin/artifacts/search.py) requires a candidate to match at least a quarter of the query's distinct analyzer terms. The frame adds 14 terms that no memory contains. For the remembered decision "Deploy database migrations before rolling out the application.":How should we deploy the migrations?Two cases are affected:
preparereturnsemptyfor every ordinary Bub prompt.With a working embedding model, vector recall still finds the memory, but the frame still costs every Bub recall its lexical evidence.
The recall text has to come from each inbound message, not just the first one in a turn. Bub can steer a follow-up into a running turn: the steering inbox is drained into the next model step through
build_prompt, withoutload_state. Following bubbuild/bub#400, the plugin implementsbuild_promptitself attryfirstpriority. It delegates to the other implementations and records which inbound text each built prompt came from. Bub callsbuild_promptfor the turn's message and for every drained follow-up, so each model-facing user message maps back to what the user sent. No prompt parsing and no new Bub hook are needed.What changes are included in this PR?
integrations/bub/src/powercontext_bub/plugin.py:build_prompt(tryfirst) builds the prompt through the otherbuild_promptimplementations, resolved as Bub resolves them: in precedence order, awaiting each until one returns a result. It falls back to the message content as Bub does and returns the same prompt Bub would have built. It then records, in the turn state, the built prompt's text → the message'stext(Bub'sChannelMessage.text, added after 0.6.1 by feat(channels): expose what the sender wrote on Telegram messages bubbuild/bub#399), or itscontentwhentextis absent orNone. The prompt's text is recorded both as sent with steering and as the turn's message reaches the model after Bub's legacy prompt form joins its text parts with newlines.build_promptthe same way and calls back into this one, it returnsNoneso that the delegation continues instead of recursing.before_llm_callrecalls with the recorded text for the latest user message. A prompt Bub did not build from an inbound message, such as a subagent's, is recalled as the model sees it. An empty inbound text skips prepare, including an explicitly emptytextbeside JSONcontent.user_promptcapture event still records the model-facing prompt, and the 8,192-character/byte bound still applies to the query.e2e/bub/tests/test_bub_recall_query.pyruns Bub's own framework with its builtin hooks and the plugin registered after them, as Bub loads it. It checks:textwhen a message carries it beside JSON content.textbeside JSON content skips prepare, also throughprocess_inbound; withtextset toNoneor absent, the query is the JSON content.process_inbound.build_promptthe same way does not recurse.process_inboundand Bub's steering inbox recalls with its own text.Are there any user-facing changes?
Yes. Without an embedding model, automatic recall now works for normal prompts on Bub's CLI and on channels whose content is the user's text, including follow-ups steered into a running turn. Before, it returned
emptyunless the prompt exceeded the recall bound. With embeddings, these recalls also get lexical matches.Telegram recall changes once a Bub release includes bubbuild/bub#399, which sets
text. On Bub 0.6.1 it still uses the JSONcontent. Nothing changes in the API, configuration, or docs.How was this change tested?
uv run --project e2e/bub python -m pytest e2e/bub/tests/test_bub_recall_query.py: 23 passed. With the plugin from master, 12 fail; with this PR's previousload_stateversion, 11 fail, including the steering case, where the follow-up recalls with the first question.make harness-check: passed.make check: passed.powercontextentry-point plugin,process_inbound("How should we deploy the migrations?"), and a follow-up steered into the turn after the first model call. It ran against a local lexical-only SQLite PowerContext Server holding a migration decision and a support escalation policy, with a recording OpenAI-compatible stub model.build_promptresolved aspowercontext, thenbuiltin.load_stateversion, both carried the migration decision.process_inboundof supplied Telegram-shaped envelopes, a local lexical-only SQLite PowerContext Server holding the support escalation policy, and a recording stub model.text=""and JSONcontentthat quotes the policy asreply_to_message, no prepare was issued and no context was injected. Falling back withtext or contentinstead prepared with the JSON and injected the policy.text=" "issued no prepare.textset to the question, and JSONcontentwithouttext, each prepared with that text or JSON and injected the policy.build_promptmapping, so an emptytextthere also skips recall. No other integration falls back fromtexttocontent.textyet.AI usage statement
This PR was prepared with Claude Code (Claude Opus 5.5). It traced Bub's prompt framing, steering, and hook resolution, made the change, ran the checks and the real Bub runs, and drafted this description. I reviewed the change and the results.