b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
113 lines
3.6 KiB
Python
113 lines
3.6 KiB
Python
from types import SimpleNamespace
|
|
|
|
from agent.turn_finalizer import finalize_turn
|
|
|
|
|
|
class FakeAgent:
|
|
def __init__(self):
|
|
self.max_iterations = 90
|
|
self.iteration_budget = SimpleNamespace(remaining=10, used=1, max_total=90)
|
|
self.quiet_mode = True
|
|
self.model = "test-model"
|
|
self.provider = "test-provider"
|
|
self.base_url = ""
|
|
self.session_id = "sess-test"
|
|
self.context_compressor = SimpleNamespace(last_prompt_tokens=0)
|
|
self.session_input_tokens = 0
|
|
self.session_output_tokens = 0
|
|
self.session_cache_read_tokens = 0
|
|
self.session_cache_write_tokens = 0
|
|
self.session_reasoning_tokens = 0
|
|
self.session_prompt_tokens = 0
|
|
self.session_completion_tokens = 0
|
|
self.session_total_tokens = 0
|
|
self.session_estimated_cost_usd = 0
|
|
self.session_cost_status = "unknown"
|
|
self.session_cost_source = "test"
|
|
self._tool_guardrail_halt_decision = None
|
|
self._interrupt_message = None
|
|
self._response_was_previewed = True
|
|
self._skill_nudge_interval = 0
|
|
self._iters_since_skill = 0
|
|
self.valid_tool_names = []
|
|
self.persisted_messages = None
|
|
|
|
def _handle_max_iterations(self, messages, api_call_count):
|
|
raise AssertionError("not expected")
|
|
|
|
def _emit_status(self, *_args, **_kwargs):
|
|
pass
|
|
|
|
def _safe_print(self, *_args, **_kwargs):
|
|
pass
|
|
|
|
def _save_trajectory(self, *_args, **_kwargs):
|
|
pass
|
|
|
|
def _cleanup_task_resources(self, *_args, **_kwargs):
|
|
pass
|
|
|
|
def _drop_trailing_empty_response_scaffolding(self, messages):
|
|
pass
|
|
|
|
def _persist_session(self, messages, conversation_history):
|
|
self.persisted_messages = list(messages)
|
|
|
|
def _file_mutation_verifier_enabled(self):
|
|
return False
|
|
|
|
def _turn_completion_explainer_enabled(self):
|
|
return False
|
|
|
|
def _drain_pending_steer(self):
|
|
return None
|
|
|
|
def clear_interrupt(self):
|
|
pass
|
|
|
|
def _sync_external_memory_for_turn(self, **_kwargs):
|
|
pass
|
|
|
|
|
|
def test_final_response_closes_tool_tail_before_persistence(monkeypatch):
|
|
"""A recovered/previewed final response must be durable in session history.
|
|
|
|
Regression for turns where the caller receives a non-empty final_response,
|
|
but the message transcript still ends at a tool result. If persisted that
|
|
way, the next turn reloads a stale/malformed history and can appear to loop
|
|
because the assistant's visible final answer is missing from durable state.
|
|
"""
|
|
monkeypatch.setattr("hermes_cli.plugins.invoke_hook", lambda *_a, **_kw: [])
|
|
agent = FakeAgent()
|
|
messages = [
|
|
{"role": "user", "content": "do it"},
|
|
{
|
|
"role": "assistant",
|
|
"content": "I'll check.",
|
|
"tool_calls": [
|
|
{"id": "call-1", "function": {"name": "terminal", "arguments": "{}"}}
|
|
],
|
|
},
|
|
{"role": "tool", "tool_call_id": "call-1", "name": "terminal", "content": "ok"},
|
|
]
|
|
|
|
result = finalize_turn(
|
|
agent,
|
|
final_response="Done.",
|
|
api_call_count=2,
|
|
interrupted=False,
|
|
failed=False,
|
|
messages=messages,
|
|
conversation_history=[],
|
|
effective_task_id="task",
|
|
turn_id="turn",
|
|
user_message="do it",
|
|
original_user_message="do it",
|
|
_should_review_memory=False,
|
|
_turn_exit_reason="fallback_prior_turn_content",
|
|
)
|
|
|
|
assert result["messages"][-1] == {"role": "assistant", "content": "Done."}
|
|
assert agent.persisted_messages is not None
|
|
assert agent.persisted_messages[-1] == {"role": "assistant", "content": "Done."}
|