Repository navigation
Description
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
- UI cancel → Trinity gateway sends stop signal to Claude Code in the agent container.
- Claude Code catches it, writes a brief final response, exits with code 0.
- Container task-runner reports
[Task] ... completed successfully(because exit code is 0). - Trinity DB stores
status: successfor the execution. - 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_atadvances as if the run succeeded, suppressing recovery on the next cron tick. - Cost telemetry (
$1.30here) 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
fix(executions): block SUCCESS over CANCELLED so user cancel survives…
vybe commentedon Jun 1, 2026
Shipped in v0.6.0 (released via #998).
Release: v0.6.1 (#1171)
fix(executor): consume the terminal-write CAS verdict (#671/H4) + #1095…
feat(executions): propagate cancelled terminal status end-to-end (#679)…
Release: v0.8.0 (#1529)