Skip to content

Enforce OCF schema field constraints#269

Draft
HardlyDifficult wants to merge 87 commits into
codex/ocf-reference-integrity-categoryfrom
codex/ocf-schema-constraints-category
Draft

Enforce OCF schema field constraints#269
HardlyDifficult wants to merge 87 commits into
codex/ocf-reference-integrity-categoryfrom
codex/ocf-schema-constraints-category

Conversation

@HardlyDifficult

@HardlyDifficult HardlyDifficult commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Consolidates the schema/field-format OCF enforcement PRs into one category branch stacked on #268. Supersedes #257, #258, #259, #260, #261, #262, #263, #264, #265, #266, and #267.

Grouped requirements enforced here:

  • Transfer and consolidation arrays enforce schema-declared non-empty/unique cardinality. Every resulting-security array rejects duplicate successor IDs for object-identity consistency while retaining each OCF schema's empty-array behavior.
  • Document path / uri mutual-exclusion schema rule.
  • Conversion-mechanism and trigger constraints representable by the v34 model, including strict convertible/warrant variants and the v34 stock-class ratio subset.
  • Conversion mechanism variant constraints for share-price, valuation-based, and conversion-trigger payloads.
  • Currency code, phone number, and country subdivision code format constraints.
  • Stock issuance share-number range consistency and non-overlap checks, including final-state overlaps across issuances in the same stock class.
  • Optional stock cost_basis and warrant exercise_price payloads enforce the OCF Monetary amount/currency constraints on both create and edit.
  • Materialized non-split reissuance and consolidation results preserve the numbered certificate ranges of their source lineage.

Review feedback carried forward from superseded PRs:

  • #259: stock-class ratio conversion rights now reject expires_at.
  • #263: stock-class conversion-right validation ignores the non-OCF placeholder trigger and enforces the ratio fields representable by v34; exact structural parity requires a package-version model change.
  • #267: stock issuance share-number overlaps are checked across the final cap-table state, per stock class.

OCF documentation

The exercise, release, reissuance, and conversion schemas require the field but do not declare minItems or uniqueItems. This PR preserves zero-cardinality input while rejecting repeated references to the same resulting OCF object as a contract-level consistency rule.

Scope boundary

This PR strictly validates constraints representable by OpenCapTable-v34. It does not claim complete structural parity for StockClassConversionRight: the v34 record predates the current nested ratio mechanism and cannot represent required rounding_type or a targetless future-round right without changing the package model. This PR intentionally does not synthesize dummy target, trigger, or rounding values. The proper completion is a corrected next-version model plus an explicit v34-to-next-version migration.

Validation

  • npm run build
  • Focused stock/warrant issuance suite (28 behavioral scripts plus 2 setup scripts)
  • npm test (536 behavioral scripts plus 2 setup scripts)
  • 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.10 -> 0.0.11)
  • git diff --check
  • OpenCapTable-v34-0.0.11.dar: SHA-256 23fc9940acf68156ce2594da14b0783ce38c9195d9aaf15e113fb5124f05d8ee, 3,114,372 bytes

Note

High Risk
Wide validation tightening on issuance, conversion, transfers, and share-number lineage can reject previously accepted cap-table payloads; stock-class conversion is narrowed to ratio-only in v34, which is a breaking behavioral change for importers.

Overview
Bumps OpenCapTable-v34 to 0.0.11 and tightens OCF-shaped validation across cap-table templates and shared types, with a large DAML test expansion.

Arrays and documents: Transfer/consolidation paths use shared non-empty + unique string-array helpers; other transaction types still allow empty resulting_security_ids but reject duplicates. Documents must have exactly one of path or uri, not both or neither.

Formats: ISO currency (3 uppercase letters), phone (space-separated parts with optional ext./extension), and country subdivision codes are validated centrally; issuer and address fields use the shared rules.

Conversion: Shared trigger variant rules (validateOcfConversionTriggerFields) gate which optional date/condition fields are allowed. Convertible mechanisms no longer accept PPS/valuation/ratio variants OCF disallows; warrant valuation uses CAP/FIXED/ACTUAL; share-price and valuation-based discount rules are stricter. Stock-class conversion rights in v34 are limited to ratio mechanics with required conversion_price and no extra mechanism fields; non-ratio stock-class rights fail validation.

Stock issuance: Optional cost_basis and warrant exercise_price go through Monetary validation. Share number ranges must sum to quantity, not overlap on the issuance, and cap-table logic (tests) enforces per-class final-state overlap and lineage rules on transfers, reissuance, and consolidation.

Packaging: New 0.0.7–0.0.11 DAR artifacts and lockfile entries; tests depend on 0.0.11.

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

HardlyDifficult and others added 30 commits July 8, 2026 21:03
…nto codex/ocf-stock-plan-pool-ceiling-v2

# Conflicts:
#	scripts/codegen/templates/CapTable.daml.template
Also reject expires_at on ratio stock-class conversion rights and refresh fixtures for the stricter validator.
@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

@copilot review

Retrying the mandatory review gate for exact head 66c1b9bf4be98f5cca64fea5be68ee134703fbc5; the prior request has not received a response. Please focus on mixed numbered/unnumbered consolidation lineage, empty stock-reissuance lifecycle rejection, and partial numbered-stock balance successors. CI is green, the branch is merge-clean, and the thread-aware sweep is clear.

Copilot AI commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

@copilot review

Retrying the mandatory review gate for exact head 66c1b9bf4be98f5cca64fea5be68ee134703fbc5; the prior request has not received a response. Please focus on mixed numbered/unnumbered ...

Reviewed exact head 66c1b9bf4be98f5cca64fea5be68ee134703fbc5 in the requested areas (mixed numbered/unnumbered consolidation lineage, empty stock-reissuance lifecycle rejection, and partial numbered-stock balance successors). I don’t see any additional blocking issues to address.

@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

@codex review current head 66c1b9bf4be98f5cca64fea5be68ee134703fbc5

@coderabbitai resume
@coderabbitai review current head 66c1b9bf4be98f5cca64fea5be68ee134703fbc5

cursor review current head 66c1b9bf4be98f5cca64fea5be68ee134703fbc5

Copilot completed its exact-head review with no blocking findings. Please review the grouped OCF field-shape constraints and numbered-security lineage behavior on this same revision.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

@HardlyDifficult I'll resume automatic reviews and review the latest changes on exact head 66c1b9bf4be98f5cca64fea5be68ee134703fbc5, focusing on the grouped OCF field-shape constraints and numbered-security lineage behavior.

✅ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 66c1b9bf4b

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

@cursor review Please review exact head 66c1b9b, focusing on schema cardinality, unique identifiers, and transaction-array constraints. Copilot, Codex, and CodeRabbit have completed exact-head reviews; CI is green and review threads are clear.

@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 66c1b9b. Configure here.

@HardlyDifficult HardlyDifficult self-assigned this Jul 11, 2026
@HardlyDifficult HardlyDifficult marked this pull request as draft July 11, 2026 14:40
@HardlyDifficult HardlyDifficult removed their assignment Jul 11, 2026

HardlyDifficult commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator Author

Added the remaining direct optional Monetary enforcement in e9c512bf0ab2c5772450856ccf0864938973a706:

  • StockIssuance.cost_basis now runs validateOcfMonetary when present.
  • WarrantIssuance.exercise_price now runs validateOcfMonetary when present.
  • Contract-level regressions reject invalid currency on create and negative amount on edit for both fields.

OCF basis:

Validation is green locally: build, focused 28 behavioral + 2 setup scripts, full 536 behavioral + 2 setup scripts, codegen/package verification, format, ESLint (0 errors; 2 pre-existing warnings), DAML lint, 55/55 schema-gap check, 11 DARs, and 0.0.10 -> 0.0.11 upgrade compatibility. DAR SHA-256: 23fc9940acf68156ce2594da14b0783ce38c9195d9aaf15e113fb5124f05d8ee.

The PR is back in draft pending exact-head CI. Downstream stack heads will be restacked only after this base is green.

@HardlyDifficult HardlyDifficult marked this pull request as ready for review July 11, 2026 14:53

Copy link
Copy Markdown
Collaborator Author

@copilot review exact head e9c512bf0ab2c5772450856ccf0864938973a706.

Please review the optional Monetary enforcement for stock cost_basis and warrant exercise_price, including create/edit contract regressions. Exact-head CI is green, the branch is merge-clean, all 538 scripts pass locally, and the thread-aware sweep has zero unresolved threads.

Copilot AI commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

@copilot review exact head e9c512bf0ab2c5772450856ccf0864938973a706.

Please review the optional Monetary enforcement for stock cost_basis and warrant exercise_price, including create/edit con...

Reviewed exact head e9c512bf0ab2c5772450856ccf0864938973a706 with focus on optional Monetary enforcement for StockIssuance.cost_basis and WarrantIssuance.exercise_price, including create/edit regression coverage. I don’t see any additional blocking issues to address.

Copy link
Copy Markdown
Collaborator Author

@codex review exact head e9c512bf0ab2c5772450856ccf0864938973a706.

Copilot has completed this exact revision with no blocking findings. Please review the optional Monetary enforcement and create/edit regressions.

Copy link
Copy Markdown
Collaborator Author

@cursor review exact head e9c512bf0ab2c5772450856ccf0864938973a706.

Copilot has completed this exact revision with no blocking findings. Please review the optional Monetary enforcement and create/edit regressions.

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

Please perform the required substantive review of exact head e9c512bf0ab2c5772450856ccf0864938973a706. Copilot has completed this exact revision with no blocking findings; CI is green, the branch is merge-clean, and zero review threads are unresolved.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

@HardlyDifficult I'll review the latest changes on exact head e9c512bf0ab2c5772450856ccf0864938973a706, focusing on the optional Monetary enforcement for StockIssuance.cost_basis and WarrantIssuance.exercise_price, and the associated create/edit contract regressions.

✅ Action performed

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.

Copy link
Copy Markdown
Collaborator Author

@coderabbitai Please explicitly confirm whether your completed review of exact head e9c512bf0ab2c5772450856ccf0864938973a706 found any actionable issues. No new review is requested.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@HardlyDifficult Confirmed — the completed review of exact head e9c512bf0ab2c5772450856ccf0864938973a706 did not surface any actionable issues (no line comments were posted). As noted, CodeRabbit is an incremental review system, so that pass covered only the diff introduced up to that commit relative to the last reviewed state; no new review was triggered per your request.

@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 e9c512b. Configure here.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: e9c512bf0a

ℹ️ 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 HardlyDifficult self-assigned this Jul 11, 2026
@HardlyDifficult HardlyDifficult marked this pull request as draft July 13, 2026 19:06

Copy link
Copy Markdown
Collaborator Author

Preliminary OCF validation-policy audit

Policy: OCF Validation Policy

Appears supported

  • Formal schema rules: formats, conditional variants, document path/URI exclusivity, and array minItems/uniqueItems where OCF declares them.
  • Conversion-mechanism shapes and monetary/phone/currency/subdivision validation that directly implement official schemas.
  • Semantic share-number integrity where the OCF model explicitly treats share numbers as unique identifiers for non-fungible shares.

Needs line-by-line evidence or narrowing

  • Duplicate-result rejection for arrays whose schema omits uniqueItems, unless OCF semantics independently require uniqueness.
  • Exact share-number quantity equality, cross-issuance overlap windows, and successor-range reconstruction where the algorithm goes beyond documented share-number semantics.
  • Result cardinality or lineage constraints not declared by schema or documentation.

Proposed next step
Separate schema-parity rules from second-order share-number/lifecycle rules, then review the latter individually. No merge recommendation yet.

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