# Conflicts: # apps/desktop/src/app/session/hooks/use-message-stream/steer-arrival-order.test.tsx # apps/desktop/src/store/composer-queue.ts # apps/desktop/src/types/hermes.ts # apps/shared/src/json-rpc-gateway.ts # cron/jobs.py # cron/scheduler.py # gateway/hosted_room_policy_checkpoint.py # gateway/run.py # hermes_cli/env_loader.py # tests/acp_adapter/test_catalog_read_only.py # tests/acp_adapter/test_gateway_cancel_admission.py # tests/acp_adapter/test_gateway_catalog_cwd.py # tests/acp_adapter/test_gateway_client_boundary.py # tests/acp_adapter/test_gateway_controls.py # tests/acp_adapter/test_gateway_editor_cwd.py # tests/acp_adapter/test_gateway_editor_mcp.py # tests/acp_adapter/test_gateway_editor_policy.py # tests/acp_adapter/test_gateway_editor_v4a.py # tests/acp_adapter/test_gateway_editor_wire.py # tests/acp_adapter/test_gateway_entry_lifecycle.py # tests/acp_adapter/test_gateway_new_cold.py # tests/acp_adapter/test_gateway_prompt_content.py # tests/acp_adapter/test_gateway_sessions.py # tests/acp_adapter/test_gateway_terminal_projection.py # tests/acp_adapter/test_gateway_tool_projection.py # tests/acp_adapter/test_gateway_wire_controls.py # tests/acp_adapter/test_policy_identity_compat.py # tests/acp_adapter/test_session_mcp_frozen.py # tests/acp_adapter/test_session_mcp_policy.py # tests/cron/test_scheduler.py # tests/hermes_state/test_ledger_delete_consistency.py # tests/hermes_state/test_runtime_admission.py # tests/hermes_state/test_runtime_adoption.py # tests/hermes_state/test_runtime_destructive_mutations.py # tests/hermes_state/test_runtime_import_mutations.py # tests/hermes_state/test_runtime_mutation_actions.py # tests/hermes_state/test_runtime_mutation_retired_import.py # tests/hermes_state/test_runtime_mutations.py # tests/hermes_state/test_runtime_recovery.py # tests/hermes_state/test_runtime_rewind_mutations.py # tests/hermes_state/test_runtime_schema.py # tests/hermes_state/test_runtime_worker.py # tests/hermes_state/test_runtime_worker_compaction.py # tests/hermes_state/test_runtime_worker_compression.py # tests/hermes_state/test_runtime_worker_compression_admission.py # tests/hermes_state/test_runtime_worker_compression_annotations.py # tests/hermes_state/test_runtime_worker_compression_cleanup.py # tests/hermes_state/test_runtime_worker_compression_flush.py # tests/hermes_state/test_runtime_worker_context.py # tests/hermes_state/test_runtime_worker_history.py # tests/hermes_state/test_runtime_worker_lifecycle.py # tests/hermes_state/test_runtime_worker_metadata.py # tests/hermes_state/test_runtime_worker_operations.py # tests/hermes_state/test_runtime_worker_rotation_automation.py # tests/hermes_state/test_runtime_worker_title_retry.py # tests/hermes_state/test_runtime_worker_turn_cleanup.py # tests/hermes_state/test_runtime_worker_usage.py # tests/hermes_state/test_terminal_retirement.py # tests/tui_gateway/test_bot_relay_methods.py # tools/async_delegation.py # tools/bot_relay.py # tui_gateway/server.py # ui-tui/src/app/createGatewayEventHandler.ts # ui-tui/src/app/useSessionLifecycle.ts # ui-tui/src/app/useSubmission.ts # ui-tui/src/gatewayClient.ts # ui-tui/src/gatewayTypes.ts # ui-tui/src/types.ts # web/src/lib/api.ts # website/docs/developer-guide/gateway-classic-cli.md # website/docs/developer-guide/gateway-local-sessions.md # website/docs/user-guide/sessions.md
77 lines
4.3 KiB
Python
77 lines
4.3 KiB
Python
"""Constructor context is assignment-scoped and shares durable mutation receipts."""
|
|
import pytest
|
|
|
|
from agent.runtime_session_store import RuntimeSessionStore, WorkerPersistenceError
|
|
from hermes_state import SessionDB
|
|
from hermes_state_runtime import begin_runtime_epoch, mutate_worker_execution, register_worker_execution
|
|
|
|
|
|
def test_worker_context_preserves_authority_identity_and_prompt_receipts(tmp_path):
|
|
db = SessionDB(tmp_path / 'state.db')
|
|
try:
|
|
db.create_session('owned', 'subagent', parent_session_id=None, model='requested',
|
|
model_config={'_delegate_from': 'parent'}, system_prompt='prefix', profile_name='fixture')
|
|
db.create_session('foreign', 'cli', system_prompt='private')
|
|
epoch = begin_runtime_epoch(db, instance_id='fixture')
|
|
scope = dict(epoch=epoch, execution_id='worker', session_id='owned', generation=0)
|
|
register_worker_execution(db, **scope, kind='child', adoption_secret='test-secret')
|
|
store = RuntimeSessionStore(lambda method, **p: mutate_worker_execution(db, **p), scope, tmp_path / 'outbox')
|
|
try:
|
|
assert store.get_session('owned')['system_prompt'] == 'prefix'
|
|
with pytest.raises(WorkerPersistenceError, match='permission_denied'):
|
|
store.get_session('foreign')
|
|
store.update_system_prompt('owned', 'stable-prefix')
|
|
store.patch_session_model_config('owned', {'_usage_anchor': {'tokens': 23}})
|
|
assert store.get_session_model_config_value('owned', '_usage_anchor') == {'tokens': 23}
|
|
assert db.get_session_model_config_value('owned', '_delegate_from') == 'parent'
|
|
assert db.get_session('foreign')['system_prompt'] == 'private'
|
|
original = store.rpc
|
|
def lost_ack(method, **params):
|
|
original(method, **params)
|
|
raise TimeoutError('lost-ack')
|
|
store.rpc = lost_ack
|
|
with pytest.raises(TimeoutError, match='lost-ack'):
|
|
store.update_system_prompt('owned', 'durable-prefix')
|
|
store.rpc = original
|
|
assert len(store.retry_pending()) == 1
|
|
assert db.get_session('owned')['system_prompt'] == 'durable-prefix'
|
|
with pytest.raises(Exception, match='invalid_params'):
|
|
mutate_worker_execution(db, **scope, sequence=store.journal['next_sequence'],
|
|
operation='session.sidecars', payload={'patch': {'_delegate_from': 'foreign'}})
|
|
finally:
|
|
store.close()
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
def test_worker_constructor_restores_persisted_compressor_guards(tmp_path):
|
|
import time
|
|
from agent.context_compressor import ContextCompressor
|
|
db = SessionDB(tmp_path / 'state.db')
|
|
try:
|
|
db.create_session('owned', 'cli', model_config={'_proactive_prune_rearm_tokens': 1234})
|
|
db.set_compression_fallback_streak('owned', 4)
|
|
db.set_compression_ineffective_count('owned', 3)
|
|
deadline = time.time() + 3600
|
|
db.set_compression_recovery_deadline('owned', deadline)
|
|
db.record_compression_failure_cooldown('owned', deadline, 'fixture-cooldown')
|
|
epoch = begin_runtime_epoch(db, instance_id='fixture')
|
|
scope = dict(epoch=epoch, execution_id='worker', session_id='owned', generation=0)
|
|
register_worker_execution(db, **scope, kind='compute', adoption_secret='test-secret')
|
|
store = RuntimeSessionStore(lambda method, **p: mutate_worker_execution(db, **p), scope, tmp_path / 'outbox')
|
|
try:
|
|
compressor = ContextCompressor(model='fixture', config_context_length=100000, quiet_mode=True)
|
|
compressor.bind_session_state(store, 'owned')
|
|
assert compressor._fallback_compression_streak == 4
|
|
assert compressor._ineffective_compression_count == 3
|
|
assert compressor._anti_thrash_recovery_deadline == deadline
|
|
assert compressor._proactive_prune_rearm_tokens == 1234
|
|
assert store.get_compression_failure_cooldown_row('owned') == db.get_compression_failure_cooldown_row('owned')
|
|
assert store.get_compression_failure_cooldown('owned')['cooldown_until'] == deadline
|
|
db.set_session_title('owned', 'retained-title')
|
|
assert store.get_session_title('owned') == db.get_session_title('owned')
|
|
finally:
|
|
store.close()
|
|
finally:
|
|
db.close()
|