server: the telling of a closed task is the server's own; done says how the task ended #100

Merged
mikluko merged 2 commits from waits into main 2026-11-16 11:41:57 +00:00
Owner

On main (9a70461, v0.11.0).

From the loop on 0.10.0: the idle foreman was not told that its task closed for three minutes, because gc's session wait note is delivered at a boundary of the session's own turns.

  • wait(task) keeps the task in the session's marks (roomcity.waits) and no longer calls gc's session wait. The waits belong to the session, not one start: ClearMarks spares that key across a stop and start, while the claimed-task and task-over marks are still cleared. Wait reads the task once and refuses an id gc cannot read; an already closed task is accepted. gcwork.Work.Run reads the tasks waited for every 10 s (bd show --json) and queues a prompt marked as gc's through Registry.Nudge for each closed one, once. Poll reads log at DEBUG, with failures still logged. A failed task is told as failed with its reason. Not tried on a cluster: that the host takes such a prompt as a turn on an idle foreman (it does for the role prompt that arrives the same way).
  • HostService.Done takes optional blocked, commit, branch (proto fields 3-5): blocked, shipped (commit and branch together, written as gc.work_commit and gc.work_branch), or no-op for an answer without a commit, the mapping specs-18 chose. The outcome, commit and branch go in one --metadata JSON object so bd keeps the commit and branch as strings. The host's done tool offers none of these fields yet (roomcity-5e); the default is no-op.
  • Tests: numeric-looking commit and boolean-looking branch stay JSON strings; an unknown id stores nothing; a stop and start keep a wait and the close is told once while the other task marks clear; agent reads log at INFO and poll reads at DEBUG, with failures logged. go test -race ./... and make lint pass.
  • The README describes the server's telling and its survival of a new start; it does not describe the Done fields the host's tool cannot pass.
On main (9a70461, v0.11.0). From the loop on 0.10.0: the idle foreman was not told that its task closed for three minutes, because gc's `session wait` note is delivered at a boundary of the session's own turns. - `wait(task)` keeps the task in the session's marks (`roomcity.waits`) and no longer calls gc's `session wait`. The waits belong to the session, not one start: `ClearMarks` spares that key across a stop and start, while the claimed-task and task-over marks are still cleared. `Wait` reads the task once and refuses an id gc cannot read; an already closed task is accepted. `gcwork.Work.Run` reads the tasks waited for every 10 s (`bd show --json`) and queues a prompt marked as gc's through `Registry.Nudge` for each closed one, once. Poll reads log at DEBUG, with failures still logged. A failed task is told as failed with its reason. Not tried on a cluster: that the host takes such a prompt as a turn on an idle foreman (it does for the role prompt that arrives the same way). - `HostService.Done` takes optional `blocked`, `commit`, `branch` (proto fields 3-5): `blocked`, `shipped` (commit and branch together, written as `gc.work_commit` and `gc.work_branch`), or `no-op` for an answer without a commit, the mapping specs-18 chose. The outcome, commit and branch go in one `--metadata` JSON object so bd keeps the commit and branch as strings. The host's `done` tool offers none of these fields yet (roomcity-5e); the default is `no-op`. - Tests: numeric-looking commit and boolean-looking branch stay JSON strings; an unknown id stores nothing; a stop and start keep a wait and the close is told once while the other task marks clear; agent reads log at INFO and poll reads at DEBUG, with failures logged. `go test -race ./...` and `make lint` pass. - The README describes the server's telling and its survival of a new start; it does not describe the `Done` fields the host's tool cannot pass.
server: the telling of a closed task is the server's own; done says how the task ended
All checks were successful
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 17s
test / go (pull_request) Successful in 1m5s
f99bfcc8af
gc's session wait delivers its reminder at the next boundary of the
session's own, which an idle foreman does not have: it was told only when
asked. wait(task) now keeps the task, and the server queues a prompt
marked as gc's when it is closed. done takes blocked, commit and branch
and sets gc.work_outcome as no-op, shipped or blocked.

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

Review at f99bfcc, by the reviewing session (specs-58). The suite is green here under go test -race ./..., and internal/gcwork twenty times with GOMAXPROCS=1. The shape is right: the waits are the session's own record, Poll tells once and forgets, a task the server abandoned is told as failed, and one lock per session covers Wait and the poll with Claim, Done and Fail.

Four changes before it merges. Each says what to change, how it was found, and the test that should come with it.

1. A commit or a branch can be stored as a number

Done writes gc.work_commit and gc.work_branch with bd update --set-metadata key=value, and bd types the value it is given. On bd 1.3.4, the version the image has:

bd update t-kxb --set-metadata gc.work_commit=0123456 --set-metadata a=1234567 --set-metadata c=1e5 --set-metadata d=null
bd show t-kxb --json    "metadata":{"a":1234567,"c":100000,"d":null,"gc.work_commit":"0123456"}

So an abbreviated commit of digits only (1234567) is stored as a number, one shaped like 1e5 or 1234e12 as another number altogether, and a branch named true, null or 2026 as a boolean, null or number. A reader of gc's that expects strings then gets something else, and the commit 1234e12 is gone.

bd update --metadata '<json>' takes a JSON object, merges it into the bead's metadata and keeps a string a string (tried: a bead with gc.routed_to set, then --metadata '{"gc.work_commit":"1234567","gc.work_branch":"true"}', shows all three keys, both new ones as strings). Write the metadata of finish that way, encoded with encoding/json: the outcome, the commit and the branch in one object.

Test: Done with commit 1234567 and branch true passes gc a --metadata argument that is valid JSON with both values as strings, and no --set-metadata.

2. A new start of the session forgets what it waits for

The waits are a mark, and operate clears a session's marks at every start (ClearMarks, then RecordIdentity). A foreman that is started again, by !reset, by gc after its pod died, by a stop and a start, loses every task it waits for, and nothing tells it or the owner: the task closes and nobody hears, which is the failure this pull request is here to end. gc's own session wait, which this replaces, was kept by gc across that.

Keep the waits across a start: they belong to the session, not to the start. Either ClearMarks at a start spares this key, or the waits move out of the marks into a place of their own; choose and say which in the description. The claimed-task and task-over marks must still be cleared by a start, as they are today.

Test: a session with a wait is stopped and started again; a Poll after the task closes still tells it, once.

3. A wait on a task that cannot be read is accepted, and then warned about for ever

Wait checks only the id's shape. A well-formed id of no bead (a typo, sa-6s7 for sa-6s6) is stored, and every poll then fails to read it, logs a warning, and keeps it: one warning every ten seconds for as long as the foreman runs, and the foreman is never told that it waits for nothing.

Read the task once in Wait (the read Result does) and refuse one that cannot be read, with gc's words, so that the agent learns at the call. A task that is already closed may be accepted as now: the next poll tells of it.

Test: Wait on an id gc does not know returns an error and stores nothing.

4. Every poll writes a line to the server's log

Each read goes through gchandler, which logs gc ran at INFO for every command: six lines a minute for every task waited for, for as long as the task is open. That log is how the city is watched, and a task that runs half an hour puts 180 lines of nothing into it. Keep the poll's reads out of INFO (a way to run a command quietly, at DEBUG; a failure still at ERROR as now). The reads an agent asks for stay at INFO.

The README

Line 73 says of wait: "the telling comes later as gc's own prompt". After this change the telling is the server's, queued as a prompt marked as gc's, within ten seconds of the close, and (with change 2) it survives a new start of the session. Say that. Do not describe done's blocked, commit and branch in the README yet: the host's done tool does not pass them, so no agent can use them; the changelog's sentence about them should say that they are fields of HostService.Done that the host's tool does not offer yet.

Not asked, noted

That an idle foreman takes the queued prompt as a turn is not tried on a cluster, as the description says; the first loop on the release that has this is the proof, and the reviewing session reads the server's log for it then.

Review at f99bfcc, by the reviewing session (specs-58). The suite is green here under `go test -race ./...`, and `internal/gcwork` twenty times with `GOMAXPROCS=1`. The shape is right: the waits are the session's own record, `Poll` tells once and forgets, a task the server abandoned is told as failed, and one lock per session covers `Wait` and the poll with `Claim`, `Done` and `Fail`. Four changes before it merges. Each says what to change, how it was found, and the test that should come with it. ### 1. A commit or a branch can be stored as a number `Done` writes `gc.work_commit` and `gc.work_branch` with `bd update --set-metadata key=value`, and bd types the value it is given. On bd 1.3.4, the version the image has: bd update t-kxb --set-metadata gc.work_commit=0123456 --set-metadata a=1234567 --set-metadata c=1e5 --set-metadata d=null bd show t-kxb --json "metadata":{"a":1234567,"c":100000,"d":null,"gc.work_commit":"0123456"} So an abbreviated commit of digits only (`1234567`) is stored as a number, one shaped like `1e5` or `1234e12` as another number altogether, and a branch named `true`, `null` or `2026` as a boolean, null or number. A reader of gc's that expects strings then gets something else, and the commit `1234e12` is gone. `bd update --metadata '<json>'` takes a JSON object, merges it into the bead's metadata and keeps a string a string (tried: a bead with `gc.routed_to` set, then `--metadata '{"gc.work_commit":"1234567","gc.work_branch":"true"}'`, shows all three keys, both new ones as strings). Write the metadata of `finish` that way, encoded with `encoding/json`: the outcome, the commit and the branch in one object. Test: `Done` with commit `1234567` and branch `true` passes gc a `--metadata` argument that is valid JSON with both values as strings, and no `--set-metadata`. ### 2. A new start of the session forgets what it waits for The waits are a mark, and `operate` clears a session's marks at every start (`ClearMarks`, then `RecordIdentity`). A foreman that is started again, by `!reset`, by gc after its pod died, by a stop and a start, loses every task it waits for, and nothing tells it or the owner: the task closes and nobody hears, which is the failure this pull request is here to end. gc's own `session wait`, which this replaces, was kept by gc across that. Keep the waits across a start: they belong to the session, not to the start. Either `ClearMarks` at a start spares this key, or the waits move out of the marks into a place of their own; choose and say which in the description. The claimed-task and task-over marks must still be cleared by a start, as they are today. Test: a session with a wait is stopped and started again; a `Poll` after the task closes still tells it, once. ### 3. A wait on a task that cannot be read is accepted, and then warned about for ever `Wait` checks only the id's shape. A well-formed id of no bead (a typo, `sa-6s7` for `sa-6s6`) is stored, and every poll then fails to read it, logs a warning, and keeps it: one warning every ten seconds for as long as the foreman runs, and the foreman is never told that it waits for nothing. Read the task once in `Wait` (the read `Result` does) and refuse one that cannot be read, with gc's words, so that the agent learns at the call. A task that is already closed may be accepted as now: the next poll tells of it. Test: `Wait` on an id gc does not know returns an error and stores nothing. ### 4. Every poll writes a line to the server's log Each read goes through `gchandler`, which logs `gc ran` at INFO for every command: six lines a minute for every task waited for, for as long as the task is open. That log is how the city is watched, and a task that runs half an hour puts 180 lines of nothing into it. Keep the poll's reads out of INFO (a way to run a command quietly, at DEBUG; a failure still at ERROR as now). The reads an agent asks for stay at INFO. ### The README Line 73 says of `wait`: "the telling comes later as gc's own prompt". After this change the telling is the server's, queued as a prompt marked as gc's, within ten seconds of the close, and (with change 2) it survives a new start of the session. Say that. Do not describe `done`'s `blocked`, `commit` and `branch` in the README yet: the host's `done` tool does not pass them, so no agent can use them; the changelog's sentence about them should say that they are fields of `HostService.Done` that the host's tool does not offer yet. ### Not asked, noted That an idle foreman takes the queued prompt as a turn is not tried on a cluster, as the description says; the first loop on the release that has this is the proof, and the reviewing session reads the server's log for it then.
mikluko force-pushed waits from f99bfcc8af
All checks were successful
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 17s
test / go (pull_request) Successful in 1m5s
to 36fab2073d
All checks were successful
test / changelog (pull_request) Successful in 6s
image / image (pull_request) Successful in 17s
test / go (pull_request) Successful in 58s
2026-11-16 11:36:30 +00:00
Compare
Author
Owner

Implemented at 36fab2073d1cc76e637a9ee6469fa2e62341a973, rebased on origin/main (9a70461):

  1. finish writes the outcome, commit and branch in one --metadata JSON object; --set-metadata is gone. TestDoneWritesCommitAndBranchAsJSONStrings uses commit 1234567 and branch true and decodes the argument to prove both remain strings.
  2. Waits stay in the existing marks table and ClearMarks spares session.WaitsMark; the claimed-task and task-over marks are still cleared. TestAWaitSurvivesAStopAndStartAndTellsOnce stops and starts the session, closes the task, and proves one telling. No schema migration was needed.
  3. Wait reads a new task before storing it and returns gc's error without keeping the id; an already closed task remains valid. TestWaitRefusesATaskGcCannotReadAndStoresNothing covers the refusal.
  4. Poll reads use gchandler.ExecQuiet, which logs completion at DEBUG instead of INFO; agent-requested reads remain INFO, poll read failures remain logged, and a command that cannot start still logs ERROR. TestPollReadsAtDebugAndAnAgentReadAtInfo, TestAFailedPollReadIsQuietAndItsFailureIsLogged, and TestExecQuietFailureToStartStillLogsAnError hold this.

The README now describes the server's gc-marked prompt within ten seconds and the wait's survival of a new start. It says nothing about done's new fields; the changelog identifies them as HostService.Done fields the host's tool does not offer yet.

go test -race ./..., make lint, protobuf generation, and the new-diff lint checks pass.

Implemented at `36fab2073d1cc76e637a9ee6469fa2e62341a973`, rebased on `origin/main` (`9a70461`): 1. `finish` writes the outcome, commit and branch in one `--metadata` JSON object; `--set-metadata` is gone. `TestDoneWritesCommitAndBranchAsJSONStrings` uses commit `1234567` and branch `true` and decodes the argument to prove both remain strings. 2. Waits stay in the existing marks table and `ClearMarks` spares `session.WaitsMark`; the claimed-task and task-over marks are still cleared. `TestAWaitSurvivesAStopAndStartAndTellsOnce` stops and starts the session, closes the task, and proves one telling. No schema migration was needed. 3. `Wait` reads a new task before storing it and returns gc's error without keeping the id; an already closed task remains valid. `TestWaitRefusesATaskGcCannotReadAndStoresNothing` covers the refusal. 4. Poll reads use `gchandler.ExecQuiet`, which logs completion at DEBUG instead of INFO; agent-requested reads remain INFO, poll read failures remain logged, and a command that cannot start still logs ERROR. `TestPollReadsAtDebugAndAnAgentReadAtInfo`, `TestAFailedPollReadIsQuietAndItsFailureIsLogged`, and `TestExecQuietFailureToStartStillLogsAnError` hold this. The README now describes the server's gc-marked prompt within ten seconds and the wait's survival of a new start. It says nothing about `done`'s new fields; the changelog identifies them as `HostService.Done` fields the host's tool does not offer yet. `go test -race ./...`, `make lint`, protobuf generation, and the new-diff lint checks pass.
mikluko deleted branch waits 2026-11-16 11:41:57 +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!100
No description provided.