Skip to content

fix(daemon): make subscribe-loop silent failures loud (card 807193ab) - #1102

Merged
joelteply merged 6 commits into
rust-rewritefrom
807193ab/loud-subscribe-fail
Jun 6, 2026
Merged

joelteply merged 6 commits into
rust-rewritefrom
807193ab/loud-subscribe-fail

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

No description provided.

joelteply and others added 6 commits May 31, 2026 09:26
…-host constructor

Multi-citizen hosts (Continuum personas, future external-agent
hosts) need to spawn each hosted citizen with BOTH:
  1. Its own identity (so `airc peers` from another scope sees
     each citizen as a separate enrolled participant), and
  2. The daemon's live publish/subscribe (so the citizen can
     `say()` / `subscribe()` over the router, not just inspect
     local state).

Today the constructor matrix only offers ONE of these per call:
  - `Airc::open_as(home, agent_name)` — identity ✓, daemon ✗
  - `Airc::attach(home, socket)`      — daemon ✓, identity ✗

So a host hosting N citizens has to reach for the
(intentionally private) `with_daemon_client` builder via some
awkward dance — or fork the bootstrap inline. Neither is
ergonomic; both leak abstraction the public API meant to seal.

This PR adds the natural diagonal of the matrix:

  pub async fn attach_as(home, agent_name, socket) -> Result<Self>

Equivalent to `open_as(home, agent_name).await?.with_daemon_client
(DaemonClient::new(socket))` but spelled as one method so
consumers don't reach for the private builder.

### Concrete consumer

Continuum-core's upcoming `PersonaAircRuntime` (continuum PR
#1, see continuum task #86) spawns one `Airc` instance per
hosted persona — each persona at its own
`~/.continuum/personas/<name>/airc/` home, with its own
Ed25519 identity, addressed by `agent_name = <persona>` — and
needs the daemon-connected variant so the persona can
participate in live rooms.

The mental model: continuum is to airc what Codex is to airc —
a host that runs N citizens, each first-class on the substrate.
That host needs one constructor that gives it (identity ×
daemon) cleanly. `attach_as` IS that.

### Drift guard

The implementation is a 5-line delegation to the existing
`open_as` + `with_daemon_client` private helper, so this
constructor cannot drift from the pair it composes. Any future
change to either half automatically applies here.

### Test plan

- [x] `cargo test -p airc-lib` — 1 passed, 0 failed (existing
  doctests; new constructor uses the same delegation paths
  that `attach` and `open_as` already cover)
- [x] `cargo clippy -p airc-lib --no-deps -- -D warnings` clean
- [x] `cargo fmt --check` clean
- [ ] Adversarial reviewer agent verdict per AGENTS.md §0 + airc#1094
- [ ] Continuum PR #1 (task #86) consumes this constructor in
  `PersonaAircRuntime::bootstrap` — substantive integration test

### References

- Continuum memory `personas-are-citizens-airc-is-identity-provider`
- Continuum memory `airc-headers-are-the-routing-layer`
- Continuum workflow w801jcu9r design synthesis — identified
  this missing constructor in the airc-lib API audit's `gaps`
  field
- Joel, 2026-05-31: "We can enhance facilities we edit airc.
  They use airc as their identity provider and their own
  connection to the grid." This PR is the airc-side facility
  enhancement for the persona-as-citizen architecture.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
… IPC wire vocabulary

External consumers building `PublishRequest`/`InboxRequest` from SDK-
shaped state (continuum-core, OpenClaw, Hermes, future grid workers,
this repo's own CLI) need to translate the chat-flavored types
(`FrameKind`, `MentionTarget`, `TranscriptCursor`) into the v5 IPC
wire vocabulary (`IpcKind`, `IpcTarget`, `IpcCursor`).

Before this PR these conversions lived as private free functions
(`framekind_to_ipc`, `mention_to_ipc_target`, `pack_seq`,
`unpack_seq`) in `airc-lib/src/daemon.rs`. Any external consumer
had to either:
  (a) Pull all of `airc-lib` for one private function — wrong
      surface for drive-by use, and the helpers are `fn` not `pub fn`.
  (b) Re-implement the same bit-shifting + variant matching in their
      own code — drift class. Continuum did this transitionally
      during the v5 migration before promoting them here.

This PR promotes them to **`impl From<>` blocks in airc-ipc**, the
smallest crate that depends on both `airc-core` (where the SDK
types live) and `airc-protocol` (where `FrameKind` lives). Co-
locating the conversions with the IPC vocabulary they produce gives
every consumer `pub_req.kind = frame_kind.into()` instead of
reaching for a free function.

### What ships

- `crates/airc-ipc/src/sdk_conversions.rs` (NEW, ~170 lines including
  6 tests):
  - `impl From<FrameKind> for IpcKind` — total, lossless
  - `impl From<MentionTarget> for IpcTarget` — total, lossless
    (room mentions round-trip via the `room:<uuid>` endpoint convention)
  - `impl From<TranscriptCursor> for IpcCursor` — total, lossless
  - `impl From<IpcCursor> for TranscriptCursor` — total, lossless,
    round-trip safe
  - `pub const COUNTER_BITS: u32 = 40` + `COUNTER_MASK` — published
    so any consumer needing to reproduce the lamport-packing layout
    (without going through the conversion) pins against the same
    constant. If anyone shifts the layout, every dependent recompiles
    + the round-trip tests fail loud.

- `crates/airc-ipc/src/lib.rs` — re-export `COUNTER_BITS`/`COUNTER_MASK`;
  declare the new module.

- `crates/airc-lib/src/daemon.rs` — delete the private duplicates
  (`framekind_to_ipc`, `mention_to_ipc_target`); switch call sites
  to `.into()`; import `COUNTER_BITS`/`COUNTER_MASK` from `airc-ipc`
  so the local `pack_seq`/`unpack_seq` helpers stay byte-compatible
  via shared constant.

### Doctrinal alignment

Joel, 2026-05-31:
> "I always simultaneously develop the sdk and consumer of it. It
>  helps you build the best patterns."

This PR is the SDK half of the v5 owner-core consumer migration
landing in continuum's sibling PR. The conversion shape was chosen
to fit continuum's call sites (idiomatic `.into()` in
`PublishRequest`/`InboxRequest` construction) — exactly the
co-evolution pattern. Doing them simultaneously also caught the
"airc-lib internals are the wrong surface" anti-pattern that would
have otherwise persisted as drift.

Pattern memory for future PRs: when continuum (or any other airc
consumer) needs an airc-side helper that's currently private,
upstream it as the natural extension of the existing public
vocabulary — not as a "consumer-shaped" SDK method nor a duplicated
helper in the consumer.

### Test plan

- [x] `cargo test -p airc-ipc` — 33/33 pass (6 new tests in
  `sdk_conversions::tests`)
- [x] `cargo test -p airc-lib` — 1 passed, 0 failed, 4 ignored
  (doc-test compile check); no regressions from removing the
  internal `framekind_to_ipc`/`mention_to_ipc_target` helpers
- [x] `cargo build --release --bin airc` — clean
- [ ] Adversarial reviewer agent verdict (per AGENTS.md §0 doctrine)

### References

- Continuum task #82 — headless break #3 (Response::Event schema
  mismatch); this airc PR is the SDK half, continuum sibling PR is
  the consumer half.
- AGENTS.md §0 + airc#1094 — agent sign-off doctrine.
- airc#1095 (still open pending Windows CI) — `airc ipc-endpoint`
  command. Same iteration loop pattern.
- `crates/airc-lib/src/daemon.rs` — historical home of these helpers,
  now thinned to call the From impls.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
…rs, not identity-holders

When a bridge connects an external surface (Slack, Discord, Telegram,
Teams, Zoom, X, etc.) the citizen's stable identity stays in airc.
The bridge holds whatever platform credentials it needs to post on
the citizen's behalf, but it never owns the persona. Unplug a bridge
and the citizen persists; plug in a different platform's bridge and
the same citizen appears there with the same keypair, name, and
reputation.

This formalizes what "same personas, everywhere" means at the
substrate level — pairing with the continuum-side README change
on feat/persona-helper-ai-as-airc-citizen.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
#1100)

* fix(work): work_board(usize::MAX) → work_board_complete(PAGE_SIZE) at all 9 callsites (card acd72c81)

`airc work state X closed` and 8 other CLI paths called
`airc.work_board(usize::MAX)` to look up a single card or compute
a snapshot. With `usize::MAX`, the daemon-attached path issues
ONE Inbox RPC asking for every event in the room (the fetch
multiplier saturates), and the daemon serializes all of them
into a single CBOR frame. Once the room accumulates ~9000+ bus
events (operationally hit on Joel's box 2026-06-01), the response
trips `airc_ipc::codec::MAX_FRAME_BYTES`:

  daemon I/O: ipc frame too large: 16973574 bytes exceeds 16777216

Every state transition through these callsites then fails, the
kanban freezes behind merged PRs, and other agents pile up on
the same flake without recourse.

## Fix

`work_board_complete(page_size)` already exists for the same
intent (complete projection) but paginates the IPC transcript
fetch (airc-lib/src/work.rs:776 → daemon_room_transcripts at
airc-lib/src/daemon.rs:314). Each Inbox RPC asks for `page_size`
events, the client loops until done, no individual frame exceeds
the cap. Same projection completeness, low-latency per RPC,
correct architecture.

This commit:

1. Introduces `pub const WORK_BOARD_PROJECTION_PAGE_SIZE: usize = 1024`
   in airc-lib/src/work.rs as the canonical page size for
   complete-projection callers. 1024 events per page is
   comfortably under the 16 MiB cap (events are typed records
   in the kilobyte range, not blobs) and keeps the round-trip
   count low for 9000+ event rooms.
2. Updates `work_board(limit)`'s docstring to call out
   `usize::MAX` as forbidden and point at
   `work_board_complete`.
3. Swaps all 9 `work_board(usize::MAX)` callsites to
   `work_board_complete(WORK_BOARD_PROJECTION_PAGE_SIZE)`:
   - airc-cli/src/work_commands.rs (5 sites)
   - airc-cli/src/work_commands_git.rs (1 site)
   - airc-cli/src/work_commands_gh.rs (2 sites)
   - airc-lib/src/agent_heartbeat.rs (1 site)
4. Exports `WORK_BOARD_PROJECTION_PAGE_SIZE` from the airc-lib
   crate root so future callers reference one canonical
   constant instead of re-picking page sizes.

## Verification

- `cargo check --workspace`: clean.
- `cargo build --release -p airc-cli`: clean.
- Reinstalled the binary to /Users/joel/.local/bin/airc,
  restarted daemon, ran `airc work state 0462c1a8... closed` —
  the 16 MiB IPC frame error is gone; the CLI now correctly
  reports the close-lifecycle gate's actual semantic
  refusal ("requires Merged predecessor"). Same writes that
  failed pre-fix now reach the daemon successfully.

## Doctrine

[[every-error-is-an-opportunity-to-battle-harden]]: fix the
immediate symptom AND the class. Every existing callsite gets
the paginated path; future ones reference the canonical const.

[[host-the-seemingly-impossible]]: the substrate now scales to
9000+ events without IPC-cap failures on routine writes.

Card: acd72c81

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* feat(merger): reconcile already-merged PRs instead of skipping (card acd72c81 follow-up)

When `gh pr view` reports `state="MERGED"` for a card's linked PR,
the merger previously returned `GateResult::NotReady("PR state is
MERGED (not OPEN)")` and skipped. That left the kanban projection
permanently out of sync with GitHub: the PR was merged but the
card stayed in Review. Stale cards accumulated; closure
(Review → Closed) needs a Merged predecessor and never got one.

This is the third symptom of the same root cause as the IPC
cap fix: the merger had every piece of information it needed to
reconcile, but the gate only had a "merge it" path and a "skip
it" path — no "the merge already happened, just update our
projection" path.

## Behavior change

The merger now distinguishes:
- `GateResult::Green` — open + green CI → call `gh pr merge` +
  emit `PullRequestMerged` (unchanged)
- `GateResult::AlreadyMerged { merged_at_ms }` — state==MERGED
  → emit `PullRequestMerged` ONLY; no `gh pr merge` call
  (new)
- `GateResult::NotReady(reason)` — state != OPEN and !=
  MERGED, or open with failures (unchanged)

The reconcile path uses `view.mergedAt` as the canonical
`merged_at_ms` when gh supplies it, falling back to wall-clock-now.
gh's `--json` query now includes `mergedAt` (one extra field; no
new RPC).

## Symmetry with `airc work merge`

The manual `airc work merge X` CLI command consumes the same
gate. It now handles `AlreadyMerged` symmetrically: reconciles
without a `gh pr merge` call, prints
`reconciled: card=X pr=#N repo=R (PR was already merged on GitHub)`.

## End-to-end verification

Built + reinstalled the binary, ran the merger against the
Joel-box backlog of 4 already-merged cards (PR #1500, #1501,
#1502, #1503):

  airc-merger: reconciled already-merged card=0462c1a8 pr=#1502
  airc-merger: reconciled already-merged card=2c844fae pr=#1500
  airc-merger: reconciled already-merged card=63ca1f00 pr=#1501
  airc-merger: reconciled already-merged card=87fbb385 pr=#1503

Board after: all 4 transitioned Review → Merged. `airc work
close` then succeeded on each (Merged → Closed). Kanban finally
matches GitHub reality.

## Tests

- `evaluate_gh_view_routes_merged_state_to_already_merged`: MERGED
  + mergedAt → AlreadyMerged with parsed canonical ms
- `evaluate_gh_view_falls_back_to_wallclock_when_mergedAt_absent`:
  the fallback path produces a nonzero ms
- `evaluate_gh_view_routes_closed_state_to_not_ready`: CLOSED
  (without merge) stays NotReady — we don't auto-reconcile abandoned
  PRs into Merged state
- `parse_iso8601_to_ms_handles_standard_gh_format`: the helper
  handles the standard gh timestamp shape + invalid input
- Updated `refuses_when_pr_is_already_merged` →
  `reconciles_when_pr_is_already_merged` to encode the new
  behavior and the rationale

All 28 merger tests pass.

## Doctrine

[[every-error-is-an-opportunity-to-battle-harden]]: the
"skip-and-leak" anti-pattern is gone — every terminal PR state
the merger sees now has a kanban-reconciliation action, not just
the happy-path "merge".

Card: acd72c81 (follow-up slice; same PR #1100)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(merger): cargo fmt + clippy fixes for CI green (card acd72c81 follow-up)

PR #1100's CI surfaced three issues missed in local cargo check:

1. cargo fmt: AlreadyMerged variant's anonymous field, the
   "MERGED + mergedAt" json test literal, and the work_board_complete
   call sites reflowed by rustfmt's wrap rules.

2. clippy --deny-warnings: the new test
   `evaluate_gh_view_falls_back_to_wallclock_when_mergedAt_absent`
   used `mergedAt` (camelCase from gh) in the function name — clippy
   non_snake_case lint. Renamed to `merged_at`.

3. workspace test: airc-lib's internal `ok_view` test helper
   constructs PrView { state, mergeable, status_check_rollup, .. }
   without the new `merged_at` field. Added `merged_at: None`.

Local cargo fmt --check + clippy --deny-warnings + cargo test
-p airc-cli -p airc-lib are now green; the same three CI jobs
that failed on the prior push (cargo fmt, cargo clippy, cargo
test on macos/ubuntu/windows) should pass on this push.

Card: acd72c81

Co-Authored-By: Claude Opus 4.7 <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 <[email protected]>
Replace the previous eprintln!-based silent-fail surfacing with
structured tracing::warn! calls. Each warning carries the
channel UUID, the error chain, and (for reattach paths) the
current backoff_ms as KV fields — operators can filter by field,
parse with jq, alert on specific channel/error pairs.

Matches the airc-relay convention (server.rs / connection.rs use
tracing::warn! the same way) and lets airc-lib's diagnostics
land in whatever subscriber the embedder installs.

Adds tracing = "0.1" to airc-lib's deps; sibling crates
(airc-relay, airc-transport via their own deps) already pull
the same major.

Card: 807193ab

Co-Authored-By: Claude Opus 4.7 <[email protected]>
joelteply added a commit that referenced this pull request Jun 6, 2026
…ard c9b28925) (#1105)

* feat(airc-lib): `Airc::attach_as(home, agent_name, socket)` — citizen-host constructor

Multi-citizen hosts (Continuum personas, future external-agent
hosts) need to spawn each hosted citizen with BOTH:
  1. Its own identity (so `airc peers` from another scope sees
     each citizen as a separate enrolled participant), and
  2. The daemon's live publish/subscribe (so the citizen can
     `say()` / `subscribe()` over the router, not just inspect
     local state).

Today the constructor matrix only offers ONE of these per call:
  - `Airc::open_as(home, agent_name)` — identity ✓, daemon ✗
  - `Airc::attach(home, socket)`      — daemon ✓, identity ✗

So a host hosting N citizens has to reach for the
(intentionally private) `with_daemon_client` builder via some
awkward dance — or fork the bootstrap inline. Neither is
ergonomic; both leak abstraction the public API meant to seal.

This PR adds the natural diagonal of the matrix:

  pub async fn attach_as(home, agent_name, socket) -> Result<Self>

Equivalent to `open_as(home, agent_name).await?.with_daemon_client
(DaemonClient::new(socket))` but spelled as one method so
consumers don't reach for the private builder.

### Concrete consumer

Continuum-core's upcoming `PersonaAircRuntime` (continuum PR
#1, see continuum task #86) spawns one `Airc` instance per
hosted persona — each persona at its own
`~/.continuum/personas/<name>/airc/` home, with its own
Ed25519 identity, addressed by `agent_name = <persona>` — and
needs the daemon-connected variant so the persona can
participate in live rooms.

The mental model: continuum is to airc what Codex is to airc —
a host that runs N citizens, each first-class on the substrate.
That host needs one constructor that gives it (identity ×
daemon) cleanly. `attach_as` IS that.

### Drift guard

The implementation is a 5-line delegation to the existing
`open_as` + `with_daemon_client` private helper, so this
constructor cannot drift from the pair it composes. Any future
change to either half automatically applies here.

### Test plan

- [x] `cargo test -p airc-lib` — 1 passed, 0 failed (existing
  doctests; new constructor uses the same delegation paths
  that `attach` and `open_as` already cover)
- [x] `cargo clippy -p airc-lib --no-deps -- -D warnings` clean
- [x] `cargo fmt --check` clean
- [ ] Adversarial reviewer agent verdict per AGENTS.md §0 + airc#1094
- [ ] Continuum PR #1 (task #86) consumes this constructor in
  `PersonaAircRuntime::bootstrap` — substantive integration test

### References

- Continuum memory `personas-are-citizens-airc-is-identity-provider`
- Continuum memory `airc-headers-are-the-routing-layer`
- Continuum workflow w801jcu9r design synthesis — identified
  this missing constructor in the airc-lib API audit's `gaps`
  field
- Joel, 2026-05-31: "We can enhance facilities we edit airc.
  They use airc as their identity provider and their own
  connection to the grid." This PR is the airc-side facility
  enhancement for the persona-as-citizen architecture.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* feat(airc-ipc): `impl From<>` blocks bridging SDK transcript types to IPC wire vocabulary

External consumers building `PublishRequest`/`InboxRequest` from SDK-
shaped state (continuum-core, OpenClaw, Hermes, future grid workers,
this repo's own CLI) need to translate the chat-flavored types
(`FrameKind`, `MentionTarget`, `TranscriptCursor`) into the v5 IPC
wire vocabulary (`IpcKind`, `IpcTarget`, `IpcCursor`).

Before this PR these conversions lived as private free functions
(`framekind_to_ipc`, `mention_to_ipc_target`, `pack_seq`,
`unpack_seq`) in `airc-lib/src/daemon.rs`. Any external consumer
had to either:
  (a) Pull all of `airc-lib` for one private function — wrong
      surface for drive-by use, and the helpers are `fn` not `pub fn`.
  (b) Re-implement the same bit-shifting + variant matching in their
      own code — drift class. Continuum did this transitionally
      during the v5 migration before promoting them here.

This PR promotes them to **`impl From<>` blocks in airc-ipc**, the
smallest crate that depends on both `airc-core` (where the SDK
types live) and `airc-protocol` (where `FrameKind` lives). Co-
locating the conversions with the IPC vocabulary they produce gives
every consumer `pub_req.kind = frame_kind.into()` instead of
reaching for a free function.

### What ships

- `crates/airc-ipc/src/sdk_conversions.rs` (NEW, ~170 lines including
  6 tests):
  - `impl From<FrameKind> for IpcKind` — total, lossless
  - `impl From<MentionTarget> for IpcTarget` — total, lossless
    (room mentions round-trip via the `room:<uuid>` endpoint convention)
  - `impl From<TranscriptCursor> for IpcCursor` — total, lossless
  - `impl From<IpcCursor> for TranscriptCursor` — total, lossless,
    round-trip safe
  - `pub const COUNTER_BITS: u32 = 40` + `COUNTER_MASK` — published
    so any consumer needing to reproduce the lamport-packing layout
    (without going through the conversion) pins against the same
    constant. If anyone shifts the layout, every dependent recompiles
    + the round-trip tests fail loud.

- `crates/airc-ipc/src/lib.rs` — re-export `COUNTER_BITS`/`COUNTER_MASK`;
  declare the new module.

- `crates/airc-lib/src/daemon.rs` — delete the private duplicates
  (`framekind_to_ipc`, `mention_to_ipc_target`); switch call sites
  to `.into()`; import `COUNTER_BITS`/`COUNTER_MASK` from `airc-ipc`
  so the local `pack_seq`/`unpack_seq` helpers stay byte-compatible
  via shared constant.

### Doctrinal alignment

Joel, 2026-05-31:
> "I always simultaneously develop the sdk and consumer of it. It
>  helps you build the best patterns."

This PR is the SDK half of the v5 owner-core consumer migration
landing in continuum's sibling PR. The conversion shape was chosen
to fit continuum's call sites (idiomatic `.into()` in
`PublishRequest`/`InboxRequest` construction) — exactly the
co-evolution pattern. Doing them simultaneously also caught the
"airc-lib internals are the wrong surface" anti-pattern that would
have otherwise persisted as drift.

Pattern memory for future PRs: when continuum (or any other airc
consumer) needs an airc-side helper that's currently private,
upstream it as the natural extension of the existing public
vocabulary — not as a "consumer-shaped" SDK method nor a duplicated
helper in the consumer.

### Test plan

- [x] `cargo test -p airc-ipc` — 33/33 pass (6 new tests in
  `sdk_conversions::tests`)
- [x] `cargo test -p airc-lib` — 1 passed, 0 failed, 4 ignored
  (doc-test compile check); no regressions from removing the
  internal `framekind_to_ipc`/`mention_to_ipc_target` helpers
- [x] `cargo build --release --bin airc` — clean
- [ ] Adversarial reviewer agent verdict (per AGENTS.md §0 doctrine)

### References

- Continuum task #82 — headless break #3 (Response::Event schema
  mismatch); this airc PR is the SDK half, continuum sibling PR is
  the consumer half.
- AGENTS.md §0 + airc#1094 — agent sign-off doctrine.
- airc#1095 (still open pending Windows CI) — `airc ipc-endpoint`
  command. Same iteration loop pattern.
- `crates/airc-lib/src/daemon.rs` — historical home of these helpers,
  now thinned to call the From impls.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* docs(README): cross-surface identity doctrine — bridges are translators, not identity-holders

When a bridge connects an external surface (Slack, Discord, Telegram,
Teams, Zoom, X, etc.) the citizen's stable identity stays in airc.
The bridge holds whatever platform credentials it needs to post on
the citizen's behalf, but it never owns the persona. Unplug a bridge
and the citizen persists; plug in a different platform's bridge and
the same citizen appears there with the same keypair, name, and
reputation.

This formalizes what "same personas, everywhere" means at the
substrate level — pairing with the continuum-side README change
on feat/persona-helper-ai-as-airc-citizen.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(work): work_board(usize::MAX) trips 16 MiB IPC cap (card acd72c81) (#1100)

* fix(work): work_board(usize::MAX) → work_board_complete(PAGE_SIZE) at all 9 callsites (card acd72c81)

`airc work state X closed` and 8 other CLI paths called
`airc.work_board(usize::MAX)` to look up a single card or compute
a snapshot. With `usize::MAX`, the daemon-attached path issues
ONE Inbox RPC asking for every event in the room (the fetch
multiplier saturates), and the daemon serializes all of them
into a single CBOR frame. Once the room accumulates ~9000+ bus
events (operationally hit on Joel's box 2026-06-01), the response
trips `airc_ipc::codec::MAX_FRAME_BYTES`:

  daemon I/O: ipc frame too large: 16973574 bytes exceeds 16777216

Every state transition through these callsites then fails, the
kanban freezes behind merged PRs, and other agents pile up on
the same flake without recourse.

## Fix

`work_board_complete(page_size)` already exists for the same
intent (complete projection) but paginates the IPC transcript
fetch (airc-lib/src/work.rs:776 → daemon_room_transcripts at
airc-lib/src/daemon.rs:314). Each Inbox RPC asks for `page_size`
events, the client loops until done, no individual frame exceeds
the cap. Same projection completeness, low-latency per RPC,
correct architecture.

This commit:

1. Introduces `pub const WORK_BOARD_PROJECTION_PAGE_SIZE: usize = 1024`
   in airc-lib/src/work.rs as the canonical page size for
   complete-projection callers. 1024 events per page is
   comfortably under the 16 MiB cap (events are typed records
   in the kilobyte range, not blobs) and keeps the round-trip
   count low for 9000+ event rooms.
2. Updates `work_board(limit)`'s docstring to call out
   `usize::MAX` as forbidden and point at
   `work_board_complete`.
3. Swaps all 9 `work_board(usize::MAX)` callsites to
   `work_board_complete(WORK_BOARD_PROJECTION_PAGE_SIZE)`:
   - airc-cli/src/work_commands.rs (5 sites)
   - airc-cli/src/work_commands_git.rs (1 site)
   - airc-cli/src/work_commands_gh.rs (2 sites)
   - airc-lib/src/agent_heartbeat.rs (1 site)
4. Exports `WORK_BOARD_PROJECTION_PAGE_SIZE` from the airc-lib
   crate root so future callers reference one canonical
   constant instead of re-picking page sizes.

## Verification

- `cargo check --workspace`: clean.
- `cargo build --release -p airc-cli`: clean.
- Reinstalled the binary to /Users/joel/.local/bin/airc,
  restarted daemon, ran `airc work state 0462c1a8... closed` —
  the 16 MiB IPC frame error is gone; the CLI now correctly
  reports the close-lifecycle gate's actual semantic
  refusal ("requires Merged predecessor"). Same writes that
  failed pre-fix now reach the daemon successfully.

## Doctrine

[[every-error-is-an-opportunity-to-battle-harden]]: fix the
immediate symptom AND the class. Every existing callsite gets
the paginated path; future ones reference the canonical const.

[[host-the-seemingly-impossible]]: the substrate now scales to
9000+ events without IPC-cap failures on routine writes.

Card: acd72c81

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* feat(merger): reconcile already-merged PRs instead of skipping (card acd72c81 follow-up)

When `gh pr view` reports `state="MERGED"` for a card's linked PR,
the merger previously returned `GateResult::NotReady("PR state is
MERGED (not OPEN)")` and skipped. That left the kanban projection
permanently out of sync with GitHub: the PR was merged but the
card stayed in Review. Stale cards accumulated; closure
(Review → Closed) needs a Merged predecessor and never got one.

This is the third symptom of the same root cause as the IPC
cap fix: the merger had every piece of information it needed to
reconcile, but the gate only had a "merge it" path and a "skip
it" path — no "the merge already happened, just update our
projection" path.

## Behavior change

The merger now distinguishes:
- `GateResult::Green` — open + green CI → call `gh pr merge` +
  emit `PullRequestMerged` (unchanged)
- `GateResult::AlreadyMerged { merged_at_ms }` — state==MERGED
  → emit `PullRequestMerged` ONLY; no `gh pr merge` call
  (new)
- `GateResult::NotReady(reason)` — state != OPEN and !=
  MERGED, or open with failures (unchanged)

The reconcile path uses `view.mergedAt` as the canonical
`merged_at_ms` when gh supplies it, falling back to wall-clock-now.
gh's `--json` query now includes `mergedAt` (one extra field; no
new RPC).

## Symmetry with `airc work merge`

The manual `airc work merge X` CLI command consumes the same
gate. It now handles `AlreadyMerged` symmetrically: reconciles
without a `gh pr merge` call, prints
`reconciled: card=X pr=#N repo=R (PR was already merged on GitHub)`.

## End-to-end verification

Built + reinstalled the binary, ran the merger against the
Joel-box backlog of 4 already-merged cards (PR #1500, #1501,
#1502, #1503):

  airc-merger: reconciled already-merged card=0462c1a8 pr=#1502
  airc-merger: reconciled already-merged card=2c844fae pr=#1500
  airc-merger: reconciled already-merged card=63ca1f00 pr=#1501
  airc-merger: reconciled already-merged card=87fbb385 pr=#1503

Board after: all 4 transitioned Review → Merged. `airc work
close` then succeeded on each (Merged → Closed). Kanban finally
matches GitHub reality.

## Tests

- `evaluate_gh_view_routes_merged_state_to_already_merged`: MERGED
  + mergedAt → AlreadyMerged with parsed canonical ms
- `evaluate_gh_view_falls_back_to_wallclock_when_mergedAt_absent`:
  the fallback path produces a nonzero ms
- `evaluate_gh_view_routes_closed_state_to_not_ready`: CLOSED
  (without merge) stays NotReady — we don't auto-reconcile abandoned
  PRs into Merged state
- `parse_iso8601_to_ms_handles_standard_gh_format`: the helper
  handles the standard gh timestamp shape + invalid input
- Updated `refuses_when_pr_is_already_merged` →
  `reconciles_when_pr_is_already_merged` to encode the new
  behavior and the rationale

All 28 merger tests pass.

## Doctrine

[[every-error-is-an-opportunity-to-battle-harden]]: the
"skip-and-leak" anti-pattern is gone — every terminal PR state
the merger sees now has a kanban-reconciliation action, not just
the happy-path "merge".

Card: acd72c81 (follow-up slice; same PR #1100)

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(merger): cargo fmt + clippy fixes for CI green (card acd72c81 follow-up)

PR #1100's CI surfaced three issues missed in local cargo check:

1. cargo fmt: AlreadyMerged variant's anonymous field, the
   "MERGED + mergedAt" json test literal, and the work_board_complete
   call sites reflowed by rustfmt's wrap rules.

2. clippy --deny-warnings: the new test
   `evaluate_gh_view_falls_back_to_wallclock_when_mergedAt_absent`
   used `mergedAt` (camelCase from gh) in the function name — clippy
   non_snake_case lint. Renamed to `merged_at`.

3. workspace test: airc-lib's internal `ok_view` test helper
   constructs PrView { state, mergeable, status_check_rollup, .. }
   without the new `merged_at` field. Added `merged_at: None`.

Local cargo fmt --check + clippy --deny-warnings + cargo test
-p airc-cli -p airc-lib are now green; the same three CI jobs
that failed on the prior push (cargo fmt, cargo clippy, cargo
test on macos/ubuntu/windows) should pass on this push.

Card: acd72c81

Co-Authored-By: Claude Opus 4.7 <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 <[email protected]>

* feat(work): `airc work cleanup` — auto-prune merged-card worktrees (card c9b28925)

Today's session manually ran `git worktree remove acd72c81` after PR
#1100 merged, then cleaned 75+ GiB of stale build caches by hand
across two repos and four worktrees. Multi-session reality is worse —
a sustained operator builds up 10+ stale worktrees over weeks, each
holding a checkout + (when rebuilt) GiB of target cache. The
substrate already names the principle (`local-worktree-is-temp-dir`,
`substrate-is-a-good-citizen-on-the-host`); this commit starts
automating it.

## What ships

`airc work cleanup [--dry-run] [--force]`:

  $ airc work cleanup
  worktrees scanned: 4
    KeepActive:
      800ce5bd  PR #1103  Review
      807193ab  PR #1102  Review
      c409eaf5  PR #1104  Review
    SkipDirty:
      c9b28925  no PR  InProgress  uncommitted changes
  Nothing to remove.

Scan logic:

- List `~/.airc/worktrees/*/`.
- Resolve each worktree's card by short id (first 8 hex chars of the
  worktree dir name) via `work_board_complete`.
- Probe `git status --porcelain` for dirty / clean / unknown.
- Classify into one of five dispositions:
    - `Removable`     — card is Closed or Merged, worktree is clean.
    - `KeepActive`    — card is Open / Claimed / InProgress / Review / Blocked.
    - `SkipDirty`     — worktree has uncommitted changes.
    - `SkipNotGit`    — `git status` probe failed.
    - `SkipUnknownCard` — basename matches the short-id pattern but no
                          card on the current board (orphan).

Default behaviour: classify + print + do nothing destructive.
`--force` runs `git worktree remove` against everything in
`Removable`. `--dry-run` is the explicit-intent alias of the default.

## Safety: operator's WIP outranks hygiene

Worktrees in `SkipDirty`, `SkipNotGit`, or `SkipUnknownCard` are
NEVER removed silently — even with `--force`. The first slice
refuses to make destructive decisions on dirty / unknown state. The
operator commits, pushes, deletes manually, then re-runs cleanup —
which is the same discipline a careful human applies today.

## What this DOES NOT do (yet)

- Doesn't touch `target/` dirs. Build caches are per-project under
  operator-owned paths; the substrate can't safely wipe them without
  consent. Follow-up.
- Doesn't run on a timer. The always-on hygiene tick (with typed
  `WorkspaceCleaned` / `WorkspaceSkipped` events, disk-pressure
  thresholds) is the next slice on continuum task #88.
- Doesn't detect `git worktree lock`. The locked .claude/worktrees
  in Joel's setup are under `Development/airc/.claude/worktrees/`
  (outside the lease zone), so they're never seen by the scan
  today; explicit lock detection is a follow-up.

## Tests

Pure-function classifier + parser get unit-tested in isolation:

- `parse_worktree_short_id_accepts_canonical_shape` / rejects /
  truncates — covers the parser.
- `classifier_closed_clean_removes`
- `classifier_merged_clean_removes`
- `classifier_active_states_keep` — table-drive every active state.
- `classifier_dirty_never_removes_even_when_card_closed` — pins the
  WIP-outranks-hygiene contract.
- `classifier_no_card_returns_skip_unknown_card`
- `classifier_not_git_returns_skip_not_git`
- `disposition_display_priority_orders_removable_first` — pin the
  table sort so the operator sees actionable items first.

34/34 work_commands tests pass.

## Live smoke

Built + reinstalled + ran on Joel's machine after today's session.
Result above: 3 open PRs correctly identified as KeepActive, this
card's own worktree correctly identified as SkipDirty (in-flight
code), nothing destroyed. Exactly the desired safety posture.

Card: c9b28925

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(work): probe_dirty_status — detect unpushed commits, close WIP footgun (PR #1105 reviewer round 1)

Adversarial reviewer caught the headline footgun: the original
`git_status_porcelain` only checked working-tree-vs-HEAD
(uncommitted/untracked), NEVER HEAD-vs-upstream (unpushed
commits). A closed-card worktree with committed-but-unpushed WIP
on a branch with upstream tracking would have been classified
Clean → Removable → silently destroyed by `airc work cleanup
--force`. The PR's headline safety claim ("operator's WIP
outranks hygiene") was effectively false-advertised — the doc on
`cleanup_card_worktree` even explicitly promised an
unpushed-commits check the body never implemented.

This commit ships the actual check + reconciles the doc.

## Fixes

### BLOCK 1 — `cleanup_card_worktree` doc lie

Old doc claimed:
> REFUSES if the worktree has unpushed commits AND its branch is
> the worktree's current HEAD — those commits would be unreachable
> after pruning.

Body did no such check; only `git status --porcelain` was probed.
New doc describes ACTUAL behavior + the new two-pass
`probe_dirty_status` contract.

### BLOCK 2 — `probe_dirty_status` adds unpushed-commits probe

Renamed `git_status_porcelain` → `probe_dirty_status`. New two-pass
check:

1. `git status --porcelain` — uncommitted/untracked. Non-empty ⇒
   Dirty (unchanged from prior behavior).
2. `git rev-list --count @{u}..HEAD` — committed-but-not-pushed.
   Non-zero ⇒ Dirty.
   - If `@{u}` errors (no upstream tracking, detached HEAD,
     orphan branch): refuse to classify, return Unknown. Per
     `[[no-fallbacks-ever]]` we don't guess Clean for the
     ambiguous case.

### BLOCK 3 — unify protection across both terminal paths

`cleanup_card_worktree` (called by merger via #1091 and CLI `work
close`) now calls `probe_dirty_status` instead of its inline
porcelain-only check. Both terminal paths apply identical
safety:

- merger `perform_merge` → `cleanup_card_worktree` →
  `probe_dirty_status` (uncommitted + unpushed)
- CLI `airc work close` → `cleanup_card_worktree` → same
- CLI `airc work cleanup --force` → classifier-filtered to
  Removable (which means probe_dirty_status returned Clean) →
  `git_worktree_remove`

Same probe drives both gate decisions; no semantic drift.

## Doc updates

- `Disposition::SkipDirty` — clarified to "uncommitted or
  unpushed work" (was "uncommitted / unpushed" but only the first
  was actually checked).
- `Disposition::suffix(SkipDirty)` — "uncommitted or unpushed
  work" in the operator-facing table.
- `DirtyStatus` enum — variant docs describe the new two-pass
  contract + the Unknown-refuses-rather-than-guesses doctrine.

## Tests (+5 new, all 40 pass)

Real-git fixture tests (vs the prior tests which only exercised
the classifier's reaction to the `DirtyStatus` enum):

- `probe_dirty_status_clean_when_committed_and_pushed` — happy
  path
- `probe_dirty_status_dirty_on_uncommitted_change` — porcelain
  pass
- `probe_dirty_status_dirty_on_unpushed_commit` — the BLOCK 2
  scenario specifically; pins the safety contract on the function
  where the bug lived
- `probe_dirty_status_unknown_when_no_upstream_tracking` —
  ambiguous case refuses to classify
- `probe_dirty_status_unknown_when_not_a_git_dir` — probe
  failure → Unknown

40/40 work_commands tests pass.

## Doctrine

- `[[no-fallbacks-ever]]` — Unknown-on-ambiguous probe; no silent
  Clean assumption
- `[[local-worktree-is-temp-dir]]` — extended: the worktree IS
  the temp dir AS LONG AS its content is captured upstream;
  unpushed work is not captured upstream
- `[[every-error-is-an-opportunity-to-battle-harden]]` — the
  reviewer caught a real foot-gun; the fix is the production
  fix, not a test workaround

Card: c9b28925

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(work): fmt + clippy compliance on probe_dirty_status touch-up

CI on cce1b8a flagged cargo fmt + cargo clippy (deny warnings).
Both auto-fixable:
- cargo fmt — reformat the new test block + doc comments to repo
  style (74 lines reflowed in work_commands.rs)
- clippy doc_lazy_continuation — the four-line "REFUSES via
  probe_dirty_status if..." bullet had inner sub-bullets at
  inconsistent indentation; collapsed to a single prose
  paragraph that conveys the same three conditions inline.

No behavior change; the probe_dirty_status logic + tests from
cce1b8a are untouched.

Card: c9b28925

Co-Authored-By: Claude Opus 4.7 <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 <[email protected]>
@joelteply
joelteply merged commit 43b9a38 into rust-rewrite Jun 6, 2026
5 of 6 checks passed
@joelteply
joelteply deleted the 807193ab/loud-subscribe-fail branch June 6, 2026 07:30
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