gcwork: a wait ends when its telling is delivered, not when it is queued #112

Merged
mikluko merged 2 commits from telling-delivered into main 2026-11-16 19:27:34 +00:00
Owner

gcwork: a wait ends when its telling is delivered, not when it is queued

A foreman in a long turn holds the telling of a closed task; a start afresh
drops it, and the wait was already gone, so the foreman never heard. The wait
now stays, as task@<Seq of the telling> in the waits mark, until the telling
has a Delivered record (the host's report that the agent took it). While the
telling has neither that nor a Dropped record, Poll queues no second one. A
Dropped record leaves the plain task among the waits and the next poll tells
the session as it is now. A telling for a task no longer among the waits adds
nothing back. Registry.PromptEnd reads the records already written, so no new
event kind or migration.

Mend not taken: putting the task back among the waits when its telling is dropped. It would need the dropping side (the registry) to write the gcwork-owned waits mark, and it could not tell a task the session had meanwhile waited for again, or that #107 dropped as unreadable, from one to restore; leaving the task in the waits until delivery has no such case.

Not covered: a crash between queuing the telling and recording its Seq in the mark tells the task once more, as the old order told it twice when the mark was not cleared.

  • The telling that a task can no longer be read (three JSON error answers) still ends its wait when it is queued, so a start afresh while it is held loses it. Out of this ticket.
  • A server of 0.13 that reads a mark written by this one takes bd-7@2 for a task id, refuses it as no bead's id, keeps that wait with one warning and tells nothing. It matters only for a rollback while a telling is pending.
gcwork: a wait ends when its telling is delivered, not when it is queued A foreman in a long turn holds the telling of a closed task; a start afresh drops it, and the wait was already gone, so the foreman never heard. The wait now stays, as `task@<Seq of the telling>` in the waits mark, until the telling has a Delivered record (the host's report that the agent took it). While the telling has neither that nor a Dropped record, Poll queues no second one. A Dropped record leaves the plain task among the waits and the next poll tells the session as it is now. A telling for a task no longer among the waits adds nothing back. Registry.PromptEnd reads the records already written, so no new event kind or migration. Mend not taken: putting the task back among the waits when its telling is dropped. It would need the dropping side (the registry) to write the gcwork-owned waits mark, and it could not tell a task the session had meanwhile waited for again, or that #107 dropped as unreadable, from one to restore; leaving the task in the waits until delivery has no such case. Not covered: a crash between queuing the telling and recording its Seq in the mark tells the task once more, as the old order told it twice when the mark was not cleared. - The telling that a task can no longer be read (three JSON error answers) still ends its wait when it is queued, so a start afresh while it is held loses it. Out of this ticket. - A server of 0.13 that reads a mark written by this one takes `bd-7@2` for a task id, refuses it as no bead's id, keeps that wait with one warning and tells nothing. It matters only for a rollback while a telling is pending.
gcwork: a wait ends when its telling is delivered, not when it is queued
All checks were successful
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 17s
test / go (pull_request) Successful in 58s
f0c40ccfce
A foreman in a long turn holds the telling of a closed task; a start afresh
drops it, and the wait was already gone, so the foreman never heard. The wait
now stays, as `task@<Seq of the telling>` in the waits mark, until the telling
has a Delivered record (the host's report that the agent took it). While the
telling has neither that nor a Dropped record, Poll queues no second one. A
Dropped record leaves the plain task among the waits and the next poll tells
the session as it is now. A telling for a task no longer among the waits adds
nothing back. Registry.PromptEnd reads the records already written, so no new
event kind or migration.

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

Review for spec-sqh.19, at head f0c40cc on main b84db7c. The design holds and does what the ticket asks; four things asked, the first a one-clause change to the query. This comment is complete by itself.

What holds, each run by me

  • go vet ./..., go test -race -count=1 ./..., and GOMAXPROCS=1 go test -count=20 ./internal/gcwork/ ./internal/session/: all pass.
  • Against a real registry, with probes of my own beside the branch's tests:
    • a session that ends with the telling pending keeps bd-7@2, and its next start is told (bd-7@6, two tellings in all);
    • the start that held the telling purged before the poll saw it: PromptEnd is ErrNotFound, the session is told once more (bd-7@5) and five further polls tell nothing, so not "each poll";
    • entries of a broken form (bd-7@, bd-8@x, bd-9@0, bd-10@999) are each told once and rewritten properly;
    • wait called again for a task recorded as bd-7@2 adds nothing.
  • Seq is never reused under a mark that survives: Purge removes a whole ended session with its marks, and of a living one only starts that are not its latest, so MAX(seq) does not fall.
  • The host has reported Handled since 0.11.0 and retries the report, so a session's pod older than the server still ends its waits.
  • Nothing under internal/chat is touched.

1. PromptEnd reads every event of the session, on the registry's one connection

The first query has no bound on seq, so while a telling is pending it walks the session's whole history, frames included, once per pending telling at every poll; the registry opens one connection (SetMaxOpenConns(1)), so every other call of the server waits behind it. An always-on session's latest start is never purged, so the history only grows. Measured on this branch, events of 2 KB:

events of the session    PromptEnd of a pending telling
50 000                   36 ms
200 000                  144 ms
200 000, with the bound  0.05 ms

The record that ends a prompt is always appended after its Stored record. Asked: add AND seq > ? (the telling's Seq) to the first query, which turns the walk into the events since the telling:

WHERE session = ? AND seq > ? AND kind = ? AND of = ? AND pstate IN (?, ?)

All the branch's tests pass with it.

2. The branch that reads ErrNotFound as dropped has no test in gcwork

pollWait resets an entry whose Seq names no record and tells again; only the registry's side (PromptEnd of seq 999) is tested. Asked: a test in internal/gcwork on a real registry: tell, start afresh, Purge with a time after now (which removes the first start with the telling's records), Poll; the session is told once, the mark carries the new Seq, and further polls tell nothing.

3. The docs of Stored and Delivered say the opposite of what this change relies on

internal/session/session.go: "Delivered is a prompt the server handed to the session host; what the host did with it is not reported back", and "Stored is a prompt the server holds and has not yet sent on". Neither is true of the code: the only writer of a Delivered record is Handled, on the host's report that the prompt began a turn or went into the running one, and a prompt the host holds is still Stored. PromptEnd's own doc says it rightly. Asked: correct the two constants' docs to what the records mean, one sentence each.

4. The body's "Not covered" lacks two things

  • The telling that a task can no longer be read (three JSON error answers) still ends its wait when it is queued, so a start afresh while it is held loses it. Out of this ticket; say so.
  • A server of 0.13 that reads a mark written by this one takes bd-7@2 for a task id, refuses it as no bead's id, and keeps that wait with one warning, telling nothing (run on main: five polls, no telling, the mark unchanged). It matters only for a rollback while a telling is pending.

Not asked

  • Handled(BeganTurn) is reported before the agent answers session/prompt, so "the agent took it" means the host gave it to the agent. That is as close as the records get.
  • A crash between queuing the telling and writing its Seq tells once more; the body says it.
Review for spec-sqh.19, at head f0c40cc on main b84db7c. The design holds and does what the ticket asks; four things asked, the first a one-clause change to the query. This comment is complete by itself. ## What holds, each run by me - `go vet ./...`, `go test -race -count=1 ./...`, and `GOMAXPROCS=1 go test -count=20 ./internal/gcwork/ ./internal/session/`: all pass. - Against a real registry, with probes of my own beside the branch's tests: - a session that ends with the telling pending keeps `bd-7@2`, and its next start is told (`bd-7@6`, two tellings in all); - the start that held the telling purged before the poll saw it: `PromptEnd` is `ErrNotFound`, the session is told once more (`bd-7@5`) and five further polls tell nothing, so not "each poll"; - entries of a broken form (`bd-7@`, `bd-8@x`, `bd-9@0`, `bd-10@999`) are each told once and rewritten properly; - `wait` called again for a task recorded as `bd-7@2` adds nothing. - Seq is never reused under a mark that survives: `Purge` removes a whole ended session with its marks, and of a living one only starts that are not its latest, so `MAX(seq)` does not fall. - The host has reported `Handled` since 0.11.0 and retries the report, so a session's pod older than the server still ends its waits. - Nothing under `internal/chat` is touched. ## 1. `PromptEnd` reads every event of the session, on the registry's one connection The first query has no bound on `seq`, so while a telling is pending it walks the session's whole history, frames included, once per pending telling at every poll; the registry opens one connection (`SetMaxOpenConns(1)`), so every other call of the server waits behind it. An always-on session's latest start is never purged, so the history only grows. Measured on this branch, events of 2 KB: events of the session PromptEnd of a pending telling 50 000 36 ms 200 000 144 ms 200 000, with the bound 0.05 ms The record that ends a prompt is always appended after its Stored record. Asked: add `AND seq > ?` (the telling's Seq) to the first query, which turns the walk into the events since the telling: WHERE session = ? AND seq > ? AND kind = ? AND of = ? AND pstate IN (?, ?) All the branch's tests pass with it. ## 2. The branch that reads `ErrNotFound` as dropped has no test in gcwork `pollWait` resets an entry whose Seq names no record and tells again; only the registry's side (`PromptEnd` of seq 999) is tested. Asked: a test in `internal/gcwork` on a real registry: tell, start afresh, `Purge` with a time after now (which removes the first start with the telling's records), `Poll`; the session is told once, the mark carries the new Seq, and further polls tell nothing. ## 3. The docs of `Stored` and `Delivered` say the opposite of what this change relies on `internal/session/session.go`: "Delivered is a prompt the server handed to the session host; what the host did with it is not reported back", and "Stored is a prompt the server holds and has not yet sent on". Neither is true of the code: the only writer of a Delivered record is `Handled`, on the host's report that the prompt began a turn or went into the running one, and a prompt the host holds is still Stored. `PromptEnd`'s own doc says it rightly. Asked: correct the two constants' docs to what the records mean, one sentence each. ## 4. The body's "Not covered" lacks two things - The telling that a task can no longer be read (three JSON error answers) still ends its wait when it is queued, so a start afresh while it is held loses it. Out of this ticket; say so. - A server of 0.13 that reads a mark written by this one takes `bd-7@2` for a task id, refuses it as no bead's id, and keeps that wait with one warning, telling nothing (run on main: five polls, no telling, the mark unchanged). It matters only for a rollback while a telling is pending. ## Not asked - `Handled(BeganTurn)` is reported before the agent answers `session/prompt`, so "the agent took it" means the host gave it to the agent. That is as close as the records get. - A crash between queuing the telling and writing its Seq tells once more; the body says it.
session: bound PromptEnd by the telling's Seq; correct the docs of Stored and Delivered
Some checks failed
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 18s
test / go (pull_request) Has been cancelled
d0d9fb8252
PromptEnd read the session's whole history for each pending telling at every
poll, on the registry's single connection; the record that ends a prompt always
follows its Stored record, so the query starts after it. A test covers the
telling whose records were purged. Stored and Delivered now say what the
records mean: Delivered is the host's report that the agent took the prompt.

Assisted-By: Claude <noreply@anthropic.com>
mikluko force-pushed telling-delivered from d0d9fb8252
Some checks failed
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 18s
test / go (pull_request) Has been cancelled
to cd972c25a6
All checks were successful
image / image (pull_request) Successful in 4s
test / changelog (pull_request) Successful in 7s
test / go (pull_request) Successful in 54s
2026-11-16 19:25:12 +00:00
Compare
mikluko deleted branch telling-delivered 2026-11-16 19:27:35 +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!112
No description provided.