hermes-agent/tests/run_agent
devsart95 06ae5b6faa perf(state): batch the turn flush into one SQLite transaction
Re-derivation of #23254 (@devsart95) on today's flush loop. The turn
flush in _flush_messages_to_session_db wrote one BEGIN IMMEDIATE
transaction per message row; a typical agent turn (user + assistant +
tool results) paid 3-8 transactions -- and, off WAL (the default on
macOS while the WAL-reset guard is active), 3-8 fsyncs -- per turn.

Adds SessionDB.append_messages_batch: same row shape as append_message
(shared _prepare_message_row serializer + _MESSAGE_INSERT_SQL column
list, so the two writers cannot drift), same compression-lock and
compression-closed guards, one aggregated session-counter UPDATE, one
transaction for the whole batch. Row serialization stays outside the
write lock.

The flush loop now collects the turn's new rows and writes them in one
call. All-or-nothing pairs exactly with the persisted-marker stamping:
on failure no rows landed and no markers were stamped, so the next
flush re-writes the whole tail (same recovery contract as before,
minus the partial-prefix case that could double-count).

Measured (same harness, 5-message turn, journal_mode=DELETE,
synchronous=FULL): 2.32ms -> 0.83ms median per turn flush (64% faster,
5 fsyncs -> 1). On WAL the win is smaller but the atomicity fix holds.
2026-08-03 20:43:38 +05:30
..
__init__.py
…
conftest.py
…
repro_48013_image_shrink_brick.py
…
test_413_compression.py fix(context): persist NVIDIA DeepSeek endpoint limit 2026-07-31 22:31:22 -07:00
test_860_dedup.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_1630_context_overflow_loop.py Merge remote-tracking branch 'origin/main' into tests/prune-low-value 2026-07-29 15:24:14 -07:00
test_18028_content_policy_blocked.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_24996_fallback_exhaustion_cooldown.py
…
test_28161_anthropic_stream_pool_cleanup.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_31273_402_not_retried.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_32646_fallback_429_after_timeout.py
…
test_63425_credential_pool_auto_detect.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_66267_multimodal_interim.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_70773_shared_client_fd_corruption.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_agent_guardrails.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_anthropic_prompt_cache_policy.py fix: exclude DeepSeek from OpenCode caching path to prevent HTTP 400 2026-08-03 14:20:41 +05:30
test_anthropic_response_header_capture.py nous portal anthropic wire 2026-07-27 11:53:48 -04:00
test_anthropic_third_party_oauth_guard.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_anthropic_truncation_continuation.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_api_max_retries_config.py test: pair load_config_readonly stubs at pruned-file sites (post-merge with main's readonly sweep) 2026-07-29 15:37:24 -07:00
test_async_httpx_del_neuter.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_auth_provider_failover.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_background_review.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_background_review_cache_parity.py fix(background-review): inherit prefill messages + OpenRouter provider pins on non-routed forks 2026-08-02 23:48:42 +05:30
test_background_review_cost_controls.py test: patch load_config_readonly alongside load_config across affected suites 2026-07-29 15:28:15 -07:00
test_background_review_summary.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_background_review_toolset_restriction.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_callable_api_key.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_codex_app_server_compaction.py fix(agent): force-persist compression completed past SessionDB rate limit 2026-08-02 16:16:36 -07:00
test_codex_app_server_integration.py perf(tools): use load_config_readonly on the approval guard path 2026-08-02 21:17:49 +05:30
test_codex_multimodal_tool_result.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_codex_no_tools_nonetype.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_codex_silent_hang_hint.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_codex_xai_oauth_recovery.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_commit_memory_session_context_engine.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_compress_focus_plugin_fallback.py
…
test_compression_abort_state_reset.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_compression_boundary.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_compression_boundary_hook.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_compression_feasibility.py test: pair load_config_readonly stubs at pruned-file sites (post-merge with main's readonly sweep) 2026-07-29 15:37:24 -07:00
test_compression_lock_defer.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_compression_persistence.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_compression_trigger_excludes_reasoning.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_compressor_fallback_update.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_concurrent_interrupt.py
…
test_context_token_tracking.py
…
test_conversation_fallback_state.py Merge remote-tracking branch 'origin/main' into tests/prune-low-value 2026-07-29 15:24:14 -07:00
test_copilot_native_vision_headers.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_create_openai_client_disables_sdk_retries.py
…
test_create_openai_client_kwargs_isolation.py
…
test_create_openai_client_proxy_env.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_create_openai_client_reuse.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_create_openai_client_ssl_verify.py
…
test_credential_pool_interrupt.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_credential_rotation_route_settings.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_credits_notices_toggle.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_custom_provider_extra_headers_client.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_deepseek_reasoning_content_echo.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_deepseek_v4_thinking_live.py
…
test_dict_tool_call_args.py
…
test_dropped_tool_call_recovery.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_empty_response_recovery_persistence.py perf(state): batch the turn flush into one SQLite transaction 2026-08-03 20:43:38 +05:30
test_empty_terminal_reasoning_surface.py feat(agent): surface a labeled reasoning excerpt at the empty-response terminal 2026-07-26 20:59:21 -07:00
test_exit_cleanup_interrupt.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_fallback_credential_isolation.py
…
test_fallback_reasoning_override.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_file_mutation_verifier.py fix(agent): scope parallel batches from V4A patch headers 2026-08-01 11:40:59 -07:00
test_fireworks_live.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_identity_flush.py fix(agent): invalidate flush-scan cursor when finalizer pops db marker 2026-07-31 23:18:12 -07:00
test_image_rejection_fallback.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_image_shrink_recovery.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_in_place_compaction.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_infinite_compaction_loop.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_init_fallback_on_exhausted_pool.py
…
test_interactive_interrupt.py
…
test_interrupt_propagation.py fix(compression): let explicit interrupts cancel safely 2026-08-02 22:15:20 +05:30
test_invalid_context_length_warning.py test: pair load_config_readonly stubs at pruned-file sites (post-merge with main's readonly sweep) 2026-07-29 15:37:24 -07:00
test_iteration_budget_race.py
…
test_jsondecodeerror_retryable.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_last_reasoning_per_turn.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_lmstudio_load_mode.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_long_context_tier_429.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_malformed_tool_arguments.py refactor(agent): remove the inter-tool delay 2026-07-29 15:21:26 -07:00
test_materialize_data_url_cleanup.py
…
test_memory_nudge_counter_hydration.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_memory_provider_init.py test: pair load_config_readonly stubs at pruned-file sites (post-merge with main's readonly sweep) 2026-07-29 15:37:24 -07:00
test_memory_sync_interrupted.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_message_sequence_repair.py perf(state): batch the turn flush into one SQLite transaction 2026-08-03 20:43:38 +05:30
test_moa_fanout_cadence.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_moa_loop_mode.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_moa_privacy_filter.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_moa_streaming.py fix(moa): restore a valid preset after fallback model drift 2026-07-31 21:52:36 -07:00
test_multimodal_tool_content_recovery.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_nonretryable_error_html_summary.py refactor(agent): remove the inter-tool delay 2026-07-29 15:21:26 -07:00
test_notice_spine.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_nous_429_fallback_reentry.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_nous_fallback_unavailable.py
…
test_openai_client_lifecycle.py perf(agent): reuse the per-request OpenAI wire client across sequential LLM calls 2026-07-28 19:06:59 +05:30
test_overflow_overhead_aware_tokens.py fix(compression): route overhead-aware tokens in post-tool compress + add recovery-path tests 2026-08-03 10:01:45 +05:30
test_partial_stream_finish_reason.py Merge remote-tracking branch 'origin/main' into tests/prune-low-value 2026-07-29 15:24:14 -07:00
test_per_model_compression_threshold.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_per_model_threshold_init_ordering.py test: pair load_config_readonly stubs at pruned-file sites (post-merge with main's readonly sweep) 2026-07-29 15:37:24 -07:00
test_percentage_clamp.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_plugin_context_engine_init.py test: pair load_config_readonly stubs at pruned-file sites (post-merge with main's readonly sweep) 2026-07-29 15:37:24 -07:00
test_post_tool_compression_attempt_cap.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_pre_compress_memory_context.py fix(redaction): normalize URL credential key aliases 2026-07-20 02:25:57 -07:00
test_preflight_compression_cap_e2e.py test: pair load_config_readonly stubs at pruned-file sites (post-merge with main's readonly sweep) 2026-07-29 15:37:24 -07:00
test_primary_runtime_restore.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_proactive_prune_loop_wiring.py feat(compression): prompt-cache reclaim gate + hardened wiring for proactive prune 2026-07-23 16:44:12 -07:00
test_provider_attribution_headers.py Revert "remove Vercel AI Gateway and Vercel Sandbox (#33067)" 2026-07-29 19:48:37 -07:00
test_provider_fallback.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_provider_parity.py Revert "remove Vercel AI Gateway and Vercel Sandbox (#33067)" 2026-07-29 19:48:37 -07:00
test_repair_tool_call_arguments.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_repair_tool_call_name.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_request_client_reuse_abort_races.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_reset_aware_primary_restore.py fix(credential_pool): unpack the tuple in next_available_at's gate 2026-08-03 19:32:50 +05:30
test_retry_status_buffer.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_review_prompt_class_first.py test(background-review): reanchor unresolved-failure coverage 2026-07-31 22:33:03 -07:00
test_run_agent.py test: fake clock for the backoff-status test (was busy-spinning 7.5s) 2026-08-03 17:15:12 +05:30
test_run_agent_codex_responses.py fix(codex): defang reserved Harmony tokens in requests 2026-07-31 22:53:20 -07:00
test_run_agent_multimodal_prologue.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_sequential_chats_live.py
…
test_session_activity_persist.py refactor(agent): pin session activity heartbeat cadence + harden best-effort write 2026-08-02 16:16:36 -07:00
test_session_id_env.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_session_meta_filtering.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_session_reset_fix.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_session_source.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_steer.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_stream_drop_logging.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_stream_interrupt_retry.py fix(streaming): block stale stream deltas 2026-07-18 19:55:16 +05:30
test_stream_single_writer_65991.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_stream_stale_breaker_reset.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_stream_stale_circuit_breaker.py fix(agent): request-local Anthropic clients so the stale/interrupt watchdog never corrupts SQLite (#67142) 2026-07-18 21:20:48 -04:00
test_streaming.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_streaming_tool_call_repair.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_strict_api_validation.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_strip_reasoning_tags_cli.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_summarize_api_error.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_switch_model_context.py test: pair load_config_readonly stubs at pruned-file sites (post-merge with main's readonly sweep) 2026-07-29 15:37:24 -07:00
test_switch_model_fallback_prune.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_switch_model_pool_reload_52727.py
…
test_switch_model_reapplies_headers.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_switch_model_reasoning_override.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_switch_model_rollback.py
…
test_switch_model_stale_base_url.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_thinking_only_sanitizer.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_thinking_sig_recovery_persistence.py
…
test_tls_fd_recycle_corruption.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_token_persistence_non_cli.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_tool_arg_coercion.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_tool_batch_segmentation.py fix(agent): scope parallel batches from V4A patch headers 2026-08-01 11:40:59 -07:00
test_tool_call_args_sanitizer.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_tool_call_guardrail_runtime.py test: pair load_config_readonly stubs at pruned-file sites (post-merge with main's readonly sweep) 2026-07-29 15:37:24 -07:00
test_tool_call_incremental_persistence.py fix(tool-executor): emit tool results on hard interrupt to keep alternation 2026-08-01 16:42:57 -07:00
test_tool_executor_contextvar_propagation.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_tool_name_db_persistence.py perf(state): batch the turn flush into one SQLite transaction 2026-08-03 20:43:38 +05:30
test_turn_completion_explainer.py Merge remote-tracking branch 'origin/main' into tests/prune-low-value 2026-07-29 15:24:14 -07:00
test_unicode_ascii_codec.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_verification_continuation_budget.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_vision_aware_preprocessing.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_vision_tool_messages.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00
test_wait_state_visibility.py test: prune low-value tests suite-wide (wave 1) — 46,820 → 28,106 test functions 2026-07-29 13:10:23 -07:00