Auto-connect and auto-register artifacts on client connection lifecycle#11
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added
ChronicleClientnow auto-connects on the firstgetEventStore()call and retries indefinitely with exponential backoff (1 s → 30 s cap) until the Chronicle kernel is available.ChronicleClientauto-registers all discovered artifacts on connect and reconnect via an internal connection lifecycle — no manualregister*ordiscover()calls are required from application code.Changed
getVersionInfo) instead of the contractsconnect(), which was unreliable — it rejected as soon as the channel transitioned to CONNECTING rather than waiting for READY.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.index.tsand all artifact modules updated to remove manual register/discover orchestration.diag.createComponentLogger()for all output, routed through an ASP.NET-style colored console logger configured intelemetry.ts.