Files
hermes-agent/tests/agent
liuzikaii a940858290 fix(agent): run deferred background reviews under the enqueuing profile's context (#108537, salvage #108538)
ReviewIdleQueue stored (agent, session_key, kwargs, enqueued_at) with no
context, and the shared dispatcher thread called _still_enabled(item) and
item.agent._spawn_background_review_now(**item.kwargs) under its own
AMBIENT context. On a multiplexed gateway that meant the wrong profile's
background_review.enabled gate decided whether a queued review ran, and the
spawned worker inherited the ambient home / no secret scope (the
propagate_context_to_thread in _spawn_background_review_now copies a
context that no longer carries the originating profile).

Capture contextvars.copy_context() at enqueue() on _PendingReview and run
both the enabled re-check and the spawn via item.context.run(...).

Test: two profile homes (enabled / disabled) plus a disabled ambient home
under set_multiplex_active(True); only the enabled profile's item spawns,
and it observes its own home override + secret scope.

Salvaged from #108538 by @Liuzikaii (mechanism kept, test trimmed into the
existing test module).

Fixes #108537

(cherry picked from commit 4f8a64fd680e40de270a18b52c8f44a414334c56)
2026-09-28 05:37:55 -07:00
..