Skip to content

fix(review): isolate background-review fork from the canonical session (salvage #50296) - #56308

Merged
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage-bgreview
Jul 1, 2026
Merged

kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage-bgreview

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Contributor

Salvage of #50296 (@arminanton), rebased onto current main.

Issue

The forked skill/memory review agent shares the parent's session_id for prompt-cache warmth. Without isolation it wrote its harness turn ("Review the conversation above and update the skill library…") plus its curator-mode reply into the user's real session in state.db. The next live turn re-read that injected user message as a standing instruction → the agent "became" the curator and refused the actual task. Silent.

Fix (defense-in-depth)

  • Root: a _persist_disabled flag on the fork that hard-stops every DB write / lazy-open path (_flush_messages_to_session_db, _ensure_db_session, _get_session_db_for_recall). The review writes only to the skill/memory stores via its tools.
  • Heal: _strip_background_review_harness drops any stray harness message (and the assistant reply that followed) at load time in get_messages_as_conversation, so an already-polluted session resumes clean.

Verification

Contributor shipped 13 unit tests of the pure matcher/stripper. Phase 2c mutation-check found those covered zero of the two integration wirings (removing the _persist_disabled flush guard or the load-time _strip call left all 13 green). Added 2 integration guards (my follow-up commit): a _persist_disabled agent's flush writes nothing to a live DB; a polluted session resumes clean end-to-end through get_messages_as_conversation. Mutation-checked: each fails when its wiring is reverted. 15 tests pass (canonical runner).

Closes #50296.

Co-authored-by: arminanton 29869547+arminanton@users.noreply.github.com

arminanton and others added 2 commits July 1, 2026 16:15
…ssion

The forked skill/memory review agent shares the parent's session_id for
prompt-cache warmth. Without isolation it wrote its harness turn ('Review the
conversation above and update the skill library…') plus its curator-mode reply
straight into the user's REAL session in state.db; the next live turn re-read
that injected user message as a standing instruction and the agent 'became' the
curator, refusing the actual task.

Root fix: a _persist_disabled flag on the fork that hard-stops every DB write
and lazy-open path (_flush_messages_to_session_db, _ensure_db_session,
_get_session_db_for_recall) — the review writes only to the skill/memory stores
via its tools. Defense-in-depth: _strip_background_review_harness drops any
stray harness message (and the assistant reply that followed) at load time in
get_messages_as_conversation, so an already-polluted session resumes clean.

Salvaged from NousResearch#50296.

Co-authored-by: arminanton <29869547+arminanton@users.noreply.github.com>
…eview)

Phase 2c mutation-check found the salvaged tests covered only the pure helpers
(_is_background_review_harness_message / _strip_background_review_harness) — the
two integration WIRINGS had zero coverage: removing the _persist_disabled guard
in _flush_messages_to_session_db, or the _strip call in
get_messages_as_conversation, left all 13 tests green.

Add:
- TestPersistDisabledHardStop: a _persist_disabled agent's flush writes nothing
  to a live SessionDB (guards the run_agent hard-stop).
- TestGetMessagesAsConversationStripsHarness: a session with stray harness rows
  resumes clean end-to-end through get_messages_as_conversation (guards the
  hermes_state load-time wiring).
Mutation-checked: each new test fails when its wiring is reverted.
@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) July 1, 2026 10:46
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jul 1, 2026
@kshitijk4poor
kshitijk4poor merged commit 23518a5 into NousResearch:main Jul 1, 2026
29 checks passed
@kshitijk4poor
kshitijk4poor deleted the salvage-bgreview branch August 5, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P1 High — major feature broken, no workaround sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants