Skip to content

feat(contracts): finalize cyclic topology and Contracts 1.0 closure execution - #29

Merged
piotr-blue merged 37 commits into
nextfrom
feature/cyclic-topology
Aug 20, 2026
Merged

feat(contracts): finalize cyclic topology and Contracts 1.0 closure execution#29
piotr-blue merged 37 commits into
nextfrom
feature/cyclic-topology

Conversation

@piotr-blue

Copy link
Copy Markdown
Contributor

Summary

This PR completes the Language foundation for deterministic Contracts 1.0 cyclic managed-document processing.

Cyclic document relationships are now processed as one authenticated closure: work is ordered causally, identities are finalized deterministically, gas is metered once, and publication remains atomic.

What changed

  • Added graph-native execution for cyclic managed-document closures.
  • Added deterministic component finalization and proof verification.
  • Preserved exact document, component, occurrence, and binding identities.
  • Enforced canonical work ordering, gas accounting, rollback, and retry behavior.
  • Added prospective managed-document initialization, including multiple occurrences of one lineage.
  • Finalized each independent SCC before beginning the next initialization batch.
  • Resolved event routes from the latest document state at dequeue while retaining creation-time lineage evidence.
  • Added extensive ordinary, cyclic, initialization, detachment, merge/split, ordering, and failure-path coverage.
  • Hardened final-quality and reproducible release evidence.

Compatibility

The implementation preserves the frozen Contracts 1.0:

  • work-kind set;
  • gas weights and limits;
  • cyclic-set identity;
  • result and proof model;
  • causal scheduler semantics.

Verification

  • 3,156 tests passed
  • 0 failures
  • 0 skipped
  • 153/153 Language fixtures passed
  • 167/167 ordinary Contracts fixtures passed
  • 67/67 closure Contracts fixtures passed
  • 387/387 total release fixtures passed
  • Final-quality verification passed with no blockers
  • Reproducible 1,751-file source archive verified
  • Staged Language 3.1.0-rc.21 artifacts verified

Review notes

The diff is intentionally large because it includes the recovered Contracts 1.0 topology implementation, normative fixtures, verification tooling, documentation, and artifact-bound evidence.

@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: e0dfc897ea

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +50 to +52
if (!GasSchedule.CONTRACTS_1_0_SCHEDULE.equals(gas.schedule())
|| !GasSchedule.CONTRACTS_1_0_PACKAGE_IDENTITY.equals(
gas.packageIdentity())) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require byte-bound schedules before emitting the released digest

When a caller supplies DocumentProcessor.Builder.gasSchedule(GasSchedule.load(...)) with a manifest having the released schedule and package identity but different raw bytes (even formatting-only differences), this check accepts it and capture() falsely reports CONTRACTS_1_0_RESOURCE_SHA256 as its byte identity. The same processor then fails during closure execution because ProcessorInvocationServices.gasManifestIdentity() requires the singleton returned by GasSchedule.contracts10(). Require that exact byte-bound schedule here as well, or retain and verify the loaded manifest's actual byte digest so descriptor capture and execution agree.

Useful? React with 👍 / 👎.

Comment on lines +327 to +331
if (input.cause().kind() == ProcessingCause.Kind.EXTERNAL
&& input.directDeliveries().isEmpty()) {
throw new ClosureCapabilityGapException(
"EXTERNAL_DIRECT_DELIVERY_REQUIRED",
"The first concrete engine lane requires one accepted direct delivery");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Return the defined status for empty external delivery sets

When an external event has no accepted direct delivery, an empty directDeliveries sequence is a valid invocation that must produce the noncommitting NO_MATCH (or, after classification, STALE/TERMINATED) result. This guard instead converts that routine case into CAPABILITY_FAILURE before classification or status selection, so hosts cannot process unmatched external events through the closure API. Remove the accepted-delivery requirement and assemble the appropriate rollback status from the classification result.

Useful? React with 👍 / 👎.

Comment on lines +1306 to +1308
throw new ClosureCapabilityGapException(
"LIFECYCLE_TERMINATION_REQUIRED",
"Termination requires the lifecycle and marker batch lane");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Execute managed termination instead of returning a capability gap

Whenever a managed Handler requests graceful termination, this continuation aborts the entire closure with CAPABILITY_FAILURE. The required behavior is to run the Document Processing Terminated lifecycle, drain already emitted events under the termination cut-off, write the terminated marker, finalize affected components, and commit the successful business transition; consequently any contract using requestTermination cannot complete through the new closure runtime.

Useful? React with 👍 / 👎.

Comment on lines +414 to +416
if (!candidate.rawChannelKey().equals(delivery.channelKey())
|| !candidate.handlerChannelKey().equals(
delivery.channelKey())) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Honor delegated handler-channel selection

When an External Channel's HANDLER_CHANNEL_KEY selects another valid same-scope Channel, classification returns distinct raw-source and handler keys by design, but this condition rejects that valid delivery as CAPABILITY_FAILURE. Delegated/routed channel protocols therefore cannot execute in a closure even though the ordinary runtime supports them; retain the source key for checkpoint ownership and dispatch the seed through the classified handler key instead of requiring equality.

Useful? React with 👍 / 👎.

Comment on lines +373 to +377
if (!stepProcessor.classifyDocumentUpdateRoutes(
currentDocument, update).isEmpty()) {
throw new ClosureCapabilityGapException(
"INITIALIZATION_DOCUMENT_UPDATE_QUEUE_REQUIRED",
"Initialization-caused Document Update routes are outside the bounded admission lane");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Run initialization-caused work during admission

During ADMIT_CLOSURE, an initialization Handler may legitimately apply a patch whose Document Update matches another Handler or emit an application event; both must enter the same causal queues and drain before the initialization marker batch. This branch instead turns any matching update route into CAPABILITY_FAILURE (and onApplicationEvent similarly fails unconditionally), so ordinary initialization logic that causes follow-up work can never be admitted.

Useful? React with 👍 / 👎.

@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: b6d3507a54

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +2047 to +2052
boolean exactTarget = ManagedOccurrenceTargetVerifier
.establishesExactTarget(value, target);
if (!exactTarget) {
throw new ClosureCapabilityGapException(
"NEW_OCCURRENCE_ADMISSION_REQUIRED",
"A changed occurrence target requires affected-closure admission");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Admit retargeted managed occurrences into the closure

When a Handler patches an existing Process Embedded occurrence to reference a different document, establishesExactTarget is false because target is still the old bound document, so this branch returns CAPABILITY_FAILURE. Dynamic graph changes are required to expand the affected closure, admit the new exact target, initialize it if necessary, and continue the same causal queue; as written, valid contracts cannot replace an embedded target during processing.

Useful? React with 👍 / 👎.

Comment on lines +340 to +343
if (document.terminated()) {
throw new ClosureCapabilityGapException(
"TERMINATED_MEMBER_POLICY_REQUIRED",
"Terminated members require lifecycle delivery policy");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Allow live members to process alongside terminated members

When an affected closure contains any previously terminated member, this unconditional loop rejects the entire invocation before routing begins, even if a nonempty direct delivery targets a different live member. Termination is scope-local—the event-routing code below already skips terminated sources and containers—so a terminated descendant or sibling must not turn valid work for the rest of the closure into CAPABILITY_FAILURE.

Useful? React with 👍 / 👎.

Comment on lines +336 to +340
ClosureEnvironment environment = input.environment();
if (!environment.runtimeRegistryIdentity().equals(
runtimeDescriptor.runtimeRegistryIdentity())) {
throw new IllegalArgumentException(
"Invocation runtime registry is not the configured implementation");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Bind invocations to the implemented specification artifacts

A caller can supply arbitrary valid SHA-256 values for blueLanguageSpecificationIdentity and contractsSpecificationIdentity; invocation verification merely includes them in the hash, while this runtime-binding check never compares them with the specifications actually implemented. The closure is then executed with the released semantics and emits a commit companion claiming different specification artifacts, allowing results and receipts to be mislabeled as executions under unsupported rules.

Useful? React with 👍 / 👎.

@piotr-blue
piotr-blue merged commit 24dc31c into next Aug 20, 2026
2 checks passed
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