Consolidate reconciliation recency maps into RecencyMap<K>#4386
Merged
cjdsellers merged 1 commit intoJul 5, 2026
Merged
Conversation
The live execution manager tracked four "mark now / within window? / prune older than TTL" gates as bare IndexMap<K, dst::time::Instant>: order_query_recency, order_local_activity, position_local_activity, and recent_fills_cache. Every call site had to remember to stamp from the monotonic dst::time clock rather than the trading self.clock, and to handle a future-marked instant in the safe direction by hand. Extract a RecencyMap<K> that owns dst::time::Instant::now() internally, so the monotonic-clock choice becomes structural: a call site can no longer reach for self.clock to build a recency gate. within/within_at, elapsed/elapsed_at, and prune_older_than all resolve a None checked_duration_since to the safe direction, matching each original site. Migrate the four maps onto it. Also apply the residual ts_*-named renames cjdsellers flagged in the nautechsystems#4376 review, since ts_* repo-wide means a domain UnixNanos but these hold monotonic instants: InflightCheck::ts_submitted -> submitted_at, last_query_ts -> last_query_at, the node scheduler's ts_last_* locals and state fields -> last_*_check, and the one map field whose ts_ prefix survived the type change, ts_last_query -> order_query_recency. Add focused RecencyMap unit tests for mark/contains/remove, monotonic expiry under paused time, pruning, and safe handling of a future-marked instant. Coded by an LLM.
8c1903a to
e1f9f36
Compare
Member
|
Hi @folknor, Thanks for the PR. I like the naming convention here: dropping the Hungarian-notation-esque domain I traced the converted call sites and ran the focused recency, open-order query, inflight, fill-cache, and position-grace test slices. This looks good to me. Will get to the next PR shortly! |
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.
Right now the monotonic-clock choice is a discipline, not a rule. Every one of
those four sites -
ts_last_query,order_local_activity,position_local_activity,recent_fills_cache- has to remember to stamp fromdst::time::Instant::now()and notself.clock, and to handle a future-markedinstant in the safe direction by hand.
So make it structural.
RecencyMap<K>ownsInstant::now()internally - youmark(key), askwithin(key, window),prune_older_than(ttl), and there is noseam left to thread the wrong clock through.
The shape
The
_atvariants exist so the reconciliation loop passes its loop-topnowonce instead of resampling
Instant::now()per order - the second half of thatsame review note. Every
checked_duration_sinceresolves aNone(marked-in-the-future) to the safe direction, matching what each original site
did by hand, so a garbage future instant reads as "0 elapsed, within window"
rather than panicking.
Renames
The
ts_*-named fields you flagged in #4376 -ts_*repo-wide means a domainUnixNanos, but these hold monotonicInstants, so the names lie:InflightCheck::ts_submitted->submitted_atInflightCheck::last_query_ts->last_query_atts_last_*locals andReconciliationCheckStatefields->
last_*_checkts_last_query->order_query_recency(keyed onClientOrderId, parallelsorder_local_activity; the other three map fields self-document underRecencyMap<K>, but this one'sts_prefix did not survive the type changegracefully, so it got a real name too)
Tests
Focused
RecencyMapunit tests: mark/contains/remove, monotonic expiry underpaused virtual time, pruning older-than-TTL, and the future-marked-instant safe
direction.
Still to come
The second promised follow-up - close the class:
handle_missing_order'svenue-
ts_lastgate onto receipt time, plus the wider timer/throttle audit.