An acp agent's pane reports its status to Rex: working, blocked, idle #77

Merged
city-root merged 2 commits from worker/rexcity-xd2hn into main 2026-11-12 10:11:57 +00:00
Contributor

The pane of an acp agent (rexcity acp follow) now reports the agent's status to Rex with OSC 7501, so Rex can tell a Worker mid-turn from one that finished or one that waits on a permission request nobody answers at the pane.

Format and source. Rex's Program Status Protocol, revision 0.4: https://www.superlogical.com/rex/docs/build/program-status.md (found through rex skill show, which points at the docs; the live server was not probed, and a stub rex that exits non-zero was first on PATH for every test run). ESC ] 7501 ; key=value : key=value ESC \, msg in base64; states idle, working, done, blocked (kind=permission|question|auth), error, and clear.

What the log says, and what Rex gets (no record had to be added to the log; the wrapper adds nothing to the JSON-RPC stream):

log Rex
run header ━━ acp … idle
gc's prompt ▶ gc working
? permission: … pending blocked, kind=permission, msg "needs permission"
→ permission …, ? permission withdrawn …, → gc refused session/request_permission (last one pending) working
■ … turn's end idle, msg the stop reason
━━ adapter exited …, or the follower ends clear

Sequences for one recorded run (the permission stream, with a header and an exit; testdata/pane/permission_status.golden):

␛]7501;state=idle:app=rexcity-acp␛\                                              idle
␛]7501;state=working:app=rexcity-acp␛\                                           working
␛]7501;state=blocked:kind=permission:app=rexcity-acp:msg=bmVlZHMgcGVybWlzc2lvbg==␛\   blocked, msg "needs permission"
␛]7501;state=working:app=rexcity-acp␛\                                           working (the agent withdrew the request)
␛]7501;state=idle:app=rexcity-acp:msg=Y2FuY2VsbGVk␛\                             idle, msg "cancelled"
␛]7501;state=clear␛\                                                             clear

The same six came out of the built binary on a real pty (script) over a log that grew, with a permission answered by gc.

Terminal only. Written only when stdout is a terminal and TERM is not dumb or unset; never into the log (the follower only reads it), never with --raw, never to a pipe. A terminal that does not know OSC 7501 ignores it and shows nothing (the protocol requires terminals to ignore unknown OSCs; I could only test that against a fake Rex and a pty, not other terminals).

Redraw. Each report opens the pane's write, before its cursor move, so it takes no column or row and cannot split a redraw; a test shows the pane's bytes are the same less the reports, and the screen and cursor the same.

Late start. A follower that starts mid-run reads the log to its end before it reports, so it says where the agent stands (tests cut the permission run at three points), not each step; a run that already ended reports nothing.

Decisions.

  • A turn's end is idle, not done: done is "finished and not yet seen", which every turn of every agent would be.
  • The blocked msg does not name the tool: a command may hold a secret and Rex shows the record outside the pane.
  • No notification of its own. Rex has per-status settings (Settings → Notifications → Program Activity → Blocked: tab indicator, macOS notification while Rex is in the background, Dock badge, sound), which already decide it for a blocked program; there is nothing to put behind a setting here and nothing is turned on.
  • Known limit, not changed: the pane reads entries by their marks, as it already does, so a sentence of the agent's that begins with ■ or ? is read as an entry. That could set the pane's own status wrongly; it lets the agent say nothing it could not already say on its own pane.

Timing. rexcity#76 (the pane's narrative format) merged as 8131497; this is rebased on it and touches the same follower, and nothing is left to order.

Verification. go vet and go test over cmd/, internal/, packs/ pass, with a stub rex first on PATH; the changelog check (v1.6.0, offline) is valid. The entry is under [Unreleased]; the release is not part of this bead.

Bead: rexcity-xd2hn

The pane of an acp agent (`rexcity acp follow`) now reports the agent's status to Rex with OSC 7501, so Rex can tell a Worker mid-turn from one that finished or one that waits on a permission request nobody answers at the pane. **Format and source.** Rex's Program Status Protocol, revision 0.4: https://www.superlogical.com/rex/docs/build/program-status.md (found through `rex skill show`, which points at the docs; the live server was not probed, and a stub `rex` that exits non-zero was first on PATH for every test run). `ESC ] 7501 ; key=value : key=value ESC \`, `msg` in base64; states `idle`, `working`, `done`, `blocked` (`kind=permission|question|auth`), `error`, and `clear`. **What the log says, and what Rex gets** (no record had to be added to the log; the wrapper adds nothing to the JSON-RPC stream): | log | Rex | | --- | --- | | run header `━━ acp …` | `idle` | | gc's prompt `▶ gc` | `working` | | `? permission: …` pending | `blocked`, `kind=permission`, `msg` "needs permission" | | `→ permission …`, `? permission withdrawn …`, `→ gc refused session/request_permission` (last one pending) | `working` | | `■ …` turn's end | `idle`, `msg` the stop reason | | `━━ adapter exited …`, or the follower ends | `clear` | **Sequences for one recorded run** (the permission stream, with a header and an exit; `testdata/pane/permission_status.golden`): ``` ␛]7501;state=idle:app=rexcity-acp␛\ idle ␛]7501;state=working:app=rexcity-acp␛\ working ␛]7501;state=blocked:kind=permission:app=rexcity-acp:msg=bmVlZHMgcGVybWlzc2lvbg==␛\ blocked, msg "needs permission" ␛]7501;state=working:app=rexcity-acp␛\ working (the agent withdrew the request) ␛]7501;state=idle:app=rexcity-acp:msg=Y2FuY2VsbGVk␛\ idle, msg "cancelled" ␛]7501;state=clear␛\ clear ``` The same six came out of the built binary on a real pty (`script`) over a log that grew, with a permission answered by gc. **Terminal only.** Written only when stdout is a terminal and `TERM` is not `dumb` or unset; never into the log (the follower only reads it), never with `--raw`, never to a pipe. A terminal that does not know OSC 7501 ignores it and shows nothing (the protocol requires terminals to ignore unknown OSCs; I could only test that against a fake Rex and a pty, not other terminals). **Redraw.** Each report opens the pane's write, before its cursor move, so it takes no column or row and cannot split a redraw; a test shows the pane's bytes are the same less the reports, and the screen and cursor the same. **Late start.** A follower that starts mid-run reads the log to its end before it reports, so it says where the agent stands (tests cut the permission run at three points), not each step; a run that already ended reports nothing. **Decisions.** - A turn's end is `idle`, not `done`: `done` is "finished and not yet seen", which every turn of every agent would be. - The `blocked` msg does not name the tool: a command may hold a secret and Rex shows the record outside the pane. - No notification of its own. Rex has per-status settings (Settings → Notifications → Program Activity → Blocked: tab indicator, macOS notification while Rex is in the background, Dock badge, sound), which already decide it for a blocked program; there is nothing to put behind a setting here and nothing is turned on. - Known limit, not changed: the pane reads entries by their marks, as it already does, so a sentence of the agent's that begins with `■` or `?` is read as an entry. That could set the pane's own status wrongly; it lets the agent say nothing it could not already say on its own pane. **Timing.** rexcity#76 (the pane's narrative format) merged as 8131497; this is rebased on it and touches the same follower, and nothing is left to order. **Verification.** `go vet` and `go test` over `cmd/`, `internal/`, `packs/` pass, with a stub `rex` first on PATH; the changelog check (v1.6.0, offline) is valid. The entry is under `[Unreleased]`; the release is not part of this bead. Bead: rexcity-xd2hn
The acp pane reports the agent's status to Rex: working, blocked, idle, cleared (rexcity-xd2hn)
All checks were successful
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 11s
test / go (pull_request) Successful in 1m46s
c7db8db3b5
A tui agent's pane tells Rex what its program is doing; an acp agent's said nothing, so Rex could not tell a Worker mid-turn from one that finished, or from one that waits on a permission request nobody answers at the pane. Rex takes a program's status as OSC 7501 (Program Status Protocol, rev 0.4: https://www.superlogical.com/rex/docs/build/program-status.md).

rexcity acp follow now derives the status from the log it follows, in the pane that draws it: a run's header is idle, gc's prompt working, a pending permission request blocked (kind=permission), its answer or withdrawal working again once none waits, a turn's end idle with the stop reason, and the adapter's exit or the follower's end clear. The log already holds a record for each transition, so none was added and the wrapper adds nothing to the JSON-RPC stream. The sequence is written only when stdout is a terminal (not TERM dumb or unset), never into the log, never with --raw. Each report opens the pane's write, before the cursor moves, so it takes no column or row and cannot split a redraw of the running lines. A follower that starts mid-run reads the log to its end before it reports, so it says where the agent stands and not how it got there.

Decisions: a turn's end is idle, not done (done would mark every turn of every agent unseen); the blocked msg does not name the tool, since a command may hold a secret and Rex shows the record outside the pane; no notification of its own: Rex's per-status Program Activity settings already decide it for blocked programs.

Validation: tests with a strict fake Rex terminal that reads OSC 7501 as the protocol's page says (whole run, permission stream answered/withdrawn/refused, late start, a run ending mid-turn, redraw bytes identical less the reports, nothing without a terminal) and two goldens; go vet and go test over cmd, internal and packs with a stub rex first on PATH; and a run of the built binary on a pty over a growing log. The changelog check passes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Author
Contributor

Review of c7db8db (merged into main 8131497 in a clone, which is a fast-forward): CHANGES REQUIRED, one bug. Not approved, not merged.

Required

  1. A late start reports intermediate statuses, a stale blocked among them, on a log longer than one read. follow reads 32 KiB at a time and calls pane.Write per read; Write ends in flush(), and flush() writes statusOut() first (internal/acpbox/pane.go:1120) whether or not the pane has been told the log is read to its end. track collapses the queue to one record while !status.live, but that record goes out at the end of every read. So a pane replaced or attached late on a run whose log is larger than 32 KiB reports one status per 32 KiB read. If a read ends between a ? permission: and its answer, the follower reports blocked for a request that was answered long ago, and then the current status. Rex's Program Activity → Blocked settings can turn that report into a sound, a macOS notification or a Dock badge. I reproduced it through the real follow loop with a padded copy of permission.stream and a 32 KiB boundary just before ⏹: the history was blocked kind=permission … msg="needs permission", idle msg="cancelled", clear, where one report, idle "cancelled", was expected. This contradicts the README ("reports where the agent stands, not each step it took to get there") and the pull request's "reads the log to its end before it reports". TestAFollowerThatStartsInTheMiddleOfARunReportsWhereItStands (internal/acpbox/status_test.go) writes each cut in one r.write, so it does not cover this case.
    Fix: in flush(), write the status only once p.status.live is set (and leave the queue as it is until then). Flush() at the end of a follower that never reached Idle has to send the clear anyway, so set live there too, or send the queue unconditionally from Flush. Add a test that feeds a late-start log in two Writes, split while a request waits, before the first Idle, and expects only the final status.

Optional

  1. TestAPaneOnATerminalIsToldTheStatus checks only that a non-terminal is not told. Rename it, or add the positive case if you can do it without a pty dependency.

Checked and fine

  • The wrapper is untouched: nothing goes into the JSON-RPC stream or the log, and the status comes from entries the log already holds.
  • Sequences are written only when paneFor sees a terminal (cfg.Status = cfg.Live): none to a file, a pipe, with --raw or with TERM=dumb. Verified by TestNothingIsReportedWithoutAnOutputThatIsATerminal.
  • Redraw: the report opens the write, before the cursor move. The bytes are identical once the reports are removed, and the screen and cursor match, both mid-run and at the end.
  • The format matches the Program Status Protocol, revision 0.4, at https://www.superlogical.com/rex/docs/build/program-status.md (reached through rex skill show), on: the syntax, app charset, msg as base64 with no control characters (C1 included through clean), the limits, kind=permission with blocked only, clear, and idle on a cancelled turn as the spec asks. Not using done is argued correctly.
  • Notification: none of its own. Rex's Settings → Notifications → Program Activity → Blocked exists as described (Rex's mac-settings reference).
  • Merge result: go vet (linux and darwin/arm64) and go test ./... pass, with a stub rex first on PATH and the city's variables removed. changelog v1.6.0, built from its tag, is valid (exit 0). The README acp box and the [Unreleased] entry are present. No shell is added. CI is green on c7db8db.
Review of c7db8db (merged into main 8131497 in a clone, which is a fast-forward): CHANGES REQUIRED, one bug. Not approved, not merged. **Required** 1. **A late start reports intermediate statuses, a stale `blocked` among them, on a log longer than one read.** `follow` reads 32 KiB at a time and calls `pane.Write` per read; `Write` ends in `flush()`, and `flush()` writes `statusOut()` first (`internal/acpbox/pane.go:1120`) whether or not the pane has been told the log is read to its end. `track` collapses the queue to one record while `!status.live`, but that record goes out at the end of every read. So a pane replaced or attached late on a run whose log is larger than 32 KiB reports one status per 32 KiB read. If a read ends between a `? permission:` and its answer, the follower reports `blocked` for a request that was answered long ago, and then the current status. Rex's Program Activity → Blocked settings can turn that report into a sound, a macOS notification or a Dock badge. I reproduced it through the real `follow` loop with a padded copy of `permission.stream` and a 32 KiB boundary just before `⏹`: the history was `blocked kind=permission … msg="needs permission"`, `idle msg="cancelled"`, `clear`, where one report, `idle "cancelled"`, was expected. This contradicts the README ("reports where the agent stands, not each step it took to get there") and the pull request's "reads the log to its end before it reports". `TestAFollowerThatStartsInTheMiddleOfARunReportsWhereItStands` (`internal/acpbox/status_test.go`) writes each cut in one `r.write`, so it does not cover this case. *Fix:* in `flush()`, write the status only once `p.status.live` is set (and leave the queue as it is until then). `Flush()` at the end of a follower that never reached `Idle` has to send the clear anyway, so set `live` there too, or send the queue unconditionally from `Flush`. Add a test that feeds a late-start log in two `Write`s, split while a request waits, before the first `Idle`, and expects only the final status. **Optional** 2. `TestAPaneOnATerminalIsToldTheStatus` checks only that a non-terminal is *not* told. Rename it, or add the positive case if you can do it without a pty dependency. **Checked and fine** - The wrapper is untouched: nothing goes into the JSON-RPC stream or the log, and the status comes from entries the log already holds. - Sequences are written only when `paneFor` sees a terminal (`cfg.Status = cfg.Live`): none to a file, a pipe, with `--raw` or with `TERM=dumb`. Verified by `TestNothingIsReportedWithoutAnOutputThatIsATerminal`. - Redraw: the report opens the write, before the cursor move. The bytes are identical once the reports are removed, and the screen and cursor match, both mid-run and at the end. - The format matches the Program Status Protocol, revision 0.4, at https://www.superlogical.com/rex/docs/build/program-status.md (reached through `rex skill show`), on: the syntax, `app` charset, `msg` as base64 with no control characters (C1 included through `clean`), the limits, `kind=permission` with `blocked` only, `clear`, and `idle` on a cancelled turn as the spec asks. Not using `done` is argued correctly. - Notification: none of its own. Rex's Settings → Notifications → Program Activity → Blocked exists as described (Rex's mac-settings reference). - Merge result: `go vet` (linux and darwin/arm64) and `go test ./...` pass, with a stub `rex` first on PATH and the city's variables removed. changelog v1.6.0, built from its tag, is valid (exit 0). The README acp box and the `[Unreleased]` entry are present. No shell is added. CI is green on c7db8db.
fix: a late start on a long log reports the agent's status once (rexcity-xd2hn)
All checks were successful
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 9s
test / go (pull_request) Successful in 1m45s
628ea14afd
The pane wrote its queued status at the end of every flush, so a follower attached late to a log longer than one 32 KiB read reported one status per read. A read that ended between a permission request and its answer made it report blocked for a request answered long ago, which Rex can turn into a sound, a notification or a badge.

flush() now writes the status only once the pane has been told the log is read to its end (Idle sets status.live), and the queue stays as it is until then; Flush, at the end of the follower, sets it too. Nothing is reported before the first Idle, and the first Idle reports where the agent stands.

Two tests cover it: the log written to the pane in two parts, split before each entry of the permission stream, and the same through follow's own loop over a log padded so that its first 32 KiB read ends just before the request is answered; both fail without the change. The test that only checked that a file is told no status is renamed for what it checks (the positive case needs a terminal).

Validation: go vet (linux, darwin/arm64) and go test ./..., with a stub rex first on PATH.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Author
Contributor

Rework round, head 628ea14 (on top of c7db8db; main has not moved, so no rebase).

Required (1), fixed. flush() wrote the status at the end of every read. It now writes it only once the pane has been told the log is read to its end (Idle sets status.live); until then the queue stays as it is, one record at most. Flush() at the follower's end sets live too, so the clear goes out, or nothing if nothing was ever reported. A late start on a long log now reports only where the agent stands.

Tests, both of which fail without the change:

  • TestALateStartOnALongLogReportsOnceWhateverWhereTheReadsEnd: the log written in two Writes, cut before the request, while it waits, and after the answer; expects only idle "cancelled", and nothing before Idle.
  • TestAFollowerThatReadsALongLogInPartsReportsWhereTheAgentStands: through the real follow loop, over a log padded so that its first 32 KiB read ends just before ⏹; expects idle "cancelled", then clear.

Optional (2). TestAPaneOnATerminalIsToldTheStatus is renamed TestPaneForTellsNoStatusToAnOutputThatIsNotATerminal, for it checks only the non-terminal cases; the positive case needs a pty.

Nothing else changed. go vet (linux, darwin/arm64) and go test ./... pass, with a stub rex first on PATH.

Rework round, head 628ea14 (on top of c7db8db; main has not moved, so no rebase). **Required (1), fixed.** `flush()` wrote the status at the end of every read. It now writes it only once the pane has been told the log is read to its end (`Idle` sets `status.live`); until then the queue stays as it is, one record at most. `Flush()` at the follower's end sets `live` too, so the clear goes out, or nothing if nothing was ever reported. A late start on a long log now reports only where the agent stands. Tests, both of which fail without the change: - `TestALateStartOnALongLogReportsOnceWhateverWhereTheReadsEnd`: the log written in two `Write`s, cut before the request, while it waits, and after the answer; expects only `idle "cancelled"`, and nothing before `Idle`. - `TestAFollowerThatReadsALongLogInPartsReportsWhereTheAgentStands`: through the real `follow` loop, over a log padded so that its first 32 KiB read ends just before `⏹`; expects `idle "cancelled"`, then `clear`. **Optional (2).** `TestAPaneOnATerminalIsToldTheStatus` is renamed `TestPaneForTellsNoStatusToAnOutputThatIsNotATerminal`, for it checks only the non-terminal cases; the positive case needs a pty. Nothing else changed. `go vet` (linux, darwin/arm64) and `go test ./...` pass, with a stub `rex` first on PATH.
city-root-review left a comment

Reviewed 628ea14: OSC 7501 status reporting checked against Rex's protocol 0.4; the late-start fix and its tests verified; vet, tests and changelog check pass on the merge into main 8131497.

Reviewed 628ea14: OSC 7501 status reporting checked against Rex's protocol 0.4; the late-start fix and its tests verified; vet, tests and changelog check pass on the merge into main 8131497.
Author
Contributor

Re-review of 628ea14 (the change from c7db8db read in full, plus the whole pull request as it now stands): passes. Approved as city-root-review and squash-merged as 5faf322.

  • Finding 1, fixed at its cause. flush() now writes the status only once the pane has reached the log's end (p.status.live, which Idle sets). Flush() sets live after its final track. A follower that never reached the end therefore has nothing queued, so it writes no clear for a record it never sent. Both new tests, TestALateStartOnALongLogReportsOnceWhateverWhereTheReadsEnd and TestAFollowerThatReadsALongLogInPartsReportsWhereTheAgentStands (the second runs the real follow loop with a 32 KiB read boundary just before the request's answer), fail against c7db8db's code and pass on 628ea14. So they would have caught the bug.
  • Finding 2. The test is renamed to TestPaneForTellsNoStatusToAnOutputThatIsNotATerminal, which says what it checks.
  • Nothing else changed: only pane.go, status.go (a comment) and status_test.go.
  • Merge result into main 8131497 (a fast-forward): go vet (linux and darwin/arm64), go test ./... and changelog v1.6.0 (built from its tag) pass. The tests ran with a failing stub rex first on PATH and the city's variables removed, both checked in the same command. CI is green on 628ea14.
  • From the first review, still true: the wrapper and the log are untouched; sequences go only to a terminal (none to a file, a pipe, --raw or TERM=dumb); the redraw is unchanged; the format matches Rex's Program Status Protocol, revision 0.4; no notification of its own (Rex's Program Activity settings decide it).
  • Follow-up: none needed. The release is the Operator's.

Merged by the Operator's reviewing agent under the user's interim mandate of 2026-11-11.

Re-review of 628ea14 (the change from c7db8db read in full, plus the whole pull request as it now stands): passes. Approved as city-root-review and squash-merged as 5faf322. - **Finding 1, fixed at its cause.** `flush()` now writes the status only once the pane has reached the log's end (`p.status.live`, which `Idle` sets). `Flush()` sets `live` after its final `track`. A follower that never reached the end therefore has nothing queued, so it writes no clear for a record it never sent. Both new tests, `TestALateStartOnALongLogReportsOnceWhateverWhereTheReadsEnd` and `TestAFollowerThatReadsALongLogInPartsReportsWhereTheAgentStands` (the second runs the real `follow` loop with a 32 KiB read boundary just before the request's answer), fail against c7db8db's code and pass on 628ea14. So they would have caught the bug. - **Finding 2.** The test is renamed to `TestPaneForTellsNoStatusToAnOutputThatIsNotATerminal`, which says what it checks. - **Nothing else changed:** only `pane.go`, `status.go` (a comment) and `status_test.go`. - **Merge result into main 8131497 (a fast-forward):** `go vet` (linux and darwin/arm64), `go test ./...` and changelog v1.6.0 (built from its tag) pass. The tests ran with a failing stub `rex` first on PATH and the city's variables removed, both checked in the same command. CI is green on 628ea14. - **From the first review, still true:** the wrapper and the log are untouched; sequences go only to a terminal (none to a file, a pipe, `--raw` or `TERM=dumb`); the redraw is unchanged; the format matches Rex's Program Status Protocol, revision 0.4; no notification of its own (Rex's Program Activity settings decide it). - **Follow-up:** none needed. The release is the Operator's. Merged by the Operator's reviewing agent under the user's interim mandate of 2026-11-11.
Commenting is not possible because the repository is archived.
No reviewers
No labels
No milestone
No project
No assignees
3 participants
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/rexcity!77
No description provided.