Skip to content

The agent that grows with you

test: retain real-process read-only search A/B probe

Teknium551ccfcad149
diff --git a/evals/shared_gateway/README.md b/evals/shared_gateway/README.md
index ad12b61a4cc..800a8814b5d 100644
--- a/evals/shared_gateway/README.md
+++ b/evals/shared_gateway/README.md
@@ -10,4 +10,8 @@ Run against a real driver's report:
Evidence paths are relative to the receipt directory. Supply a full report with schema=1, source_sha, native_os, fixture_home_isolated=true, production_dispatch=true, model_boundary (loopback or live-provider), remaining_owned_processes=[], and cases. Each case contains name, status, positive integer assertions, and nonempty evidence_paths pointing to nonempty files.
+## Retained standalone reader A/B
+
+`search_readonly_ab.py` runs the real registered session-search tool in fresh interpreters with disposable homes. Its three cases cover empty, foreign-profile and existing-profile reads on both trees. It asserts the baseline creates an unwanted current-profile DB or commits a read-side write, while the fixed tree preserves marker reads without those mutations. Run with the project venv Python and explicit `--baseline`, `--fixed`, and private `--output` paths. The script records both tested SHAs and search-source hashes. Its receipt is deliberately narrower than the full `readonly-client` scenario, which also requires list/export and other reader paths.
+
The unified `run.py` driver is not implemented yet. Existing private native and subprocess probes have different receipt formats; do not rename them or manufacture a full report to obtain a pass. Test fixtures in `test_shared_gateway_harness.py` exercise the checker only and are not acceptance evidence.
diff --git a/evals/shared_gateway/search_readonly_ab.py b/evals/shared_gateway/search_readonly_ab.py
new file mode 100644
index 00000000000..1a350534a68
--- /dev/null
+++ b/evals/shared_gateway/search_readonly_ab.py
@@ -0,0 +1,98 @@
+"""Fresh-process production tool A/B; all storage is disposable."""
+import argparse
+import json
+import os
+from pathlib import Path
+import sqlite3
+import subprocess
+import sys
+import tempfile
+
+
+def child(repo, case, account):
+ home = account / '.hermes'
+ home.mkdir()
+ os.environ['HOME'] = str(account)
+ os.environ['HERMES_HOME'] = str(home)
+ sys.path.insert(0, str(repo))
+ from hermes_state import SessionDB
+ import tools.session_search_tool as search
+ from tools.registry import registry
+
+ target = home / 'profiles' / 'reader-target' if case == 'foreign' else home
+ if case != 'empty':
+ target.mkdir(parents=True, exist_ok=True)
+ owner = SessionDB(target / 'state.db')
+ owner.create_session('probe-session', source='cli')
+ owner.append_message('probe-session', role='user', content='owned probe marker')
+ owner.close()
+ params = {} if case == 'empty' else {'session_id': 'probe-session'}
+ if case == 'foreign':
+ params['profile'] = 'reader-target'
+ observer = sqlite3.connect(target / 'state.db') if case != 'empty' else None
+ before = observer.execute('PRAGMA data_version').fetchone()[0] if observer else None
+ entry = registry.get_entry('session_search')
+ assert entry is not None
+ result = json.loads(entry.handler(params))
+ after = observer.execute('PRAGMA data_version').fetchone()[0] if observer else None
+ if observer:
+ observer.close()
+ print(json.dumps({
+ 'module': search.__file__, 'case': case,
+ 'current_db_exists': (home / 'state.db').exists(),
+ 'success': result.get('success'),
+ 'read_marker': any(m.get('content') == 'owned probe marker' for m in result.get('messages', [])),
+ 'read_committed_write': before != after,
+ }))
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--baseline', type=Path)
+ parser.add_argument('--fixed', type=Path)
+ parser.add_argument('--output', type=Path)
+ parser.add_argument('--child', type=Path)
+ parser.add_argument('--case')
+ parser.add_argument('--account', type=Path)
+ args = parser.parse_args()
+ if args.child:
+ child(args.child, args.case, args.account)
+ return
+ receipts = []
+ for label, repo in [('baseline', args.baseline), ('fixed', args.fixed)]:
+ sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repo, text=True).strip()
+ diff = subprocess.check_output(['git', 'diff', 'HEAD', '--', 'tools/session_search_tool.py'], cwd=repo, text=True)
+ import hashlib
+ source_hash = hashlib.sha256((repo / 'tools/session_search_tool.py').read_bytes()).hexdigest()
+ for case in ['empty', 'foreign', 'existing']:
+ with tempfile.TemporaryDirectory(prefix='hermes-reader-ab-') as tmp:
+ env = {'PATH': os.environ.get('PATH', ''), 'LANG': 'C.UTF-8', 'TZ': 'UTC',
+ 'HOME': tmp, 'HERMES_HOME': str(Path(tmp) / '.hermes'),
+ 'PYTHONDONTWRITEBYTECODE': '1'}
+ proc = subprocess.run([sys.executable, str(Path(__file__).resolve()), '--child', str(repo),
+ '--case', case, '--account', tmp], cwd=repo, env=env,
+ stdin=subprocess.DEVNULL, capture_output=True, text=True, timeout=45)
+ if proc.returncode:
+ raise RuntimeError(f'{label}/{case} failed: {proc.stderr}')
+ row = json.loads(proc.stdout.strip().splitlines()[-1])
+ assert Path(row['module']).resolve() == (repo / 'tools/session_search_tool.py').resolve()
+ row.update(label=label, head_sha=sha, source_sha256=source_hash, source_dirty=bool(diff))
+ receipts.append(row)
+ args.output.write_text(json.dumps({'passed': False, 'receipts': receipts}, indent=2) + '\n')
+ by = {(r['label'], r['case']): r for r in receipts}
+ for case in ['empty', 'foreign']:
+ assert by['baseline', case]['current_db_exists'] is True
+ assert by['fixed', case]['current_db_exists'] is False
+ for label in ['baseline', 'fixed']:
+ for case in ['foreign', 'existing']:
+ assert by[label, case]['success'] is True
+ assert by[label, case]['read_marker'] is True
+ assert by[label, case]['read_committed_write'] is (label == 'baseline' and case == 'existing')
+ assert by['fixed', 'empty']['success'] is False
+ args.output.write_text(json.dumps({'passed': True, 'receipts': receipts}, indent=2) + '\n')
+ print(json.dumps({'passed': True, 'process_cases': len(receipts), 'receipt': str(args.output)}))
+
+
+if __name__ == '__main__':
+ main()
+
diff --git a/website/docs/developer-guide/context-compression-and-caching.md b/website/docs/developer-guide/context-compression-and-caching.md
index 0d08bdcc57a..b0a41b414f6 100644
--- a/website/docs/developer-guide/context-compression-and-caching.md
+++ b/website/docs/developer-guide/context-compression-and-caching.md
@@ -4,7 +4,7 @@ Hermes Agent uses a dual compression system and Anthropic prompt caching to
manage context window usage efficiently across long conversations.
Source files: `agent/context_engine.py` (ABC), `agent/context_compressor.py` (default engine),
-`agent/prompt_caching.py`, `gateway/run_turn.py` (session hygiene), `agent/compression_facade.py` (search for `_compress_context`)
+`agent/prompt_caching.py`, `gateway/run_turn_hygiene.py` (session hygiene), `agent/compression_facade.py` (search for `_compress_context`)
## Pluggable Context Engine
@@ -53,7 +53,7 @@ Hermes has two separate compression layers that operate independently:
### 1. Gateway Session Hygiene (85% threshold)
-Located in `gateway/run_turn.py` (search for `Session hygiene`). This is a **safety net** that
+Located in `gateway/run_turn_hygiene.py` (search for `Session hygiene`). This is a **safety net** that
runs before the agent processes a message. It prevents API failures when sessions
grow too large between turns (e.g., overnight accumulation in Telegram/Discord).