Add the operator kill switch, stop (A4)
CI / checks (push) Skipped
CI / checks (pull_request) Successful in 49s
CI / checks (push) Skipped
CI / checks (pull_request) Successful in 49s
`stop` could not have worked by adding the command alone. Planning turns, milestones and review responses ran synchronously on the thread that delivered the message, so the Matrix sync loop read nothing until the work finished. The state store was also opened on the main thread and used from the transport and poller threads, which SQLite refuses with its default same-thread check; the in-memory test transport never showed it. A single worker thread now runs every handler and owns the store: - The worker opens the store, so the same-thread check stays on and fails loudly if anything touches the store from elsewhere - Matrix messages are handed to the worker; pollers hand over and wait, so their cursor never passes an unhandled comment - A message that arrives during long work gets an immediate "busy; say 'stop' to halt" reply and is recorded, not applied later in a state the operator was not answering - Tests keep running inline through InlineWorker, which defers a job submitted from inside another as the real worker would queue it `stop` sets a shared Cancel flag straight from the transport's thread. The executor and delegation loops check it before each model call and between tool calls; the planner checks it before each turn. Calls left unrun get a result saying so, so the transcript still renders. A stopped delegation is discarded like a failed one. The orchestrator moves to AWAIT_INPUT and asks why the work was stopped. The reply is recorded for the model, and a stopped planning turn resumes with it as the answer. `stop` with nothing running says so and changes nothing; at a gate it is no longer taken as rejection feedback. Closes #40 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d2fe3d5642
commit
abb7fa0216
12 files changed
+887
-39
No files matched your search
@@ -4,6 +4,7 @@ from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from nisse_dev.cancel import STOPPED_RESULT, Cancel
|
||||
from nisse_dev.canonical import (
|
||||
AssistantText,
|
||||
CanonicalEvent,
|
||||
@@ -134,6 +135,46 @@ def test_abort_discards_the_branch_and_its_work(
|
||||
assert not (repo.root / "half-done.py").exists()
|
||||
|
||||
|
||||
def test_stop_discards_the_branch_and_settles_the_intent(
|
||||
store: StateStore, ws: Workspace, repo: GitRepo
|
||||
) -> None:
|
||||
# A4 stop is treated like a failure, not like an outage: the operator
|
||||
# stopped it for a reason, so nothing is kept for resuming.
|
||||
cancel = Cancel()
|
||||
client = ScriptedClient(
|
||||
[
|
||||
[call("write_file", path="half-done.py", content="oops")],
|
||||
[call("list_dir", path=".")],
|
||||
]
|
||||
)
|
||||
original = client.complete
|
||||
|
||||
def complete_then_stop(*args: Any, **kwargs: Any) -> list[CanonicalEvent]:
|
||||
produced = original(*args, **kwargs)
|
||||
if len(client.calls) == 2:
|
||||
cancel.set() # the operator says stop during turn 2's model call
|
||||
return produced
|
||||
|
||||
client.complete = complete_then_stop # type: ignore[method-assign]
|
||||
result = build(client, store, ws, repo, cancel=cancel).run(
|
||||
brief="b", branch="deleg-stop"
|
||||
)
|
||||
|
||||
assert result.status == "stopped"
|
||||
assert not result.usable
|
||||
assert repo.current_branch() == "main"
|
||||
assert not repo.branch_exists("deleg-stop")
|
||||
assert not (repo.root / "half-done.py").exists()
|
||||
assert store.pending_intents() == []
|
||||
# The unrun call still has a result, so the transcript renders.
|
||||
skipped = [
|
||||
e.event
|
||||
for e in store.read_events()
|
||||
if isinstance(e.event, ToolResult) and e.event.result == STOPPED_RESULT
|
||||
]
|
||||
assert len(skipped) == 1
|
||||
|
||||
|
||||
def test_turn_cap_is_hard(store: StateStore, ws: Workspace, repo: GitRepo) -> None:
|
||||
forever = [[call("list_dir", path=".")] for _ in range(20)]
|
||||
client = ScriptedClient(forever)
|
||||
|
||||
Reference in new issue
Block a user