Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/core/src/opendirector/domain/creation/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ def missing_versions_message(self, supplied) -> str:
return contract_text('version_required', entries=', '.join(entries), options=' '.join(options))


class CreationCommitCommandBase(CommandBase):
clientIntentFingerprint: Digest | None = Field(default=None, exclude_if=lambda value: value is None,
description='Caller-supplied SHA-256 of its original request before it was expanded into a command.')


# HTTP/application contracts; Agent tool registration is a separate boundary.
_COMMANDS = (
('ProjectCreateCommand', 'project.create', ProjectCreate, 'Create a project.'),
Expand Down Expand Up @@ -555,7 +560,8 @@ def missing_versions_message(self, supplied) -> str:
)
COMMAND_MODELS = {}
for _name, _type, _payload, _description in _COMMANDS:
_model = create_model(_name, __base__=CommandBase, __doc__=_description, type=(Literal[_type], Field(description='Command discriminator.')),
_base = CommandBase if _type.startswith('pipeline.') else CreationCommitCommandBase
_model = create_model(_name, __base__=_base, __doc__=_description, type=(Literal[_type], Field(description='Command discriminator.')),
payload=(_payload, Field(description=_description)))
COMMAND_MODELS[_type] = _model
globals()[_name] = _model
Expand All @@ -574,7 +580,7 @@ class BatchPayload(Contract):
operations: tuple[Operation, ...] = Field(min_length=1, max_length=500, description='Ordered operations committed as one atomic transaction.')


BatchCommand = create_model('BatchCommand', __base__=CommandBase,
BatchCommand = create_model('BatchCommand', __base__=CreationCommitCommandBase,
__doc__='Apply multiple operations atomically; all succeed or none are committed.',
type=(Literal['creation.batch'], Field(description='Batch command discriminator.')),
payload=(BatchPayload, Field(description='Ordered operations committed atomically.')))
Expand Down Expand Up @@ -638,6 +644,8 @@ class CommandReceipt(Contract):
commandId: UUID = Field(description='Stable command ID for idempotent replay.')
projectId: UUID = Field(description='Owning project ID.')
inputFingerprint: Digest = Field(description='Fingerprint of the fixed execution input.')
clientIntentFingerprint: Digest | None = Field(default=None, exclude_if=lambda value: value is None,
description='Original request fingerprint supplied by the caller, if present in the recorded command.')
status: Literal['applied', 'accepted', 'noop', 'rejected'] = Field(description='Current operation lifecycle state.')
changed: tuple[ObjectVersion, ...] = Field(default=(), description='Business objects changed by the operation.')
jobIds: tuple[UUID, ...] = Field(default=(), description='Generation jobs associated with this operation.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def _make_record(command, head, snapshot, changed, source, issue=None, *, placem
event = ProjectEvent(projectId=command.projectId, cursor=snapshot.eventCursor, commandId=command.commandId,
source=source, changed=changed, jobIds=job_ids) if changed else None
receipt = CommandReceipt(commandId=command.commandId, projectId=command.projectId,
inputFingerprint=command_fingerprint(command), status='rejected' if issue else 'accepted' if job_ids else 'applied' if changed else 'noop',
inputFingerprint=command_fingerprint(command), clientIntentFingerprint=command.clientIntentFingerprint,
status='rejected' if issue else 'accepted' if job_ids else 'applied' if changed else 'noop',
changed=[item['version'] for item in changed], jobIds=job_ids, issues=[issue] if issue else [], eventCursor=snapshot.eventCursor,
canvasPlacements=placements)
return CommitRecord(command=command, previousHead=head, snapshot=snapshot, receipt=receipt, event=event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def consistent(self):
or self.receipt.projectId != self.command.projectId
or self.receipt.commandId != self.command.commandId
or self.receipt.inputFingerprint != command_fingerprint(self.command)
or self.receipt.clientIntentFingerprint != self.command.clientIntentFingerprint
or self.receipt.eventCursor != self.snapshot.eventCursor):
raise ValueError('Commit identity is inconsistent')
applied = self.receipt.status in {'applied', 'accepted'}
Expand Down
Loading