Skip to content

Sessions left StateRunning by a crash report as in-progress forever #475

Closed

Description

@jhrozek

Summary

When the process running mecatl crashes mid-turn (confirmed cause: a full
machine crash), a session's persisted state snapshot is left at running
forever. /sessions (mecatui) and Service.ListSessions report the session
as still in-progress indefinitely, even across restarts, even if nobody ever
touches it again.

Confirmed repro

Session 645004ce13d2b8dd10adc384e161f786 (a background subagent child of an
interactive session), stored under
~/.local/state/mecatui/sessions/.../645004ce13d2b8dd10adc384e161f786.session.jsonl:

  • The last snapshot line (108/108) reads {"state":"running", ...}.
  • The corresponding .events.jsonl tail ends mid-flight on a subagent.tool
    Grep tool call event with no matching tool result ever recorded —
    consistent with the whole machine dying mid-tool-call.

Root cause

e.save(ctx, sess) inside engine/agent/loop.go persists the session's
state mid-turn, well before a turn/run completes. If the process dies
before a terminal transition (terminate/terminateComplete) runs, the last
durable snapshot is stuck at StateRunning forever.

The run-entry funnel loadAndReopen (internal/adapter/server/service.go)
already has recovery seams for the three terminal states —
completed → Reopen, cancelled → Interrupt, failed → Recover — but none
for running. The state machine's own doc comment
(engine/session/session.go) documents exactly three recovery seams and
never mentions one for StateRunning at all. Service.ListSessions also
reads the persisted state directly with no liveness check.

A working precedent exists but is scoped only to the scheduler:
internal/app/scheduler_reconcile.go's stale-fire reconciler detects a stale
running schedule-fire session and settles it — but it never sees ordinary
interactive or subagent sessions, which have no ScheduleStore row.

Practically, the stuck snapshot's trailing assistant message can carry
unanswered tool_use calls (the confirmed case), so a follow-up prompt on
that session risks a provider HTTP 400 from a dangling tool call, in addition
to the /sessions display bug.

Fix

Tracked by an internal design/implementation plan generalizing the
scheduler's reconcile pattern into a 4th session recovery seam plus a
liveness-aware sweep, correct under both single-process and
multi-replica/leased deployments (mecak8s + Redis).

Activity

  1. added 3 commits that reference this issue on Aug 13, 2026
    14d6e95
    6e15fe1
    f25a494
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