Repository navigation
Description
What happened
Found by reading the code on dev@ca8e437b7, not seen in the field yet.
When the desktop app quits, markQuit in cmd/codeaf/appquit.go decides which open chats were mid-work and should read "Interrupted" with Continue after the app opens again. It keeps one tasks slice for every agent in the loop and tests len(tasks) > 0 for each agent. That slice is never reset between agents:
var resume, tasks []string
...
for _, a := range agents {
...
b.locked(func() {
for key, task := range live.tasks {
if task.State == appwire.TaskRunning {
tasks = append(tasks, key)
}
}
})
if running || len(tasks) > 0 {
resume = append(resume, id)
}So once one chat has a running task, every chat after it in the list goes into ResumeAfterQuit, even when it is idle and has no tasks. interruptAfterQuit then marks each of those chats Interrupted with Reply: false and no tasks. After a restart the person sees an idle chat read "Interrupted" with Continue, and there is nothing in it to continue.
Replication
Deterministic (no model). This is a unit-level replication, because the wrong value is the state file markQuit writes:
- Build an
appBackendwith two assembled agents. Agent A is idle and has one task inappwire.TaskRunning. Agent B comes after A in the slice, is idle and has no tasks. The fakes incmd/codeaf/appquit_live_test.goalready build assembled and live-only agents. - Call
b.markQuit([]*appAgent{a, b}). - Read the state file's
ResumeAfterQuit.
Today it holds both A's id and B's id. It should hold only A's.
Field. Open two chats in the desktop app. Start a task in the first chat (a propose_task that is still running). Leave the second chat idle. Quit the app and reopen it. The second chat reads "Interrupted" · Continue. The bug only fires when the chat with the running task comes earlier in the app's agent list than the idle one.
Where
markQuit in cmd/codeaf/appquit.go; search for len(tasks) > 0. The marks are written by interruptAfterQuit in the same file.
The fix
Count running tasks per agent. Keep a per-agent count or slice for the running || <this agent has a running task> test, and keep appending to the shared tasks list, which still goes into QuitTasks. A chat is marked Interrupted after a quit only when that chat was mid-reply or had a task of its own running.
Acceptance
- e2e: In the keyless automations/desktop e2e, open two chats against the scripted model endpoint. Start a long task in the first chat and leave the second idle. Quit and reopen. Assert that the first chat shows "Interrupted" and the second chat's footer does not.
- Unit: For agents A (a running task) and B (idle, listed after A),
markQuitwritesResumeAfterQuit == [A]andQuitTasks == [A's task]. The control case: with B listed before A, the result is the same. - No manual change is needed. "Quitting the desktop app mid-reply" in
internal/manual/chat/running-from-the-terminal.mdalready describes the right behaviour.
Activity