Skip to content

fix(hermes): stop queued prefetch work that recall never reads - #2781

Merged
PsiACE merged 3 commits into
oceanbase:masterfrom
Fengzdadi:fix/hermes-queued-prefetch
Nov 23, 2026
Merged

PsiACE merged 3 commits into
oceanbase:masterfrom
Fengzdadi:fix/hermes-queued-prefetch

Conversation

@Fengzdadi

Copy link
Copy Markdown
Collaborator

Which issue or RFC does this PR close?

No tracking issue. This fixes a defect in the Hermes provider's background prefetch and updates the Hermes row of RFC 1489 (docs/en/rfcs/1489_prepared_context_text_assembly.md) to match.

Rationale for this change

Hermes calls queue_prefetch after turn N with turn N's text (run_agent.py) and prefetch at the start of turn N+1 with the next prompt (agent/turn_context.py). The provider cached the queued result under the exact query, so the cache almost never hit: every turn paid one background prepare_context whose result was never read, and _prefetch_cache kept growing until the Scope or session changed.

What changes are included in this PR?

  • queue_prefetch in integrations/hermes/plugins/powercontext/provider.py is now an explicit no-op, as in Hermes' own ByteRover provider. The prefetch cache, its lock, its cleanup and the cache trace status are removed. Turn-start recall stays synchronous and prepares the current prompt.
  • Reusing the previous turn's queued result was not adopted: it would change what recall is based on, which is a product decision rather than a fix.
  • plugin.yaml drops queue_prefetch from the advertised hooks. Hermes reads that list only for its plugin catalog and validation, not for loading.
  • integrations/hermes/README.md, docs/{en,zh}/docs/integrations/hermes.md and docs/{en,zh}/rfcs/1489_prepared_context_text_assembly.md (the Hermes row and the cache-identity paragraph) describe the new behavior.
  • tests/integrations/test_hermes_provider.py gains a regression test: queue_prefetch sends nothing, and the next prefetch prepares only its own prompt. The Scope-binding test now blocks a capture and checks that the recalled content comes from the new Scope.
  • tests/inprocess_adapter_turns.py drops the Hermes queue_prefetch entry, which no longer sends a request.

Are there any user-facing changes?

Hermes users see one fewer prepare_context request per turn, and recall still uses each turn's current prompt. A prompt that repeats the previous turn's text is now prepared fresh instead of being served from the result queued after that turn. With evaluation_trace enabled, recall trace records no longer use the cache status. There are no configuration, API or persisted-format changes.

How was this change tested?

  • UV_OFFLINE=1 UV_NO_SYNC=1 uv run pytest -q tests/integrations/test_hermes_provider.py tests/integration_conformance tests/test_recall_query_bound.py tests/test_integration_manifest.py: 294 passed, 1 skipped (the real-manager test without a Hermes checkout).
  • The real-manager conformance test (tests/integration_conformance/hermes/test_real_manager.py) passed against a Hermes checkout at the pinned 4131fd95 on Python 3.14.7.
  • Restoring the previous provider.py makes the new regression test fail.
  • ruff check, ruff format --check and ty check on the changed paths are clean. prek run --from-ref upstream/master --to-ref HEAD passes every hook except ty-check, whose 20 unresolved-import diagnostics are in master's deepagents and Gemini CLI code, because the offline environment predates those dependencies.
  • Not verified: Linux, a full Hermes agent loop with a live model, and Hermes versions other than the pinned one.

AI usage statement

Claude Code (Claude Opus 5.5) wrote the code, tests and this description; the diff and test results were reviewed before submission.

Hermes queues a background prefetch after turn N with that turn's text and
prefetches turn N+1 with the next prompt. The provider cached the queued
result under the exact query, so real turns almost never hit it: each turn
paid an extra prepare request, and nonempty results stayed in the cache
until a Scope or session change.

Turn-start prefetch already prepares the current prompt synchronously, the
behavior the README documents and other hosts share. Make queue_prefetch an
explicit no-op, as Hermes' ByteRover provider does, and remove the cache,
its lock, its cleanup and the trace's "cache" status. Recalled content on
real turns is unchanged.

Rewrite the tests that relied on the cache, cover that a queued prefetch
sends nothing and the next prefetch prepares its own prompt, drop the
queue_prefetch in-process entry, and update the user-facing docs and the
plugin manifest's hook list.
…l in RFC 1489

The Scope-binding test asserts the recalled text again comes from the newly bound Scope. The RFC 1489 Hermes row and cache-identity paragraph describe per-turn preparation instead of a prefetch cache.

@Alanxtl Alanxtl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@PsiACE PsiACE left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

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.

3 participants