mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-21 16:18:55 +00:00
* feat(attribution): conflict-free contributor mappings via contributors/emails/ directory
The AUTHOR_MAP dict in scripts/release.py was a merge-conflict magnet:
every concurrent salvage PR appended entries to the same lines of the
same file, so parallel PRs re-conflicted on every merge to main.
New system: one file per email under contributors/emails/ — filename is
the commit-author email, first non-comment line is the GitHub login.
File additions never conflict, so any number of PRs can add mappings
concurrently.
- scripts/release.py: AUTHOR_MAP is now LEGACY_AUTHOR_MAP (frozen)
merged with the directory at import time (directory wins). All
existing consumers (resolve_author, contributor_audit.py) unchanged.
- scripts/add_contributor.py: idempotent CLI to add a mapping; refuses
conflicting reassignments (incl. against the legacy map), validates
email/login shapes.
- contributor-check.yml: attribution gate now accepts a mapping file OR
a legacy entry; failure message prints the exact add_contributor
command. Also auto-resolves bare <login>@users.noreply.github.com
emails is intentionally NOT added (kept id+login form only, matching
previous behavior).
- contributor_audit.py: guidance now points at add_contributor.py.
- tests/scripts/test_contributor_map.py: 12 tests covering loader,
merge precedence, CLI idempotency/conflict/validation, subprocess E2E.
* feat(ci): one-shot per-file flake retry in the parallel test runner
A failing test FILE is re-run once in a fresh subprocess. Pass-on-retry
counts as green but is loudly reported in a '⚠ FLAKY' summary section
(with both attempts' output preserved) so the flake gets fixed instead
of eating a full-run rerun. Deterministic failures fail both attempts —
regressions cannot be laundered green.
- --file-retries N / HERMES_TEST_FILE_RETRIES (default 1, 0 disables)
- E2E verified: simulated first-run-fail flake goes green with banner;
deterministic failure still exits 1; retries=0 restores old behavior.
This converts the dominant CI failure mode (one timing-sensitive test
flaking a 4600-test shard, requiring a manual 10-minute rerun and an
agent triage loop) into a self-healing retry that costs one file's
runtime.
* test(approval): loosen wall-clock perf bounds 0.15s -> 2.0s
These guard against catastrophic regex backtracking (seconds-to-minutes
class), but 0.15s is within scheduler-stall noise on loaded shared CI
runners — test_max_accepted_separator_free_input_is_fast failed a CI
shard this week on runner load alone. 2.0s still catches the regression
class with zero flake surface.
* fix(ci): job timeouts everywhere + retries on all network installs
Reliability pass over every workflow:
- timeout-minutes on all 21 jobs that lacked one (a hung job previously
burned the 6-hour default runner budget)
- ./.github/actions/retry wrapped around every network-fetching install
that lacked it: pip installs (deploy-site, skills-index), npm ci
(deploy-site website, upload_to_pypi web + ui-tui), uv sync (docker
test deps). Deterministic build steps (npm run build) deliberately
NOT retried — split into separate steps so a real build failure fails
fast instead of retrying 3x.
* docs(agents): document the file-retry flake policy
* fix(ci): curl retries on deploy hook + skills-index probe
* fix(ci): kill the remaining transient-failure classes in workflows + Dockerfile
From the workflow reliability audit:
- tests.yml: duration-cache restore had NO restore-keys while saves use
run_id-suffixed keys — the cache never matched once, so LPT slicing
always ran blind and unbalanced slices pushed heavy files toward the
per-file timeout. One-line restore-keys fixes slice balancing.
- Label gates (lint ci-reviewed, supply-chain mcp-catalog-reviewed):
'gh pr view || true' turned an API blip into 'label absent' → false
BLOCKING failure. Now 3x retry, and API failure is reported as an API
failure instead of a missing label.
- detect-changes action: compare API retried before failing open (was
silently running all lanes on any blip).
- uv-lockfile-check: 'uv lock --check' resolves against PyPI — retried
so registry blips don't read as 'lockfile stale'.
- docker.yml merge job: imagetools create retried (Docker Hub eventual
consistency on just-pushed digests).
- Dockerfile: apt-get Acquire::Retries=3; s6-overlay ADDs converted to
curl --retry 3 (ADD cannot retry; checksums still enforced); npm
--fetch-retries=5; playwright chromium fetch retried 3x.
- Advisory artifact uploads (per-slice durations, ci-timings report)
get continue-on-error so an artifact-service blip can't fail a green
test slice.
* fix(tests): kill the two root-cause flakes — leaking pre-warm timer + env-dependent provider list
- test_tui_gateway_server.py: session.create / non-eager session.resume
arm a 50ms threading.Timer (_schedule_agent_build) that outlives its
test and fires into the NEXT test's _make_agent mock, racily
corrupting captured state (the recurring session_resume shard
failures). Replaced the per-test whack-a-mole stub with a module-wide
autouse fixture; the 3 worker-lifecycle tests that genuinely need the
deferred build opt back in via @pytest.mark.real_agent_prewarm (new
marker in pyproject).
- test_api_key_providers.py: PROVIDER_ENV_VARS is now derived from the
live PROVIDER_REGISTRY instead of a hand-list that had drifted
(missing HF_TOKEN / DEEPINFRA_API_KEY) — resolve_provider('auto')
tests failed on any machine with HF_TOKEN exported. E2E-verified with
HF_TOKEN/DEEPINFRA_API_KEY set: 42/42 pass.
* test: de-flake 30 timing-sensitive test files for loaded CI runners
Root-cause fixes from the flake audit (session-DB mining + repo sweep):
Event-based sync instead of sleep-sync:
- title_generator: mock sets threading.Event, wait(10) replaces
sleep(0.3) hoping the daemon thread got scheduled
- docker zombie_reaping / profile_gateway: poll-for-state helpers
replace fixed 1-3s sleeps (s6 transitions + SIGCHLD reaping are async)
- process_registry tree test: select()-bounded readline replaces an
unbounded blocking read (parent wedge now fails THIS test with a clear
message instead of an opaque rc=124 file kill); SIGTERM grace 1s->2s
(the 1s partition window mid-interpreter-startup is how a child PID
escaped the live-system guard in CI)
Timeout raises (loaded 8-way-sliced runners see ~5s scheduling floors;
all of these complete in ms-to-1s when healthy so the raises cost
nothing on green runs):
- subprocess/thread waits <= 2s raised to 10-15s across mcp_tool,
mcp_circuit_breaker, mcp_reconnect_retry_reset, mcp_parked_self_probe,
mcp_cancelled_error_propagation, registry, clarify_gateway, interrupt,
voice_cli_integration, docker_environment, session_store_lock_io,
planned_stop_watcher, cli_interrupt_subagent, thread_scoped_output
(joins now also assert not is_alive() so stragglers fail loudly)
- wall-clock discrimination ceilings loosened where the guarded hang is
10x larger: local_background_child_hang 4s->10s, interrupt_cleanup
setup 5s->20s + pgid-exit 30s->60s, mcp_stability grandchild spinup
5s->15s, protocol/gil-starvation fast-handler 0.5s->2s,
iso_certify_seam 1.5s->5s, wait_for_mcp_discovery 0.1s->1s
- narrow assertion windows widened: honcho first-turn wait 0.4..0.65 ->
0.25..2.0 (property is bounded-not-hung, not an exact wall-clock);
compression fork-lock TTL 1s->3s (12 refresh chances per lease);
compression-lock expiry margins symmetric (ttl 0.05->0.5, sleep 1.0)
- telegram hung-DNS bound 1.0->1.4 (fake hang is 1.5s — must stay under)
* fix(tests): repair indentation from de-flake batch edit
* fix(tests): harden env isolation and replace remaining sleep-sync races
The full 42k-test run and complete npm check surfaced three more classes:
- Environment isolation: local ~/.honcho defaultHost and SSH_* variables
leaked into Python/TUI tests. Pin the default Honcho host in the
hermetic fixture, isolate the one fallback test from ~/.honcho, and
blank SSH_* around terminalSetup tests. This flipped 20 false failures
back to deterministic behavior on developer machines.
- Background-thread sleep-sync: Honcho async writer tests patched
time.sleep globally, then busy-polled with that same mocked sleep. Under
full-suite load the poller could starve the writer. Each test now waits
on an Event emitted by the exact flush/retry transition; 30/30 passed
under 15-way contention.
- Desktop streaming: the test slept 80ms and assumed a 500ms timer could
not fire before its assertion. A loaded runner descheduled the test for
>500ms and both chunks arrived. Producer controls now gate second-chunk
and completion transitions explicitly.
Also make file-retry observability complete: a self-healed flaky file now
prints BOTH attempts' full output in the FLAKY summary. Two behavioral
runner tests prove pass-on-retry is green+loud+traceback-preserving, while
a deterministic failure remains red.
* refactor(ci): use gh bot pat, better retries
refactor(ci): use retry action for PR label fetch
the retry action now captures stdout as a step output, so it can serve
double duty: retry + output capture for commands like 'gh pr view' whose
result must be consumed by later steps.
Retry action gains:
- 'stdout' output (heredoc-delimited to preserve newlines)
- tee to temp file so stdout still streams to the job log
- step id 'retry' for output reference
Both lint.yml and supply-chain-audit.yml now use the retry action
directly with 'command: gh pr view ...' and read
steps.<id>.outputs.stdout.
ci: use AUTOFIX_BOT_PAT for all gh CLI / GitHub API auth
Replace secrets.GITHUB_TOKEN and github.token with
secrets.AUTOFIX_BOT_PAT across all workflows and composite actions
that use the gh CLI or GitHub API. The PAT has consistent permissions
across fork PRs (where GITHUB_TOKEN is read-only), avoids API rate
limit sharing with the default token, and is already used by
js-autofix.yml for the same reasons.
19 sites swapped across 9 files:
- lint.yml (3): label fetch, comment post/edit, comment update
- supply-chain-audit.yml (5): scan, critical comment, unbounded dep
comment, label fetch, mcp-catalog comment
- lockfile-diff.yml (1): PR comment post/update
- skills-index-freshness.yml (1): issue creation on degraded probe
- skills-index.yml (2): index build, trigger deploy workflow
- upload_to_pypi.yml (2): release view poll, release upload
- ci.yml (1): timings report
- deploy-site.yml (2): skills index crawl
- detect-changes/action.yml (1): compare API call
---------
Co-authored-by: ethernet <arilotter@gmail.com>
448 lines
15 KiB
Python
448 lines
15 KiB
Python
"""Regression tests for Honcho startup fail-open behavior."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import threading
|
|
import time
|
|
from types import SimpleNamespace
|
|
|
|
from plugins.memory.honcho import HonchoMemoryProvider
|
|
|
|
|
|
class _FakeHonchoConfig(SimpleNamespace):
|
|
def resolve_session_name(self, **kwargs):
|
|
return "test-session"
|
|
|
|
|
|
def _configured_hybrid_config() -> _FakeHonchoConfig:
|
|
return _FakeHonchoConfig(
|
|
enabled=True,
|
|
api_key=None,
|
|
base_url="http://127.0.0.1:8000",
|
|
recall_mode="hybrid",
|
|
init_on_session_start=False,
|
|
injection_frequency="every-turn",
|
|
context_cadence=1,
|
|
dialectic_cadence=1,
|
|
query_rewrite=False,
|
|
first_turn_base_wait=3.0,
|
|
first_turn_dialectic_wait=2.0,
|
|
dialectic_depth=1,
|
|
dialectic_depth_levels=None,
|
|
reasoning_heuristic=True,
|
|
reasoning_level_cap="high",
|
|
context_tokens=None,
|
|
message_max_chars=25000,
|
|
session_strategy="per-directory",
|
|
)
|
|
|
|
|
|
def _configured_tools_config(*, init_on_session_start: bool = False) -> _FakeHonchoConfig:
|
|
cfg = _configured_hybrid_config()
|
|
cfg.recall_mode = "tools"
|
|
cfg.init_on_session_start = init_on_session_start
|
|
return cfg
|
|
|
|
|
|
def test_honcho_hybrid_initialize_returns_without_waiting_for_session_init(monkeypatch):
|
|
"""Slow Honcho session creation must not block agent startup."""
|
|
provider = HonchoMemoryProvider()
|
|
cfg = _configured_hybrid_config()
|
|
started = threading.Event()
|
|
release = threading.Event()
|
|
|
|
monkeypatch.setattr(
|
|
"plugins.memory.honcho.client.HonchoClientConfig.from_global_config",
|
|
lambda: cfg,
|
|
)
|
|
|
|
def slow_session_init(self, cfg, session_id, **kwargs):
|
|
started.set()
|
|
release.wait(timeout=5)
|
|
self._session_initialized = True
|
|
|
|
monkeypatch.setattr(HonchoMemoryProvider, "_do_session_init", slow_session_init)
|
|
|
|
start = time.perf_counter()
|
|
provider.initialize("session-1", platform="cli")
|
|
elapsed = time.perf_counter() - start
|
|
|
|
try:
|
|
assert elapsed < 0.5
|
|
assert started.wait(timeout=1)
|
|
assert provider._session_key == "test-session"
|
|
finally:
|
|
release.set()
|
|
init_thread = getattr(provider, "_init_thread", None)
|
|
if init_thread:
|
|
init_thread.join(timeout=1)
|
|
|
|
|
|
def test_stalled_init_only_delays_first_turn_prefetch(monkeypatch):
|
|
"""A stalled session init may bound-wait on turn 1 only; every later
|
|
prefetch must keep the fail-open contract and return immediately."""
|
|
provider = HonchoMemoryProvider()
|
|
cfg = _configured_hybrid_config()
|
|
release = threading.Event()
|
|
|
|
monkeypatch.setattr(
|
|
"plugins.memory.honcho.client.HonchoClientConfig.from_global_config",
|
|
lambda: cfg,
|
|
)
|
|
|
|
def stalled_session_init(self, cfg, session_id, **kwargs):
|
|
release.wait(timeout=10)
|
|
|
|
monkeypatch.setattr(HonchoMemoryProvider, "_do_session_init", stalled_session_init)
|
|
provider.initialize("session-1", platform="cli")
|
|
provider._FIRST_TURN_BASE_TIMEOUT = 1.0
|
|
|
|
try:
|
|
provider._turn_count = 1
|
|
start = time.perf_counter()
|
|
assert provider.prefetch("first question") == ""
|
|
assert time.perf_counter() - start >= 0.5 # turn 1 waited (bounded)
|
|
|
|
for turn in (2, 3, 4):
|
|
provider._turn_count = turn
|
|
start = time.perf_counter()
|
|
assert provider.prefetch("follow-up question") == ""
|
|
assert time.perf_counter() - start < 0.4 # fail-open, no wait
|
|
finally:
|
|
release.set()
|
|
init_thread = getattr(provider, "_init_thread", None)
|
|
if init_thread:
|
|
init_thread.join(timeout=1)
|
|
|
|
|
|
def test_honcho_background_init_rechecks_state_after_lock_race():
|
|
"""Startup should not spawn/crash if init completes while waiting for lock."""
|
|
provider = HonchoMemoryProvider()
|
|
provider._config = _configured_hybrid_config()
|
|
provider._lazy_init_kwargs = {"platform": "cli"}
|
|
provider._lazy_init_session_id = "session-1"
|
|
|
|
class RacingLock:
|
|
def __enter__(self):
|
|
provider._session_initialized = True
|
|
provider._lazy_init_kwargs = None
|
|
return self
|
|
|
|
def __exit__(self, exc_type, exc, tb):
|
|
return False
|
|
|
|
provider._init_lock = RacingLock()
|
|
|
|
provider._start_session_init_background()
|
|
|
|
assert provider._init_thread is None
|
|
assert provider._session_initialized is True
|
|
|
|
|
|
def test_honcho_prefetch_returns_without_waiting_for_first_context_fetch():
|
|
"""First-turn context injection must fail open when Honcho is slow."""
|
|
provider = HonchoMemoryProvider()
|
|
cfg = _configured_hybrid_config()
|
|
cfg.timeout = 0.1
|
|
fetch_started = threading.Event()
|
|
|
|
class SlowManager:
|
|
def get_prefetch_context(self, session_key, user_message=None):
|
|
fetch_started.set()
|
|
time.sleep(5)
|
|
return {"representation": "late"}
|
|
|
|
def prefetch_context(self, session_key, user_message=None):
|
|
fetch_started.set()
|
|
|
|
def pop_context_result(self, session_key):
|
|
return {}
|
|
|
|
provider._config = cfg
|
|
provider._manager = SlowManager()
|
|
provider._session_key = "test-session"
|
|
provider._session_initialized = True
|
|
provider._turn_count = 1
|
|
|
|
start = time.perf_counter()
|
|
result = provider.prefetch("what do you know about me?")
|
|
elapsed = time.perf_counter() - start
|
|
|
|
assert result == ""
|
|
assert elapsed < 0.5
|
|
assert fetch_started.is_set()
|
|
|
|
|
|
def test_first_turn_base_wait_is_shared_by_init_and_context_fetch():
|
|
"""Session init and base retrieval share one configured turn-1 deadline."""
|
|
provider = HonchoMemoryProvider()
|
|
cfg = _configured_hybrid_config()
|
|
cfg.first_turn_base_wait = 0.5
|
|
cfg.timeout = None
|
|
release_context = threading.Event()
|
|
|
|
class SlowManager:
|
|
def get_prefetch_context(self, session_key, user_message=None):
|
|
release_context.wait(timeout=5)
|
|
return {"representation": "late"}
|
|
|
|
def set_context_result(self, session_key, result):
|
|
pass
|
|
|
|
def pop_context_result(self, session_key):
|
|
return {}
|
|
|
|
def finish_init():
|
|
time.sleep(0.3)
|
|
provider._manager = SlowManager()
|
|
provider._session_initialized = True
|
|
|
|
provider._config = cfg
|
|
provider._session_key = "test-session"
|
|
provider._recall_mode = "context"
|
|
provider._turn_count = 1
|
|
provider._last_dialectic_turn = 0
|
|
provider._FIRST_TURN_BASE_TIMEOUT = cfg.first_turn_base_wait
|
|
provider._init_thread = threading.Thread(target=finish_init, daemon=True)
|
|
provider._init_thread.start()
|
|
|
|
try:
|
|
started = time.perf_counter()
|
|
assert provider.prefetch("what do you know about me?") == ""
|
|
elapsed = time.perf_counter() - started
|
|
# Property: prefetch waits for init (0.3s sleep) but is bounded by
|
|
# first_turn_base_wait rather than blocking forever on the slow
|
|
# context fetch. The old 0.4..0.65 window was 0.25s wide — pure
|
|
# scheduler noise on a loaded runner. Lower bound proves the wait
|
|
# happened; loose upper bound proves it didn't hang.
|
|
assert 0.25 <= elapsed < 2.0
|
|
finally:
|
|
release_context.set()
|
|
provider._init_thread.join(timeout=10)
|
|
|
|
|
|
|
|
def test_honcho_sync_turn_does_not_start_network_write_before_session_init():
|
|
"""Session-end sync must not create a blocking writer before init finishes."""
|
|
provider = HonchoMemoryProvider()
|
|
cfg = _configured_hybrid_config()
|
|
get_started = threading.Event()
|
|
background_started = threading.Event()
|
|
release_init = threading.Event()
|
|
|
|
class SlowManager:
|
|
def get_or_create(self, session_key):
|
|
get_started.set()
|
|
time.sleep(5)
|
|
return SimpleNamespace()
|
|
|
|
def _flush_session(self, session):
|
|
pass
|
|
|
|
provider._config = cfg
|
|
provider._manager = SlowManager()
|
|
provider._session_key = "test-session"
|
|
provider._session_initialized = False
|
|
provider._start_session_init_background = background_started.set
|
|
provider._init_thread = threading.Thread(
|
|
target=lambda: release_init.wait(timeout=5), daemon=True
|
|
)
|
|
provider._init_thread.start()
|
|
|
|
try:
|
|
provider.sync_turn("hello", "world")
|
|
|
|
assert provider._sync_thread is None
|
|
assert background_started.is_set()
|
|
assert not get_started.wait(timeout=0.1)
|
|
finally:
|
|
release_init.set()
|
|
provider._init_thread.join(timeout=1)
|
|
|
|
|
|
def test_honcho_sync_turn_waits_for_full_background_startup(monkeypatch):
|
|
"""Manager assignment alone is not readiness while background init continues."""
|
|
provider = HonchoMemoryProvider()
|
|
cfg = _configured_hybrid_config()
|
|
session_created = threading.Event()
|
|
migration_started = threading.Event()
|
|
release_migration = threading.Event()
|
|
get_calls = []
|
|
|
|
class StartupManager:
|
|
def __init__(self, *args, **kwargs):
|
|
pass
|
|
|
|
def get_or_create(self, session_key):
|
|
get_calls.append(session_key)
|
|
session_created.set()
|
|
return SimpleNamespace(messages=[])
|
|
|
|
def migrate_memory_files(self, session_key, mem_dir):
|
|
migration_started.set()
|
|
release_migration.wait(timeout=5)
|
|
|
|
def prefetch_context(self, session_key, user_message=None):
|
|
pass
|
|
|
|
def _flush_session(self, session):
|
|
pass
|
|
|
|
monkeypatch.setattr(
|
|
"plugins.memory.honcho.client.HonchoClientConfig.from_global_config",
|
|
lambda: cfg,
|
|
)
|
|
monkeypatch.setattr("plugins.memory.honcho.client.get_honcho_client", lambda cfg: object())
|
|
monkeypatch.setattr("plugins.memory.honcho.session.HonchoSessionManager", StartupManager)
|
|
|
|
provider.initialize("session-1", platform="cli")
|
|
try:
|
|
assert session_created.wait(timeout=1)
|
|
assert migration_started.wait(timeout=1)
|
|
assert provider._manager is not None
|
|
assert provider._session_initialized is False
|
|
|
|
provider.sync_turn("hello", "world")
|
|
|
|
assert provider._sync_thread is None
|
|
assert get_calls == ["test-session"]
|
|
finally:
|
|
release_migration.set()
|
|
init_thread = getattr(provider, "_init_thread", None)
|
|
if init_thread:
|
|
init_thread.join(timeout=1)
|
|
if provider._prefetch_thread:
|
|
provider._prefetch_thread.join(timeout=1)
|
|
|
|
assert provider._session_initialized is True
|
|
|
|
|
|
def test_honcho_system_prompt_advertises_active_while_background_init_runs(monkeypatch):
|
|
"""Prompt metadata should not require a completed network session."""
|
|
provider = HonchoMemoryProvider()
|
|
cfg = _configured_hybrid_config()
|
|
release = threading.Event()
|
|
|
|
monkeypatch.setattr(
|
|
"plugins.memory.honcho.client.HonchoClientConfig.from_global_config",
|
|
lambda: cfg,
|
|
)
|
|
|
|
def slow_session_init(self, cfg, session_id, **kwargs):
|
|
release.wait(timeout=5)
|
|
self._session_initialized = True
|
|
|
|
monkeypatch.setattr(HonchoMemoryProvider, "_do_session_init", slow_session_init)
|
|
|
|
provider.initialize("session-1", platform="cli")
|
|
try:
|
|
prompt = provider.system_prompt_block()
|
|
assert "Honcho Memory" in prompt
|
|
assert "hybrid mode" in prompt
|
|
finally:
|
|
release.set()
|
|
init_thread = getattr(provider, "_init_thread", None)
|
|
if init_thread:
|
|
init_thread.join(timeout=1)
|
|
|
|
|
|
def test_honcho_tools_eager_init_still_ready_on_return(monkeypatch):
|
|
"""tools + initOnSessionStart=true keeps its ready-on-return contract."""
|
|
provider = HonchoMemoryProvider()
|
|
cfg = _configured_tools_config(init_on_session_start=True)
|
|
|
|
monkeypatch.setattr(
|
|
"plugins.memory.honcho.client.HonchoClientConfig.from_global_config",
|
|
lambda: cfg,
|
|
)
|
|
|
|
def fake_session_init(self, cfg, session_id, **kwargs):
|
|
self._manager = SimpleNamespace()
|
|
self._session_key = "test-session"
|
|
self._session_initialized = True
|
|
|
|
monkeypatch.setattr(HonchoMemoryProvider, "_do_session_init", fake_session_init)
|
|
|
|
provider.initialize("session-1", platform="cli")
|
|
|
|
assert provider._session_initialized is True
|
|
assert provider._manager is not None
|
|
assert provider._init_thread is None
|
|
|
|
|
|
def test_honcho_tools_eager_init_failure_does_not_leave_ready_manager(monkeypatch):
|
|
"""Failed eager tools startup must not leave hooks seeing a ready session."""
|
|
provider = HonchoMemoryProvider()
|
|
cfg = _configured_tools_config(init_on_session_start=True)
|
|
|
|
monkeypatch.setattr(
|
|
"plugins.memory.honcho.client.HonchoClientConfig.from_global_config",
|
|
lambda: cfg,
|
|
)
|
|
|
|
def failing_session_init(self, cfg, session_id, **kwargs):
|
|
self._manager = SimpleNamespace()
|
|
self._session_key = "test-session"
|
|
raise RuntimeError("boom")
|
|
|
|
monkeypatch.setattr(HonchoMemoryProvider, "_do_session_init", failing_session_init)
|
|
|
|
provider.initialize("session-1", platform="cli")
|
|
assert provider._session_initialized is False
|
|
assert provider._manager is None
|
|
|
|
background_started = threading.Event()
|
|
provider._start_session_init_background = background_started.set
|
|
provider.sync_turn("hello", "world")
|
|
provider.on_memory_write("add", "user", "prefers safe Honcho startup")
|
|
|
|
assert provider._sync_thread is None
|
|
assert not background_started.is_set()
|
|
|
|
result = json.loads(provider.handle_tool_call("honcho_profile", {"peer": "user"}))
|
|
assert "could not be initialized" in result["error"]
|
|
assert provider._manager is None
|
|
|
|
|
|
def test_honcho_tools_lazy_hooks_do_not_prestart_background_init(monkeypatch):
|
|
"""tools lazy mode lets the first tool call own session initialization."""
|
|
provider = HonchoMemoryProvider()
|
|
cfg = _configured_tools_config(init_on_session_start=False)
|
|
|
|
monkeypatch.setattr(
|
|
"plugins.memory.honcho.client.HonchoClientConfig.from_global_config",
|
|
lambda: cfg,
|
|
)
|
|
|
|
provider.initialize("session-1", platform="cli")
|
|
background_started = threading.Event()
|
|
provider._start_session_init_background = background_started.set
|
|
|
|
provider.prefetch("what do you know?")
|
|
provider.queue_prefetch("what do you know?")
|
|
provider.sync_turn("hello", "world")
|
|
provider.on_memory_write("add", "user", "prefers fail-open memory")
|
|
|
|
assert not background_started.is_set()
|
|
assert provider._session_initialized is False
|
|
|
|
class ToolManager:
|
|
def get_peer_card(self, session_key, peer="user"):
|
|
return ["ready"]
|
|
|
|
init_calls = []
|
|
|
|
def fake_session_init(self, cfg, session_id, **kwargs):
|
|
init_calls.append(session_id)
|
|
self._manager = ToolManager()
|
|
self._session_key = "test-session"
|
|
self._session_initialized = True
|
|
|
|
monkeypatch.setattr(HonchoMemoryProvider, "_do_session_init", fake_session_init)
|
|
|
|
result = json.loads(provider.handle_tool_call("honcho_profile", {"peer": "user"}))
|
|
|
|
assert result == {"result": ["ready"]}
|
|
assert init_calls == ["session-1"]
|
|
assert not background_started.is_set()
|