fix(goal): make cancellation a user-only control (#6667)
This commit is contained in:
1 parent
c927808aff
commit
12a86eaa86
33 files changed
+641
-63
No files matched your search
@@ -1368,7 +1368,7 @@ async def test_stop_during_committed_goal_checkpoint_settles_queued_command(
|
||||
if calls == 4:
|
||||
assert "list-1" in str(kwargs["messages"]) and "list-3" in str(kwargs["messages"])
|
||||
return LLMResponse(content=None, tool_calls=[ToolCallRequest(
|
||||
id="cancel", name="update_goal", arguments={"action": "cancel", "recap": "Stopped work."},
|
||||
id="block", name="update_goal", arguments={"action": "block", "recap": "Waiting for user input."},
|
||||
)])
|
||||
assert calls == 5
|
||||
return LLMResponse(content="handled later")
|
||||
@@ -1475,6 +1475,10 @@ async def test_stop_during_committed_goal_checkpoint_settles_queued_command(
|
||||
await asyncio.sleep(0)
|
||||
assert calls == 5 and loop.runner.run.await_count == 2
|
||||
assert msg.session_key not in loop._pending_queues
|
||||
saved = await loop.sessions.state.read(msg.session_key)
|
||||
assert saved.metadata[GOAL_STATE_KEY]["status"] == "blocked"
|
||||
assert [event.outcome for event in completed
|
||||
if event.context.metadata.get("message_id") == "independent-input"] == ["completed"]
|
||||
followup_outbound = []
|
||||
while loop.bus.outbound_size:
|
||||
followup_outbound.append(await loop.bus.consume_outbound())
|
||||
|
||||
@@ -528,3 +528,24 @@ async def test_goal_assembly_preserves_builtin_plugin_precedence(tmp_path, monke
|
||||
assert isinstance(loop.tools.get("create_goal"), CreateGoalTool)
|
||||
finally:
|
||||
await loop.aclose()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("status", ["active", "blocked"])
|
||||
async def test_agent_cannot_cancel_a_goal(tmp_path, status):
|
||||
sm = SessionManager(tmp_path)
|
||||
create, update, ctx = _tools(sm)
|
||||
try:
|
||||
await _execute(create, ctx, objective="Finish the task")
|
||||
if status == "blocked":
|
||||
await _execute(update, ctx, action="block", recap="Waiting for access")
|
||||
before = (await sm.state.read_header("websocket:c1")).metadata[GOAL_STATE_KEY]
|
||||
result = await _execute(update, ctx, action="cancel", recap="Cancelled by agent")
|
||||
assert result.is_error
|
||||
assert "complete, block, or replace" in result
|
||||
assert (await sm.state.read_header("websocket:c1")).metadata[GOAL_STATE_KEY] == before
|
||||
guidance = await create.runtime_context_provider()(_request_context(metadata={}))
|
||||
assert guidance is not None and "/cancel_goal" in guidance.content
|
||||
assert f"Goal ({status}):\nFinish the task" in guidance.content
|
||||
finally:
|
||||
await sm.state.aclose()
|
||||
Reference in new issue
Block a user