Skip to content

Deepen Console live streams behind one subscription interface #1238

Closed

Description

@JacobStephens2

What to build

Deepen the Console's live streams behind one subscription interface. Inbox notices and live Command log or Session trace readers should share the implementation that keeps a viewer authorized, follows changes, sleeps while idle and releases its observer when it ends.

Preserve what the Day shift sees: immediate catch-up on connection, prompt updates, account revocation and expiry, and complete log output through writer completion. This is a refactor of existing Console behavior.

Acceptance criteria

  • Both Inbox notices and live log streaming use the same Console subscription module. Their callers no longer own account-revision bookkeeping, authorization scheduling, change-channel closure handling or the shared observer lease.
  • A connection or reconnect can produce its first result immediately. Later Inbox notices follow changes to Commands and coalesce to the latest revision; an account-only revision rechecks authorization without producing a Commands notice.
  • Both streams close after CLI sign-out, password reset, allowlist removal or session expiry. Stream checks do not extend idle sign-in lifetime. The existing no-sign-in behavior remains available.
  • Before each log batch, including consecutive buffered batches, the subscription checks channel availability and any required authorization. A nonterminal batch with output can be followed immediately by another batch without a new notification. An empty unfinished read sleeps until a relevant change; a completed final batch is emitted once and the stream ends.
  • Notifications arriving during an authorization check or a log read are not lost. If an account revision changes during its check, the newer revision is checked before another work turn is permitted. Observed channel closure or a failed viewer check cannot permit another work turn.
  • Each subscription retains the existing shared live-work observer for its lifetime and releases its lease on termination or drop. Multiple viewers continue sharing that observer; idle streams do not poll the log store or repeatedly read account contents.
  • Authorization read failures and blocking-task failures terminate the subscription. Inbox keeps its diagnostic-and-close behavior; log streaming keeps its single terminal log-error event. Log read failures keep the same behavior. No further payload is produced after a terminal result.
  • Log selection, inventory eligibility, the captured writer, line framing, the 256 KiB batch budget, byte offsets, Last-Event-ID, lines/commands event names, response headers, keep-alives and the finite JSON request path retain their existing contracts.
  • Deterministic tests at the subscription interface cover first readiness, account-only changes, wait versus drain, coalescing, a revision arriving during authorization, a change arriving during a read, closure, terminal errors and permanent termination. Existing HTTP tests continue exercising real Console accounts; extend the log route to the Inbox route's password-reset and allowlist-removal cases.
  • Add a log regression with more than two batch budgets buffered and no subsequent append: every byte is delivered in order without another notification, with a single final completion. Retain the idle-I/O and captured-writer completion regressions. Extend the existing child-clock expiry check to exercise both routes without changing the host clock.
  • Update the domain-to-code navigation if ownership moves. No glossary term or ADR change is needed: the module belongs to the existing Console concept and changes no domain behavior or recorded decision.

Blocked by

None (can start immediately).

Decisions

The design tree is settled in three rounds; no product decision remains open.

Round 1: scope and ownership

  1. One standalone Ticket. Two callers and one small shared lifecycle implementation fit one fresh implementation session. Splitting them would leave the duplicated policy in place between Tickets.
  2. Put the seam inside the Console, between readiness and payload production. The subscription owns viewer checks, revisions, sleeping, channel termination and observer lifetime. Inbox event construction and log selection, rendering, offsets, draining and error presentation remain with their existing callers, because those behaviors differ and already have useful interfaces.
  3. Use the existing Console concept. Subscription is a private implementation name, not a new domain concept. This reversible internal refactor preserves the Console's read-only role and the blocking/async split of ADR 0016; it warrants neither a new glossary entry nor an ADR.

Round 2: interface and lifecycle

  1. Expose construction and one asynchronous readiness operation. Construction accepts the existing change receiver, viewer and notifier and retains the notifier's shared observer lease. Readiness accepts Wait or Drain and returns an ordinary result containing a readiness boolean. True permits one work turn; false means normal terminal closure. This keeps the interface small and puts revision knowledge behind the seam.
  2. Use two readiness modes because both exist today. Wait permits initial catch-up immediately, then waits for a Commands revision, reauthorizing account-only revisions internally. Drain checks eligibility immediately, without requiring a new notification. Inbox always uses Wait; logs use Drain before each batch and switch to Wait only after an empty unfinished read. This preserves buffered output and avoids busy loops while idle.
  3. Keep authorization non-refreshing and off the async executor. Use the existing viewer check through blocking-task execution, initially and whenever the accounts revision changes. Keep the existing recovery-driven accounts revisions for time-based expiry. No independent timer or new account cache is needed, and work turns with the same checked accounts revision do not reread accounts.
  4. Capture revisions before allowing payload work, and retain intervening changes. Do not hold a watch borrow across an await. Record an accounts revision as authorized only after its check succeeds; if a newer accounts revision arrived during that check, check it before permitting work. Consume the Commands revision only when readiness is granted. Recheck channel closure before granting readiness after an awaited check. A change during a payload read therefore remains available when that read next needs to wait.
  5. Make terminal results permanent and release the observer lease. Revocation and channel closure return false. Authorization or blocking-task failures return an error once; later readiness calls return false. Routes preserve their current error presentation. Dropping or terminating the subscription drops its lease, so the notifier's existing shared-observer ownership continues to govern lifetime without a detached per-client producer.
  6. Choose the minimal state object over the two alternative designs. A controller returning raw revisions leaves Commands filtering and more lifecycle knowledge in both callers. A generic stream driver with callbacks and emit/wait/final control results makes Inbox simpler but adds payload scheduling and error conventions to the shared interface. The selected object concentrates the repeated policy while keeping the two actual payload loops explicit; it provides the best depth for this scope.

Round 3: tests and completion

  1. Test policy through the subscription interface and behavior through the existing HTTP seam. Use real Tokio watch channels for deterministic scheduling and termination tests. A private authorization seam uses two concrete adapters: the existing viewer check in production and a scripted check in scheduling tests. Keep that seam internal; callers do not receive another dependency interface. Scripted checks make revisions during a pending check, denial and errors deterministic, while the HTTP tests retain the real account/file implementation. No new public trait or execution framework is needed.
  2. Preserve tests that protect different behavior; replace duplicated lifecycle assertions only after shared-interface coverage exists. Real-account route tests protect wiring and revocation, idle-I/O tests protect sleeping, and writer tests protect draining and completion. The large buffered-log regression specifically prevents an incorrect implementation that waits after every yielded batch. Extend the existing child-clock expiry fixture for both routes so expiry is verified without changing machine time or treating stream activity as a sign-in refresh.
  3. Validate the implementation with focused Console tests, then the repository's affected-test selector against main. This is entirely internal, so no user-facing site text or generated prompts change. Recheck the hand-written pages only if implementation discovers an actual behavior change; such a change is outside this Ticket's settled scope.
  4. Publish only this recommendation. The open-issue corpus was checked for the same deepening, not merely the same files. The GitHub-driven Inbox work and the Inbox browser-selection bug do not cover subscription lifecycle consolidation. The top issue has only needs-triage; thirdshift owns its later readiness.

Architecture review

Strength: Strong · Dependencies: local-substitutable

Files: src/console/live.rs:15, src/console/logs.rs:108, src/console/auth.rs:45, src/console/changes.rs:25, src/console/watching.rs:18, tests/console/accounts.rs:444, tests/console/idle.rs:50, tests/console/watching.rs:54, tests/console/session-expiry.py

Before

flowchart LR
  Inbox["Inbox notices"] --> InboxState["Inbox lifecycle"]
  Logs["Log reader"] --> LogState["Log lifecycle"]
  InboxState -.-> Accounts["Console accounts"]
  LogState -.-> Accounts
  InboxState -.-> Changes["Console changes and observer"]
  LogState -.-> Changes
  classDef leak stroke:#dc2626,stroke-width:2px;
  class InboxState,LogState leak
Loading

After

flowchart LR
  Inbox["Inbox notices"] --> Subscription["Console live streams"]
  Logs["Log reader"] --> Subscription
  Subscription --> Accounts["Console accounts"]
  Subscription --> Changes["Console changes and observer"]
  classDef deep stroke:#2563eb,stroke-width:3px;
  class Subscription deep
Loading

Problem: Two stream loops repeat a shallow lifecycle interface of authorization, revision and observer obligations, so changes to that implementation lack locality.

Solution: Deepen one Console module behind a subscription seam, keeping account and change adapters inside and payload production in its callers.

Deletion test: Removing the deep module redistributes its lifecycle implementation across both callers.

Wins

  • locality: authorization rules live together
  • leverage: both callers share policy
  • depth: two operations hide lifecycle
  • Tests cross one subscription seam

Review basis: main at 45192775001d85b90a24f47aedfaa7b53e537b52; recent observer, expiry and captured-reader changes establish active maintenance. Four existing Console tests pass: both route revocation tests, idle-reader wakeup and captured-writer completion. The affected-test selector against main reports no changed files. No source files were changed.

Activity

  1. added
    needs-triage
    ready-for-agent
    architect-plan
    in-progress
    and removed
    needs-triage
    ready-for-agent
    on Oct 24, 2026
  2. removed
    in-progress
    on Oct 24, 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-plan

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions