Repository navigation
perf(engine): fix LiveScheduling projector/host bugs and eliminate history/coordinator allocation hotspots - #65
Merged
Conversation
…story/coordinator allocation hotspots
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.
Summary
Supersedes #54.
Fixes LiveScheduling projector, coordinator, intent, and reference-host correctness/security bugs, and eliminates allocation and quadratic-scaling hotspots in core history validation, event deep-freezing, live scheduling, and retained-history verification — with zero bidding/pricing semantics changes.
Correctness & Security Fixes
LiveScheduling::Projector(projector.rb):"maximum_reduced"alongside"maximum_accepted"/"maximum_increased"when replaying qualifying linked bid extensions.closes_at > before.closes_at) actually qualified under the closing set's extension policy, occurred insidetrigger_window_seconds, matches[before.closes_at, effective_at + duration_seconds].max, and matches theclosing_configuration_changeddelta's resulting closing set; reject forged, out-of-window, or unexpected scheduling deltas withRBBB::InvalidState.executed_amount_changed,notification_requested, and all state-transition events are:privileged, and only public companion events (standing_bid_changed,reserve_status_changed,closing_time_changed,bidding_closed) are:public.LiveScheduling::Coordinator&Intent(coordinator.rb,intent.rb):ArgumentError, RangeErrorinCoordinator#close(returningreject("invalid_request")) instead of raising on invalideffective_at.RangeErrorextension overflow inCoordinator#bidcleanly withreject("invalid_closing_time")."extend_on_void": falseinIntent.normalize_registration(preservingtimed-proxy.schema.jsoncompatibility while stripping it fromclosing_set["extension"]percontract.schema.json) and reject"extend_on_void": truewith"extend_on_void is not supported for linked live scheduling".examples/):LiveSchedulingHost: remove non-spec"notification_policy"fromchange_reserveallowlist, add"expected_version"tobidallowlist, and stop calling privatecoordinator.send(:reject, ...).SharedGroupHost/DurableSharedGroupHost: replace private.send(:normalize_request)/.send(:normalize_close_request)andinstance_variable_get(:@snapshot)with clean public methods (normalize_request,normalize_close_request,public_snapshot).examples/support/sqlite_store.rb(File::EXCL+File.lstatregular-file/uid/mode checks +BEGIN IMMEDIATEtransactions) and adopt it inDurableSharedGroupHost,LiveSchedulingHost, andLiveSchedulingConsumer(closing the symlink/TOCTOU vulnerability inLiveSchedulingConsumer).RBBB::LiveScheduling::Intent.canonical(payload)for SHA-256 checkpoint hashing inLiveSchedulingReaderandLiveSchedulingConsumer.Performance & Allocation Optimizations (Folding & Expanding #54)
State,Event,Engine:State#validate_authorization_history!and#validate_reserve_history!with monotonicprev_priority < prioritychecks,Hashlookups forbid_ids/auth_priorities, direct type comparisons, and empty-reserve-history short-circuit.State#coerce_authorization/#coerce_reserve_change, skip redundanttransform_keyson string-keyed hashes, and skip re-allocating already-deeply-frozen structures inEvent#deep_freeze.state.authorization_history.map(&:dup)/state.reserve_history.map(&:dup)inEnginewhere entries are already frozen; preserve private method names/signatures (:position_priority,:price_positions,:apply_executions!,:replay_authorizations).LiveScheduling&InitialClosingSchedule:JSON.parse(JSON.generate(value))inLiveScheduling.copywith a pure Ruby recursive deep copy.closing_setsinCoordinator(discover,affected_sets,edit,change_kinds,result,bid,close) andProjector#applyvia Hash indices (unit_to_set,group_to_set); replacebefore.to_h["closes_at"]inProjectorwithTimestamp.dump(before.closes_at).InitialClosingSchedule.planwith O(1) Hash lookups.LiveSchedulingHost#validate_retained_history!:journaledrows bycommit_idin a Hash and batch-fetchoutboxrows in a singleSELECT ... INNER JOIN commitsquery instead of N+1 queries.Verification
ruby scripts/validate_documents.rb: Validated 21 JSON Schemas, 44 conformance scenarios, and the OpenAPI/AsyncAPI documents.cd ruby/engine && bundle exec rake: 439 runs, 357,557 assertions, 0 failures, 0 errors, 0 skips;verify_package.rbpassed (19 files, clean install, smoke tests).ruby -Iruby/engine/lib ruby/engine/script/benchmark_history_validation.rb, Ruby 3.4.10 ARM, 1,000 history entries, 3 × 300 iterations):restore: median 925,590 → 320,150 allocated objects (-65.4%), 0.280 s → 0.267 sdecide_and_apply: median 1,558,100 → 49,809 allocated objects (-96.8%), 0.466 s → 0.303 s (-35.0%)