Repository navigation
fix: exact Postgres timestamps; no panic on invalid command projections - #345
Merged
Merged
Conversation
Postgres timestamps went through f64 epoch seconds both ways (`to_timestamp($n)` and `EXTRACT(EPOCH ...)::double precision`). At present-day magnitudes an f64 resolves only about 240 ns, so a scheduled outbox message's `deliver_at` read back about 76 ns off even for a whole millisecond. The Postgres backend now carries timestamps as i64 microseconds, the resolution `timestamptz` stores: writes are `TIMESTAMPTZ 'epoch' + $n * INTERVAL '1 microsecond'` and reads are `(EXTRACT(EPOCH FROM col) * 1000000)::bigint`, both exact on Postgres 14+. `push_timestamp_cmp` takes a `SystemTime` so each backend encodes it exactly. The scheduled outbox conformance case asserts equality again instead of a 1 ms tolerance. Resolves [[incidents/postgres-outbox-deliver-at-precision]] Implements [[tasks/v5-review-28]]
`TypedCommandContract::canonical_value` validated the contract's domain-event projections with `.expect`, so a hand-built or deserialized contract carrying declaration errors panicked deep inside fingerprinting. `canonical_value` and `fingerprint_bytes` now return `Result`. `CommandSpec::from_contract` validates projections, so registration fails through its existing "typed command contract cannot compile" path, and binding a GraphQL service maps the error to `GraphqlServiceBindError::InvalidInventory`. A direct-projection bind that fails leaves the registered contract unchanged. Resolves [[incidents/typed-command-canonical-value-panics]] Implements [[tasks/v5-review-28]]
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
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.
Two incidents found during the test-suite work (task 27), fixed as part of task 28.
Postgres timestamps lost precision (incident
postgres-outbox-deliver-at-precision)The Postgres backend wrote timestamps with
to_timestamp(<f64 epoch seconds>)and read them withEXTRACT(EPOCH ...)::double precision. At present-day magnitudes anf64resolves only about 240 ns, so a scheduled outbox message'sdeliver_atcame back about 76 ns off, even for a whole millisecond.i64microseconds, which istimestamptz's own resolution.TIMESTAMPTZ 'epoch' + $n * INTERVAL '1 microsecond'.(EXTRACT(EPOCH FROM col) * 1000000)::bigint.SqlxRepoBackend::push_timestamp_cmptakes aSystemTime, so each backend encodes it exactly. SQLite is unchanged.Typed command
canonical_valuepanicked (incidenttyped-command-canonical-value-panics)TypedCommandContract::canonical_valueandfingerprint_bytesreturnResultinstead of calling.expecton projection validation.CommandSpec::from_contractvalidates projections, so a bad contract fails registration with the existing "typed command contract cannot compile" message rather than an opaque panic later.GraphqlServiceBindError::InvalidInventory. A failed bind leaves the registered contract unchanged.command::tests::invalid_projection_declaration_is_an_error_not_a_panic.Verification (local)
cargo test -p distributed --all-featuresagainst Postgres 16: 2,190 passed, 0 failed (88 ignored; these need external services).cargo test -p distributed --features postgres,sqlite: 1,476 passed, 0 failed.cargo check --workspace --all-targets --all-featurescargo check -p distributed --no-default-features --tests--features postgresalone and--features sqlitealonescripts/check-wasm32-domains.shtests/celld/workerandexamples/game/cellsNot done
timestamptzcannot store it. SQLite keeps nanoseconds.thin-command-succeeded-fails-with-domain-events, is not reproduced yet and is not in this PR.