Repository navigation
Conversation
A prompt holding an unpaired surrogate, such as a file name decoded with surrogateescape, made _bounded_recall_query raise UnicodeEncodeError before the plugin's client error handling, so before_llm_call raised out of the plugin. Recall is now skipped for such a query: no prepare request is sent, the model request goes on unchanged, and the capture log records a skipped context. A long prompt whose unencodable text falls before the kept tail still recalls.
This branch has not been deployed
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 (automatic recall in the host adapters). It applies the fail-open contract from #2647 to the Bub plugin.
Rationale for this change
A prompt can hold an unpaired surrogate, for example a file name decoded with
surrogateescapeor a JSON\ud800escape. Such a string has no UTF-8 form. The Bub plugin bounds the recall query with_bounded_recall_query, which encodes the query to UTF-8, and it does this before its client error handling. Sobefore_llm_callraisedUnicodeEncodeErrorout of the plugin.#2647 fixed the same class of failure for Hermes, LangChain, LangGraph, and Pydantic AI: when the query has no UTF-8 form, automatic recall is skipped and the turn proceeds. Bub is the remaining in-process Python adapter.
What a Bub 0.6.1 user sees on master: Bub's
PluginAgentHooks._safe_call_onecatches the exception and logshook.agent_hook_failed hook=before_llm_call adapter=powercontextas a WARNING with a traceback intopowercontext_bub/plugin.py. Then Bub continues without injected context. The turn still fails afterwards, but in Bub itself: encoding the model request (httpx2/_content.py) and appending the tape entry (bub/core/store.py) both raiseUnicodeEncodeErrorfor the same prompt. This change does not make such a turn succeed on Bub 0.6.1. It removes the plugin's own failure, so the plugin does not depend on Bub's hook guard, and the log no longer blames PowerContext for a prompt that Bub itself cannot send.What changes are included in this PR?
integrations/bub/src/powercontext_bub/plugin.py:_prepare_contextbounds the query inside aUnicodeEncodeErrorhandler. For a query without a UTF-8 form it sends no prepare request, returns no context, and writes a capture-log record withevent: "context",status: "skipped", anderror: "UnicodeEncodeError". Prepare failures keep their existingstatus: "failed"record.before_llm_callthen returnsNone, so Bub's model request goes on unchanged.render_capture_eventserializes withensure_ascii=True, so theuser_promptevent carries the surrogate as a JSON escape and is still captured.save_stateonly flushes and sends no prompt text.The new record needs no schema change:
CaptureRecordine2e/bubalready accepts anystatusand anerrorname, and the evaluation counts onlystatus: "ready"context records.Are there any user-facing changes?
No API or configuration changes. For a prompt without a UTF-8 form, the plugin no longer raises from
before_llm_call, and Bub no longer logs a PowerContext hook failure for it. Withcapture_logset, the JSONL file gets acontextrecord withstatus: "skipped". The integration docs do not describe this failure case, so no docs change.How was this change tested?
e2e/bub/tests/test_bub_recall_query.pycall the plugin'sbefore_llm_callhook with capture enabled and a capture log:test_recall_is_skipped_when_the_query_has_no_utf8_form[short]and[in-the-kept-tail]: the hook returnsNone, no prepare request is sent, theuser_promptevent is captured as ASCII content, and the capture log readsuser_prompt captured, thencontext skipped. Both cases fail on master withUnicodeEncodeError.test_recall_keeps_the_tail_when_the_unencodable_text_falls_before_it: the prepare query is the bounded tail. It passes on master too and guards against skipping every prompt that holds a surrogate.e2e/bub/.venv/bin/python -m pytest e2e/bub/tests: 326 passed.BubFramework.process_inbound, with a stub model transport and a surrogate prompt, was run before and after the change (an ad-hoc probe, not committed). Before:hook.agent_hook_failed hook=before_llm_call adapter=powercontext, then Bub's own model request encoding fails. After: no PowerContext hook warning; Bub's model request encoding still fails.make checkandmake harness-checkpass.Not validated: no real Bub run against a model provider or a running PowerContext Server.
Self-review against
REVIEW.mdand an independent Opus review of the diff found no blocking defect; their non-blocking notes follow.Notes (non-blocking)
"caf\udce9.txt " + "é" * 5000). The sharedbounded_recall_queryused by the hooks and the fix(integrations): recall with the end of a long prompt in Hermes, LangChain, LangGraph, and Pydantic AI #2647 adapters behaves the same way; this change keeps the Bub copy identical rather than diverging for prompts that already hold invalid text.workspace_binding_keyencodes the resolved workspace path inload_state, which Bub does not isolate, so a Linux workspace directory with a non-UTF-8 byte fails the turn;_source_idencodes the session id for capture. Neither comes from prompt text.powercontext.search,powercontext.context,powercontext.remember) still raise for a surrogate argument; Bub's tool runner reports that as a tool error, so the turn continues.AI usage statement
Claude Code (Claude Opus 5.5) wrote this change and its tests, ran the checks listed above, and drafted this description.