Skip to content

fix(core): validate replay operation identity - #698

Open
zhongkechen wants to merge 7 commits into
mainfrom
fix/replay-operation-identity
Open

fix(core): validate replay operation identity#698
zhongkechen wants to merge 7 commits into
mainfrom
fix/replay-operation-identity

Conversation

@zhongkechen

Copy link
Copy Markdown
Contributor

Summary

  • validate checkpoint type, subtype, and name before operation-specific replay handling
  • fail mismatches with NonDeterministicExecutionError instead of consuming another operation's checkpoint
  • cover type, subtype, and name drift through unit and end-to-end regression tests

Testing

  • 1,587 core non-e2e tests passed
  • 46 core e2e tests passed
  • hatch run dev-core:typecheck
  • hatch fmt --check

Closes #692

@zhongkechen
zhongkechen temporarily deployed to ai-pr-review-runtime August 31, 2026 18:58 — with GitHub Actions Inactive
@zhongkechen
zhongkechen had a problem deploying to ai-pr-review-runtime August 31, 2026 19:11 — with GitHub Actions Failure
@zhongkechen
zhongkechen had a problem deploying to ai-pr-review-runtime August 31, 2026 19:11 — with GitHub Actions Failure
@zhongkechen
zhongkechen had a problem deploying to ai-pr-review-runtime August 31, 2026 19:31 — with GitHub Actions Failure
@zhongkechen
zhongkechen temporarily deployed to ai-pr-review-runtime August 31, 2026 19:31 — with GitHub Actions Inactive
@github-actions

This comment has been minimized.

@zhongkechen
zhongkechen had a problem deploying to ai-pr-review-runtime August 31, 2026 22:50 — with GitHub Actions Failure
@zhongkechen
zhongkechen temporarily deployed to ai-pr-review-runtime August 31, 2026 22:50 — with GitHub Actions Inactive
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

) -> Iterator[OperationIdentifier]:
"""Allocate an operation and validate its replay identity before hooks."""
operation_identifier = OperationIdentifier(
operation_id=self._peek_next_operation_id(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Codex AI review · Finding arf_v1_o3j43byu5wye3ohznhuk67z3bs

[P1] Allocate the operation ID atomically

_peek_next_operation_id() and _create_step_id() lock the counter separately. Two threads sharing a DurableContext can therefore both construct identifiers for step N; the second thread increments to N+1 but still checkpoints operation N, causing duplicate IDs and cross-operation checkpoint consumption. Atomically reserve the ID first, then make _replay_aware inspect that allocated ID. Add a barrier-based shared-context test.

checkpointed_result: CheckpointedResult = self.state.get_checkpoint_result(
self.operation_identifier.operation_id
)
checkpointed_result = self._get_checkpoint_result()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Codex AI review · Finding arf_v1_qvxigbpmdlmtzxjwsutttqe7or

[P1] Reject container checkpoints for virtual children

Virtualness is not part of OperationIdentifier. If a previously non-virtual run_in_child_context changes to ChildConfig(is_virtual=True), its existing successful CONTEXT checkpoint passes this validation and the method returns the cached result without executing the now-virtual body, so the changed inner hierarchy is never validated. When self.is_virtual, reject any existing container checkpoint before terminal handling, and add a non-virtual-to-virtual replay test.

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Codex AI review

Two replay-safety issues remain: shared contexts can allocate duplicate operation IDs, and virtual child contexts can consume checkpoints from non-virtual history.

Reviewed commit a2233e9a9a3d88aedb29fe9b7dcc775f3b056252. Workflow run

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.

[Bug]: Replay mismatch silently consumes a checkpoint from a different operation

1 participant