Skip to content

Terminating a running execution writes no audit row when the in-flight request wins the status race (v1.0.5-rc2, B20) #4475

Closed

Description

@pavshulin

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

  1. On an instance where agents can run model turns, start a long turn on an agent you own, for example POST /api/agents/{name}/task with a message that makes the agent run sleep 60.
  2. While it is running, call POST /api/agents/{name}/executions/{execution_id}/terminate.
  3. Read GET /api/audit-log?limit=40 (or the audit page) and look for event_action = execution_terminate on 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 /task caller receives 503 "Execution cancelled by user".
  • The execution row ends as cancelled with an empty error text for a task turn, and as failed for a chat turn (POST /api/agents/{name}/chat).
  • The audit log has the agent's create, circuit_breaker_reset and chat_started rows around the same minute, and no execution_terminate row. 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_terminate is passed as on_ended (comment: "only when THIS request ended work … a repeat, already_finished and every error arm write nothing").
  • src/backend/services/chat_execution_service.py::_proxy_terminate_and_finalize — cancel_won is set by db.update_execution_status(... CANCELLED, error="Execution terminated by user"), and the hook reads cancel_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

  1. added
    priority-p2
    type-bug
    theme-security
    on Nov 11, 2026
  2. obasilakis commented on Nov 13, 2026

    @obasilakis
    Contributor

    /claim

  3. added
    status-in-progress
    on Nov 13, 2026
  4. github-actions commented on Nov 13, 2026

    @github-actions

    Claimed by @obasilakis. Label status-in-progress added.

    Next steps:

    1. Create branch: feature/4475-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #4475
  5. added
    status-in-dev
    and removed
    status-in-progress
    on Nov 13, 2026
  6. removed
    status-in-dev
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority-p2theme-securitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions