Repository navigation
Description
Summary
Terminating a running execution stops the work and returns 200 {"status": "terminated"}, but no execution_terminate row is written to the audit log. Seen 3 of 3 times on an instance with a working model.
Found in v1.0.5 release testing, row B20 (audit — changed slice), build v1.0.5-rc2 (af465288a). The behaviour under test is the one added by PR #4035.
Steps
- On an instance where agents can run model turns, start a long turn on an agent you own, for example
POST /api/agents/{name}/taskwith a message that makes the agent runsleep 60. - While it is
running, callPOST /api/agents/{name}/executions/{execution_id}/terminate. - Read
GET /api/audit-log?limit=40(or the audit page) and look forevent_action = execution_terminateon that agent.
Expected
One audit row: event_type=execution, event_action=execution_terminate, the actor, the agent as target, and the execution id in details — as #4035 describes.
Actual
- Terminate answers
200 {"status":"terminated","execution_id":"…"}; a second terminate answers 404 (correct). - The original
/taskcaller receives503 "Execution cancelled by user". - The execution row ends as
cancelledwith an empty error text for a task turn, and asfailedfor a chat turn (POST /api/agents/{name}/chat). - The audit log has the agent's
create,circuit_breaker_resetandchat_startedrows around the same minute, and noexecution_terminaterow. Reproduced on two task turns and one chat turn.
A circuit-breaker reset on the same agent, same session, does write its audit row.
Likely cause (read from source, not confirmed by server logs)
The audit hook fires only when the terminate request wins the CANCELLED compare-and-swap:
src/backend/routers/chat.py—_audit_terminateis passed ason_ended(comment: "only when THIS request ended work … a repeat,already_finishedand every error arm write nothing").src/backend/services/chat_execution_service.py::_proxy_terminate_and_finalize—cancel_wonis set bydb.update_execution_status(... CANCELLED, error="Execution terminated by user"), and the hook readscancel_won.
When the turn was started by a synchronous request that is still in flight, that request sees the agent stop and writes the terminal status first. The terminate then loses the CAS, logs "lost the CAS", and skips the audit row — although it is the terminate that ended the work. The empty error text on the cancelled row (not "Execution terminated by user") is consistent with this.
On a stack without a model credential the turn dies before it can be terminated, so this path is easy to miss locally; in an earlier local run the terminate did win the CAS and the row was written.
Impact
A person stopping an agent's work is a security-relevant action that #4035 set out to make traceable. As built, whether it is recorded depends on which writer wins a race, and on a real instance the record is lost in the common case.
Suggested direction
Decide the audit write on "the agent answered terminated to this request" rather than on winning the status CAS (keep the CAS for the status row itself), or have the losing arm still record the terminate attempt with its outcome. Secondary: a terminated chat turn should end cancelled, like a task turn, not failed.
Not checked
- Queued and parked turns (different arms of
terminate_execution). - Whether builds before rc2 behave the same on an instance with a working model.
Activity
obasilakis commentedon Nov 13, 2026
/claim
github-actions commentedon Nov 13, 2026
Claimed by @obasilakis. Label
status-in-progressadded.Next steps:
feature/4475-<short-slug>Fixes #4475fix(audit): release the terminate audit claim when the audit write fa…
fix(audit): record a terminate that ended the turn when another write…