Skip to content

feat(j5): one change stream per environment to replace the J5 read polls #182

Closed

Description

@Jacksondr5

Problem

Every J5 read surface refreshes on a foreground timer whether or not anything changed. On the crews stack head (crews/08) there are six visible-refresh polls:

Surface Interval Where
Inbox bell count 7.5s apps/web/src/j5/a2a/HumanInboxBell.tsx
Inbox page 7.5s apps/web/src/j5/a2a/HumanInboxPage.tsx
Crew proposals (roster gate + bell) 7.5s apps/web/src/j5/crew/crewProposalsClient.ts
Fleet page + rail badge 30s apps/web/src/j5/fleet/fleetClient.ts
Fleet detail 30s apps/web/src/j5/fleet/fleetClient.ts
Squadron directory 30s apps/web/src/j5/squadron/SquadronDirectory.ts

Each tick is a full re-read per connected environment. The Fleet tick also re-pends every requested thread id through threadHomes.refreshRequested, so memberships and children are re-read for the whole thread list in batches of 200 (#149 review). Every new J5 surface has added another timer. AGENTS.md: "We regularly audit for performance regressions, often caused by sending too much data over websockets".

Proposal

One J5 change stream per environment, built the way the artifact change stream was in #145:

Contract. packages/contracts/src/j5/reads.ts (new): J5_READS_WS_METHODS.subscribeChanges, an Rpc.make with stream: true, payload {} (per-environment, the session is the scope), success { source: "inbox" | "crewProposals" | "fleet" | "squadrons", revision: number }, error union with EnvironmentAuthorizationError. J5ReadsRpcGroup merged into WsRpcGroup beside the persona and artifact groups (one .merge(...) line in rpc.ts).

Server. A small in-process hub under apps/server/src/j5/a2a/ that the existing services publish to after their commits: the ledger (inbox), AgentCrewProposalService (proposals), PlacementService / HomeRegistrar / AgentCrewInstanceService (fleet), squadron management (squadrons). The RPC handler subscribes to the hub and emits one event per source change with a monotonic revision, coalescing bursts. Handler built in a J5 module and spread into the ws.ts handler map; scope spread into RPC_REQUIRED_SCOPES (orchestration:read). Same four one-line upstream touch points as case 33.

Client. One createEnvironmentRpcSubscriptionAtomFamily in packages/client-runtime/src/j5/ (tag added to the EnvironmentSubscriptionRpcTag union, as #145 did). Each event calls the refresh function the poll calls today (refreshFleet, refreshCrewProposals, the inbox count and page refreshes, the directory refresh), so the read sources, the cross-environment merge, and the capability probe are untouched. The timers drop to one long fallback (a few minutes) or go away. The subscription is durable across reconnects through the supervisor, like every other J5 stream; a server that lacks the method is detected the same way case 34 detects a missing route, and that client keeps polling.

Why this shape

  • The notification is a few bytes on the socket that already exists and reconnects durably; the reads stay on HTTP where per-request auth, the capability probe, and the multi-environment merge already live. Same split as artifacts, which is now verified on direct, Tailscale, SSH, hosted web, and T3 Connect.
  • Fixed upstream cost, once, instead of one more timer per surface.
  • Mobile gets the same stream for free when it grows a J5 surface, through client-runtime.

Not in scope

Came out of the transport discussion during the #145 review and the Fleet poll finding in #149.

Activity

  1. added a commit that references this issue on Oct 13, 2026
    24e80de
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions