feat(fleet): give the fleet connect a status instead of a log nobody reads
The gap
The dial that makes Factory's own agent online had no status on any surface.
#ensureEventSubscription(): void {
if (this.#eventsStarted) return
this.#eventsStarted = true
void this.#subscribeEvents().catch((error) => {
this.#eventsStarted = false
this.#log(`relay fleet event subscription failed: ${errorMessage(error)}`) // <- the only trace
})
}
Fire-and-forget, and the rejection went to #log alone. A client that registered an agent and then failed to connect was indistinguishable from a healthy one on /healthz, on /evidence, and in factory status.
Readers substituted eventListener — but that is the orchestrator's issue subscription (factory.ts returns subscribed whenever #subscription is truthy), a different subsystem entirely. That conflation is why days of instruments read healthy while the fleet socket was never up.
Context: AgentWorkforce/factory-cloud#55, where seven consecutive Factory fleet identities show created == last_seen to the second across two published versions.
What this adds
FleetConnectStatus on the fleet port — never-attempted | connecting | connected | failed, with attempts, timestamps and a reduced lastError. The void-catch rejection now lands in that field instead of only in a log line.
Three deliberate choices:
connectedis stamped at the dial, not when#subscribeEventsresolves. That function also returns early when the client is disposed, and reporting that as connected would recreate the exact false-healthy signal this removes.- The method is optional on the port. A backend with no socket (the internal fleet) omits it, and an absent value stays absent rather than being invented as healthy.
guardFleetControlPlane's Proxy passes it through untouched. - Redaction reuses
describeControlPlaneError, now exported so there is one reducer rather than two that can drift. Any cause becomesName (CODE), code matched against/^[A-Z0-9_]{1,80}$/— no transport message, URL or credential can reach it.
Deliberately NOT dispatch-gating
fleetConnect is published on /healthz but is not added to DISPATCH_GATING_SUBSYSTEMS.
A failed socket does not itself stop dispatch — roster() runs over HTTP — and listing it would flip ok on a live deployment and hand the container-replacement logic a new reason to cycle. Publishing the fact is the goal; changing what ok means is a separate decision belonging to whoever owns dispatch behaviour. lastError stays behind authenticated /evidence, exactly as it does for the circuit.
Verification
Build typecheck (tsconfig.build.json) | exit 0, zero errors |
src/fleet + public-health + cli/fleet | 363 passed |
health-projection-guard, atomic-json-file, reaper, diagnose | 49 passed |
orchestrator/factory | 574 passed |
| Total | 986 green |
Mutation control: reverting the catch to log-only (the pre-fix behaviour) fails exactly the three tests that assert recording — exit 1, 3 failed | 68 passed — while never-attempted and connected keep passing, because they do not depend on the catch. Restoring returns 71/71.
There is also an explicit control test proving the same harness yields connected when the gate does not throw, so the failure arm is not quietly passing against a client that reports failed unconditionally.
Note: the full tsconfig.json typecheck has pre-existing errors in unrelated test files (e.g. dist-entrypoints.test.ts needs a build). None of the touched files appear, and the build config this package ships from is clean.
Not in scope
No version bump and no release — publishing is not mine to do. This needs a publish and a factory-version.json bump in factory-cloud before it reaches production; the companion factory-cloud PR projects fleetConnect into /evidence and is ready to follow.
Summary by cubic
Publishes a first-class fleet socket status and exposes it on /healthz, CLI, and the heartbeat so failed connects are visible. Previously, failed connects only logged while health read healthy; now fleetConnect reports lifecycle and counters, with redacted causes shown only via authenticated /evidence.
- Adds
FleetConnectStatusto theFleetClientport:never-attempted | connecting | dialed | connected | failed.dialedmeans the SDK acceptedconnect()but no stream event has confirmed the socket; a silent workspace can remaindialed. - Relay client records lifecycle: listens before dialing, marks
dialedafterconnect(), upgrades toconnectedon first event, and records drops/errors asfailed(RelayEventStreamDisconnected/RelayEventStreamError). Tracks attempts and timestamps. - Orchestrator writes
fleetConnectinto the heartbeat and projects it to public health. Unauthenticated/healthzpublishes state and counters only;lastErrorremains behind/evidence. Not dispatch-gating;oksemantics do not change. - CLI:
factory statusanddiagnoserenderfleetConnect.diagnosenow readsfleetConnect.lastErrorfrom/evidencewhen a token is provided and prints it; it also explainsdialedas unconfirmed. - Exports
describeControlPlaneErrorand introducesFactoryAgentRegistrationErrorCode; registration failures render asName (CODE)across surfaces. - Optional on the port: backends without a socket omit the field and absence is preserved. No migrations required.