/stop reports success and genuinely does stop the container, but the task row is never updated, so the dashboard, /status and task_list all show the task as running indefinitely. Observed 2026-08-24: task #3 was stopped and was still displayed as running the following day.
Root cause
Daemon.runViaAgent (internal/daemon/daemon.go:1010-1100) writes its terminal state with the SAME context that was just cancelled, and discards the result:
store.Transition writes through tx.ExecContext(ctx, ...) (internal/store/store.go:358-365), so on a cancelled context the write fails immediately and the _ = throws the error away. The row stays running with nothing left to correct it.
There are SIX such writes in runViaAgent (grant unavailable, grant failed, encode failed, request failed, decode failed, run failed). Every one is unreachable in exactly the situation it exists for -- cancellation -- because cancellation is what invalidates the context it writes with.
cleanupTerminalTaskWorktree (daemon.go:897) has the same defect: it re-reads via d.Store.TaskByID(ctx, ...) and returns early on error, so a cancelled task also skips worktree cleanup.
Why the container is NOT the problem
Pool.Release already gets this right and is the precedent for the fix: it detaches deliberately with context.WithTimeout(context.WithoutCancel(ctx), 10*time.Second) and documents why -- "the most important reason a task is on its way out is that it was cancelled... Teardown is cleanup, so it gets its own deadline rather than inheriting the caller's cancellation." So teardown works; only state recording is broken.
Contributing factor
StoreTaskController.StopRunning (internal/gateway/tasks.go:227) deliberately writes no terminal state, documented as "A stopped task unwinds through its own error paths and lands wherever that leaves it, usually parked". That assumption is now false: the unwind path cannot record anything, so nothing lands. Note CancelChatTask (the /cancel path) DOES write state explicitly and is unaffected.
Steps to Reproduce
Start an autonomous task so it reaches running with a live archie-agent container.
Issue /stop from chat (or Stop from the dashboard).
Observe the container is stopped and removed by Pool.Release.
Observe the task row is still status = running in the store, in task_list, in /status and on the dashboard.
Wait: nothing ever corrects it. Only a daemon restart re-queues it, via the crash-recovery path that re-queues tasks left running.
Acceptance Criteria
Terminal state writes on the cancellation path use a context that survives cancellation (context.WithoutCancel, with its own timeout, mirroring Pool.Release); their errors are logged rather than discarded; a stopped task reaches a terminal state observable in the store, task_list and the dashboard without a daemon restart; cleanupTerminalTaskWorktree also runs for a cancelled task; a regression test cancels a task mid-run and asserts the row is no longer running, and fails against the current code.
Notes
Timeline correction: the task was observed still 'running' roughly ONE HOUR after /stop, not a day (an earlier note said a day; that was inferred wrongly from a date rollover). An hour is if anything stronger evidence, since no plausible refresh interval covers it.
Chronology correction: the agent's pre-/stop task_list reading 'still marked running' is NOT evidence of this bug -- nothing had stopped the task at that point, so it was reporting correctly. The genuine evidence is (a) the row still 'running' an hour after /stop, and (b) the code path itself, which predicts exactly that and was found by reading runViaAgent rather than from the transcript.
Scope note: this bug explains a stale ROW only. It does not explain a still-live container, because container.Pool.Release deliberately detaches from the cancelled context and does tear down. If a container is ever found alive after /stop, that is a SEPARATE defect, not this one.
Close reason
Closed
Imported from beads archie-core-0dic · GitHub #628 · type bug · priority P1 · created 2026-08-24 · closed 2026-08-24
/stop reports success and genuinely does stop the container, but the task row is never updated, so the dashboard, /status and task_list all show the task as running indefinitely. Observed 2026-08-24: task #3 was stopped and was still displayed as running the following day.
## Root cause
`Daemon.runViaAgent` (internal/daemon/daemon.go:1010-1100) writes its terminal state with the SAME context that was just cancelled, and discards the result:
reply, err := d.requestTaskRun(ctx, task.ID, data) // returns ctx.Err() on /stop
if err != nil {
_ = d.Store.Transition(ctx, task.ID, store.StatusRunning, store.StatusParked, "taskrun request failed: "+err.Error())
`store.Transition` writes through `tx.ExecContext(ctx, ...)` (internal/store/store.go:358-365), so on a cancelled context the write fails immediately and the `_ =` throws the error away. The row stays `running` with nothing left to correct it.
There are SIX such writes in runViaAgent (grant unavailable, grant failed, encode failed, request failed, decode failed, run failed). Every one is unreachable in exactly the situation it exists for -- cancellation -- because cancellation is what invalidates the context it writes with.
`cleanupTerminalTaskWorktree` (daemon.go:897) has the same defect: it re-reads via `d.Store.TaskByID(ctx, ...)` and returns early on error, so a cancelled task also skips worktree cleanup.
## Why the container is NOT the problem
`Pool.Release` already gets this right and is the precedent for the fix: it detaches deliberately with `context.WithTimeout(context.WithoutCancel(ctx), 10*time.Second)` and documents why -- "the most important reason a task is on its way out is that it was cancelled... Teardown is cleanup, so it gets its own deadline rather than inheriting the caller's cancellation." So teardown works; only state recording is broken.
## Contributing factor
`StoreTaskController.StopRunning` (internal/gateway/tasks.go:227) deliberately writes no terminal state, documented as "A stopped task unwinds through its own error paths and lands wherever that leaves it, usually parked". That assumption is now false: the unwind path cannot record anything, so nothing lands. Note `CancelChatTask` (the /cancel path) DOES write state explicitly and is unaffected.
## Steps to Reproduce
1. Start an autonomous task so it reaches `running` with a live archie-agent container.
2. Issue `/stop` from chat (or Stop from the dashboard).
3. Observe the container is stopped and removed by Pool.Release.
4. Observe the task row is still `status = running` in the store, in `task_list`, in `/status` and on the dashboard.
5. Wait: nothing ever corrects it. Only a daemon restart re-queues it, via the crash-recovery path that re-queues tasks left `running`.
## Acceptance Criteria
Terminal state writes on the cancellation path use a context that survives cancellation (`context.WithoutCancel`, with its own timeout, mirroring Pool.Release); their errors are logged rather than discarded; a stopped task reaches a terminal state observable in the store, task_list and the dashboard without a daemon restart; cleanupTerminalTaskWorktree also runs for a cancelled task; a regression test cancels a task mid-run and asserts the row is no longer `running`, and fails against the current code.
### Notes
Timeline correction: the task was observed still 'running' roughly ONE HOUR after /stop, not a day (an earlier note said a day; that was inferred wrongly from a date rollover). An hour is if anything stronger evidence, since no plausible refresh interval covers it.
Chronology correction: the agent's pre-/stop task_list reading 'still marked running' is NOT evidence of this bug -- nothing had stopped the task at that point, so it was reporting correctly. The genuine evidence is (a) the row still 'running' an hour after /stop, and (b) the code path itself, which predicts exactly that and was found by reading runViaAgent rather than from the transcript.
Scope note: this bug explains a stale ROW only. It does not explain a still-live container, because container.Pool.Release deliberately detaches from the cancelled context and does tear down. If a container is ever found alive after /stop, that is a SEPARATE defect, not this one.
### Close reason
Closed
---
_Imported from beads `archie-core-0dic` · GitHub #628 · type bug · priority P1 · created 2026-08-24 · closed 2026-08-24_
sam
added the highbug labels 2026-10-27 13:36:38 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
/stop reports success and genuinely does stop the container, but the task row is never updated, so the dashboard, /status and task_list all show the task as running indefinitely. Observed 2026-08-24: task #3 was stopped and was still displayed as running the following day.
Root cause
Daemon.runViaAgent(internal/daemon/daemon.go:1010-1100) writes its terminal state with the SAME context that was just cancelled, and discards the result:store.Transitionwrites throughtx.ExecContext(ctx, ...)(internal/store/store.go:358-365), so on a cancelled context the write fails immediately and the_ =throws the error away. The row staysrunningwith nothing left to correct it.There are SIX such writes in runViaAgent (grant unavailable, grant failed, encode failed, request failed, decode failed, run failed). Every one is unreachable in exactly the situation it exists for -- cancellation -- because cancellation is what invalidates the context it writes with.
cleanupTerminalTaskWorktree(daemon.go:897) has the same defect: it re-reads viad.Store.TaskByID(ctx, ...)and returns early on error, so a cancelled task also skips worktree cleanup.Why the container is NOT the problem
Pool.Releasealready gets this right and is the precedent for the fix: it detaches deliberately withcontext.WithTimeout(context.WithoutCancel(ctx), 10*time.Second)and documents why -- "the most important reason a task is on its way out is that it was cancelled... Teardown is cleanup, so it gets its own deadline rather than inheriting the caller's cancellation." So teardown works; only state recording is broken.Contributing factor
StoreTaskController.StopRunning(internal/gateway/tasks.go:227) deliberately writes no terminal state, documented as "A stopped task unwinds through its own error paths and lands wherever that leaves it, usually parked". That assumption is now false: the unwind path cannot record anything, so nothing lands. NoteCancelChatTask(the /cancel path) DOES write state explicitly and is unaffected.Steps to Reproduce
runningwith a live archie-agent container./stopfrom chat (or Stop from the dashboard).status = runningin the store, intask_list, in/statusand on the dashboard.running.Acceptance Criteria
Terminal state writes on the cancellation path use a context that survives cancellation (
context.WithoutCancel, with its own timeout, mirroring Pool.Release); their errors are logged rather than discarded; a stopped task reaches a terminal state observable in the store, task_list and the dashboard without a daemon restart; cleanupTerminalTaskWorktree also runs for a cancelled task; a regression test cancels a task mid-run and asserts the row is no longerrunning, and fails against the current code.Notes
Timeline correction: the task was observed still 'running' roughly ONE HOUR after /stop, not a day (an earlier note said a day; that was inferred wrongly from a date rollover). An hour is if anything stronger evidence, since no plausible refresh interval covers it.
Chronology correction: the agent's pre-/stop task_list reading 'still marked running' is NOT evidence of this bug -- nothing had stopped the task at that point, so it was reporting correctly. The genuine evidence is (a) the row still 'running' an hour after /stop, and (b) the code path itself, which predicts exactly that and was found by reading runViaAgent rather than from the transcript.
Scope note: this bug explains a stale ROW only. It does not explain a still-live container, because container.Pool.Release deliberately detaches from the cancelled context and does tear down. If a container is ever found alive after /stop, that is a SEPARATE defect, not this one.
Close reason
Closed
Imported from beads
archie-core-0dic· GitHub #628 · type bug · priority P1 · created 2026-08-24 · closed 2026-08-24