Hermes Agent context engine: the main model writes the compaction handoff on its cached prompt prefix
Merge main and verify the whitespace fix with current compatibility checks
Elevatormusicc74512b0de6e
diff --cc evidence/issue-12-whitespace.jsonindex 70c07c2,0000000..56a2ae8mode 100644,000000..100644--- a/evidence/issue-12-whitespace.json+++ b/evidence/issue-12-whitespace.json@@@ -1,317 -1,0 +1,619 @@@+{+ "issue": "https://github.com/Elevatormusic/hermes-warm-compaction/issues/12",+ "date": "2026-10-07",+ "scope": "Trailing whitespace removal from complete text strings during source validation.",+ "synthetic": true,+ "privacy": "Metadata only. No conversation text, request bodies, credentials, or private paths.",+ "base_plugin_commit": "f5dd19c1c1e25edbb15e1f1754dc6e99ddbef151",+ "hermes": {+ "commit": "e36a818033f5246e5fcfe9a6967bb85e885ba155",+ "clean": true+ },+ "integration_python": "3.11.14",+ "script_sha256": "c8eea9bddb3df78cf6f2b4dfec8f2a182e221548644c4e1455e4aae57c9b5c44",+ "fixed_plugin_files_sha256": {+ "warm_compaction/__init__.py": "760484ace80b9da77d7397828f69178905c9ac95df7b8114956bde727bd98aef",+ "warm_compaction/capture.py": "a9f907ada5d83eba79628454630d9295664b8215a2f2409cfc26223bcb2ad40f",+ "warm_compaction/engine.py": "d3f24174f807a2b63441b957f1eafd45e25f2faf30427591dab85010485216bd",+ "warm_compaction/fallback.py": "9b2d0529767ff157bbe0d1cbf096ca6ac35217118f81eee769adf41d50189a9a",+ "warm_compaction/handoff.py": "fcab51def8fbcc2b1928957930c9a5c58a4ad202c949fd9f870a77f3b30276ae",+ "warm_compaction/layout.py": "b49314c5236268247c337d9fae939135c97b47384300dcdfd00b0da0c040db93",+ "warm_compaction/plugin.yaml": "baa7820b3ce9a40d2a53f70a4d0525131860ea2ec670143d0a7742b59c4d937b",+ "warm_compaction/rows.py": "f2ca69a7361affc4fd84388ab9ac718a0e9affa609c87d75efd6e0c25fa860cf",+ "warm_compaction/warm.py": "db4826e3ba7762c386f523354fe02833bdb4947c03ac80b67e058f9a67333640"+ },+ "baseline_with_final_regression_script": {+ "scenario": "manual_whitespace",+ "status": "failed",+ "checks": 48,+ "failed_checks": [+ "turn2_path_warm",+ "turn2_one_warm_request",+ "turn2_handoff_in_summary",+ "turn3_path_warm",+ "turn3_one_warm_request",+ "turn3_handoff_in_summary",+ "no_fallback_request"+ ],+ "install_checks_passed": true,+ "worker_exit_codes": [+ 0,+ 0+ ],+ "request_counts": {+ "main": 3,+ "warm": 1,+ "fallback": 2+ },+ "outcomes": [+ [+ "warm",+ "accepted"+ ],+ [+ "fallback",+ "source_transform_unsupported"+ ],+ [+ "fallback",+ "source_transform_unsupported"+ ]+ ]+ },+ "fixed_scenarios": [+ {+ "scenario": "enable_manual_warm",+ "status": "passed",+ "checks": 24,+ "failed_checks": [],+ "install_checks_passed": true,+ "worker_exit_codes": [+ 0,+ 0+ ],+ "request_counts": {+ "main": 2,+ "warm": 1+ }+ },+ {+ "scenario": "manual_whitespace",+ "status": "passed",+ "checks": 60,+ "failed_checks": [],+ "install_checks_passed": true,+ "worker_exit_codes": [+ 0,+ 0+ ],+ "request_counts": {+ "main": 3,+ "warm": 3+ },+ "outcomes": [+ [+ "warm",+ "accepted"+ ],+ [+ "warm",+ "accepted"+ ],+ [+ "warm",+ "accepted"+ ]+ ]+ },+ {+ "scenario": "manual_fallback",+ "status": "passed",+ "checks": 18,+ "failed_checks": [],+ "install_checks_passed": true,+ "worker_exit_codes": [+ 0,+ 0+ ],+ "request_counts": {+ "main": 2,+ "warm": 1,+ "fallback": 1+ }+ },+ {+ "scenario": "manual_fixed",+ "status": "passed",+ "checks": 17,+ "failed_checks": [],+ "install_checks_passed": true,+ "worker_exit_codes": [+ 0,+ 0+ ],+ "request_counts": {+ "main": 2,+ "warm": 1,+ "fallback": 1+ }+ },+ {+ "scenario": "auto_tool_loop",+ "status": "passed",+ "checks": 27,+ "failed_checks": [],+ "install_checks_passed": true,+ "worker_exit_codes": [+ 0,+ 0+ ],+ "request_counts": {+ "main": 4,+ "warm": 2+ }+ },+ {+ "scenario": "auto_warm_failures",+ "status": "passed",+ "checks": 38,+ "failed_checks": [],+ "install_checks_passed": true,+ "worker_exit_codes": [+ 0,+ 0+ ],+ "request_counts": {+ "main": 8,+ "warm": 4,+ "fallback": 3+ },+ "outcomes": [+ [+ "fallback",+ "provider_error"+ ],+ [+ "fallback",+ "provider_error"+ ],+ [+ "fallback",+ "provider_error"+ ],+ [+ "warm",+ "accepted"+ ]+ ]+ },+ {+ "scenario": "rollback",+ "status": "passed",+ "checks": 16,+ "failed_checks": [],+ "install_checks_passed": true,+ "worker_exit_codes": [+ 0,+ 0,+ 0+ ],+ "request_counts": {+ "main": 2,+ "warm": 1+ },+ "rollback_status": "passed",+ "rollback_failed_checks": []+ }+ ],+ "fixed_whitespace_checks": {+ "listed_in_engine_picker": true,+ "engine_selected": true,+ "turn1_reply": true,+ "turn1_stored_question_exact": true,+ "turn1_sent_question_stripped": true,+ "turn1_path_warm": true,+ "turn1_one_warm_request": true,+ "turn1_prefix_exact": true,+ "turn1_new_rows": true,+ "turn1_instruction_last": true,+ "turn1_not_streamed": true,+ "turn1_settings_kept": true,+ "turn1_reply_limit": true,+ "turn1_removed_rows": true,+ "turn1_summary_rows": true,+ "turn1_handoff_in_summary": true,+ "turn1_tail_question_exact": true,+ "turn1_history_saved": true,+ "turn1_saved_question_matches_host": true,+ "turn1_engine_session_follows": true,+ "turn2_reply": true,+ "turn2_stored_question_exact": true,+ "turn2_sent_question_stripped": true,+ "turn2_path_warm": true,+ "turn2_one_warm_request": true,+ "turn2_prefix_exact": true,+ "turn2_new_rows": true,+ "turn2_instruction_last": true,+ "turn2_not_streamed": true,+ "turn2_settings_kept": true,+ "turn2_reply_limit": true,+ "turn2_removed_rows": true,+ "turn2_summary_rows": true,+ "turn2_handoff_in_summary": true,+ "turn2_tail_question_exact": true,+ "turn2_history_saved": true,+ "turn2_saved_question_matches_host": true,+ "turn2_engine_session_follows": true,+ "turn3_reply": true,+ "turn3_stored_question_exact": true,+ "turn3_sent_question_stripped": true,+ "turn3_path_warm": true,+ "turn3_one_warm_request": true,+ "turn3_prefix_exact": true,+ "turn3_new_rows": true,+ "turn3_instruction_last": true,+ "turn3_not_streamed": true,+ "turn3_settings_kept": true,+ "turn3_reply_limit": true,+ "turn3_removed_rows": true,+ "turn3_summary_rows": true,+ "turn3_handoff_in_summary": true,+ "turn3_tail_question_exact": true,+ "turn3_history_saved": true,+ "turn3_saved_question_matches_host": true,+ "turn3_engine_session_follows": true,+ "three_compactions": true,+ "three_main_requests": true,+ "no_fallback_request": true,+ "plugin_made_no_blocked_call": true+ },+ "retry": {+ "scenario": "enable_manual_warm",+ "initial_status": "failed",+ "initial_error": "Windows DLL path length limit in the temporary Hermes dependency runtime.",+ "initial_worker_exit_codes": [+ 0,+ 1+ ],+ "action": "Run only this scenario again with a shorter temporary work path.",+ "result": "passed"+ },+ "unit_checks": {+ "focused_command": "python -m unittest discover -s tests -p test_wc_warm.py",+ "before_fix": {+ "status": "failed_expected",+ "tests": 61,+ "error_cases": 24,+ "error_code": "source_transform_unsupported"+ },+ "after_fix": {+ "status": "passed",+ "tests": 61+ },+ "full_command": "python -m unittest discover -s tests -p \"test_wc_*.py\"",+ "full_results": [+ {+ "python": "3.14.5",+ "status": "passed",+ "tests": 291+ },+ {+ "python": "3.13.1",+ "status": "passed",+ "tests": 291+ }+ ]+ },+ "lint": {+ "version": "0.16.10",+ "command": "ruff check .",+ "status": "passed"+ },+ "limits": [+ "Loopback fake server only; no real model or live provider route.",+ "Live cache reuse, summary quality, and speed were not measured.",+ "Leading and inner whitespace changes and content-list rewrites remain refused."- ]++ ],++ "main_merge_validation": {++ "main_commit": "0457d6cd478467065beae6867ec040678b28aea8",++ "hermes": {++ "commit": "e36a818033f5246e5fcfe9a6967bb85e885ba155",++ "clean": true++ },++ "python": "3.11.14",++ "plugin_files_sha256": {++ "warm_compaction/__init__.py": "760484ace80b9da77d7397828f69178905c9ac95df7b8114956bde727bd98aef",++ "warm_compaction/capture.py": "a9f907ada5d83eba79628454630d9295664b8215a2f2409cfc26223bcb2ad40f",++ "warm_compaction/engine.py": "2e655513faef234ae773c8b5cfd193cb972addca2ed830e8ac70c9bb5cba250d",++ "warm_compaction/fallback.py": "9b2d0529767ff157bbe0d1cbf096ca6ac35217118f81eee769adf41d50189a9a",++ "warm_compaction/handoff.py": "fcab51def8fbcc2b1928957930c9a5c58a4ad202c949fd9f870a77f3b30276ae",++ "warm_compaction/layout.py": "b49314c5236268247c337d9fae939135c97b47384300dcdfd00b0da0c040db93",++ "warm_compaction/native.py": "2bac322bf7779e7d4ec78137a1ba1fdff25d3e58910ace51200147aebf15f494",++ "warm_compaction/plugin.yaml": "baa7820b3ce9a40d2a53f70a4d0525131860ea2ec670143d0a7742b59c4d937b",++ "warm_compaction/rows.py": "f2ca69a7361affc4fd84388ab9ac718a0e9affa609c87d75efd6e0c25fa860cf",++ "warm_compaction/warm.py": "db4826e3ba7762c386f523354fe02833bdb4947c03ac80b67e058f9a67333640"++ },++ "script_sha256": "47dd18b7a403c298eebbc1fbc5e6f0d41b926ac22b541da275f155c77d4485ec",++ "integration_passed": true,++ "scenarios": [++ {++ "scenario": "enable_manual_warm",++ "status": "passed",++ "checks": 32,++ "failed_checks": [],++ "install_checks_passed": true,++ "worker_exit_codes": [++ 0,++ 0++ ],++ "request_counts": {++ "main": 2,++ "warm": 1++ },++ "rollback_status": null++ },++ {++ "scenario": "manual_whitespace",++ "status": "passed",++ "checks": 67,++ "failed_checks": [],++ "install_checks_passed": true,++ "worker_exit_codes": [++ 0,++ 0++ ],++ "request_counts": {++ "main": 3,++ "warm": 3++ },++ "rollback_status": null++ },++ {++ "scenario": "manual_fallback",++ "status": "passed",++ "checks": 26,++ "failed_checks": [],++ "install_checks_passed": true,++ "worker_exit_codes": [++ 0,++ 0++ ],++ "request_counts": {++ "main": 2,++ "warm": 1,++ "fallback": 1++ },++ "rollback_status": null++ },++ {++ "scenario": "manual_fixed",++ "status": "passed",++ "checks": 25,++ "failed_checks": [],++ "install_checks_passed": true,++ "worker_exit_codes": [++ 0,++ 0++ ],++ "request_counts": {++ "main": 2,++ "warm": 1,++ "fallback": 1++ },++ "rollback_status": null++ },++ {++ "scenario": "auto_tool_loop",++ "status": "passed",++ "checks": 37,++ "failed_checks": [],++ "install_checks_passed": true,++ "worker_exit_codes": [++ 0,++ 0++ ],++ "request_counts": {++ "main": 4,++ "warm": 2++ },++ "rollback_status": null++ },++ {++ "scenario": "auto_warm_failures",++ "status": "passed",++ "checks": 45,++ "failed_checks": [],++ "install_checks_passed": true,++ "worker_exit_codes": [++ 0,++ 0++ ],++ "request_counts": {++ "main": 8,++ "warm": 4,++ "fallback": 3++ },++ "rollback_status": null++ },++ {++ "scenario": "rollback",++ "status": "passed",++ "checks": 24,++ "failed_checks": [],++ "install_checks_passed": true,++ "worker_exit_codes": [++ 0,++ 0,++ 0++ ],++ "request_counts": {++ "main": 2,++ "warm": 1++ },++ "rollback_status": "passed"++ }++ ],++ "whitespace_checks": {++ "listed_in_engine_picker": true,++ "engine_selected": true,++ "native_notice_not_logged_before_compaction": true,++ "turn1_reply": true,++ "turn1_stored_question_exact": true,++ "turn1_sent_question_stripped": true,++ "turn1_path_warm": true,++ "turn1_one_warm_request": true,++ "turn1_prefix_exact": true,++ "turn1_new_rows": true,++ "turn1_instruction_last": true,++ "turn1_not_streamed": true,++ "turn1_settings_kept": true,++ "turn1_reply_limit": true,++ "turn1_removed_rows": true,++ "turn1_summary_rows": true,++ "turn1_handoff_in_summary": true,++ "turn1_tail_question_exact": true,++ "turn1_history_saved": true,++ "turn1_saved_question_matches_host": true,++ "turn1_engine_session_follows": true,++ "turn2_reply": true,++ "turn2_stored_question_exact": true,++ "turn2_sent_question_stripped": true,++ "turn2_path_warm": true,++ "turn2_one_warm_request": true,++ "turn2_prefix_exact": true,++ "turn2_new_rows": true,++ "turn2_instruction_last": true,++ "turn2_not_streamed": true,++ "turn2_settings_kept": true,++ "turn2_reply_limit": true,++ "turn2_removed_rows": true,++ "turn2_summary_rows": true,++ "turn2_handoff_in_summary": true,++ "turn2_tail_question_exact": true,++ "turn2_history_saved": true,++ "turn2_saved_question_matches_host": true,++ "turn2_engine_session_follows": true,++ "turn3_reply": true,++ "turn3_stored_question_exact": true,++ "turn3_sent_question_stripped": true,++ "turn3_path_warm": true,++ "turn3_one_warm_request": true,++ "turn3_prefix_exact": true,++ "turn3_new_rows": true,++ "turn3_instruction_last": true,++ "turn3_not_streamed": true,++ "turn3_settings_kept": true,++ "turn3_reply_limit": true,++ "turn3_removed_rows": true,++ "turn3_summary_rows": true,++ "turn3_handoff_in_summary": true,++ "turn3_tail_question_exact": true,++ "turn3_history_saved": true,++ "turn3_saved_question_matches_host": true,++ "turn3_engine_session_follows": true,++ "three_compactions": true,++ "three_main_requests": true,++ "no_fallback_request": true,++ "native_notice_status_count": true,++ "native_notice_log_count": true,++ "native_notice_engine_unchanged": true,++ "native_notice_config_unchanged": true,++ "native_notice_not_in_requests": true,++ "native_notice_not_in_saved_history": true,++ "plugin_made_no_blocked_call": true++ },++ "compatibility": {++ "passed": true,++ "script_sha256": "641b1acb9a311ebad570c4a06800ff866030471db3b4d745148244b2e8ca75c0",++ "checks": {++ "hermes_source_unchanged": true,++ "plugin_source_unchanged": true,++ "script_unchanged": true++ },++ "cases": [++ {++ "case": "capture_last",++ "passed": true,++ "checks": {++ "capture_body_exact": true,++ "capture_headers_exact": true,++ "import_origins_match_source": true,++ "refusal_expected": true,++ "reported_prompt_tokens": true,++ "request_header_forwarded": true,++ "request_middleware_applied": true,++ "response_unchanged": true,++ "terminal_once": true,++ "terminal_payload_exact": true++ }++ },++ {++ "case": "earlier_rewrite",++ "passed": true,++ "checks": {++ "capture_body_exact": true,++ "capture_headers_exact": true,++ "execution_rewrite_reaches_terminal": true,++ "import_origins_match_source": true,++ "refusal_expected": true,++ "reported_prompt_tokens": true,++ "request_header_forwarded": true,++ "request_middleware_applied": true,++ "response_unchanged": true,++ "terminal_once": true,++ "terminal_payload_exact": true++ }++ },++ {++ "case": "later_rewrite",++ "passed": true,++ "checks": {++ "capture_body_refused": true,++ "capture_headers_refused": true,++ "execution_rewrite_reaches_terminal": true,++ "import_origins_match_source": true,++ "refusal_expected": true,++ "reported_prompt_tokens": true,++ "request_header_forwarded": true,++ "request_middleware_applied": true,++ "response_unchanged": true,++ "terminal_once": true,++ "terminal_payload_exact": true++ }++ },++ {++ "case": "unknown_order",++ "passed": true,++ "checks": {++ "capture_body_refused": true,++ "capture_headers_refused": true,++ "import_origins_match_source": true,++ "refusal_expected": true,++ "reported_prompt_tokens": true,++ "request_header_forwarded": true,++ "request_middleware_applied": true,++ "response_unchanged": true,++ "terminal_once": true,++ "terminal_payload_exact": true++ }++ }++ ]++ },++ "unit_results": [++ {++ "python": "3.14.5",++ "tests": 305,++ "status": "passed"++ },++ {++ "python": "3.13.1",++ "tests": 305,++ "status": "passed"++ }++ ],++ "ruff": {++ "version": "0.16.10",++ "status": "passed"++ }++ }+}diff --cc scripts/check_plugin_hermes.pyindex ef6b93a,0867b71..eef9cf4--- a/scripts/check_plugin_hermes.py+++ b/scripts/check_plugin_hermes.py@@@ -534,14 -534,12 +538,15 @@@ def run_phase(spec, session_dir)checks["engine_selected"] = getattr(engine, "name", None) == "warm_compaction"result["engine"] = {"name": getattr(engine, "name", None), "threshold_tokens": engine.threshold_tokens,"context_length": engine.context_length}+ checks["native_notice_not_logged_before_compaction"] = NATIVE_NOTICE_MARK not in read_agent_log(home)history = db.get_messages_as_conversation(sid)if scenario == "auto_tool_loop":- run_auto(agent, engine, history, server, result, checks)+ run_auto(agent, engine, history, server, result, checks, statuses)elif scenario == "auto_warm_failures":run_auto_failures(agent, engine, history, server, result, checks, statuses, home)+ elif scenario == "manual_whitespace":+ run_manual_whitespace(agent, engine, db, history, server, result, checks,+ _compress_session_history, finalize_context_engine_compression_notification)else:run_manual(agent, engine, db, history, server, result, checks, scenario,_compress_session_history, finalize_context_engine_compression_notification)@@@ -773,58 -812,12 +819,61 @@@ def run_manual(agent, engine, db, histolater[0]["body"]["messages"][0].get("content") or "")+def run_manual_whitespace(agent, engine, db, history, server, result, checks, compress, finalize):+ """Repeat manual compaction when Hermes strips a string only in the sent request."""+ messages, outcomes = history, []+ for index, question in enumerate((SEED_QUESTION, *WHITESPACE_QUESTIONS), 1):+ if index > 1:+ # Add enough synthetic rows for another compaction. Only the new question has outer white space.+ extra = synthetic_history(20)+ for row in extra:+ row["content"] = row["content"].strip()+ messages = list(messages) + extra+ reply = agent.run_conversation(question, system_message=SYSTEM, conversation_history=messages)+ messages = list(reply.get("messages") or [])+ label = f"turn{index}"+ checks[f"{label}_reply"] = bool(str(reply.get("final_response") or "").strip())+ checks[f"{label}_stored_question_exact"] = len(messages) >= 2 and messages[-2].get("content") == question+ main = by_kind(server, "main")[-1]+ checks[f"{label}_sent_question_stripped"] = main["body"]["messages"][-1].get("content") == question.strip()+ session = {"agent": agent, "history": messages, "history_lock": threading.Lock(),+ "history_version": index, "session_key": agent.session_id}+ warm_before = len(by_kind(server, "warm"))+ removed, _usage = compress(session, "")+ finalize(agent, committed=True)+ last = dict(engine.warm_last or {})+ outcomes.append([last.get("path"), last.get("reason")])+ result[f"warm_last_{index}"] = last+ checks[f"{label}_path_warm"] = (last.get("path"), last.get("reason")) == ("warm", "accepted")+ checks[f"{label}_one_warm_request"] = len(by_kind(server, "warm")) == warm_before + 1+ if checks[f"{label}_one_warm_request"]:+ check_warm_request(server, checks, label)+ checks[f"{label}_removed_rows"] = removed > 0+ messages = session["history"]+ checks[f"{label}_summary_rows"] = summary_rows_ok(messages)+ checks[f"{label}_handoff_in_summary"] = len(messages) >= 2 and HANDOFF in str(messages[1].get("content"))+ checks[f"{label}_tail_question_exact"] = any(+ row.get("role") == "user" and row.get("content") == question for row in messages[2:])+ saved = db.get_messages_as_conversation(agent.session_id)+ # Hermes strips outer white space when it reloads user and assistant strings from the database.+ checks[f"{label}_history_saved"] = [row.get("content") for row in saved] == [+ str(row.get("content") or "").strip() for row in messages]+ checks[f"{label}_saved_question_matches_host"] = any(+ row.get("role") == "user" and row.get("content") == question.strip() for row in saved[2:])+ checks[f"{label}_engine_session_follows"] = engine._wc_session_id == agent.session_id+ result["outcomes"] = outcomes+ result["compression_count"] = engine.compression_count+ checks["three_compactions"] = engine.compression_count == 3+ checks["three_main_requests"] = len(by_kind(server, "main")) == 3+ checks["no_fallback_request"] = not by_kind(server, "fallback")++- def run_auto(agent, engine, history, server, result, checks):+ def run_auto(agent, engine, history, server, result, checks, statuses):checks["threshold_from_settings"] = engine.threshold_tokens == int(CONTEXT_LENGTH * 0.4)first = agent.run_conversation(TOOL_QUESTION, system_message=SYSTEM, conversation_history=history)+ first_notice_count = sum(NATIVE_NOTICE_MARK in message for _kind, message in statuses)+ checks["native_notice_on_first_automatic_compaction"] = (+ first_notice_count == int(result["native_warm_handoff"]["available"]))checks["first_turn_final"] = first.get("final_response") == "Done."checks["first_warm_request"] = len(by_kind(server, "warm")) == 1result["warm_last_1"] = dict(engine.warm_last or {})