Skip to content

feat: expose consensus timestamp in user properties#64

Open
justynspooner wants to merge 5 commits intotashigit:mainfrom
justynspooner:feat/consensus-timestamp-user-property
Open

feat: expose consensus timestamp in user properties#64
justynspooner wants to merge 5 commits intotashigit:mainfrom
justynspooner:feat/consensus-timestamp-user-property

Conversation

@justynspooner
Copy link
Copy Markdown

Warning

Proof of concept — this was authored with the assistance of Claude 4.6 (Opus) and has not been compiled or tested as I don't have SSH access to the private tashi-consensus-engine dependency. rustfmt passes but cargo check/clippy could not be run. Please review with that in mind.

Summary

  • Threads the TCE consensus timestamp (nanosecond precision) through the dispatch → deliver → mailbox → packet chain
  • Adds consensus_timestamp_ns as a user property on delivered PUBLISH packets when include_broker_timestamps is enabled
  • Includes the consensus timestamp on retained message replay (when TCE is active)
  • Non-TCE paths (local dispatch, system publishes, will messages) pass None, so the property is omitted
  • Updates consensus-timestamps.test.js to assert consensus_timestamp_ns is present and valid

Known limitation

  • Locally-originated messages on the same broker are dispatched eagerly before consensus is reached, so they will not have consensus_timestamp_ns set. Only messages arriving through the TCE event handler include it. This is a pre-existing design tradeoff (latency vs consistency) and should be addressed in a separate PR.

Test plan

  • Verify consensus_timestamp_ns user property appears on messages delivered via TCE
  • Verify the value is a nanosecond Unix epoch
  • Verify consensus_timestamp_ns is absent for locally dispatched messages (no TCE)
  • Verify retained messages replayed to new subscribers include consensus_timestamp_ns
  • Run existing consensus-timestamps.test.js integration test

Thread the TCE consensus timestamp (nanosecond precision) through the
dispatch chain and include it as a `consensus_timestamp` user property
on delivered PUBLISH packets when `include_broker_timestamps` is enabled.
The value is a raw nanosecond Unix epoch, so the property name should
make the unit explicit to avoid consumer ambiguity.
When a new subscriber receives retained messages, pass through the
original consensus timestamp so that the consensus_timestamp_ns user
property is present. Only set when TCE is active, since non-TCE
retained timestamps are local system time, not consensus time.
Assert that consensus_timestamp_ns is present and is a valid
nanosecond Unix epoch on messages delivered with broker timestamps.
Copy link
Copy Markdown
Contributor

@Divyanshu11011 Divyanshu11011 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plumbing looks clean : Option<u64> threaded through dispatchMailSender::deliverOrderedMail/UnorderedMail/Deliverytxn_to_packet,
with Some(consensus_timestamp) only from handle_tce_event. Retained replay correctly reuses the consensus timestamp used as the retain index key. Both
txn_to_packet call sites in connection.rs are updated.

One coupling concern: without #65, the "known limitation" you documented means clients see consensus_timestamp_ns on messages from remote publishers but
never on their own publishes : a silently inconsistent semantic that's hard for clients to reason about. Strongly recommend landing this with or after #65, not before.

Nit: a Rust unit test on txn_to_packet with Some(consensus_timestamp) would lock in the property name and encoding without needing the TCE stack.

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.

2 participants