taskwatch: a task session that cannot finish is ended, and the task reads as failed #97

Merged
mikluko merged 3 commits from task-end into main 2026-11-16 11:10:55 +00:00
Owner

From the first foreman-to-worker run: a worker whose model fails every turn is nudged by gc three times, then nothing ends it and the foreman is never told. specs-18 accepted task_timeout, a failed task that does not read as done, gc.work_outcome, and the cheaper signal beside the clock.

  • internal/taskwatch: ends a task session after [agents.<n>] task_timeout and after failed_turns failed turns in a row (default 3 for an agent with the tool claim; negative is none). A failed turn is a JSON-RPC error answering a session/prompt, which is what the room renders as "The turn ended with an error"; an answer ends the run. Observed at Report; ended once.
  • gcwork.Fail: the task (claimed on the session's behalf with gc hook --claim when it never claimed) gets the reason in its notes, gc.work_outcome=abandoned and a close reason, then gc runtime drain-ack. The foreman's wait fires and result returns closed with outcome abandoned and the reason.
  • done sets gc.work_outcome=no-op. gc has four outcomes (shipped needs a commit and a branch, no-op, blocked, abandoned); a task answered with text and no commit has none of its own, so no-op, which gc's gate accepts without a commit. A choice, said here: say so if another reading is wanted.
  • HostService.ResultResponse.outcome. roomcity-5e's host tool result should say "failed" for abandoned and not read the notes as an answer.

Read from gc's source and the registry, not run on a cluster: that bd update --set-metadata, bd close --reason= and bd show --json's metadata map are as the stub has them.

From the first foreman-to-worker run: a worker whose model fails every turn is nudged by gc three times, then nothing ends it and the foreman is never told. specs-18 accepted `task_timeout`, a failed task that does not read as done, `gc.work_outcome`, and the cheaper signal beside the clock. - `internal/taskwatch`: ends a task session after `[agents.<n>] task_timeout` and after `failed_turns` failed turns in a row (default 3 for an agent with the tool `claim`; negative is none). A failed turn is a JSON-RPC error answering a `session/prompt`, which is what the room renders as "The turn ended with an error"; an answer ends the run. Observed at `Report`; ended once. - `gcwork.Fail`: the task (claimed on the session's behalf with `gc hook --claim` when it never claimed) gets the reason in its notes, `gc.work_outcome=abandoned` and a close reason, then `gc runtime drain-ack`. The foreman's `wait` fires and `result` returns closed with outcome `abandoned` and the reason. - `done` sets `gc.work_outcome=no-op`. gc has four outcomes (shipped needs a commit and a branch, no-op, blocked, abandoned); a task answered with text and no commit has none of its own, so no-op, which gc's gate accepts without a commit. A choice, said here: say so if another reading is wanted. - `HostService.ResultResponse.outcome`. roomcity-5e's host tool `result` should say "failed" for `abandoned` and not read the notes as an answer. Read from gc's source and the registry, not run on a cluster: that `bd update --set-metadata`, `bd close --reason=` and `bd show --json`'s `metadata` map are as the stub has them.
taskwatch: a task session that cannot finish is ended, and the task reads as failed
All checks were successful
test / changelog (pull_request) Successful in 6s
image / image (pull_request) Successful in 21s
test / go (pull_request) Successful in 1m20s
009fa5c6c2
Nothing ended a worker whose model refused it: gc's nudges to claim give
up, the task stays open and demand keeps the session, and the foreman is
never told. The server now ends it, after [agents.<n>] task_timeout and
after failed_turns turns in a row that end in an error response to
session/prompt (3 for an agent that has the tool claim): the task is
claimed on the session's behalf if it never claimed it, closed with
gc.work_outcome=abandoned and the reason in its notes, and gc ends the
session, so the foreman's wait fires and result says abandoned.

done sets gc.work_outcome=no-op, which asks for no commit, so that gc's
close gate has its record; gc has no outcome for work that was answered.
HostService.ResultResponse carries the outcome.

Assisted-By: Claude <noreply@anthropic.com>
Author
Owner

Read at 009fa5c. Green here under -race; internal/taskwatch and internal/gcwork twenty times with GOMAXPROCS=1.

Two things you read and did not run, run here:

  • The failed worker's stream in the city (worker-sa-wisp-sbd2z, ids and shapes only): four session/prompt to the agent (ids 3 to 6), each answered from the agent by a JSON-RPC error, -32000 "Authentication required". That is exactly what Observe counts; with the default it would have ended the session at the third.
  • bd 1.3.4, the image's, in a scratch store: bd update <id> --notes=... --set-metadata gc.work_outcome=no-op and bd close <id> --reason=... are taken, and bd show --json gives close_reason and metadata as an object.

The second found the first change:

1. Result cannot read a bead whose metadata holds anything but strings. bd types what --set-metadata is given:

bd update t-azb --set-metadata n=5 --set-metadata flag=true
bd show t-azb --json    "metadata":{"n":5,"flag":true,"gc.work_outcome":"no-op"}

Metadata map[string]string fails on that object, and Result then answers "bd show answered nothing that can be read" for a task that is closed and has its notes. The one work bead the city has (sa-6s6) holds only gc.routed_to, a string, so it does not bite today; it does the first time gc or a person puts a count or a flag on a task. Decode the values loosely (map[string]any or raw) and take gc.work_outcome when it is a string; a test with a number beside it.

2. Fail can abandon a task that is not the session's. With no claimed task in the session's mark, Fail claims one on its behalf. That is right for a session that never claimed. It is wrong for one that has finished: after done the mark is empty and the session is still Running until gc stops it, so a timeout that falls in that gap makes Fail run gc hook --claim, and whatever task waits in the pool for the next worker is taken and closed as abandoned, "timed out". The same pair, the other way round: the worker's done and the watch's Fail at one moment both run finish on one task, and the last bd update wins, which may be the reason over the worker's result.

Both go with one thing: Done, Claim and Fail of a session one at a time, and a record that the session's task is over (set where finish clears the claimed mark), on which Fail only asks gc to end the session. Tests for each: a Fail after done claims nothing; a Fail beside a done leaves the result.

3. The README. task_timeout and failed_turns are in no page. They belong in "The room's tools for an agent" (on main since #94), beside tools: the two keys, the default of three for an agent with claim, what a failed turn is, and what the foreman then sees (wait fires, result is closed with outcome abandoned and the reason as its notes).

As you see fit:

  • turns and ended keep an entry for every session name the server ever saw. Drop a session's when it is ended.
  • The start of a session the watch ended is recorded "stop", as any stop gc asks for. If the transcript should say why, that is EndAs with a how of its own; say in the pull request if it is left.

no-op for done: no objection from the code's side; it is specs-18's to accept, and I pass it on.

Rebase over main (12763da is Release 0.10.0's parent; the changelog's Added you add to is now under 0.10.0, and your line belongs under Unreleased).

Read at 009fa5c. Green here under `-race`; `internal/taskwatch` and `internal/gcwork` twenty times with `GOMAXPROCS=1`. Two things you read and did not run, run here: - The failed worker's stream in the city (`worker-sa-wisp-sbd2z`, ids and shapes only): four `session/prompt` to the agent (ids 3 to 6), each answered from the agent by a JSON-RPC error, `-32000 "Authentication required"`. That is exactly what `Observe` counts; with the default it would have ended the session at the third. - bd 1.3.4, the image's, in a scratch store: `bd update <id> --notes=... --set-metadata gc.work_outcome=no-op` and `bd close <id> --reason=...` are taken, and `bd show --json` gives `close_reason` and `metadata` as an object. The second found the first change: **1. `Result` cannot read a bead whose metadata holds anything but strings.** bd types what `--set-metadata` is given: bd update t-azb --set-metadata n=5 --set-metadata flag=true bd show t-azb --json "metadata":{"n":5,"flag":true,"gc.work_outcome":"no-op"} `Metadata map[string]string` fails on that object, and `Result` then answers "bd show answered nothing that can be read" for a task that is closed and has its notes. The one work bead the city has (`sa-6s6`) holds only `gc.routed_to`, a string, so it does not bite today; it does the first time gc or a person puts a count or a flag on a task. Decode the values loosely (`map[string]any` or raw) and take `gc.work_outcome` when it is a string; a test with a number beside it. **2. `Fail` can abandon a task that is not the session's.** With no claimed task in the session's mark, `Fail` claims one on its behalf. That is right for a session that never claimed. It is wrong for one that has finished: after `done` the mark is empty and the session is still Running until gc stops it, so a timeout that falls in that gap makes `Fail` run `gc hook --claim`, and whatever task waits in the pool for the next worker is taken and closed as abandoned, "timed out". The same pair, the other way round: the worker's `done` and the watch's `Fail` at one moment both run `finish` on one task, and the last `bd update` wins, which may be the reason over the worker's result. Both go with one thing: `Done`, `Claim` and `Fail` of a session one at a time, and a record that the session's task is over (set where `finish` clears the claimed mark), on which `Fail` only asks gc to end the session. Tests for each: a `Fail` after `done` claims nothing; a `Fail` beside a `done` leaves the result. **3. The README.** `task_timeout` and `failed_turns` are in no page. They belong in "The room's tools for an agent" (on main since #94), beside `tools`: the two keys, the default of three for an agent with `claim`, what a failed turn is, and what the foreman then sees (`wait` fires, `result` is closed with outcome `abandoned` and the reason as its notes). As you see fit: - `turns` and `ended` keep an entry for every session name the server ever saw. Drop a session's when it is ended. - The start of a session the watch ended is recorded "stop", as any stop gc asks for. If the transcript should say why, that is `EndAs` with a `how` of its own; say in the pull request if it is left. `no-op` for `done`: no objection from the code's side; it is specs-18's to accept, and I pass it on. Rebase over main (12763da is `Release 0.10.0`'s parent; the changelog's `Added` you add to is now under 0.10.0, and your line belongs under Unreleased).
mikluko force-pushed task-end from 009fa5c6c2
All checks were successful
test / changelog (pull_request) Successful in 6s
image / image (pull_request) Successful in 21s
test / go (pull_request) Successful in 1m20s
to 19a675de12
All checks were successful
test / changelog (pull_request) Successful in 6s
image / image (pull_request) Successful in 19s
test / go (pull_request) Successful in 1m21s
2026-11-16 11:04:40 +00:00
Compare
Author
Owner

Read at 19a675d. Green here under -race, internal/taskwatch and internal/gcwork twenty times with GOMAXPROCS=1. The three changes are in and hold: metadata decoded loosely, one lock for a session over Claim, Done and Fail, the over mark (a start clears a session's marks, so it does not outlive the start it speaks of), the README.

One more, found by running what finish now does:

done with a long first line that is not ASCII cannot close its task. firstLine cuts at byte 200, and a cut inside a character makes the close reason invalid UTF-8, which bd's store refuses. On bd 1.3.4, a reason of 199 a and then я, cut at 200:

bd close t-kp5 --reason="Done: aaa…a\xd1..."
Error closing t-kp5: failed to close issue: Error 1105: Incorrect string value: '\xD1...' for column '<unknown>' at row 0

By then bd update has stored the notes, the close fails, Done returns the error to the worker, and every repetition fails the same way: the task stays open and claimed. The owner writes Russian, so a worker's result will be Cyrillic sooner than later, and half of all cuts in Cyrillic land inside a character. Cut by runes (and the reason of Fail, which carries the model's error text, goes through the same close: keep it valid too). A test with a first line of 300 Cyrillic letters, asserting the reason is valid UTF-8.

As you see fit: in finish, set the over mark before clearing the claimed one. Between the two writes as they stand, a failure leaves a session with neither, which is the state Fail takes for "never claimed".

Rebase over main 547f41b: #95 added ### Added under Unreleased and a key to [agents.<name>].

Read at 19a675d. Green here under `-race`, `internal/taskwatch` and `internal/gcwork` twenty times with `GOMAXPROCS=1`. The three changes are in and hold: metadata decoded loosely, one lock for a session over Claim, Done and Fail, the over mark (a start clears a session's marks, so it does not outlive the start it speaks of), the README. One more, found by running what `finish` now does: **`done` with a long first line that is not ASCII cannot close its task.** `firstLine` cuts at byte 200, and a cut inside a character makes the close reason invalid UTF-8, which bd's store refuses. On bd 1.3.4, a reason of 199 `a` and then `я`, cut at 200: bd close t-kp5 --reason="Done: aaa…a\xd1..." Error closing t-kp5: failed to close issue: Error 1105: Incorrect string value: '\xD1...' for column '<unknown>' at row 0 By then `bd update` has stored the notes, the close fails, `Done` returns the error to the worker, and every repetition fails the same way: the task stays open and claimed. The owner writes Russian, so a worker's result will be Cyrillic sooner than later, and half of all cuts in Cyrillic land inside a character. Cut by runes (and the reason of `Fail`, which carries the model's error text, goes through the same close: keep it valid too). A test with a first line of 300 Cyrillic letters, asserting the reason is valid UTF-8. As you see fit: in `finish`, set the over mark before clearing the claimed one. Between the two writes as they stand, a failure leaves a session with neither, which is the state `Fail` takes for "never claimed". Rebase over main 547f41b: #95 added `### Added` under Unreleased and a key to `[agents.<name>]`.
mikluko force-pushed task-end from 19a675de12
All checks were successful
test / changelog (pull_request) Successful in 6s
image / image (pull_request) Successful in 19s
test / go (pull_request) Successful in 1m21s
to 18bcb700a1
All checks were successful
test / changelog (pull_request) Successful in 4s
image / image (pull_request) Successful in 16s
test / go (pull_request) Successful in 1m8s
2026-11-16 11:08:07 +00:00
Compare
mikluko deleted branch task-end 2026-11-16 11:10:55 +00:00
Commenting is not possible because the repository is archived.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
mikluko/roomcity!97
No description provided.