Repository navigation
fix: End a background job at its TaskStop result #1932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,9 @@ var ( | |
| // backgroundRe is Claude Code's result for a shell command it started in the background; | ||
| // the command's <task-notification> later names the same id. | ||
| backgroundRe = regexp.MustCompile(`^Command running in background with ID: ([A-Za-z0-9_-]+)`) | ||
| // stoppedRe is TaskStop's result. A stopped job gets no <task-notification>, so without it | ||
| // the job stays open and covers every later wait of its agent. | ||
| stoppedRe = regexp.MustCompile(`^\{"message":"Successfully stopped (?:task: |background command )([A-Za-z0-9_-]+)`) | ||
| ) | ||
|
|
||
| // failedFinish are the finish reasons of a reply that did not complete: none at all, a refusal | ||
|
|
@@ -126,6 +129,12 @@ func buildAgents(t *Timeline, events []model.SessionEvent) { | |
| t.Jobs = append(t.Jobs, Job{Agent: c.agent, ID: m[1], ToolUseID: r.ToolUseID, Start: c.req.At, Seq: c.req.Seq}) | ||
| } | ||
| } | ||
| if m := stoppedRe.FindStringSubmatch(r.Content); m != nil { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: CodeRabbit's point holds. The |
||
| if j, ok := jobs[m[1]]; ok && t.Jobs[j].End == nil { | ||
| at := c.req.At | ||
| t.Jobs[j].End = &at | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,7 +138,8 @@ type Tool struct { | |
| } | ||
|
|
||
| // Job is a background shell command: from the tool result that acknowledged it ("Command | ||
| // running in background with ID: …") to the <task-notification> naming that id. Its tool call | ||
| // running in background with ID: …") to the <task-notification> naming that id, or to the | ||
| // TaskStop result that stopped it. Its tool call | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: The reflow left a short line here ( |
||
| // ends at the acknowledgement, so without this the agent looks idle while the job runs. | ||
| type Job struct { | ||
| Agent string `json:"agent"` | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Require a TaskStop call before closing the job.
If a Bash call reads a file that starts with
{"message":"Successfully stopped task: bk42 (example)"}, this branch closes an openbk42job even though no TaskStop ran. The^anchor does not exclude file content at the start of a result. The false end also removes the running job from later timeline windows.Match
r.ToolUseIDto its tool call and requireName == "TaskStop"before applying this end condition. Add this negative case alongside the successful TaskStop test.