Repository navigation
fix(runtime): make the recall embedding budget configurable and log its fallback - #2042
Merged
hidb4ai merged 2 commits intoOct 20, 2026
Merged
Conversation
…ts fallback prepare_context bounds the query embedding of Atomic Memory and Topic Memory retrieval with a module constant of 0.25 s. A remote embedding provider needs longer, so the preparation silently continued with lexical matching only and a long Hook query returned empty although the Memory existed (oceanbase#2039). - RuntimeConfig.recall_embedding_timeout_seconds, read as POWERCONTEXT_SERVER_RUNTIME_RECALL_EMBEDDING_TIMEOUT_SECONDS, replaces both constants. The default stays 0.25, so behavior is unchanged until an operator raises it. - Atomic Memory retrieval logs memory.search.embedding_fallback at WARNING when the budget expires or the provider is unavailable, with the same fields as the Topic Memory event and without the query. - Tests cover the fallback event, the setting's bounds and environment mapping, and the budget reaching the search through open_builtin_runtime. - The configuration reference lists the setting in both locales. Refs oceanbase#2039
Fengzdadi
requested review from
AlexStocks,
PsiACE,
frostming and
zhanghuidinah
as code owners
October 17, 2026 07:41
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
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.
…ecall-embedding-timeout-setting # Conflicts: # src/powercontext/builtin/runtime/atomic_memory.py
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
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.
hireview001
reviewed
Oct 20, 2026
hireview001
left a comment
Collaborator
There was a problem hiding this comment.
- CI failed: validate (failure).
- CI failed: E2E harness (failure). Failed steps: validate / Validate harness and Compose definitions.
jasondeng1997
added a commit
to jasondeng1997/powercontext
that referenced
this pull request
Oct 21, 2026
…ceanbase#2039) `prepare_context` bounded the query embedding, then said nothing when the bound expired: `status: "empty"` read the same whether nothing matched or the semantic path never ran, and oceanbase#2042's WARNING only reached the server log. Add a nullable `reason` to `PreparedContext`, mirroring `BootstrapContext.reason`: - `embedding_timeout` when `recall_embedding_timeout_seconds` expired, `embedding_unavailable` when the provider failed, `null` otherwise. The field stays outside the spec's `required` list, so a client written before it existed still parses a degraded response. - The marker is filled from the same classification that emits the fallback event, carried from `_resolve_query_embedding` and the Topic Memory searcher through the recall round into the preparation; the log and the response cannot disagree about the cause. - A preparation that never wanted vectors stays `null`: a keyword-only deployment is not degraded, only one that lost a channel it asked for. - When both channels fail, a timeout outranks an unavailable provider, because the budget is the one an operator can raise.
jasondeng1997
added a commit
to jasondeng1997/powercontext
that referenced
this pull request
Oct 21, 2026
…ceanbase#2039) `prepare_context` bounded the query embedding, then said nothing when the bound expired: `status: "empty"` read the same whether nothing matched or the semantic path never ran, and oceanbase#2042's WARNING only reached the server log. Add a nullable `reason` to `PreparedContext`, mirroring `BootstrapContext.reason`: - `embedding_timeout` when `recall_embedding_timeout_seconds` expired, `embedding_unavailable` when the provider failed, `null` otherwise. The field stays outside the spec's `required` list, so a client written before it existed still parses a degraded response. - The marker is filled from the same classification that emits the fallback event, carried from `_resolve_query_embedding` and the Topic Memory searcher through the recall round into the preparation; the log and the response cannot disagree about the cause. - A preparation that never wanted vectors stays `null`: a keyword-only deployment is not degraded, only one that lost a channel it asked for. - When both channels fail, a timeout outranks an unavailable provider, because the budget is the one an operator can raise.
jasondeng1997
added a commit
to jasondeng1997/powercontext
that referenced
this pull request
Oct 21, 2026
…oceanbase#2039) `prepare_context` bounded the query embedding, then said nothing when the bound expired: `status: "empty"` read the same whether nothing matched or the semantic path never ran, and oceanbase#2042's WARNING only reached the server log. A request can now ask with `"explain": true`, and the response then carries `reason`: `embedding_timeout` when `recall_embedding_timeout_seconds` expired, `embedding_unavailable` when the provider failed. - The field is opt-in, and absent even for an explaining request when nothing was lost. Every Host validates the injected envelope -- most by exact key set (zcode, opencode, dsh, pi, claude-code, codex, workbuddy, kimi, openclaw) -- so a fifth key on an ordinary preparation would break all of them for a fact none of them reads. RFC 1435 states the same rule for the injection value. - The marker is filled from the same classification that emits the fallback event, carried from `_resolve_query_embedding` and the Topic Memory searcher through the recall round into the preparation, so the log and the response cannot disagree about the cause. - A preparation that never wanted vectors stays silent: a keyword-only deployment is not degraded, only one that lost a channel it asked for. - When both channels fail, a timeout outranks an unavailable provider, because the budget is the one an operator can raise.
jasondeng1997
added a commit
to jasondeng1997/powercontext
that referenced
this pull request
Oct 21, 2026
…oceanbase#2039) `prepare_context` bounded the query embedding, then said nothing when the bound expired: `status: "empty"` read the same whether nothing matched or the semantic path never ran, and oceanbase#2042's WARNING only reached the server log. A request can now ask with `"explain": true`, and the response then carries `reason`: `embedding_timeout` when `recall_embedding_timeout_seconds` expired, `embedding_unavailable` when the provider failed. - The field is opt-in, and absent even for an explaining request when nothing was lost. Every Host validates the injected envelope -- most by exact key set (zcode, opencode, dsh, pi, claude-code, codex, workbuddy, kimi, openclaw) -- so a fifth key on an ordinary preparation would break all of them for a fact none of them reads. RFC 1435 states the same rule for the injection value. - The marker is filled from the same classification that emits the fallback event, carried from `_resolve_query_embedding` and the Topic Memory searcher through the recall round into the preparation, so the log and the response cannot disagree about the cause. - A preparation that never wanted vectors stays silent: a keyword-only deployment is not degraded, only one that lost a channel it asked for. - When both channels fail, a timeout outranks an unavailable provider, because the budget is the one an operator can raise.
jasondeng1997
added a commit
to jasondeng1997/powercontext
that referenced
this pull request
Oct 21, 2026
…oceanbase#2039) `prepare_context` bounded the query embedding, then said nothing when the bound expired: `status: "empty"` read the same whether nothing matched or the semantic path never ran, and oceanbase#2042's WARNING only reached the server log. A request can now ask with `"explain": true`, and the response then carries `reason`: `embedding_timeout` when `recall_embedding_timeout_seconds` expired, `embedding_unavailable` when the provider failed. - The field is opt-in, and absent even for an explaining request when nothing was lost. Every Host validates the injected envelope -- most by exact key set (zcode, opencode, dsh, pi, claude-code, codex, workbuddy, kimi, openclaw) -- so a fifth key on an ordinary preparation would break all of them for a fact none of them reads. RFC 1435 states the same rule for the injection value. - The marker is filled from the same classification that emits the fallback event, carried from `_resolve_query_embedding` and the Topic Memory searcher through the recall round into the preparation, so the log and the response cannot disagree about the cause. - A preparation that never wanted vectors stays silent: a keyword-only deployment is not degraded, only one that lost a channel it asked for. - When both channels fail, a timeout outranks an unavailable provider, because the budget is the one an operator can raise.
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 #2039. The issue also asks for a
reasononPreparedContextand for a decision on the default value; both are left for discussion there (see below).Rationale for this change
POST /v1/context/preparebounds the query embedding of Atomic Memory and Topic Memory retrieval with two module constants of 0.25 s. A remote embedding provider needs longer (0.27–0.41 s measured through OpenRouter; 315–1019 ms in #1700), so_resolve_query_embeddingquietly continued with lexical matching only, and a long Hook query returnedemptyalthough the Scope held the matching Memory. #1700 gave the host Hooks a 3 s request budget for exactly this round trip; the Server-side cap introduced with #1857 recreated the failure where the Hook budget cannot help, and nothing recorded it.This PR makes the budget an operator setting and makes the degradation visible. The default stays 0.25 s, so existing deployments behave exactly as before until an operator raises it.
What changes are included in this PR?
RuntimeConfig.recall_embedding_timeout_seconds, read asPOWERCONTEXT_SERVER_RUNTIME_RECALL_EMBEDDING_TIMEOUT_SECONDS(default0.25,0 < value <= 60, booleans rejected), replaces both constants.open_builtin_runtimepasses it toBuiltinRuntime, which uses it for the Atomic Memory search and the Topic Memory search of a preparation. The budget applies to each search; a preparation searches the Scope and each of its context references in turn, so the waits add up. The configuration row says so.memory.search.embedding_fallbackatWARNINGwhen the budget expires or the provider is unavailable, withoutcome=fallback,mode=text,error_code=inference_timeoutorinference_unavailable, andunit=memory. It mirrors the existingtopic_memory.search.embedding_fallback: fixed message, no query, exception or provider text, and only fields the operational allowlist already carries, so the formatter and the field contract are unchanged.tests/e2e/test_recall_embedding_timeout.pydrivespreparethroughopen_builtin_runtimewith an embedding stub that only slows or fails the query embedding: an expired budget still recalls the Memory lexically and emits the event while the query embedding never completes; a provider failure is classified byerror_codeand the JSON-serialized record carries no query or exception; a sufficient budget waits for the embedding and emits nothing.tests/builtin/runtime/test_recall_embedding_timeout_config.pycovers the default, the bounds, boolean rejection and the environment mapping.Are there any user-facing changes?
WARNINGevent. With a persistently slow provider it fires once per Atomic Memory search, that is once per searched Scope, plus once for Topic Memory, per preparation.Deliberately not in this PR, for discussion on #2039: the default value, and a
reasonfield onPreparedContext. Every host plugin validates the prepare response strictly and rejects unknown fields, so the field needs the hosts updated first.How was this change tested?
make check(lock, pre-commit hooks,ty check) in the branch's worktree.uv run pytest tests/e2e/test_recall_embedding_timeout.py tests/builtin/runtime/test_recall_embedding_timeout_config.py tests/builtin/runtime/test_recall_channel_weights.py -qand, before the final review amendments,uv run pytest tests/builtin/runtime tests/test_server.py tests/test_server_logging.py tests/e2e/test_worker_logging.py -q.prepare_contextabandons the query embedding after 0.25 s, so Hook recall silently degrades to lexical search with a remote embedding provider #2039 (ten prepare replays:empty0/10 behind a 300 ms delay on master,ready10/10 with the budget at 2 s; paired harness ON sessions then injecting context instead of the model callingpc_search) were taken with the constant patched locally on the same call sites this setting now controls.AI usage statement
Claude Code (Claude Fable 5.1) helped investigate the recall path, measure the embedding latency, write the change, tests and documentation, run the local checks, review the result in a separate agent pass, and draft this description. I reviewed the code, the measurements and this text.