Skip to content

fix(engine): harden apply/bounds validation, fix year overflow, and improve DX helpers - #63

Merged
willtmc merged 2 commits into
mainfrom
fix/engine-determinism-bounds-and-api
Nov 26, 2026
Merged

willtmc merged 2 commits into
mainfrom
fix/engine-determinism-bounds-and-api

Conversation

@willtmc

@willtmc willtmc commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Summary

Hardens engine determinism, bounds checking, and state-transition invariants while keeping 100% conformance with RFCs 0001–0005, all 44 conformance scenarios, and the downstream mclemoreauction.com private engine helper contract.

Determinism, Bounds & Validation Fixes

  • Centralized RFC 3339 4-digit year range (1..9999) in RBBB::Timestamp: Timestamp.parse and Timestamp.dump enforce UTC years 1..9999 (removing duplicated checks in InitialClosingSchedule and SharedClosingClock), and Engine#extended_closing_time rejects year-9999 extension overflow cleanly inside decide (invalid_closing_time) instead of returning an accepted decision that fails apply.
  • Engine#apply transition guards: Rejects transitions applied to a closed State, rejects non-monotonic effective_at (< state.last_effective_at), rejects non-empty event batches without exactly one privileged state-transition event, and preserves apply(state, []) == state compatibility for rejected-decision event batches.
  • Schema-valid rejections & strict bounds:
    • Sanitizes invalid command_id values ("", non-string, > 255 chars) to nil in Engine#reject so rejections always satisfy rejection.schema.json.
    • Rejects non-Integer or out-of-range expected_version (e.g. 0.0 float) as invalid_command.
    • Rejects explicit bid_id: false instead of falling back to command_id.
    • Enforces MAX_SAFE_INTEGER upper bounds on State#version (and guards version exhaustion in Engine#decide/#apply) and on all monetary/integer fields in State#validate!.
    • Fixes State#validate! saturation check so arbitrary standing_minor_units == next_required_minor_units (e.g. 10_000) is rejected while preserving genuine ladder-ceiling saturation round-trips.
    • Raises RBBB::InvalidConfiguration (not NoMethodError) for Configuration.from_h(nil) / non-Hash input.
    • Accepts Time objects in addition to ISO 8601 strings for closes_at in change_closing_time.

Cleanup & Additive DX Helpers

  • Removed dead RBBB::UnsupportedFeature constant.
  • Added Decision#transition_event, Decision#public_events, and Decision#privileged_events.
  • Added value equality (#==, #eql?, #hash) on State, Configuration, Event, Decision, and SharedClosingClock.
  • Exposed attr_reader :group_id, :unit_ids on SharedClosingClock.
  • Simplified Engine by hoisting TWO_DECIMAL_CURRENCIES, calling apply_executions! directly in build_bid_decision, and extracting leader_key, transition_snapshot, standing_bid_event, and closing_time_event while preserving exact names/signatures of :position_priority, :price_positions, :apply_executions!, and :replay_authorizations.

Verification

  • ruby scripts/validate_documents.rb: 21 JSON Schemas, 44 conformance scenarios, OpenAPI/AsyncAPI valid.
  • cd ruby/engine && bundle exec rake: 425 runs, 357,439 assertions, 0 failures, 0 errors, 0 skips; verify_package.rb passed.

@willtmc
willtmc merged commit 1540043 into main Nov 26, 2026
5 checks passed
@willtmc
willtmc deleted the fix/engine-determinism-bounds-and-api branch November 26, 2026 17:38
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.

1 participant