Skip to content

POST /api/chat/runs: run stalls after a completed tool step and stays running forever; no timeout, no cancel #2022

Open

Description

@sweetmantech

Bug report: a headless run started via POST /api/chat/runs stops executing steps mid-task and stays running indefinitely, with no error and no way to cancel. Seen 2026-08-27 on a scheduled-report test; the same shape ("runs sit ~40 minutes between steps") was observed on 2026-08-25 runs and never filed. Business context, once: a customer's weekly report that stalls after collecting data never sends, and the customer sees nothing — not even a failure.

Summary

Run wrun_01M10C21FAQ52YYC42ATJ78E9F (chat ab6305ae-ef22-4d0b-bee5-f4d3c7946eed, account 7ad6c0e8…, model moonshotai/kimi-k3) started 00:55 UTC, executed 22 agent steps (95 tool-bash calls, all with state: output-available), and made its last LLM call at 01:12:36 (usage_events, 18 events, 630 credits). Its last persisted part is a completed bash call whose output is the computed medians for six artists — the agent was about to write the email. At 01:58 UTC GET /api/chat/runs/{runId} still returns "status":"running", completedAt: null; no new usage_events, no Apify runs, no email_send_log row for 46 minutes. The chat_messages row for the assistant turn was written at 01:07:08 and never updated after 01:12.

Steps to reproduce (or the trigger)

  1. POST /api/chat/runs with a long multi-step prompt (the roster-signal prompt: ~18 scrapes, ~100 tool calls, ~15 minutes of collect) on a Pro account.
  2. Poll GET /api/chat/runs/{runId} every 75 s.
  3. Observe running continuing past the point where usage_events and tool activity stop. Compare a healthy run of the near-identical prompt 30 minutes earlier: wrun_01M1077P4T4NC7PBKRH61DF74V, 22:55 → completed 00:15 (41 min), email delivered.

Expected vs actual

  • Expected: every agent step is followed by the next step within seconds; if a step cannot be scheduled or fails, the run ends failed with a reason, and GET /api/chat/runs/{runId} says so.
  • Actual: the run is silent for 46+ minutes with status: running. There is no cancel (DELETE /api/chat/runs/{id} → 405, /cancel and /stop → 404), so the only remedies are waiting or re-firing (which double-charges credits and, for a real task, double-sends if the stalled run later wakes).

Where to look

  • The durable workflow behind POST /api/chat/runs (api/app/api/chat/runs, lib/chat/runAgentWorkflow): what happens between a tool step's output-available and the next model step — a step-queue/scheduling gap, a lost continuation after a long tool call, or a step retry that never fires. The last tool call before the stall was a ~2 s python3 -c over a local JSON file, not a long-running scrape.
  • Whether the workflow has any step timeout at all; the prompt's own "35-minute" instruction is advisory and the platform enforced nothing.

Done when

  • A run whose next step does not start within N minutes (N to be chosen; 5 is generous) ends failed with error: "step timeout" and the status endpoint reflects it.
  • POST /api/chat/runs/{runId}/cancel exists and is documented, so an operator can stop a wedged run before re-firing.
  • Re-running the stalled prompt shape three times completes every time within the collect + write budget; wrun_01M10C21…'s stall does not recur across those runs.

Evidence

  • Run: wrun_01M10C21FAQ52YYC42ATJ78E9F · createdAt 2026-08-27T00:55Z · status running at 01:58Z.
  • Healthy control: wrun_01M1077P4T4NC7PBKRH61DF74V (22:55 → 00:15Z, delivered, Resend id on file).
  • usage_events for account 7ad6c0e8… after 00:54Z: 18 rows, last 01:12:36Z.
  • Apify runs after 00:54Z: 30, last 01:13:45Z (all SUCCEEDED).
  • Earlier sightings, unfiled: 2026-08-25 Secondhand Talent test runs sat ~40 minutes between steps before completing.

Activity

  1. sweetmantech commented on Aug 27, 2026

    @sweetmantech
    CollaboratorAuthor

    Update 2026-08-27 02:08 UTC: the run did resume on its own. wrun_01M10C21FAQ52YYC42ATJ78E9F sent its email at 02:00:xx UTC and now reports completed — total 65 minutes, of which ~48 minutes (01:12:36 → ~02:00) had no step execution at all. So the failure mode is a very long step-scheduling gap, not a permanent hang; the ask stands (a bounded gap, plus a cancel), and the re-fire I did at 01:59 (wrun_01M10F25GFDHWKC4D0HBKAEDTV) will now double-send, which is exactly the operator-side consequence of having no cancel.

  2. sidneyswift commented on Nov 6, 2026

    @sidneyswift
    Collaborator

    An operator can already stop a headless run with POST /api/chat/{chatId}/stop, using the chatId returned by POST /api/chat/runs. Runs claim the chat's active stream, so Stop cancels them.

    Left: no step timeout (a stalled run still reads running), and no run-id cancel route. Decide whether the chat Stop route is enough, and document it on the runs page if it is.

  3. sidneyswift commented on Nov 8, 2026

    @sidneyswift
    Collaborator

    Status: stalled scheduled runs are now detected after the fact (live), but the stall itself isn't fixed.

    recoupable/api#1236 checks every hour for scheduled runs that started 2–3 hours earlier and sent no email. A run that stalls shows up in the Telegram alert as no email (no send attempted; run executing), with its account and run ids.

    Still open: no step timeout inside the workflow, so the run itself still reads running, and there's no run-id cancel route.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions