hermes-agent/agent
Gr1mmJ4w e60ca1c6ca fix(agent): stop the send-path repair from rewriting persisted history
`_canonicalize_api_tool_calls` promises copy-on-write in its own docstring
— "the persisted history is untouched" — and the call site repeats it:
"Operates on api_messages (the API copy) so the original conversation
history in `messages` is untouched."

The canonicalize branch keeps that promise (`tc = {**tc, "function": {...}}`).
The repair branch does not:

    except Exception:
        tc["function"]["arguments"] = _repair_tool_call_arguments(...)

`api_messages` is built with `msg.copy()` — a SHALLOW per-message copy — so
every `tool_calls` entry is the same dict object the persisted history
holds. Assigning into `tc["function"]` therefore writes through to the
stored turn. The sibling loop two lines above only touches `am["content"]`,
one level deep, which is why the aliasing never showed up there.

On the unrepairable path `_repair_tool_call_arguments` returns "{}", so
that write replaces the model's real arguments with an empty object in the
transcript. A stream that dies mid `write_file` loses the file content it
had already streamed — the reported symptom in #80498, where a chapter
draft was silently reduced to `{}` and only a WARNING remained:

    Unrepairable tool_call arguments for write_file — replaced with empty
    object (was: {"content": "# 骨架-第25章\n> 承接...)

Mirror the canonicalize branch: build a new tool-call dict instead of
assigning into the shared one. The API copy still carries "{}" — the
repair's whole purpose is to never ship broken JSON — but the history keeps
what the model actually sent, so the transcript, session persistence and
any later retry still have it.

The in-place write was not an oversight in isolation: it predates the memo
refactor, which preserved it deliberately for byte-parity. The existing
`test_history_not_mutated` asserts exactly this invariant but restricts
itself to valid arguments, and its docstring records the gap — "(Malformed
args take the in-place repair path — pre-existing behavior)". That is why
a test file whose header already claims "the persisted history is never
mutated (copy-on-write preserved)" stayed green through the bug.

Four tests close it: history keeps the original bytes, the send copy is
still repaired, a broken call does not disturb its siblings, and repeated
sends stay lossless. On unpatched main three of them fail; the parity and
complexity tests are unaffected because the difference is only observable
when the history list is separate from the send copy — which is the shape
production uses.

Refs #80498

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-07 16:57:11 +05:30
..
lsp fix(runtime): resolve Hermes-managed Node and uv before bare PATH 2026-08-01 21:17:51 -04:00
monitoring
…
pet
…
proxy_sources
…
secret_sources fix(gateway): hydrate cold profile secret sources 2026-08-02 00:11:50 -07:00
transports feat(providers): env-var metadata, config-driven local no-auth, reasoning-effort clamp for Actual 2026-08-05 14:08:32 -07:00
__init__.py
…
account_usage.py
…
agent_init.py Hermes can read the in-app browser (#79482) 2026-08-05 16:35:00 +00:00
agent_runtime_helpers.py Hermes can read the in-app browser (#79482) 2026-08-05 16:35:00 +00:00
anthropic_adapter.py fix: prefer explicit anthropic api key 2026-08-04 00:12:45 +05:30
async_utils.py
…
aux_accounting.py
…
auxiliary_client.py fix(auxiliary): widen effective provider to relay, logging, and endpoint detection 2026-08-07 16:56:37 +05:30
azure_identity_adapter.py fix(secrets): scope-aware Azure credential presence reads in identity diagnostics 2026-08-02 10:02:33 -07:00
backend_identity.py
…
background_review.py feat: /refine — run the memory/skill self-improvement review on demand 2026-08-05 22:40:51 -07:00
battery.py
…
bedrock_adapter.py
…
billing_links.py
…
billing_usage.py
…
billing_view.py
…
bounded_response.py
…
browser_provider.py fix(browser): replace expired cloud sessions 2026-08-02 11:18:41 +05:30
browser_registry.py
…
chat_completion_helpers.py fix(cron): move watchdog state under the request lock; fail closed on resolver errors 2026-08-07 15:32:37 +05:30
codex_responses_adapter.py fix(codex): defang reserved Harmony tokens in requests 2026-07-31 22:53:20 -07:00
codex_runtime.py fix(codex): split reasoning summary parts on summary_index 2026-08-06 22:02:46 -05:00
coding_context.py
…
context_breakdown.py
…
context_compressor.py docs: comment accuracy — pending-ness is a presumption, not a construction guarantee 2026-08-07 14:13:32 +05:30
context_engine.py
…
context_references.py
…
conversation_compression.py fix: bind continuation-marker exclusions to the queried parent (fail-open fix) 2026-08-07 13:24:56 +05:30
conversation_loop.py fix(agent): stop the send-path repair from rewriting persisted history 2026-08-07 16:57:11 +05:30
copilot_acp_client.py
…
credential_persistence.py
…
credential_pool.py fix(credential-pool): bench a billing 403 fully, even as the sole key 2026-08-04 23:33:39 +05:30
credential_sources.py
…
credits_tracker.py
…
curator.py perf(curator): trim dead tool-schema from the LLM review fork 2026-08-03 18:21:17 +05:30
curator_backup.py
…
delegation_context.py fix(cron): don't let a cron job inherit a kanban worker's dispatcher identity 2026-08-06 03:16:26 +05:30
display.py refactor(discord): simplify tool preview links 2026-08-02 21:48:06 -07:00
error_classifier.py fix(models): a model id missing its vendor prefix says so instead of 404ing (#78856) 2026-08-04 19:35:57 +00:00
errors.py
…
file_safety.py
…
gemini_native_adapter.py fix(gemini): interpose placeholder model turn between tool result and user text 2026-08-05 17:21:01 -07:00
gemini_schema.py
…
i18n.py
…
image_gen_provider.py
…
image_gen_registry.py
…
image_routing.py
…
insights.py refactor(insights): drop consumer-less get_skill_breakdown alias (simplify-pass) 2026-08-03 18:45:43 +05:30
interrupt_compat.py fix(compression): let explicit interrupts cancel safely 2026-08-02 22:15:20 +05:30
iteration_budget.py
…
jiter_preload.py
…
kanban_stop.py
…
learn_prompt.py feat(/learn): expansive knowledge-base skills for books and large corpora 2026-08-06 22:14:52 -07:00
learning_graph.py
…
learning_graph_render.py
…
learning_mutations.py
…
lmstudio_reasoning.py
…
manual_compression_feedback.py
…
markdown_tables.py
…
memory_manager.py
…
memory_provider.py fix(openviking): integrate reliability and configuration hardening 2026-08-03 20:35:47 +05:30
message_content.py
…
message_sanitization.py
…
moa_loop.py perf(moa): cache resolved preset + per-slot runtime to cut cold-start latency (#66793) 2026-08-03 22:43:15 +05:30
moa_trace.py
…
model_metadata.py fix(model_metadata): read llama.cpp context from meta.n_ctx + accept sole model 2026-08-04 11:08:32 +05:30
models_dev.py
…
moonshot_schema.py
…
nous_rate_guard.py
…
onboarding.py
…
oneshot.py
…
outbound_webhooks.py fix(hooks): flush outbound queue at interpreter exit 2026-08-02 15:01:11 -07:00
plugin_llm.py
…
portal_tags.py
…
process_bootstrap.py
…
prompt_builder.py fix(agent): prevent historical steer replay 2026-08-05 13:00:47 +05:30
prompt_caching.py perf(prompt-caching): make PromptCachePlan.marker_count lazy 2026-08-01 15:39:58 +05:30
rate_limit_tracker.py
…
reactions.py
…
reasoning_summaries.py fix(reasoning): keep gpt-5.x summary parts as separate blocks on the chat wire 2026-08-06 22:02:37 -05:00
reasoning_timeouts.py
…
redact.py perf(redact): eliminate exponential backtracking in config-key patterns 2026-08-01 15:58:25 +05:30
relay_llm.py Merge upstream main into model metrics 2026-08-02 20:10:47 -07:00
relay_runtime.py fix(relay): preserve skipped turn context 2026-08-03 13:43:17 -06:00
relay_tools.py
…
replay_cleanup.py
…
retry_utils.py
…
runtime_cwd.py
…
secret_scope.py fix(secrets): allowlist API_SERVER listener settings as global deployment env 2026-08-02 09:59:52 -07:00
session_activity.py refactor(agent): pin session activity heartbeat cadence + harden best-effort write 2026-08-02 16:16:36 -07:00
shell_hooks.py feat(hooks): outbound webhooks — push signed lifecycle events to external HTTP endpoints 2026-08-02 15:01:11 -07:00
skill_bundles.py
…
skill_commands.py
…
skill_preprocessing.py
…
skill_utils.py fix(cron): don't let a cron job inherit a kanban worker's dispatcher identity 2026-08-06 03:16:26 +05:30
ssl_guard.py
…
ssl_verify.py
…
stream_diag.py
…
stream_single_writer.py
…
subagent_lifecycle.py fix(compression): let explicit interrupts cancel safely 2026-08-02 22:15:20 +05:30
subdirectory_hints.py fix(context): dedupe subdirectory hints by content digest and skip backup/vendor dirs 2026-08-03 20:43:34 +05:30
subscription_view.py
…
system_prompt.py docs(system_prompt): fix stale reconstruct_static_prefix docstring example 2026-08-03 23:23:39 +05:30
think_scrubber.py
…
thinking_timeout_guidance.py
…
thread_scoped_output.py fix: preserve session history when a turn crashes 2026-08-06 23:08:23 -05:00
title_generator.py
…
tool_dispatch_helpers.py feat(image): parallelize image_generate batches 2026-08-03 22:53:32 +05:30
tool_executor.py refactor: fold /simplify-code findings 2026-08-06 17:03:10 +05:30
tool_guardrails.py
…
tool_result_classification.py
…
trace_upload.py
…
trajectory.py
…
transcription_provider.py
…
transcription_registry.py
…
tts_provider.py
…
tts_registry.py
…
turn_context.py fix(gateway): escalate the session-hygiene compaction cooldown on repeat failures 2026-08-06 05:00:48 +05:30
turn_finalizer.py fix: preserve session history when a turn crashes 2026-08-06 23:08:23 -05:00
turn_retry_state.py
…
turn_summary.py
…
usage_pricing.py
…
verification_evidence.py
…
verification_stop.py
…
verify_hooks.py
…
vertex_adapter.py
…
video_gen_provider.py
…
video_gen_registry.py
…
web_search_provider.py
…
web_search_registry.py
…