Skip to content

Cancelled executions reported as status=success in API and DB #671

Closed

Description

@pandore

Summary

A scheduled execution that is cancelled via the Trinity UI is recorded with status: "success" in the gateway DB and surfaced as success through the MCP API (list_recent_executions, get_execution_result). The cancel intent is never persisted onto the execution record.

This makes "did the work actually happen?" undetectable via the API, and silently advances the schedule's next_run_at as if the run had succeeded.

Repro on bdr-agent (port 2260)

Two consecutive incidents on schedule fYtR6WScyBPQDSmaDfgSJQ (Daily Lead Outreach, 0 7 * * 1-5 America/New_York):

Run Started (UTC) Duration Reported status Actual outcome
SA_Ln0AClqeK8qjW1fdLUg 2026-05-05 18:16:49 31:20 pending_retry Hit max_turns_task=50 mid-Step-4 enrichment. Container log: Claude Code max_turns reached: Reached maximum number of turns (50). ✅ Reported correctly.
2cId6kfgZsTl0x3cIV5OHQ 2026-05-05 18:49:11 10:30 success Cancelled by user via UI mid-run. No Slack ping posted, no sheet rows written, $1.30 spent. ❌ Reported as success.

Container-side evidence

For the cancelled retry, agent container logs (get_agent_logs bdr-agent) show only:

INFO:agent_server.routers.chat:[Task] Task 2cId6kfgZsTl0x3cIV5OHQ completed successfully
INFO:     172.28.0.5:37822 - "POST /api/task HTTP/1.1" 200 OK

No cancelled, no SIGTERM, no interrupted markers. Claude Code received the cancel signal, gracefully emitted a final response, and exited 0. The task-runner saw exit code 0 and reported completed successfully. Trinity's gateway recorded status: success.

Hypothesised flow

  1. UI cancel → Trinity gateway sends stop signal to Claude Code in the agent container.
  2. Claude Code catches it, writes a brief final response, exits with code 0.
  3. Container task-runner reports [Task] ... completed successfully (because exit code is 0).
  4. Trinity DB stores status: success for the execution.
  5. Cancel intent — known only to the gateway/UI at the moment of the click — is never written onto the execution record.

Why this matters

  • Operators cannot tell from the API whether deliverables (Slack post, sheet rows, etc.) were actually produced.
  • The schedule's next_run_at advances as if the run succeeded, suppressing recovery on the next cron tick.
  • Cost telemetry ($1.30 here) is recorded against a "successful" run, distorting per-run cost averages.
  • For agents that drive external side effects (Slack, Sheets, CRM), a wrongly-green status hides incomplete work from on-call.

Suggested fix

Minimum: when the gateway sends a cancel for an execution_id, write status: "cancelled" to the DB at the moment of the cancel and refuse to overwrite it later with the container's "success" report.

Defense in depth: plumb the cancel signal into the container-side task-runner so it logs [Task] ... cancelled by user rather than completed successfully, and forwards status=cancelled in its POST /api/task reply.

Adjacent issue worth flagging

This compounds the existing reader-thread bug (#issue-link-if-known): a pending_retry triggers an automatic retry, the retry inherits partial state, and if the operator cancels the retry, Trinity records the second success and the schedule advances. Net: a daily cron silently skips a day.

Happy to provide more diagnostics or a re-pro on a fresh agent if useful.

Activity

  1. added
    status-in-progress
    priority-p1
    type-bug
    on May 6, 2026
  2. self-assigned this
    on May 6, 2026
  3. added
    status-in-dev
    and removed
    status-in-progress
    on May 6, 2026
  4. vybe commented on Jun 1, 2026

    @vybe
    Contributor

    Shipped in v0.6.0 (released via #998).

  5. added
    complexity-low
    theme-reliability
    and removed
    status-in-dev
    on Jun 1, 2026
  6. added a commit that references this issue on Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-lowpriority-p1theme-reliabilitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions