hermes-agent/tests
Teknium 12afccd9ca
fix(tools): chunk long messages in send_message_tool before dispatch (#1552)
* fix: prevent infinite 400 failure loop on context overflow (#1630)

When a gateway session exceeds the model's context window, Anthropic may
return a generic 400 invalid_request_error with just 'Error' as the
message.  This bypassed the phrase-based context-length detection,
causing the agent to treat it as a non-retryable client error.  Worse,
the failed user message was still persisted to the transcript, making
the session even larger on each attempt — creating an infinite loop.

Three-layer fix:

1. run_agent.py — Fallback heuristic: when a 400 error has a very short
   generic message AND the session is large (>40% of context or >80
   messages), treat it as a probable context overflow and trigger
   compression instead of aborting.

2. run_agent.py + gateway/run.py — Don't persist failed messages:
   when the agent returns failed=True before generating any response,
   skip writing the user's message to the transcript/DB. This prevents
   the session from growing on each failure.

3. gateway/run.py — Smarter error messages: detect context-overflow
   failures and suggest /compact or /reset specifically, instead of a
   generic 'try again' that will fail identically.

* fix(skills): detect prompt injection patterns and block cache file reads

Adds two security layers to prevent prompt injection via skills hub
cache files (#1558):

1. read_file: blocks direct reads of ~/.hermes/skills/.hub/ directory
   (index-cache, catalog files). The 3.5MB clawhub_catalog_v1.json
   was the original injection vector — untrusted skill descriptions
   in the catalog contained adversarial text that the model executed.

2. skill_view: warns when skills are loaded from outside the trusted
   ~/.hermes/skills/ directory, and detects common injection patterns
   in skill content ("ignore previous instructions", "<system>", etc.).

Cherry-picked from PR #1562 by ygd58.

* fix(tools): chunk long messages in send_message_tool before dispatch (#1552)

Long messages sent via send_message tool or cron delivery silently
failed when exceeding platform limits. Gateway adapters handle this
via truncate_message(), but the standalone senders in send_message_tool
bypassed that entirely.

- Apply truncate_message() chunking in _send_to_platform() before
  dispatching to individual platform senders
- Remove naive message[i:i+2000] character split in _send_discord()
  in favor of centralized smart splitting
- Attach media files to last chunk only for Telegram
- Add regression tests for chunking and media placement

Cherry-picked from PR #1557 by llbn.

---------

Co-authored-by: buray <ygd58@users.noreply.github.com>
Co-authored-by: lbn <llbn@users.noreply.github.com>
2026-03-17 01:52:43 -07:00
..
acp feat(acp): support slash commands in ACP adapter (#1532) 2026-03-16 05:19:36 -07:00
agent fix: hermes update causes dual gateways on macOS (launchd) (#1567) 2026-03-16 12:36:29 -07:00
cron fix: skip stale cron jobs on gateway restart instead of firing immediately 2026-03-16 23:48:14 -07:00
fakes fix: streaming tool call parsing, error handling, and fake HA state mutation 2026-03-14 14:27:20 +03:00
gateway feat: auto-detect local file paths in gateway responses for native media delivery (#1640) 2026-03-17 01:47:34 -07:00
hermes_cli feat(cli): two-stage /model autocomplete with ghost text suggestions (#1641) 2026-03-17 01:47:32 -07:00
honcho_integration refactor(honcho): remove local memory mode 2026-03-12 16:23:34 -04:00
integration test(voice): add integration tests with real NaCl crypto and Opus codec 2026-03-15 05:20:17 -07:00
skills fix: persist google oauth pkce for headless auth 2026-03-14 22:11:34 -07:00
tools fix(tools): chunk long messages in send_message_tool before dispatch (#1552) 2026-03-17 01:52:43 -07:00
__init__.py
conftest.py feat: first-class plugin architecture (#1555) 2026-03-16 07:17:36 -07:00
run_interrupt_test.py fix(honcho): isolate session routing for multi-user gateway (#1500) 2026-03-16 00:23:47 -07:00
test_413_compression.py feat: improve context compaction handoff summaries (#1273) 2026-03-14 02:33:31 -07:00
test_860_dedup.py
test_1630_context_overflow_loop.py fix: prevent infinite 400 loop on context overflow + block prompt injection via cache files (#1630, #1558) 2026-03-17 01:50:59 -07:00
test_agent_loop_tool_calling.py
test_agent_loop_vllm.py test: restore vllm integration coverage and add dict-args regression 2026-03-15 08:02:29 -07:00
test_agent_loop.py fix: salvage gateway dedup and executor cleanup from PR #993 2026-03-14 11:03:20 -07:00
test_anthropic_adapter.py fix: isolate test_anthropic_adapter from local credentials 2026-03-16 22:53:32 -07:00
test_anthropic_error_handling.py fix(anthropic): retry 429/529 errors and surface error details to users 2026-03-17 01:07:11 +03:00
test_anthropic_oauth_flow.py fix: preflight Anthropic auth and prefer Claude store 2026-03-14 19:38:55 -07:00
test_anthropic_provider_persistence.py fix: preflight Anthropic auth and prefer Claude store 2026-03-14 19:38:55 -07:00
test_api_key_providers.py feat: add Vercel AI Gateway provider (#1628) 2026-03-17 00:12:16 -07:00
test_atomic_json_write.py test: cover atomic temp cleanup on interrupts 2026-03-14 22:31:51 -07:00
test_atomic_yaml_write.py test: cover atomic temp cleanup on interrupts 2026-03-14 22:31:51 -07:00
test_auth_codex_provider.py
test_auth_nous_provider.py
test_auxiliary_config_bridge.py feat: add direct endpoint overrides for auxiliary and delegation 2026-03-14 21:11:37 -07:00
test_batch_runner_checkpoint.py fix: sanitize chat payloads and provider precedence 2026-03-13 23:59:12 -07:00
test_cli_approval_ui.py fix(cli): repair dangerous command approval UI 2026-03-14 11:57:44 -07:00
test_cli_init.py fix: initialize CLI voice state for single-query mode 2026-03-14 06:31:32 -07:00
test_cli_interrupt_subagent.py
test_cli_loading_indicator.py
test_cli_mcp_config_watch.py fix: auto-reload MCP tools when mcp_servers config changes without restart (#1474) 2026-03-15 19:03:34 -07:00
test_cli_model_command.py feat: auto-detect provider when switching models via /model (#1506) 2026-03-16 04:34:45 -07:00
test_cli_new_session.py fix(cli): make /new, /reset, and /clear start real fresh sessions 2026-03-13 21:53:54 -07:00
test_cli_plan_command.py fix: save /plan output in workspace (#1381) 2026-03-14 21:28:51 -07:00
test_cli_prefix_matching.py feat(cli): two-stage /model autocomplete with ghost text suggestions (#1641) 2026-03-17 01:47:32 -07:00
test_cli_preloaded_skills.py feat: preload CLI skills on launch (#1359) 2026-03-14 19:33:59 -07:00
test_cli_provider_resolution.py fix: hermes update causes dual gateways on macOS (launchd) (#1567) 2026-03-16 12:36:29 -07:00
test_cli_retry.py test: lock retry replacement semantics 2026-03-14 21:19:22 -07:00
test_cli_secret_capture.py feat: secure skill env setup on load (core #688) 2026-03-13 03:14:04 -07:00
test_cli_skin_integration.py fix(test): add missing voice state attrs to CLI stub in skin tests 2026-03-14 15:00:45 +03:00
test_cli_status_bar.py feat: first-class plugin architecture + hide status bar cost by default (#1544) 2026-03-16 06:43:57 -07:00
test_codex_execution_paths.py
test_codex_models.py fix: add codex forward-compat model listing 2026-03-13 21:34:01 -07:00
test_context_token_tracking.py fix: context counter shows cached token count in status bar 2026-03-17 05:06:11 +03:00
test_dict_tool_call_args.py test: restore vllm integration coverage and add dict-args regression 2026-03-15 08:02:29 -07:00
test_display.py
test_evidence_store.py feat: add OSS Security Forensics skill (Skills Hub) (#1482) 2026-03-15 21:59:53 -07:00
test_external_credential_detection.py
test_fallback_model.py
test_file_permissions.py
test_flush_memories_codex.py
test_hermes_state.py fix(cli): accept session ID prefixes for session actions 2026-03-15 04:01:56 -07:00
test_honcho_client_config.py
test_insights.py feat: add persistent CLI status bar and usage details (#1522) 2026-03-16 04:42:48 -07:00
test_interactive_interrupt.py fix(honcho): isolate session routing for multi-user gateway (#1500) 2026-03-16 00:23:47 -07:00
test_interrupt_propagation.py
test_managed_server_tool_support.py test: fix stale CI assumptions in parser and quick-command coverage (#1236) 2026-03-13 21:56:12 -07:00
test_minisweagent_path.py fix: worktree-aware minisweagent path discovery + clean up requirements check (#1248) 2026-03-13 23:39:51 -07:00
test_model_provider_persistence.py
test_model_tools.py
test_openai_client_lifecycle.py fix: audit fixes — 5 bugs found and resolved 2026-03-16 06:35:46 -07:00
test_personality_none.py
test_plugins.py feat: first-class plugin architecture (#1555) 2026-03-16 07:17:36 -07:00
test_provider_parity.py feat: add Vercel AI Gateway provider (#1628) 2026-03-17 00:12:16 -07:00
test_quick_commands.py feat(cli): two-stage /model autocomplete with ghost text suggestions (#1641) 2026-03-17 01:47:32 -07:00
test_real_interrupt_subagent.py
test_reasoning_command.py
test_redirect_stdout_issue.py
test_resume_display.py
test_run_agent_codex_responses.py
test_run_agent.py fix: audit fixes — 5 bugs found and resolved 2026-03-16 06:35:46 -07:00
test_runtime_provider_resolution.py feat: add Vercel AI Gateway provider (#1628) 2026-03-17 00:12:16 -07:00
test_setup_model_selection.py fix(setup): remove dead code causing is_coding_plan NameError crash 2026-03-13 04:42:26 +03:00
test_streaming.py fix: always fall back to non-streaming on ANY streaming error 2026-03-16 06:15:09 -07:00
test_timezone.py fix: skip stale cron jobs on gateway restart instead of firing immediately 2026-03-16 23:48:14 -07:00
test_tool_call_parsers.py fix: use non-greedy regex in DeepSeek V3 parser for multi-tool calls (#1300) 2026-03-14 06:19:28 -07:00
test_toolset_distributions.py
test_toolsets.py
test_trajectory_compressor.py fix: harden trajectory compressor summary content handling 2026-03-14 11:03:25 -07:00
test_worktree_security.py fix: harden salvaged worktree include checks 2026-03-14 21:51:27 -07:00
test_worktree.py fix: harden salvaged worktree include checks 2026-03-14 21:51:27 -07:00