fix: preserve latest user objective during compaction #1
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/preserve-active-user-objective"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
max_assembly_tokensand drop it if preserving it would reintroduce overflow.Bug
In long gateway sessions, a user can change objectives and then the assistant may run many tool calls before LCM compacts. Because the fresh tail is message-count based, those assistant/tool messages can push the latest user request out of active context. The next post-compaction prompt can then contain old summarized goals plus mechanical tool traces, but not the current user request verbatim. In practice this can make the agent regress to an older task after a compression/session split.
A user-side workaround is to increase the fresh-tail count, but that is not a rigorous fix: tool-heavy turns can still exceed the configured window, and a larger tail increases context/cost for every session. The engine should preserve the active objective directly without weakening replay or overflow guardrails.
Fix
The change is intentionally narrow:
compress(), temporarily provide_assemble_context()with the original pre-compaction message window._assemble_context()finds the newest non-synthetic user message when it is not already present in the selected tail.[Current user objective preserved from compacted history].max_assembly_tokens.Testing
PYTHONPATH=/opt/hermes:/opt/hermes-runtime/repos/hermes-lcm-fix-active-objective /opt/hermes-runtime/tools/mise/use-mise.sh pytest /opt/hermes-runtime/repos/hermes-lcm-fix-active-objective/tests/test_lcm_engine.py::TestEngineABC::test_existing_compacted_session_restart_skips_synthetic_context_but_persists_new_tool /opt/hermes-runtime/repos/hermes-lcm-fix-active-objective/tests/test_lcm_engine.py::TestEngineABC::test_existing_session_restart_persists_scaffolded_delta_message_matching_store_tail /opt/hermes-runtime/repos/hermes-lcm-fix-active-objective/tests/test_lcm_engine.py::TestEngineABC::test_existing_session_restart_persists_scaffolded_delta_message_matching_store_tail_with_followup /opt/hermes-runtime/repos/hermes-lcm-fix-active-objective/tests/test_lcm_engine.py::TestEngineABC::test_existing_compacted_session_restart_ignores_preserved_objective_anchor /opt/hermes-runtime/repos/hermes-lcm-fix-active-objective/tests/test_lcm_engine.py::TestEngineCompress::test_compress_preserves_latest_user_request_outside_fresh_tail /opt/hermes-runtime/repos/hermes-lcm-fix-active-objective/tests/test_lcm_engine.py::TestAssemblyGuardrails::test_context_anchor_is_budgeted_under_max_assembly_tokens -q6 passedPYTHONPATH=/opt/hermes:/opt/hermes-runtime/repos/hermes-lcm-fix-active-objective /opt/hermes-runtime/tools/mise/use-mise.sh pytest /opt/hermes-runtime/repos/hermes-lcm-fix-active-objective/tests/test_lcm_engine.py -q306 passed, 39 warningsPYTHONPATH=/opt/hermes:/opt/hermes-runtime/repos/hermes-lcm-fix-active-objective /opt/hermes-runtime/tools/mise/use-mise.sh pytest /opt/hermes-runtime/repos/hermes-lcm-fix-active-objective/tests/test_lcm_engine.py /opt/hermes-runtime/repos/hermes-lcm-fix-active-objective/tests/test_lcm_core.py /opt/hermes-runtime/repos/hermes-lcm-fix-active-objective/tests/test_lcm_command.py -q508 passed, 39 warningsgit diff --checkPYTHONPATH=/opt/hermes:/opt/hermes-runtime/repos/hermes-lcm-fix-active-objective /opt/hermes-runtime/tools/mise/use-mise.sh pytest /opt/hermes-runtime/repos/hermes-lcm-fix-active-objective/tests -q525 passed, 39 warningsNotes for upstream
This branch is published on a Forgejo fork because I cannot open the upstream GitHub PR directly from this environment. The diff is based on upstream
mainatb8d934b(v0.9.2).8c409cc1e751022ce4deUpdated the branch after tightening the design from PR feedback: the preserved objective is now a labeled synthetic scaffold inside the summary block, budgeted under max_assembly_tokens, and covered by restart-replay/cap regressions. Local full plugin tests pass (525 passed), and Forgejo CI is green on 3.11/3.12/3.13 for head
51022ce.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.