Repository navigation
feat(sa2): authoritative orders/fills state machine and deployable capital sizing - #1221
Conversation
Slice SA2-W1: freeze Draft 2020-12 schemas and pre-implementation
test vectors before normalizer, lock, or sizing code.
- schemas/qsl-authoritative-orders-fills.v1.schema.json (C-SA-25)
- schemas/qsl-deployable-capital-sizing.v1.schema.json (C-SA-Q21)
- tests/fixtures/sa2/sa2_demo_cases.json (SA2-D1..SA2-D7)
- tests/fixtures/sa2/sa2_orders_fills_matrix.json (SA-A12)
- tests/fixtures/sa2/sa2_q21_matrix.json (SA-A13)
- tests/sa2_{demo,orders_fills,deployable_capital}_validation.mjs
Slice SA2-W2: add pure leaf orders_fills constants, domain coverage, and multi-broker normalizer under application/orders_fills/. - constants.js: zero-import enums, caps (256/512/2048), regexes - coverage.js: proven-empty & non-release K_pend coverage gates - normalize.js: (broker, environment, account) separation, null fees, non-USD unavailability, and pure adaptLegacyBrokerExecutionPayload
Slice SA2-W3: implement execution deduplication, conflict rejection, order lifecycle reconciliation, restart-persistent ORDER-UNKNOWN symbol locks (O4/Q5-2), and helpers.js composition entrypoint. - dedup_state.js: (broker, environment, account) key binding, dedup vs conflicting-duplicate throw, partial fill/cancel & K_pend math - order_unknown_lock.js: pure serializable lock store with query_target and terminal-evidence-only clearing - helpers.js & normalize.js: WeakMap submission metadata + entrypoint
Slice SA2-W4: implement exact-decimal deployable capital, whole-share sizing, fee/collar-constrained buy allocation, unblocked reductions, B_min,tier < 10% check, and rho_order diagnostic under sizing_unit/. - deployable_capital.js: C_inv, C_avail, q^ideal, delta_q^buy, emergency bypass, ORDER-UNKNOWN buy block, unset OI-COST fail-closed - normalize.js: accept resolved_at/updated_at fallback on submissions
- Add pure buildConsoleOrdersFillsReadModel in console_api/executions.js - Validate order_unknown_symbols array and symbol inputs in sizing_unit - Preserve zero new routes, DO actions, SQLite tables, and B0 contract
- Run sa2_demo, sa2_orders_fills, and sa2_deployable_capital checks - Validate workflow YAML with actionlint
- Enforce null K_pend on first unproven open-orders read and add non-overlapping visible orders without dropping prior reserves - Reject records > cap regardless of truncated flag and fail closed incomplete count != records.length domains - Harden ORDER_UNKNOWN same-batch, cross-symbol, and future-event locks; unify canonical account keys and forbid broker_order_id theft - Deduplicate IBKR Flex across observed_at, reject conflicting non-USD notional_usd, never mix non-USD qty*price or coerce zero missing fees - Fix TDZ ReferenceError, enforce cross-source identity consistency, require b_exec_usd and B_min,tier cost items, keep SELLs unblocked when buys fail collar/K_pend, validate boolean emergency_bypass, and fail closed on unpriced held positions - Tighten schema currency regex, sanitize nav.reason/evidence outputs, and remove static raw account/locator literals from sa2 JSON fixture
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aec773fd90
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Reject K_pend release on future empty cutoff domains (as_of > eval) - Partition executions at cutoff.as_of so later fills advance remaining qty without triggering false cutoff mismatches - Reconcile every sizing target q_pre against supplied positions lists (treating absent symbols as 0 shares to block oversells) - Downgrade supported domains with count > 0 and omitted records to incomplete so unexamined open orders cannot release K_pend
|
@codex review |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1dce82714f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Link client_order_id executions first before retrying broker_order_id-only fills so two-pass matching reconciles cleanly. - Advance post-cutoff terminal transitions using effective_at_ns (including updated_at) and set accurate order updated_at. - Convert legacy local_time + time_zone deterministically to UTC or emit null executed_at without fabricating midnight UTC. - Sum execution fee_usd independently when mixed fee currencies occur.
|
@codex review |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 81233062aa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Exclude untimed (executed_at: null) executions from effective fills so unproved buys without a cutoff keep conservative/null K_pend. - Reject orders_fills evaluated or dated after sizing evaluated_at (orders_fills_evaluated_after_sizing_boundary) to block look-ahead. - Reconcile definitive FILLED qty_filled/qty_remaining when fill records lag while keeping execution-derived avg_fill_price null.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8f5eecc0a9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
- Validate sizing_unit_nav observed/fetched/evaluated timestamps against the sizing evaluated_at boundary and re-check freshness at boundary. - Retain active ORDER_UNKNOWN locks when terminal evidence omits all timestamps rather than clearing without proven event ordering.
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
AI assistance
Assisted by OpenAI Codex CLI (
gpt-6.2-astrareasoning high pre-push blocker review) and Coordinator/subagent orchestration (sa2-orders-capital-engineer); all SA-2/schema/broker/naming/SA-1/gitleaks checks were re-verified on exact HEADec7b145a31dfbcfc3457a6a6453867ccbf396a8b, with fulljs(includingread_contract_boundaries_validation.mjsandtest:operations) andpythonsuites run by PR CI.What changed
Implements
SUPPLY-A SA-2(C-SA-25authoritative orders/fills state machine, multi-broker normalizer, andC-SA-Q21deployable capital & whole-share sizing) cleanly onmain(bcd52987), with zero live order submission and strict read-only ADR 0002 isolation:schemas/qsl-authoritative-orders-fills.v1.schema.json,schemas/qsl-deployable-capital-sizing.v1.schema.json,tests/fixtures/sa2/*.json):executionRecord.executed_atwhen legacy timestamps omit local time/zone rather than fabricating midnight UTC) andC-SA-Q21deployable capital / whole-share sizing (K_eff,K_pend,q_final, collar/bypass/cap metadata), plus frozen demo,C-SA-25, andQ21validation fixtures with zero raw account IDs or private locators.web/strategy-switch-console/application/orders_fills/*):cap=500) and completeness fail-closed coverage guards (including treating positivecountwith omittedrecordsasincompleteand rejecting futureas_of > evaluated_atcutoff snapshots from releasingK_pend), same-batch/cross-symbol/future-eventORDER_UNKNOWNlocks (lockStore), canonical identity preservation, and fail-closedK_pendtracking (includingnullK_pendon first unproven open-orders read and additive non-overlapping visible reserves).executed_at: null) from releasing BUYk_pend_usdor markingFILLEDwhen cutoff evidence is absent, retains activeORDER_UNKNOWNlocks on untimed terminal observations (maxEventNs === null || maxEventNs > evalAtNs), reconciles definitive non-futureFILLEDquantities (qty_filled = submitted, qty_remaining = "0") while keeping execution-derivedavg_fill_price/unbacked feesnullwhen execution details lag, honors normalizedeffective_at_nson post-cutoff terminal transitions, converts legacylocal_time+ IANAtime_zoneaccurately, sums qualifiedfee_usdindependently of mixed native fee currencies, rejects conflicting non-USDnotional_usd/ mixed-currencyqty * price, and avoids zero-fee coercion when fees are missing.web/strategy-switch-console/application/sizing_unit/deployable_capital.js):C-SA-Q21deployable capital deduction, validates suppliedorders_fills.evaluated_at/as_of/cutoff_open_orders.as_ofandnav.observed_at/fetched_at/evaluated_at+freshnessat sizing'sevaluated_atboundary (re-evaluating freshness via./freshness.jswhen needed and failing closed on future-evaluated or post-close stale inputs), checksB_min,tierandb_exec_usdcost items, preservesSELLwhenBUYfails collar orK_pend, enforces strict booleanemergency_bypassvalidation, fails closed on unpriced held positions, enforces cross-source identity checks, reconciles targetq_preagainst completepositionslists (treating absent symbols as0shares to prevent oversells), and sanitizesnav.reason/evidenceoutputs.web/strategy-switch-console/application/console_api/executions.js,tests/sa2_*.mjs,.github/workflows/validate.yml):buildConsoleOrdersFillsReadModel()helper and wirestests/sa2_demo_validation.mjs,tests/sa2_orders_fills_validation.mjs, andtests/sa2_deployable_capital_validation.mjsinto.github/workflows/validate.yml.How verified
Verified on exact HEAD
ec7b145a31dfbcfc3457a6a6453867ccbf396a8b(after remediating both Codex6049055796P1 findingsPRRT_kwDOSZeN-M67pKBv,pKB0on top ofaec773fd,1dce8271,81233062, and8f5eecc0):node tests/sa2_demo_validation.mjs: PASS (7/7)node tests/sa2_orders_fills_validation.mjs: PASS (SA-A12)node tests/sa2_deployable_capital_validation.mjs: PASS (SA-A13)node tests/schema_validators_validation.mjs: PASS (3/3)node tests/broker_executions_validation.mjs,node tests/naming_canonical_validation.mjs,node tests/sa1_sizing_contracts_validation.mjs: PASSgitleaks(11 commits,0leaks),git diff --check, commit line-width<= 72, and static raw-account/private-locator/workstation-path scan: PASS8f5eecc0/aec773fd(re-validated onec7b145aby PR CI):jsGitHub Actions suite (SUCCESS),npm --prefix web/strategy-switch-console run test:operations(PASS),python3 -m unittest discover -s python/tests(1239 tests OK, skipped=10),read_contract_boundaries_validation.mjs(110 route branches, 112 internal operations, 10 exceptions; ok).Why
Delivers the fail-closed authoritative orders/fills state machine (
C-SA-25) and deployable capital whole-share sizing unit (C-SA-Q21) needed downstream forSUPPLY-A SA-3/SA-4while guaranteeing non-double-counted reserves, look-ahead/post-cutoff/untimed-execution safety, anti-oversell position reconciliation, accurate timezone/currency handling, and zero unsafe identity leaks.Risk
Tier: R2 / Fail-closed sizing & authoritative orders/fills accounting library (offline pure computation; zero broker submission or live/paper flag unlock).
buildConsoleOrdersFillsReadModel()inweb/strategy-switch-console/application/console_api/executions.jsand the underlyingorders_fills/sizing_unit/deployable_capitalhelpers are pure read-only observations (no command endpoints added; no new registered exceptions).lockStoreis optional caller-supplied injection).account_id/deployment_idand reject raw broker account IDs (isRawAccountIdentifier) or unsafe storage locators (isUnsafePrivateLocator).evaluateAuthoritativeOrdersAndFillsandbuildConsoleOrdersFillsReadModelexplicitly emitscope, per-domain cap (500records, fail-closedpartial_domain_truncated& incomplete positive-count/missing-records guard), and completeness metadata (failing closed toK_pend: null,k_pend_release_allowed: falseon futureas_ofor untimestamped executions, orORDER-UNKNOWN, plusorders_fills_evaluated_after_sizing_boundaryfail-closed boundary checks).main; existingSA-1contracts,console_apiroutes, and live/paper gates remain untouched.