Skip to content

feat(tui): report agent state to herdr - #289

Merged
lg2m merged 4 commits into
mainfrom
feat/eng-1034-herdr-agent-state
Oct 14, 2026
Merged

lg2m merged 4 commits into
mainfrom
feat/eng-1034-herdr-agent-state

Conversation

@lg2m

@lg2m lg2m commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Closes ENG-1034.

What changes for users

In a herdr pane, qq now reports its own state ("supported by the agent"); there is nothing to install. herdr's sidebar, herdr agent list, notifications, and herdr agent wait see one state for every session the window follows:

herdr state When
blocked any session has an approval or question waiting for you (message names the session)
working otherwise, any session running, queued, or answering a side question — including while an approval delegate decides a held call
idle nothing running

After a herdr server restart the pane runs qq --session <root of the focused session> and reopens it (a focused sub-agent reopens as its tree). Quitting clears the pane. qq serve and qq run never report.

Design

  • Protocol (0f85584): tool_approval_requested gains delegated: true when the gate consults the approval reviewer before any human. Without it a client cannot tell "reviewer is deciding" from "waiting on you" until an escalation. Protocol 32 is unreleased (v0.1.6 ships 31), so no version bump; the field is omitted when false, so every existing hold and golden encodes byte-identically. New v32 golden event_tool_approval_requested_delegated.
  • Server-projected summary state (d36bdee1, Codex review): SessionSummary gains pending_holds (active run's held calls, each delegated when a delegate decides first; human-first, ≤16) and running_side_question, exact at the summary's cursor and omitted when empty. Store schema 44 → 45 (unreleased; v0.1.6 shipped 43) adds tool_calls.approval_delegated, set with the hold and cleared on escalation; pre-upgrade holds read as waiting for a human. One new golden event_session_updated_with_holds; existing goldens unchanged.
  • Client state: every summary seeds LiveStatus hold sets; events move them on, for warm and cold sessions alike, and side-question state is tracked for every session. SessionStore::activity() reads only summary-level state and folds worst-first (blocked > working > idle), so sessions whose bodies were never loaded and clients attaching mid-hold report correctly.
  • Reporter (650a42d, qq-tui/src/herdr.rs): enabled only when HERDR_ENV=1, HERDR_PANE_ID, and HERDR_SOCKET_PATH are all set. One background task fed by a watch channel sends only the newest state (herdr's "drop older states" rule) as one JSON line over the Unix socket, 500 ms bound per request, failures dropped. update never waits on I/O. The loop publishes only after input or a client update (not frame/animation ticks), deduplicated in the sink. seq is max(wall-clock µs, previous + 1). The acknowledgement read is bounded to 4 KiB. Streamed deltas (text_appended, reasoning_delta, tool_call_output_delta, run_activity_changed) do not trigger the fold. Release is best-effort and bounded on every loop exit.
  • Nested agents: tool shells already start from a cleared environment, so a qq launched by a tool never sees HERDR_* and cannot report over the parent.
  • No new dependencies. Windows: reporting is compiled out (no Unix socket); herdr's CLI fallback can come later if needed.

Verification

  • cargo test --workspace: all pass (one unrelated pre-existing timing test, plan::tests::async_compilation_bounds_waiters_and_releases_cancelled_requests, failed once under load and passed 5/5 alone).
  • Review-fix tests: store_activity_counts_sessions_whose_bodies_were_never_loaded, the_session_summary_says_who_a_hold_waits_on_until_it_settles, version_forty_four_reads_existing_holds_as_waiting_for_a_human, a_child_resolves_to_its_root_and_an_unknown_parent_resolves_to_none, an_endless_answer_without_a_newline_is_read_only_to_the_bound; the seq test injects instants.
  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets --all-features -- -D warnings: clean. cargo build --workspace: ok. docs_truth: 23 passed.
  • New tests: 7 reporter tests against a fake herdr Unix socket (env gating, exact request shape incl. control-char scrubbing and 80-char cap, monotonic seq across restart, ordered delivery + release, dedup, burst coalescing to newest while herdr is slow, absent/silent socket bounded); store activity test (delegated → working, escalated → blocked, survives reload, worst session wins, mid-hold attach follows the summary); core approval tests pin delegated for reviewer-consulted / no-reviewer / ask-with-reviewer-not-consulted.
  • End-to-end: the real qq binary under --tui-qa-root in a pty with a fake herdr socket reported pane.report_agent idle then pane.release_agent with increasing seq.

Performance

The fold is O(sessions) and runs only on state-bearing updates and input; socket I/O is off the loop. Each summary load adds one indexed side_questions lookup (partial unique index on running) and, only for sessions with an active run, one tool_calls lookup on (run_id, …) bounded to 16 rows. Event size bound test passes.

Not covered

No live run against a real herdr server (verified against herdr's documented contract and source at 241b99cd). The approval change is small but touches sessions/; workflow.md asks for an independent review.

lg2m added 2 commits October 13, 2026 10:09
`tool_approval_requested` gains `delegated: true` when the gate consults
the approval reviewer before any human (protocol 32, unreleased, so no
version bump). Omitted when false, so every earlier hold encodes
unchanged; a v32 golden pins the new shape.

The client store records delegated holds in `LiveStatus::with_delegate`,
drops them on escalation or settlement, and keeps them across a body
reload. `SessionStore::activity()` folds a whole store into one state:
blocked when any hold waits for a human, else working when any session
runs or is queued (a delegate deciding counts as work), else idle.

Refs: ENG-1034
Inside a herdr pane (HERDR_ENV=1 with HERDR_PANE_ID and
HERDR_SOCKET_PATH) the TUI reports `idle` / `working` / `blocked` for
everything it follows, with the focused session as the resume command
(`qq --session ID`), and releases the pane on exit.

One background task sends only the newest state over herdr's Unix socket,
one JSON line per request with a 500 ms bound; failures are dropped and
`update` never waits. The loop publishes only after input or a client
update, deduplicated in the sink. `seq` starts at wall-clock microseconds
so a restarted qq stays above what herdr last accepted. `qq serve` and
`qq run` never report; Windows is off (no Unix socket).

Refs: ENG-1034
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T03:33:08.542681Z 38fab64 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 650a42d2ae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/qq-client/src/state.rs Resolved
Comment thread crates/qq-tui/src/herdr.rs Resolved
Comment thread crates/qq-client/src/state.rs Resolved
Comment thread crates/qq-tui/src/herdr.rs Resolved
Comment thread crates/qq-tui/src/herdr.rs Resolved
Comment thread crates/qq-tui/src/terminal.rs Resolved
Codex review on #289 found the aggregate read state that only warm bodies
or previously seen events carry: cold sessions past the prewarmed four,
clients that attach mid-hold, and side questions all reported the wrong
state. The root cause is one: a per-session fact the client could not
reconstruct. The server now projects it.

- SessionSummary gains `pending_holds` (the active run's held calls, each
  with `delegated`, human-first, at most 16) and `running_side_question`,
  exact at the summary's cursor and omitted when empty. Protocol 32 is
  unreleased; existing goldens are unchanged, one new golden covers both.
- Store schema 44 -> 45 adds `tool_calls.approval_delegated`, written with
  the hold and cleared on escalation. Schema 44 is unreleased (v0.1.6
  shipped 43). Pre-upgrade holds read as waiting for a human.
- The client seeds hold sets from every summary and tracks side questions
  for cold sessions; `activity()` reads summary-level state only.
- herdr resume names the focused session's root (`--session` opens roots
  only), or nothing when the root is unknown.
- The acknowledgement read is bounded to 4 KiB; the sequence clock is
  max(wall clock, previous + 1) with an injectable instant, so its test is
  deterministic; streamed deltas no longer trigger the aggregate fold.

Refs: ENG-1034

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d36bdee123

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/qq-client/src/state.rs Resolved
Comment thread crates/qq-client/src/state.rs Resolved
Comment thread crates/qq-tui/src/terminal.rs Resolved
- activity() folds every stored session, including children whose parent is not loaded.
- Snapshot replay covers every installed body, not only the focused one.
- Hold and side-question projections fold into the summary query: no extra query per session.
- A failed escalation write fails the run instead of waiting unannounced.
- No herdr report before the first snapshot.

Refs: ENG-1034
@lg2m
lg2m merged commit 201b1cb into main Oct 14, 2026
6 checks passed
@lg2m
lg2m deleted the feat/eng-1034-herdr-agent-state branch October 14, 2026 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant