Skip to content

Deepen process supervision for reply-driven Plan usage reads #2443

In review

Description

@JacobStephens2

What to build

Run the Codex and Muse Plan usage exchanges through the shared process module. A read finishes as soon as its replies arrive, even if the Harness keeps running. The process module stops the work it started and closes its pipes before returning control to Plan usage.

Acceptance criteria

  • Codex app-server and Muse serve use the shared process owner for spawn, piped input and output, the deadline, interruption, and cleanup. Delete the Plan usage module's private child wait, kill and detached stdout reader. Send the same commands and newline-delimited requests and keep stderr discarded.
  • Apply the existing ten-second limit to the exchange from before launch, including request writes. Keep stdin open through reply collection. Finish when the requested replies arrive, stdout ends, or the deadline or interruption stops the exchange.
  • On every ending, stop any remaining owned work, including the process group and known descendants, reap the launcher and finish all I/O workers. A helper holding a pipe and a child that never consumes stdin must leave the process module able to enforce its deadline.
  • Preserve accepted reply IDs, reply filtering, and result interpretation. Keep nonempty partial batches at stdout termination or deadline, and keep the existing no-answer diagnostic for empty batches. On interruption, discard the batch and preserve the saved Plan usage snapshot. Keep Codex's login fallback, Muse's account and usage handling, and machine-local refresh and cache policy.
  • Exercise the process interface with local fixtures for reply-driven completion while stdin is open and the child is alive, partial replies at the deadline, and bounded cleanup with an outstanding pipe. Extend the existing Plan usage CLI interruption test to include a Muse helper that holds stdout. Keep the existing provider request, response and cache checks passing. Update the domain-to-code index to show where the exchange is owned.

Blocked by

  • None (can start immediately).

Decisions

  • Put reply-driven exchange behind the existing process seam. Give the process module a prepared command, serialized input, a deadline and a stdout consumer that can signal completion and retain what it received. The two Plan usage callers already share a protocol reader, so they need one process operation and can keep their existing reply collector. Existing capture, streaming and one-shot callers retain their completion rules.
  • Reuse the shared executor's ownership, ordinary interruption and hard-stop path. An exchange has a reply-driven ending in addition to EOF, deadline and interruption. Even a successful reply-driven ending must invoke cleanup because the server can still be running. Keep stdin open while reading replies and make the pipe I/O cancellable so a blocked write or a lingering pipe holder cannot strand a worker during cleanup. Use one deadline for the exchange because writing is part of the read.
  • Keep JSON-RPC framing and interpretation in Plan usage. Codex and Muse send different envelopes and await different reply IDs. Preserve the collector's handling of invalid JSON, unrelated lines and a final line at actual EOF. Preserve replies already collected when the deadline ends the exchange without treating a line cut off by cancellation as EOF. The launcher status and writes that end early still leave the read to judge the replies it received.
  • Let ordinary interruption win over collected replies. The Plan usage refresh already checks interruption after joining its probes and before writing the snapshot, so storing responses and releasing the refresh lock can stay with that existing flow. ADR 0031 still governs the non-billed reads and machine-local routing.
  • Test the process seam with controlled local children and check replies, elapsed bounds and fixture lifetime. Test provider behavior through the isolated Plan usage CLI using faux Harnesses, which can exercise the request and saved-snapshot contracts without subscription credentials. Use the repository's deadline guidance for fixtures and assertions.
  • Publish one standalone Ticket because both readers use one exchange and the refactor and regressions can land together. The glossary and ADRs already describe the domain policy. The earlier one-shot Ticket explicitly kept the reply-driven reads in their original implementation. #2418

Architecture review

Strength Strong · Dependencies local-substitutable

Files src/plan_usage/read.rs, src/plan_usage.rs, src/process.rs, src/process/tree.rs, src/process/tests.rs, tests/plan_usage.rs, docs/code-navigation.md

Before

flowchart LR
  usage["Plan usage"] --> rpc["Codex and Muse readers"]
  usage --> one["One-shot readers"]
  rpc --> own["Private child and pipe ownership"]
  own --> harness["Harness CLI"]
  one --> process["Process module"]
  process --> harness
  classDef leak stroke:#dc2626,stroke-width:2px
  class own leak
Loading

After

flowchart LR
  usage["Plan usage"] --> rpc["Codex and Muse readers"]
  usage --> one["One-shot readers"]
  subgraph process["Process module"]
    direction TB
    exchange["Reply-driven exchange"] --> own["Shared child and pipe ownership"]
    shot["One-shot execution"] --> own
  end
  rpc --> exchange
  one --> shot
  own --> harness["Harness CLI"]
  classDef deep stroke-width:3px
  class process deep
Loading

Problem The Plan usage exchange starts its deadline after synchronous request writes and owns its own teardown, which only kills the launcher and leaves the stdout worker unjoined.

Solution Deepen the process module to own reply-driven subprocess lifetime while the Plan usage readers supply the requests and interpret the replies.

Wins

  • Deadline and cleanup share locality
  • Two readers gain one interface
  • Fixtures test the process seam

Activity

  1. added
    needs-triage
    ready-for-agent
    architect-plan
    in-progress
    and removed
    needs-triage
    ready-for-agent
    on Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    architect-planin-progress

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions