Skip to content

Auto-connect and auto-register artifacts on client connection lifecycle#11

Merged
einari merged 6 commits into
mainfrom
feat/client-connection-lifecycle
May 10, 2026
Merged

Auto-connect and auto-register artifacts on client connection lifecycle#11
einari merged 6 commits into
mainfrom
feat/client-connection-lifecycle

Conversation

@einari
Copy link
Copy Markdown
Collaborator

@einari einari commented May 10, 2026

Added

  • ChronicleClient now auto-connects on the first getEventStore() call and retries indefinitely with exponential backoff (1 s → 30 s cap) until the Chronicle kernel is available.
  • ChronicleClient auto-registers all discovered artifacts on connect and reconnect via an internal connection lifecycle — no manual register* or discover() calls are required from application code.
  • Background watchdog health-checks the connection every 5 s and triggers reconnect when the kernel becomes unreachable.

Changed

  • Connection probing uses a real gRPC call (getVersionInfo) instead of the contracts connect(), which was unreliable — it rejected as soon as the channel transitioned to CONNECTING rather than waiting for READY.
  • Each connection retry resets the gRPC channel via resetChannel() to avoid TRANSIENT_FAILURE state left by a failed probe.
  • EventStore.registerArtifacts() is now managed internally by the client; callers no longer orchestrate discovery and registration order.
  • TestApp index.ts and all artifact modules updated to remove manual register/discover orchestration.
  • TestApp uses diag.createComponentLogger() for all output, routed through an ASP.NET-style colored console logger configured in telemetry.ts.

einari added 6 commits May 10, 2026 18:49
Wraps the contracts ChronicleConnection to delegate all ChronicleServices
members to the inner connection and expose resetChannel(), which tears down
and recreates the gRPC channel. This is needed because a failed connection
attempt leaves the channel in TRANSIENT_FAILURE — calling connect() again
on the same channel never recovers. resetChannel() provides a clean IDLE
channel before each retry without using the contracts connect(), which has
a broken watchConnectivityState-based implementation that rejects as soon
as the state transitions to CONNECTING rather than waiting for READY.
ChronicleClient now owns the full connection lifecycle:
- Connects lazily on the first getEventStore() call using an RPC probe
  (getVersionInfo) instead of the contracts connect(), which is unreliable.
- Retries indefinitely with exponential backoff (1 s → 30 s cap) so the
  client waits until the Chronicle kernel becomes available.
- Resets the gRPC channel on each retry via resetChannel() to avoid the
  TRANSIENT_FAILURE state left by a failed probe.
- Registers all discovered artifacts automatically on connect and reconnect
  via an internal ConnectionLifecycle, removing the need for callers to
  invoke register* or discover* methods manually.
- A background watchdog health-checks the connection every 5 s and triggers
  reconnect when the kernel is unreachable.

EventStore.registerArtifacts() is now package-internal: it discovers event
types, builds schemas, and registers all artifact kinds in the correct order
without requiring any caller orchestration.
The client now auto-discovers and auto-registers all artifacts on connect.
Remove all register* exported functions and discover/register call sites
from constraints, projections, reactors, and reducers modules — these were
only imported for side effects and are now fully managed by ChronicleClient.
telemetry.ts registers a custom DiagLogger with diag.setLogger() before
the OTel SDK starts. It formats output in the ASP.NET log style:

  info: @cratis/chronicle/ChronicleClient
        Connected to Chronicle kernel {"attempt":1}

Level colors match ASP.NET conventions (green=info, yellow=warn, red=fail,
cyan=dbug, dim=trce). Log level is configurable via the LOG_LEVEL env var.

index.ts is updated to use diag.createComponentLogger() for all output
instead of console.log/warn/error.
@einari einari merged commit 7b9b6d2 into main May 10, 2026
1 check failed
@einari einari deleted the feat/client-connection-lifecycle branch May 10, 2026 17:48
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