You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2026/08/04 18:47:50 UTC
(causeway) 19/22: CAUSEWAY-3910: plan command replay mapping reconciliation
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/causeway.git
commit b9412ee98a7d8fe85de8a5a87a3421e23566fe95
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Tue Aug 4 17:32:19 2026 +0100
CAUSEWAY-3910: plan command replay mapping reconciliation
---
.../.openspec.yaml | 2 +
.../reconcile-command-replay-mapping/design.md | 109 +++++++++++
.../reconcile-command-replay-mapping/proposal.md | 31 ++++
.../specs/command-execution-advisor-policy/spec.md | 99 ++++++++++
.../specs/command-replay-mapping/spec.md | 202 +++++++++++++++++++++
.../reconcile-command-replay-mapping/tasks.md | 42 +++++
6 files changed, 485 insertions(+)
diff --git a/openspec/changes/reconcile-command-replay-mapping/.openspec.yaml b/openspec/changes/reconcile-command-replay-mapping/.openspec.yaml
new file mode 100644
index 00000000000..1b062d3a7c7
--- /dev/null
+++ b/openspec/changes/reconcile-command-replay-mapping/.openspec.yaml
@@ -0,0 +1,2 @@
+schema: spec-driven
+created: 2026-08-04
diff --git a/openspec/changes/reconcile-command-replay-mapping/design.md b/openspec/changes/reconcile-command-replay-mapping/design.md
new file mode 100644
index 00000000000..f8eb4f0c64b
--- /dev/null
+++ b/openspec/changes/reconcile-command-replay-mapping/design.md
@@ -0,0 +1,109 @@
+## Context
+
+This change is the fifth dependency-ordered reconciliation slice and covers D2, M1, and M2 from `openspec/reconciliation/maintenance-branch/dependency-graph.md`.
+Causeway 4 already executes imported `CommandDto` instances through the record-based `CommandExecutorServiceDefault`, and commandlog already wraps persisted entries as `ReplayableCommand` view models.
+D1 supplies structurally independent command DTO copying and portable recorded result bookmarks.
+The remaining gap is an execution policy for interaction advisors and a commandlog-owned mechanism that remaps recorded bookmarks without making core runtime services depend on the commandlog extension.
+
+Maintenance behavior is authoritative for advisor policy, target/reference remapping, result observation, conflict handling, and conditional defaults.
+The implementation must adapt mutable configuration to Causeway 4 records, Jakarta APIs, Spring Boot 4 conditional wiring, and the current `ReplayContext`/`ReplayableCommand` transaction flow.
+
+## Goals / Non-Goals
+
+**Goals:**
+
+- Add D2 interaction-advisor policy to command DTO execution for actions and properties.
+- Add M1 bookmark-only replay mapping SPI, replay input copying/remapping, result notification, and imported-entry preservation.
+- Add M2 in-memory mapping with deterministic conflict handling and conditional default wiring.
+- Preserve compatibility when no custom listener or configuration is supplied.
+- Reuse D1 command copying and existing replay transaction boundaries.
+
+**Non-Goals:**
+
+- Persistent mapping entities, repositories, JPA/JDO adapters, or mapping menu actions from M3.
+- Rich `ReplayableCommand` participants, mapping inspection, result-presence policy, or adjacent navigation from P1.
+- Unified manager, reference-data, reachability, export remapping/validation, workflow, or background-gate behavior from P2, R1/R2, E1/W1, or B1/B2.
+- Changing plain or result-bearing command YAML formats.
+- Changing which command log entries are eligible for replay.
+
+## Decisions
+
+### Use immutable nested configuration records
+
+Add `CommandExecutorService` beneath `CausewayConfiguration.Core.RuntimeServices` with `interactionAdvisorPolicy` defaulting to `NO_CHECK`.
+The policy values are `CHECK`, `CHECK_BUT_IGNORE`, and `NO_CHECK`, matching maintenance semantics while retaining the Causeway 4 record construction model.
+
+Add `ReplayResultMapping` beneath `CausewayConfiguration.Extensions.CommandLog` with `storageStrategy` defaulting to `IN_MEMORY` and `onConflictPolicy` defaulting to `THROW_EXCEPTION`.
+The `PERSISTENT` strategy value is declared now as the selection contract required by M2, but this change deliberately supplies no persistent implementation.
+
+An alternative was to place advisor policy in commandlog configuration.
+That was rejected because `CommandExecutorService` is a core service and the policy applies to every DTO-driven execution caller, not only commandlog replay.
+
+### Apply advisors inside the existing executor
+
+`CommandExecutorServiceDefault` consults configuration immediately before action execution or property mutation.
+For actions, `CHECK` evaluates visibility, usability, and the complete argument set in that order and raises the framework's standard hidden, disabled, or invalid exception with the corresponding interaction event.
+For properties, `CHECK` evaluates visibility, usability, and proposed-value validity in that order and raises the corresponding standard exception.
+`CHECK_BUT_IGNORE` invokes the same advisors in the same order but continues regardless of veto, preserving advisor side effects such as event-phase processing.
+`NO_CHECK` invokes no advisors and preserves current default behavior.
+
+An alternative was to enforce advisors in `ReplayableCommand`.
+That was rejected because it would make DTO execution semantics depend on the commandlog caller and would leave other `CommandExecutorService` clients inconsistent.
+
+### Keep replay mapping in commandlog applib
+
+Define public `CommandReplayMappingListener` in commandlog applib with default methods `lookup(Bookmark)` and `onReplayResult(Bookmark, Bookmark, UUID)`.
+The SPI exchanges bookmark values only and never requires recorded identities to resolve to local objects.
+Passing the interaction id rather than `CommandLogEntry` avoids exposing commandlog persistence state through the SPI and follows the current maintenance contract.
+
+A commandlog `ResultRemappingService` owns an ordered list of listeners.
+Lookup checks listeners in injection order and uses the first non-empty replacement; a lookup exception is logged and lookup continues.
+Result notification is sent to every listener, and notification exceptions are deliberately not swallowed.
+
+An alternative was a core runtime mapping SPI.
+That was rejected because remapping is replay policy, while the core executor should remain unaware of commandlog import and result-observation semantics.
+
+### Remap an independent execution DTO
+
+Before each replay or retry, `ResultRemappingService` calls `CommandDtoUtils.copy(...)` and mutates only that execution copy.
+It applies the common lookup flow to each target bookmark and to action parameters whose schema value type is `REFERENCE` and whose reference OID is populated.
+Non-reference parameters and property values are unchanged.
+Every retry begins again from `CommandLogEntry.getCommandDto()` so a prior replacement or failed execution cannot become recorded input.
+
+An alternative was to remap managed objects after unmarshalling.
+That was rejected because an unresolved recorded bookmark must still be replaceable before local object resolution.
+
+### Preserve imported command-log facts during replay lifecycle synchronization
+
+`CommandLogEntry.sync(...)` continues to update execution timing while replay is enabled for the entry, but it does not overwrite imported command DTO, target, member, result, exception, username, or original timestamp.
+This prevents the normal command publisher callbacks from replacing recorded audit facts with the remapped execution DTO.
+Normal foreground and background command synchronization remains unchanged.
+
+### Observe successful results inside the replay transaction
+
+`ReplayableCommand` remaps the DTO immediately before execution.
+Within the existing `REQUIRES_NEW` replay transaction, it executes the copied DTO, obtains the actual bookmark, clears successful analysis, and notifies mappings when the imported entry has a recorded result and execution produced an actual result.
+Equal bookmarks are notified because identity mappings are meaningful lookup facts.
+Missing recorded or actual results and failed replay produce no notification.
+Listener failure propagates through the transaction, causing replay failure and rollback before the existing failure-analysis path runs.
+
+An alternative was to notify in the separate post-execution state-update transaction.
+That was rejected because maintenance requires mapping acceptance to be atomic with replayed domain changes.
+
+### Provide one conditional in-memory default
+
+`CommandReplayMappingListenerInMemory` stores the first mapping for each recorded bookmark, including identity mappings and the originating interaction id.
+Repeating the same mapping is idempotent and retains the first interaction id.
+A conflicting actual bookmark never replaces the first mapping: `THROW_EXCEPTION` rejects it, while `LOG_AND_CONTINUE` records an error and continues.
+
+Spring Boot 4 configuration creates this listener only when storage is `IN_MEMORY` and no application-defined `CommandReplayMappingListener` bean exists.
+Any custom listener causes the built-in listener to back off; selecting `PERSISTENT` also creates no in-memory listener.
+
+## Risks / Trade-offs
+
+- [Advisor checks can make previously executable DTOs fail when `CHECK` is selected] → Keep `NO_CHECK` as the compatibility default and document each policy.
+- [Advisor callbacks can have side effects even when vetoes are ignored] → Make `CHECK_BUT_IGNORE` explicit and test invocation order separately from enforcement.
+- [Multiple custom listeners can disagree] → Use deterministic first-replacement lookup order and notify all observers.
+- [A remapped DTO can be written back by normal command lifecycle callbacks] → Preserve imported fields in replay-enabled `CommandLogEntry.sync(...)` and test started/completed synchronization.
+- [Result-listener failures roll back otherwise successful domain work] → Treat this as required consistency behavior and cover it with transaction-oriented replay tests.
+- [The `PERSISTENT` selector has no implementation in this slice] → Document that selection suppresses the in-memory default and deliver persistence in the immediately following M3 change.
diff --git a/openspec/changes/reconcile-command-replay-mapping/proposal.md b/openspec/changes/reconcile-command-replay-mapping/proposal.md
new file mode 100644
index 00000000000..2d8da56042a
--- /dev/null
+++ b/openspec/changes/reconcile-command-replay-mapping/proposal.md
@@ -0,0 +1,31 @@
+## Why
+
+Causeway 4 can replay imported command DTOs, but it cannot apply interaction-advisor policy during executor-driven invocation or carry bookmark identity changes from one replayed result into later replay inputs.
+Now that recording, result metadata, safe-action publishing, and synthetic navigation are reconciled, D2, M1, and M2 are the next dependency-ordered foundation for reliable replay.
+
+## What Changes
+
+- Add immutable command-executor configuration selecting whether action and property visibility, usability, and validity advisors are enforced, invoked but ignored, or skipped during DTO execution.
+- Add a commandlog replay-mapping SPI that looks up replacement bookmarks for replay targets and reference-valued action parameters and observes recorded-to-actual result bookmarks after successful replay.
+- Remap a deep copy of each recorded command DTO so stored audit data, retries, and failures retain the imported target and parameter identities.
+- Notify replay-mapping listeners inside the replay transaction only when both recorded and actual result bookmarks exist, propagating notification failures to roll back replay.
+- Provide a conditionally configured in-memory listener with idempotent mapping, configurable conflict handling, and application-defined listener override.
+- Keep persistent mappings, replayable-command participant UI, export remapping, unified manager behavior, reference data, reachability validation, workflows, and background gates outside this change.
+
+## Capabilities
+
+### New Capabilities
+
+- `command-execution-advisor-policy`: Configurable interaction-advisor behavior for action and property execution through `CommandExecutorService`.
+- `command-replay-mapping`: Replay-time target and reference-parameter remapping, result observation, and the conditional in-memory mapping listener.
+
+### Modified Capabilities
+
+None.
+
+## Impact
+
+- `core/config`: immutable command-executor and commandlog replay-mapping configuration plus generated configuration documentation.
+- `core/runtimeservices`: action/property advisor checks in `CommandExecutorServiceDefault` with focused executor tests.
+- `extensions/core/commandlog/applib`: public replay-mapping SPI, replay DTO remapping service, replay lifecycle integration, in-memory listener, Spring Boot 4 conditional wiring, and tests.
+- Existing D1 command DTO deep copying and bookmark metadata are reused; existing C2/C3/C4 replay inputs and results gain mapping behavior without changing their publication or result formats.
diff --git a/openspec/changes/reconcile-command-replay-mapping/specs/command-execution-advisor-policy/spec.md b/openspec/changes/reconcile-command-replay-mapping/specs/command-execution-advisor-policy/spec.md
new file mode 100644
index 00000000000..5c918bec4e5
--- /dev/null
+++ b/openspec/changes/reconcile-command-replay-mapping/specs/command-execution-advisor-policy/spec.md
@@ -0,0 +1,99 @@
+## ADDED Requirements
+
+### Requirement: Command execution advisor policy is configurable
+The system SHALL provide `causeway.core.runtime-services.command-executor-service.interaction-advisor-policy` with values `CHECK`, `CHECK_BUT_IGNORE`, and `NO_CHECK`.
+The system SHALL default the policy to `NO_CHECK` so existing command DTO execution remains compatible when the property is not configured.
+The policy SHALL apply to action invocation and property modification performed by `CommandExecutorService`.
+
+#### Scenario: Default execution skips advisor enforcement
+- **WHEN** no command-executor interaction-advisor policy is configured
+- **THEN** command DTO execution uses `NO_CHECK`
+
+#### Scenario: Check policy is configured
+- **WHEN** the interaction-advisor policy is configured as `CHECK`
+- **THEN** command DTO execution enforces action and property interaction advisors
+
+### Requirement: Check policy enforces action advisors
+When the policy is `CHECK`, action command execution SHALL evaluate visibility, usability, and complete argument-set validity in that order before invocation.
+A visibility veto SHALL prevent invocation and raise the framework's standard hidden exception with the action visibility interaction event.
+A usability veto SHALL prevent invocation and raise the framework's standard disabled exception with the action usability interaction event.
+An argument-set validity veto SHALL prevent invocation and raise the framework's standard invalid exception with the action invocation interaction event.
+The system MUST NOT evaluate later advisor phases after an earlier veto.
+
+#### Scenario: Hidden action is rejected
+- **GIVEN** command execution advisor policy is `CHECK`
+- **WHEN** an action visibility advisor vetoes replay execution
+- **THEN** the action is not invoked
+- **AND** command execution fails with the standard hidden exception
+
+#### Scenario: Disabled action is rejected
+- **GIVEN** command execution advisor policy is `CHECK`
+- **AND** action visibility permits execution
+- **WHEN** an action usability advisor vetoes replay execution
+- **THEN** the action is not invoked
+- **AND** command execution fails with the standard disabled exception
+
+#### Scenario: Invalid action arguments are rejected
+- **GIVEN** command execution advisor policy is `CHECK`
+- **AND** action visibility and usability permit execution
+- **WHEN** complete argument-set validation vetoes replay execution
+- **THEN** the action is not invoked
+- **AND** command execution fails with the standard invalid exception
+
+### Requirement: Check policy enforces property advisors
+When the policy is `CHECK`, property command execution SHALL evaluate visibility, usability, and proposed-value validity in that order before mutation.
+A visibility veto SHALL prevent mutation and raise the framework's standard hidden exception with the property visibility interaction event.
+A usability veto SHALL prevent mutation and raise the framework's standard disabled exception with the property usability interaction event.
+A proposed-value validity veto SHALL prevent mutation and raise the framework's standard invalid exception with the property modification interaction event.
+The system MUST NOT evaluate later advisor phases after an earlier veto.
+
+#### Scenario: Hidden property is rejected
+- **GIVEN** command execution advisor policy is `CHECK`
+- **WHEN** a property visibility advisor vetoes execution
+- **THEN** the property is not modified
+- **AND** command execution fails with the standard hidden exception
+
+#### Scenario: Disabled property is rejected
+- **GIVEN** command execution advisor policy is `CHECK`
+- **AND** property visibility permits execution
+- **WHEN** a property usability advisor vetoes execution
+- **THEN** the property is not modified
+- **AND** command execution fails with the standard disabled exception
+
+#### Scenario: Invalid property value is rejected
+- **GIVEN** command execution advisor policy is `CHECK`
+- **AND** property visibility and usability permit execution
+- **WHEN** proposed-value validation vetoes execution
+- **THEN** the property is not modified
+- **AND** command execution fails with the standard invalid exception
+
+### Requirement: Check-but-ignore policy invokes advisors without enforcing vetoes
+When the policy is `CHECK_BUT_IGNORE`, action command execution SHALL evaluate visibility, usability, and complete argument-set validity in that order and SHALL invoke the action regardless of veto.
+When the policy is `CHECK_BUT_IGNORE`, property command execution SHALL evaluate visibility, usability, and proposed-value validity in that order and SHALL modify the property regardless of veto.
+The system SHALL invoke all advisor phases under `CHECK_BUT_IGNORE`, including phases after a veto.
+
+#### Scenario: Action vetoes are observed and ignored
+- **GIVEN** command execution advisor policy is `CHECK_BUT_IGNORE`
+- **WHEN** action visibility, usability, or argument validation vetoes execution
+- **THEN** all three action advisor phases are invoked in order
+- **AND** the action is invoked
+
+#### Scenario: Property vetoes are observed and ignored
+- **GIVEN** command execution advisor policy is `CHECK_BUT_IGNORE`
+- **WHEN** property visibility, usability, or value validation vetoes execution
+- **THEN** all three property advisor phases are invoked in order
+- **AND** the property is modified
+
+### Requirement: No-check policy bypasses advisors
+When the policy is `NO_CHECK`, action command execution MUST NOT evaluate action visibility, usability, or argument validity before invocation.
+When the policy is `NO_CHECK`, property command execution MUST NOT evaluate property visibility, usability, or proposed-value validity before mutation.
+
+#### Scenario: Action executes without advisor calls
+- **GIVEN** command execution advisor policy is `NO_CHECK`
+- **WHEN** an action command DTO is executed
+- **THEN** the action is invoked without calling its interaction advisors
+
+#### Scenario: Property changes without advisor calls
+- **GIVEN** command execution advisor policy is `NO_CHECK`
+- **WHEN** a property command DTO is executed
+- **THEN** the property is modified without calling its interaction advisors
diff --git a/openspec/changes/reconcile-command-replay-mapping/specs/command-replay-mapping/spec.md b/openspec/changes/reconcile-command-replay-mapping/specs/command-replay-mapping/spec.md
new file mode 100644
index 00000000000..40d166a612a
--- /dev/null
+++ b/openspec/changes/reconcile-command-replay-mapping/specs/command-replay-mapping/spec.md
@@ -0,0 +1,202 @@
+## ADDED Requirements
+
+### Requirement: Replay mapping SPI uses portable bookmarks
+The system SHALL provide a `CommandReplayMappingListener` SPI with a common lookup operation for recorded target and reference-parameter bookmarks.
+The lookup operation SHALL return an optional replacement bookmark and MUST NOT require the recorded bookmark to resolve to a live domain object.
+The SPI SHALL provide a replay-result observation operation receiving the recorded result bookmark, actual replay result bookmark, and replayed command interaction id.
+Both SPI operations SHALL have default no-op behavior so applications can implement lookup, observation, or both.
+
+#### Scenario: Application supplies a target replacement
+- **WHEN** replay mapping lookup receives recorded bookmark `demoCustomer:1`
+- **AND** an application listener returns `demoCustomer:2`
+- **THEN** replay can use `demoCustomer:2` without first resolving `demoCustomer:1`
+
+#### Scenario: Listener implements result observation only
+- **WHEN** an application listener overrides replay-result observation but not lookup
+- **THEN** lookup returns no replacement
+- **AND** the listener remains a valid `CommandReplayMappingListener`
+
+### Requirement: Replay targets are remapped before execution
+Before command replay or retry, the system SHALL ask replay mapping listeners for a replacement for each recorded target bookmark.
+The system SHALL consult listeners in dependency-injection order and use the first non-empty replacement.
+When a listener throws during lookup, the system SHALL log the failure and continue with remaining listeners.
+When a replacement is found, replay SHALL execute against the replacement target bookmark.
+When no replacement is found, replay SHALL retain the recorded target bookmark.
+
+#### Scenario: Target bookmark is remapped
+- **WHEN** replay is about to execute a command whose recorded target is `demoCustomer:1`
+- **AND** mapping lookup returns `demoCustomer:2`
+- **THEN** replay executes the command against target `demoCustomer:2`
+
+#### Scenario: Target bookmark has no replacement
+- **WHEN** replay is about to execute a command whose recorded target is `demoCustomer:1`
+- **AND** every mapping listener returns no replacement
+- **THEN** replay executes the command against target `demoCustomer:1`
+
+#### Scenario: First listener failure does not prevent later lookup
+- **WHEN** the first mapping listener throws while looking up `demoCustomer:1`
+- **AND** a later mapping listener returns `demoCustomer:2`
+- **THEN** replay logs the first failure
+- **AND** replay executes the command against target `demoCustomer:2`
+
+### Requirement: Replay reference action parameters are remapped before execution
+Before command replay or retry, the system SHALL use the common lookup operation for each action parameter represented by schema value type `REFERENCE` with a populated reference OID.
+When a replacement is found, replay SHALL execute with the replacement parameter reference.
+When no replacement is found, replay SHALL retain the recorded parameter reference.
+The system MUST leave non-reference action parameters and property values unchanged by reference remapping.
+The lookup operation MUST NOT require parameter name or index metadata.
+
+#### Scenario: Reference parameter is remapped
+- **WHEN** action parameter `customer` records reference bookmark `demoCustomer:1`
+- **AND** mapping lookup returns `demoCustomer:2`
+- **THEN** replay executes with parameter `customer` referring to `demoCustomer:2`
+
+#### Scenario: Reference parameter has no replacement
+- **WHEN** action parameter `customer` records reference bookmark `demoCustomer:1`
+- **AND** mapping lookup returns no replacement
+- **THEN** replay executes with parameter `customer` referring to `demoCustomer:1`
+
+#### Scenario: Scalar selector parameter is unchanged
+- **WHEN** a replayed synthetic selector action has a non-reference string or boolean parameter
+- **THEN** reference remapping does not ask listeners to replace that parameter
+- **AND** replay retains the recorded scalar value
+
+### Requirement: Replay input remapping preserves recorded command data
+The system SHALL apply target and reference-parameter replacements to a structurally independent execution copy created from the imported command DTO.
+The imported command log entry SHALL retain its recorded command DTO, target, member, result, exception, username, and original timestamp.
+Started and completed lifecycle synchronization SHALL continue to update execution timing for replay-enabled entries without overwriting those recorded fields.
+Each replay or retry SHALL create a new execution copy from the imported command DTO and MUST NOT reuse a previously remapped execution copy.
+Replay failure MUST NOT leave replacements in the imported command DTO.
+
+#### Scenario: Remapped target preserves imported DTO
+- **WHEN** replay remaps recorded target `demoCustomer:1` to `demoCustomer:2`
+- **THEN** the execution DTO contains target `demoCustomer:2`
+- **AND** the imported command log entry still contains target `demoCustomer:1`
+
+#### Scenario: Remapped parameter preserves imported DTO
+- **WHEN** replay remaps reference parameter `customer` from `demoCustomer:1` to `demoCustomer:2`
+- **THEN** the execution DTO contains parameter reference `demoCustomer:2`
+- **AND** the imported command log entry still contains parameter reference `demoCustomer:1`
+
+#### Scenario: Retry starts from recorded identities
+- **GIVEN** an earlier replay remapped target or parameter bookmark `demoCustomer:1` to `demoCustomer:2`
+- **WHEN** the command is retried
+- **THEN** mapping lookup is evaluated again using recorded bookmark `demoCustomer:1`
+
+#### Scenario: Lifecycle synchronization preserves imported facts
+- **WHEN** normal command publishing callbacks synchronize a replay-enabled command log entry during execution
+- **THEN** execution timing is updated
+- **AND** imported command DTO, target, member, result, exception, username, and original timestamp remain unchanged
+
+### Requirement: Successful replay observes result mappings atomically
+After replay execution produces an actual bookmark, the system SHALL notify every replay mapping listener when the imported command log entry has a recorded result bookmark.
+The notification SHALL include recorded bookmark, actual bookmark, and command interaction id.
+The system SHALL notify identity mappings where recorded and actual bookmarks are equal.
+Notification SHALL occur inside the same transaction as replayed command execution.
+A notification exception SHALL fail replay and roll back the replay transaction.
+
+#### Scenario: Different result bookmark is observed
+- **WHEN** an imported command records result `demoInvoice:1`
+- **AND** successful replay produces actual result `demoInvoice:2`
+- **THEN** every mapping listener is notified with `demoInvoice:1`, `demoInvoice:2`, and the command interaction id
+
+#### Scenario: Identity result bookmark is observed
+- **WHEN** an imported command records result `demoInvoice:1`
+- **AND** successful replay produces actual result `demoInvoice:1`
+- **THEN** every mapping listener is notified with the identity mapping
+
+#### Scenario: Listener rejects a result mapping
+- **WHEN** replayed domain work succeeds
+- **AND** a mapping listener throws while observing its result
+- **THEN** replay fails
+- **AND** the replay transaction rolls back
+
+### Requirement: Unavailable replay results are not observed
+The system MUST NOT notify replay mapping listeners unless replay execution succeeds and both recorded and actual result bookmarks are available.
+Replay input lookup MAY still occur when result observation data is unavailable.
+
+#### Scenario: Replay fails
+- **WHEN** command execution fails for an imported entry with a recorded result bookmark
+- **THEN** no listener receives a replay-result observation
+
+#### Scenario: Recorded result is absent
+- **WHEN** command execution succeeds but the imported entry has no recorded result bookmark
+- **THEN** no listener receives a replay-result observation
+
+#### Scenario: Actual result is absent
+- **WHEN** command execution succeeds without an actual result bookmark
+- **THEN** no listener receives a replay-result observation
+
+### Requirement: In-memory listener records deterministic mappings
+The system SHALL provide an in-memory `CommandReplayMappingListener` that stores the first actual bookmark observed for each recorded result bookmark.
+The listener SHALL store identity mappings and the originating command interaction id when available.
+Repeating the same recorded-to-actual mapping SHALL be idempotent and SHALL retain the original interaction id.
+A conflicting actual bookmark MUST NOT replace the stored bookmark or original interaction id.
+The default conflict policy SHALL throw an exception.
+The `LOG_AND_CONTINUE` conflict policy SHALL log the conflict without throwing.
+
+#### Scenario: Different mapping is recorded
+- **WHEN** the in-memory listener observes recorded result `demoInvoice:1` and actual result `demoInvoice:2`
+- **THEN** it stores `demoInvoice:1` to `demoInvoice:2`
+
+#### Scenario: Identity mapping is recorded
+- **WHEN** the in-memory listener observes recorded and actual result `demoInvoice:1`
+- **THEN** it stores `demoInvoice:1` to `demoInvoice:1`
+
+#### Scenario: Repeated mapping is idempotent
+- **GIVEN** the listener stored `demoInvoice:1` to `demoInvoice:2` with interaction id `11111111-1111-1111-1111-111111111111`
+- **WHEN** it observes the same mapping with a different interaction id
+- **THEN** the stored bookmark and original interaction id remain unchanged
+- **AND** no exception is thrown
+
+#### Scenario: Conflict is rejected by default
+- **GIVEN** the listener stored `demoInvoice:1` to `demoInvoice:2`
+- **WHEN** it observes `demoInvoice:1` mapping to `demoInvoice:3`
+- **THEN** it throws an exception
+- **AND** it retains `demoInvoice:2`
+
+#### Scenario: Conflict can be logged and ignored
+- **GIVEN** conflict policy is `LOG_AND_CONTINUE`
+- **AND** the listener stored `demoInvoice:1` to `demoInvoice:2`
+- **WHEN** it observes `demoInvoice:1` mapping to `demoInvoice:3`
+- **THEN** it logs the conflict without throwing
+- **AND** it retains `demoInvoice:2`
+
+### Requirement: In-memory mappings remap later replay inputs
+The in-memory listener SHALL return the stored actual bookmark when lookup receives a recorded bookmark with a mapping.
+When no mapping exists, the listener SHALL return no replacement.
+Mapping storage SHALL be scoped to the listener instance and SHALL NOT be required to survive application restart, application nodes, or bean recreation.
+
+#### Scenario: Later target uses earlier result mapping
+- **GIVEN** the listener stored `demoInvoice:1` to `demoInvoice:2`
+- **WHEN** a later replay target lookup receives `demoInvoice:1`
+- **THEN** lookup returns `demoInvoice:2`
+
+#### Scenario: Unmapped bookmark is retained
+- **WHEN** lookup receives `demoInvoice:9` with no stored mapping
+- **THEN** the listener returns no replacement
+
+#### Scenario: New listener has fresh state
+- **GIVEN** one in-memory listener stored a replay mapping
+- **WHEN** a new in-memory listener instance is created
+- **THEN** the new instance is not required to contain that mapping
+
+### Requirement: Built-in listener configuration is conditional
+The system SHALL provide `causeway.extensions.command-log.replay-result-mapping.storage-strategy` with values `IN_MEMORY` and `PERSISTENT`, defaulting to `IN_MEMORY`.
+The system SHALL provide `causeway.extensions.command-log.replay-result-mapping.on-conflict-policy` with values `THROW_EXCEPTION` and `LOG_AND_CONTINUE`, defaulting to `THROW_EXCEPTION`.
+When storage strategy is `IN_MEMORY` and no application-defined `CommandReplayMappingListener` bean exists, commandlog autoconfiguration SHALL provide the configured in-memory listener.
+When any application-defined listener bean exists, the in-memory default MUST back off.
+When storage strategy is `PERSISTENT`, this change MUST NOT create the in-memory listener.
+
+#### Scenario: In-memory listener is the default
+- **WHEN** no storage strategy and no custom listener are configured
+- **THEN** commandlog autoconfiguration provides one in-memory listener using `THROW_EXCEPTION`
+
+#### Scenario: Custom listener replaces the default
+- **WHEN** the application defines a `CommandReplayMappingListener` bean
+- **THEN** commandlog autoconfiguration does not provide the in-memory listener
+
+#### Scenario: Persistent selection suppresses in-memory listener
+- **WHEN** storage strategy is `PERSISTENT`
+- **THEN** commandlog autoconfiguration does not provide the in-memory listener
+- **AND** this change does not provide persistent mapping storage
diff --git a/openspec/changes/reconcile-command-replay-mapping/tasks.md b/openspec/changes/reconcile-command-replay-mapping/tasks.md
new file mode 100644
index 00000000000..444aae52629
--- /dev/null
+++ b/openspec/changes/reconcile-command-replay-mapping/tasks.md
@@ -0,0 +1,42 @@
+## 1. Immutable configuration
+
+- [ ] 1.1 Add the Causeway 4 `CommandExecutorService` configuration record and `InteractionAdvisorPolicy` values under core runtime services with `NO_CHECK` as the compatibility default.
+- [ ] 1.2 Add commandlog replay-result-mapping storage strategy and conflict policy records with `IN_MEMORY` and `THROW_EXCEPTION` defaults while reserving `PERSISTENT` for M3.
+- [ ] 1.3 Add configuration binding/default tests and regenerate or update the core configuration reference documentation.
+
+## 2. Command execution advisor policy
+
+- [ ] 2.1 Apply `CHECK` action visibility, usability, and complete argument-set validation in order within `CommandExecutorServiceDefault`, raising the standard interaction exceptions and events.
+- [ ] 2.2 Apply `CHECK` property visibility, usability, and proposed-value validation in order within `CommandExecutorServiceDefault`, raising the standard interaction exceptions and events.
+- [ ] 2.3 Implement `CHECK_BUT_IGNORE` for actions and properties so every advisor phase runs in order while vetoes do not prevent execution.
+- [ ] 2.4 Preserve `NO_CHECK` behavior without advisor calls and add focused executor tests for defaults, phase ordering, veto short-circuiting, ignored vetoes, invocation, and mutation.
+
+## 3. Replay mapping SPI and input remapping
+
+- [ ] 3.1 Add the public bookmark-only `CommandReplayMappingListener` SPI with default lookup and result-observation methods, including command interaction id on observations.
+- [ ] 3.2 Add `ResultRemappingService` with deterministic listener ordering, first non-empty lookup, logged lookup failures, and unsuppressed result-observation failures.
+- [ ] 3.3 Deep-copy recorded command DTOs through `CommandDtoUtils.copy(...)` and remap every command target without resolving the recorded bookmark.
+- [ ] 3.4 Remap only populated `REFERENCE` action parameters through the common lookup flow while preserving scalar parameters, property values, and unmapped references.
+- [ ] 3.5 Add focused remapping tests for no listeners, unmapped and mapped targets, unresolved bookmarks, listener ordering/failure, reference parameters, and non-reference values.
+
+## 4. Replay lifecycle integration
+
+- [ ] 4.1 Wire replay mapping into the current `ReplayContext` and create a fresh remapped execution DTO from the imported command log entry for every replay or retry.
+- [ ] 4.2 Adapt replay-enabled `CommandLogEntry.sync(...)` behavior so lifecycle callbacks update execution timing without overwriting imported command DTO, target, member, result, exception, username, or original timestamp.
+- [ ] 4.3 Notify all mapping listeners inside the replay transaction after successful execution when recorded and actual result bookmarks exist, including identity mappings and interaction id.
+- [ ] 4.4 Propagate result-observation failures so replay rolls back and follows the existing failure-analysis path, while failed or incomplete-result replay produces no observation.
+- [ ] 4.5 Add replay integration tests for DTO preservation across success, failure, and retry; timing synchronization; result notification conditions; transaction failure; and later target/reference remapping from earlier results.
+
+## 5. Conditional in-memory listener
+
+- [ ] 5.1 Implement instance-scoped in-memory storage for identity and changed mappings, retaining the first actual bookmark and originating interaction id.
+- [ ] 5.2 Implement idempotent repeat handling plus `THROW_EXCEPTION` and `LOG_AND_CONTINUE` conflict behavior without replacing the original mapping.
+- [ ] 5.3 Add Spring Boot 4 conditional wiring that supplies the configured in-memory listener only for `IN_MEMORY` when no application listener exists and supplies none for `PERSISTENT`.
+- [ ] 5.4 Add listener and application-context tests for lookup, identity mappings, interaction-id retention, repeat/conflict handling, custom-listener backoff, defaults, and persistent-strategy suppression.
+
+## 6. Compatibility, documentation, and verification
+
+- [ ] 6.1 Document command-executor advisor policies, replay mapping SPI behavior, in-memory defaults, conflict policy, custom-listener override, and the deferred persistent strategy.
+- [ ] 6.2 Verify synthetic selector scalar parameters remain unchanged, synthetic/reference results use normal D1/C4a metadata, and existing C1/C2/C3/C4b suppression and publication paths remain intact.
+- [ ] 6.3 Run focused core configuration, runtime-service, commandlog remapping, replay, and listener tests with JDK 21.
+- [ ] 6.4 Run the affected aggregate Maven build, IDE compilation and inspections, strict OpenSpec validation, repository checks, and a scope guard confirming no M3, P1/P2, R1/R2, E1/W1, or B1/B2 implementation is introduced.