Skip to content

Enforce OCF reference integrity#268

Draft
HardlyDifficult wants to merge 52 commits into
codex/ocf-stock-class-share-ceilingfrom
codex/ocf-reference-integrity-category
Draft

Enforce OCF reference integrity#268
HardlyDifficult wants to merge 52 commits into
codex/ocf-stock-class-share-ceilingfrom
codex/ocf-reference-integrity-category

Conversation

@HardlyDifficult

@HardlyDifficult HardlyDifficult commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Groups the OCF reference-integrity enforcement into one category PR, superseding the standalone reference PRs #251, #255, and #256.

UpdateCapTable now validates final-state object references after deletes, edits, issuer edits, and creates, including:

  • document related_objects references, including issuer references and plan-security aliases
  • stock-class conversion targets
  • stock issuance stakeholder, stock class, stock legend, stock plan, and vesting terms references
  • equity compensation issuance stakeholder, stock class, stock plan, and vesting terms references
  • warrant and convertible conversion target references, including nested stock-class conversion triggers
  • lifecycle source, balance, and resulting security IDs resolve against the correct issuance type in the batch's final state
  • valuation stock-class references
  • stock-plan stock-class references
  • warrant vesting-terms references
  • VestingStart/VestingEvent vesting_condition_id references against the referenced security's VestingTerms, including trigger-type compatibility

The branch is restacked on #238, so it includes the authorized/reserved ceiling base and uses OpenCapTable-v34 0.0.6.

OCF requirement references

Schema references are pinned to Open-Cap-Format-OCF commit dd84bdb6bafb63681c77166f315cea5a2078a4c8.

Validation

  • npm run build
  • npm test (497 scenarios)
  • npm run lint (0 errors; 2 pre-existing warnings in scripts/remove-participant-dar.ts)
  • npm run lint:daml
  • npm run format
  • npm run check:schema-gaps -- --ocf-schema-dir /tmp/open-cap-format-ocf-schema-check/schema
  • npm run verify-dars
  • npm run verify-package
  • npm run check-upgrade-compat (0.0.5 -> 0.0.6)
  • git diff --check
  • OpenCapTable-v34-0.0.6.dar: SHA-256 f321638da45f5ad87e3f91c8701eaf6ac2b846bcef7be1e8b9221144972e3997, 3,070,303 bytes

Note

High Risk
Tightens validation on all cap-table batch updates (references, deletes, and lifecycle securities), so previously accepted UpdateCapTable payloads may now reject; contract upgrade is 0.0.5 → 0.0.6.

Overview
OpenCapTable-v34 is released as 0.0.6 (Test package retargets the new DAR). The visible diff is dominated by Daml Script work that locks in OCF reference integrity on batched UpdateCapTable updates: missing balance and resulting securities, wrong security types, dangling deletes, and bad capitalization / conversion / document links are expected to fail, while references created or fixed in the same batch should succeed.

New focused suites cover balance-security successors, resulting-security rules, document and stock-plan links, stock-class and convertible conversion targets, equity-compensation prerequisites, and “final state” checks (e.g. trigger IDs, reissuance split transactions, stakeholder delete ordering). TestHelpers gains successor issuance builders (stockSuccessorIssuance, convertibleSuccessorIssuance, etc.), empty default stock legends, and shared stock plan / vesting / legend fixtures so existing transfer, conversion, exercise, release, and authorized-shares tests materialize successor issuances instead of relying on implicit placeholders.

Reviewed by Cursor Bugbot for commit 88ae4aa. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

OpenCapTable-v34 is upgraded to package version 0.0.6. Generated CapTable validation now covers cross-object, optional, issuer, document, conversion, vesting, and same-batch references. New and updated DAML scripts exercise creation, editing, deletion, and prerequisite-reference scenarios.

Changes

Reference validation and generated CapTable flow

Layer / File(s) Summary
Validation metadata and generator contracts
scripts/codegen/captable-config.yaml, scripts/codegen/generate-captable.ts
Validation configuration now supports optional references, issuer validation, object-constructor overrides, and revised processing tiers.
Generated reference validation flow
scripts/codegen/templates/CapTable.daml.template, scripts/codegen/templates/loops/*
Generated create and edit paths validate issuer, object, document, issuance, conversion, vesting, and split references, including same-batch maps and optional fields.
Reference-integrity test suites
Test/daml/OpenCapTable/Test*References.daml
New scripts cover missing, inconsistent, same-batch, edit, and deletion reference cases across documents, issuances, stock classes, valuations, warrants, and vesting conditions.
Existing fixtures and regression scenarios
Test/daml/OpenCapTable/Test*.daml
Existing fixtures now create required referenced entities, use empty default legend references, and exercise updated stock, vesting, conversion, and issuer-reference behavior.
Package publication
OpenCapTable-v34/daml.yaml, Test/daml.yaml, dars/OpenCapTable-v34/0.0.6/OpenCapTable-v34.dar
The manifest, test dependency, and DAR pointer are updated from version 0.0.5 to 0.0.6.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TestScript
  participant UpdateCapTable
  participant CapTableMaps
  participant ReferenceValidators
  TestScript->>UpdateCapTable: submit creates, edits, and deletes
  UpdateCapTable->>CapTableMaps: apply pending mutations
  UpdateCapTable->>ReferenceValidators: validate final references
  ReferenceValidators-->>UpdateCapTable: success or failure
  UpdateCapTable-->>TestScript: updated cap table or rejected submission
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the PR’s main change: enforcing OCF reference integrity across creates, edits, and deletes.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/ocf-reference-integrity-category

Comment @coderabbitai help to get the list of available commands.

@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

CI is green on the latest head (6529ed3). @copilot review

Comment thread scripts/codegen/templates/CapTable.daml.template
Comment thread scripts/codegen/templates/CapTable.daml.template

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6529ed33b8

ℹ️ 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".

Comment thread scripts/codegen/templates/CapTable.daml.template Outdated
Comment thread scripts/codegen/templates/CapTable.daml.template
Comment thread scripts/codegen/templates/CapTable.daml.template

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR centralizes post-batch referential-integrity enforcement in UpdateCapTable by validating object references against the final cap table state (after deletes/edits/creates), and updates tests/fixtures and package artifacts to match the stricter invariants.

Changes:

  • Adds final-state reference validation passes for documents’ related_objects, conversion targets, valuations, stock plans, and issuance prerequisite references.
  • Updates codegen templates/config to support final-state validation patterns (incl. optional/array ref specs and issuer-id checks).
  • Adds/updates Daml Script tests and bumps OpenCapTable-v34 to 0.0.6 with new DAR + lock updates.

Reviewed changes

Copilot reviewed 34 out of 35 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Test/daml/OpenCapTable/TestWarrantIssuanceReferences.daml New tests for warrant vesting-terms reference integrity across create/edit/delete batches.
Test/daml/OpenCapTable/TestWarrantIssuance.daml Updates warrant issuance fixture to create referenced vesting terms.
Test/daml/OpenCapTable/TestWarrantConversionRightReferences.daml New tests for warrant conversion-target references (including nested triggers).
Test/daml/OpenCapTable/TestVestingStart.daml Removes placeholder equity-comp references to avoid failing new reference checks.
Test/daml/OpenCapTable/TestVestingEvent.daml Removes placeholder equity-comp references to avoid failing new reference checks.
Test/daml/OpenCapTable/TestVestingAcceleration.daml Removes placeholder equity-comp references to avoid failing new reference checks.
Test/daml/OpenCapTable/TestValuationReferences.daml New tests for valuation stock-class reference integrity.
Test/daml/OpenCapTable/TestStockRetraction.daml Removes placeholder stock legend IDs from stock issuance fixtures.
Test/daml/OpenCapTable/TestStockPlanReferences.daml New tests for stock plan stock-class reference integrity.
Test/daml/OpenCapTable/TestStockIssuanceReferences.daml New tests for stock issuance prerequisite references (legend/plan/vesting/class).
Test/daml/OpenCapTable/TestStockIssuance.daml Updates stock issuance test to create referenced legend/plan/vesting terms.
Test/daml/OpenCapTable/TestStockClassConversionRightReferences.daml New tests for stock-class conversion target references.
Test/daml/OpenCapTable/TestStockClass.daml Refactors common stock-class fixture and ensures prerequisite creation in tests.
Test/daml/OpenCapTable/TestStockCancellation.daml Removes placeholder stock legend IDs from issuance fixtures.
Test/daml/OpenCapTable/TestStockAcceptance.daml Removes placeholder stock legend IDs from issuance fixtures.
Test/daml/OpenCapTable/TestIssuerAuthorizedSharesAdjustment.daml Adds helper + tests for issuer-id reference validation on adjustments.
Test/daml/OpenCapTable/TestHelpers.daml Adds default legend/vesting-term helpers and stops using placeholder legend IDs.
Test/daml/OpenCapTable/TestEquityCompensationTransfer.daml Removes placeholder equity-comp stock-class reference.
Test/daml/OpenCapTable/TestEquityCompensationRetraction.daml Removes placeholder equity-comp stock-class reference.
Test/daml/OpenCapTable/TestEquityCompensationIssuanceReferences.daml New tests for equity-comp issuance prerequisite references (class/plan/vesting).
Test/daml/OpenCapTable/TestEquityCompensationIssuance.daml Updates equity-comp issuance test to create referenced class/plan/vesting terms.
Test/daml/OpenCapTable/TestEquityCompensationCancellation.daml Removes placeholder equity-comp stock-class reference.
Test/daml/OpenCapTable/TestEquityCompensationAcceptance.daml Removes placeholder equity-comp stock-class reference.
Test/daml/OpenCapTable/TestDocument.daml Adds document related-object reference tests and fixes issuer reference to real issuer id.
Test/daml/OpenCapTable/TestConvertibleConversionRightReferences.daml New tests for convertible conversion target references.
Test/daml/OpenCapTable/TestConversionMechanisms.daml Ensures prerequisite stock class exists where conversion logic requires it.
Test/daml.yaml Updates Test package to depend on OpenCapTable-v34-0.0.6.dar.
scripts/codegen/templates/loops/edit-case.daml Adds optional-ref validation and issuer-id validation hooks; extends edit return tuple.
scripts/codegen/templates/loops/create-case.daml Adds optional-ref validation and issuer-id validation hooks for creates.
scripts/codegen/templates/CapTable.daml.template Adds final-state reference validation helpers and runs them post-batch.
scripts/codegen/generate-captable.ts Enhances codegen to support optional validations + object-type constructor mapping.
scripts/codegen/captable-config.yaml Retiers StockPlan/plan adjustments and shifts some validations to final-state checks.
OpenCapTable-v34/daml.yaml Bumps package version to 0.0.6.
dars/OpenCapTable-v34/0.0.6/OpenCapTable-v34.dar Adds new DAR artifact (LFS pointer) for 0.0.6.
dars/dars.lock Registers new DAR hash/size metadata for 0.0.6.

Comment thread scripts/codegen/templates/CapTable.daml.template
Comment thread scripts/codegen/templates/CapTable.daml.template
Comment thread scripts/codegen/templates/CapTable.daml.template Outdated
…ing' into codex/ocf-reference-integrity-category

# Conflicts:
#	Test/daml/OpenCapTable/TestConvertibleConversion.daml
@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

Restacked onto the final #238 head at fc71c51.

The inherited authorized-ceiling conversion tests now materialize every referenced result and balance security, so they exercise both categories together instead of failing early on missing references. The full suite passes with 496 scenarios, and all local gates pass: build, ESLint (0 errors; 2 pre-existing warnings), DAML lint, format, pinned schema parity, DAR verification, package/import verification, 0.0.5 -> 0.0.6 upgrade compatibility, and git diff --check.

Refreshed DAR: SHA-256 d93ca8aa5e52c961df9eaecb55c898324360212b04fce7be4fcc33772b41b6b1, 3,069,371 bytes. Keeping this PR in draft until exact-head CI is green.

@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

Propagated the latest #238 negative equity-exercise fix through this branch. Current head is f4788cc; all 497 scenarios and the complete local gate set pass. Refreshed 0.0.6 DAR: SHA-256 f321638da45f5ad87e3f91c8701eaf6ac2b846bcef7be1e8b9221144972e3997, 3,070,303 bytes. Remaining in draft pending exact-head CI.

@HardlyDifficult HardlyDifficult marked this pull request as ready for review July 11, 2026 03:28
@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

@copilot review

Please review exact head f4788cc61d34949a2d597df77aade295161afa39, including final-state cross-object reference validation and its interaction with the stacked authorized-ceiling rules. CI is green, the branch is merge-clean, all 497 scenarios pass locally, and there are no unresolved review threads.

@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

@copilot review exact head f4788cc61d34949a2d597df77aade295161afa39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 53 out of 54 changed files in this pull request and generated 1 comment.

Comment thread Test/daml/OpenCapTable/TestStockIssuance.daml Outdated
@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

@codex review current head 88ae4aa82427f3f1359d497434fa333420912111

@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

cursor review current head 88ae4aa82427f3f1359d497434fa333420912111

@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

@coderabbitai resume

@coderabbitai review current head 88ae4aa82427f3f1359d497434fa333420912111

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

@HardlyDifficult Resuming automatic reviews and kicking off a review of the current head 88ae4aa8.

✅ Action performed

Reviews resumed.


Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 88ae4aa. Configure here.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 88ae4aa824

ℹ️ 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".

@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

Exact head 88ae4aa82427f3f1359d497434fa333420912111 has green CI, a clean merge state, and all 26 review threads resolved. This revision addresses the prior Copilot finding, so the mandatory exact-head gate needs a fresh response. @copilot review

Copilot AI commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Exact head 88ae4aa82427f3f1359d497434fa333420912111 has green CI, a clean merge state, and all 26 review threads resolved. This revision addresses the prior Copilot finding, so the mandatory exact-h...

Reviewed exact head 88ae4aa82427f3f1359d497434fa333420912111. I don’t see any new high-confidence correctness issues to address.

Copy link
Copy Markdown
Collaborator Author

Preliminary OCF validation-policy audit

Policy: OCF Validation Policy

Important correction from the current audit: internal-reference validity is part of the OCF data model even though the official JSON Schema validator does not currently check it.

Appears supported

  • Stakeholder, stock-class, stock-legend, stock-plan, vesting-terms, valuation, conversion-target, lifecycle-security, document-object, and vesting-condition references when the official OCF sources define those relationships.
  • In particular, every non-empty StockIssuance.stock_legend_ids entry should resolve to a STOCK_LEGEND_TEMPLATE. An empty array remains valid.
  • Final-state validation after edits/deletes is appropriate when otherwise the package would retain a dangling documented reference.

Needs verification

  • Confirm every target-type or membership restriction is exactly the relationship OCF documents; do not add a stronger relationship merely because an ID field exists.
  • Tests should distinguish schema validation from complete-package reference validation and must not fabricate placeholder legal text.

Proposed next step
Audit the checks one reference family at a time. This PR should not be closed merely because these relationships are not expressible in JSON Schema.

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.

3 participants