Enforce security quantity balance invariants - #253
Conversation
📝 WalkthroughWalkthroughAdds event-based validation for stock, warrant, and equity-compensation source balances, including dated stock splits. ChangesSecurity Balance Validation
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant UpdateCapTable
participant CapTableMaps
participant EventIndexes
participant SourceBalanceValidator
UpdateCapTable->>CapTableMaps: build final maps
UpdateCapTable->>EventIndexes: build balance and split indexes
EventIndexes-->>SourceBalanceValidator: provide ordered events
UpdateCapTable->>SourceBalanceValidator: validate issuance quantities
SourceBalanceValidator-->>UpdateCapTable: return validation result
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@copilot review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de4daaf240
ℹ️ 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".
|
@copilot review |
…nto codex/ocf-stock-plan-pool-ceiling-v2
…nto codex/ocf-stock-plan-pool-ceiling-v2
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8c88a6f924
ℹ️ 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".
|
Addressed in |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ab29855. Configure here.
…' into codex/ocf-stock-security-balance # Conflicts: # Test/daml/OpenCapTable/TestStockCancellation.daml # scripts/codegen/templates/CapTable.daml.template
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7fc55abc25
ℹ️ 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".
|
Reviewed exact head |
|
CI and DAR integrity are green on exact head |
|
@codex review |
Reviewed exact head |
|
@codex review exact head |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 93bc1041cb
ℹ️ 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".
|
Exact-head replay evidence for
|
|
CI and DAR integrity are green on exact head |
|
@codex review exact head |
|
Codex Review: Didn't find any major issues. Delightful! 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". |
Reviewed exact head |
|
Definitive exact-head replay evidence for
|

Summary
Enforce source-security lifecycle invariants on current
main: known issuance quantities cannot be reduced below zero, terminal events retire their source, and lifecycle events cannot predate issuance.Covered reductions:
Direct stock-class splits are applied chronologically to stock issuances and equity-compensation issuances with an explicit
stock_class_id. Because OCF records calendar dates without intra-day ordering, same-day events use the lowest-balance valid ordering: a same-day reverse split is included when it may reduce the issuance balance, while a same-day forward split is excluded when the issuance may already be post-split.Deliberate exclusions
This PR does not validate successor identity,
balance_security_idmaterialization, resulting-security continuity, predecessor graphs, terminal completeness, or inferred stock-plan class lineage. Those remain separate rules.Warrant issuances with no quantity cannot be numerically balance-checked. A warrant exercise with omitted quantity is treated as a full retirement of the source security.
Version and branch
main, including merged Enforce conversion-ratio adjustment references #280bec4cfd5f85059c099acb579d6b58aba7f9896bbOpenCapTable-v34 0.0.30.0.3DAR and lock entry were rebuilt from the combined source.Validation
git diff --check: passedbatch,conversion, andschemaDev data correction
Four old Protelicious equity-compensation issuances recorded
quantity: "4"while their vestings totaled7.9998and their sole exercise consumed8. With approval, dev-only version 3 rows were appended changing onlyquantityto"8"; version 2 remains preserved. Independent read-only verification passed, and the definitive exact-head dev replay subsequently converged without any failure.Exact-head replay artifacts (2026-07-23)
bec4cfd5f85059c099acb579d6b58aba7f9896bbbatch,conversion, andschemaphases as the current-main baseline; replay duration 4m48sNote
High Risk
Changes core cap-table acceptance logic for all stock, warrant, and equity-comp lifecycle batches; incorrect split or retirement ordering could reject valid production data or miss invalid states.
Overview
Adds post-batch validation on
UpdateCapTableso a known issuance quantity cannot be driven below zero by recorded lifecycle events on thatsecurity_id.The contract introduces
SecurityBalanceEvent(reductions, retirements, class splits as multipliers), aggregates events for stock, warrant, and equity compensation issuances, and runsvalidateSourceSecurityBalancesafter each batch. It rejects cumulative overdraws, pre-issuance reductions, further reductions after retraction / reissuance / consolidation / full warrant exercise, and ambiguous same-day split vs reduction ordering (OCF has calendar dates only). Splits on a later date scale balances; same-day forward splits on issuance are not assumed to inflate pre-recorded quantities.DAML script coverage is expanded across cancellations, transfers, exercises, releases, repurchases, conversions, and split edge cases, with small test-helper tweaks (e.g. configurable EC grant size).
OpenCapTable-v340.0.3 DAR and lock metadata are updated to ship the new rules.Reviewed by Cursor Bugbot for commit bec4cfd. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
Bug Fixes
Tests