fix(agent): persist on a copy so early persist can't strip live user message (salvage #48817) - #56300
Merged
kshitijk4poor merged 1 commit intoJul 1, 2026
Conversation
kshitijk4poor
enabled auto-merge (rebase)
July 1, 2026 10:41
… list (NousResearch#48677) The persist user-message override was applied in place to the live messages list. On the early crash-resilience persist (which runs BEFORE api_messages is built), that stripped observed group-chat context off the live user message and silently dropped it when observe_unmentioned_group_messages was enabled. Fix at the single chokepoint: _flush_messages_to_session_db resolves the override (idx/content/timestamp) locally and applies it ONLY to the row written to the DB — the live dict is never mutated, so EVERY persist caller (early persist, mid tool-loop flush, /resume, /branch) is protected uniformly. This supersedes the earlier shallow-copy approach, which broke the intrinsic _DB_PERSISTED_MARKER idempotency (copies never propagated the marker back to the live dicts → duplicate rows) and closes the sibling class tracked in NousResearch#56303. Trailing empty-response scaffolding is still dropped from the live list in _persist_session (unchanged behavior). Salvaged from NousResearch#48817; chokepoint reworked to coexist with the marker-based dedup (NousResearch#50372). Co-authored-by: kyssta-exe <kyssta-exe@users.noreply.github.com>
kshitijk4poor
force-pushed
the
salvage-persistcopy
branch
from
July 1, 2026 11:53
dc04fd0 to
1c50027
Compare
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.
Salvage of #48817 (@kyssta-exe), rebased onto current main. Fixes #48677.
Issue (#48677)
_persist_sessionapplied_apply_persist_user_message_overridedirectly to the livemessageslist. The crash-resilience early persist inbuild_turn_contextruns BEFOREapi_messagesis built, so withobserve_unmentioned_group_messagesthe override rewrotemessages[idx]['content']to the bare current message — silently dropping observed group-chat context before the request reached the model (and withholding it from replay history). No error, no log.Fix
Operate on a shallow copy in
_persist_session. The override only writes stringcontent, so the copy is sufficient: DB/log get the cleaned transcript while the live list keeps full content for the API call. The override's existing multimodal guard (skips list-content) is unaffected.Verification
Existing
test_persist_session_rewrites_current_turn_user_messageupdated to assert the live list keeps original content AND the DB write gets the override. Mutation-checked: reverting to in-place mutation fails it.Closes #48817.
Co-authored-by: kyssta-exe kyssta-exe@users.noreply.github.com