Command context semantics ========================= The command context stores the runtime semantics of an accepted command. The command semantics describe how a command must be interpreted by the observation supervision layer. They are created when the command context is created and remain associated with that command for the whole command lifecycle. For observation-mode-dependent commands, such as ``Configure`` and ``Scan``, the configured observation mode contributes to the command interpretation, but it is not the only input. The final semantics are resolved from the accepted command, the planned devices, the configured observation mode, and the command-specific policy rules, including thresholds when required. This allows the observation supervisor and the consistency policies to evaluate observation state transitions using the same interpretation that was used when the command was accepted. Purpose ------- The observation state of the CSP.LMC Subarray is mainly derived from the observation state of the controlled devices. However, during command execution, device states can temporarily diverge. Some devices may already have reached the expected state, while others may still be transitioning or may have failed. The command context provides the additional runtime semantics required to decide whether such a state distribution is consistent with the command that is being executed. The same observed device state distribution can have different meanings depending on: * the command being executed; * the configured observation mode; * the controlled systems required by that observation mode; * the role of each controlled system in the observation; * the devices that are expected to participate in the command; * the threshold that defines how many or which systems must satisfy the expected condition, when threshold-based evaluation is required. For this reason, the command context must not be treated as a simple cache. It is part of the runtime contract between command execution and observation supervision. Observation mode based semantics -------------------------------- The configured observation mode is used to derive the command semantics when the command context is created. The observation mode identifies the controlled systems that are relevant for the current observation and assigns a role to each of them. These roles define how each system contributes to the interpretation of a command and to the resulting observation state consistency decision. A controlled system can be: * a primary system; * a commensal system; * not required by the current observation mode. A primary system is part of the main observation path. Its state contributes directly to the interpretation of the command and to the CSP.LMC Subarray observation state consistency. If a primary system is expected to participate in a command, its state is normally required to satisfy the expected command condition. A commensal system participates in the same observation together with the primary systems, but it does not define the main observation path on its own. Its state can still be relevant to consistency evaluation, depending on the command and on the configured observation mode. For example, a commensal system may be expected to follow a scan lifecycle without being the system that primarily defines the scan. A system that is not required by the current observation mode is not part of the command semantics for that observation. Its state must not drive the command consistency decision for the accepted command. The command semantics therefore capture: * which controlled systems are required by the configured observation mode; * which systems are primary; * which systems are commensal; * which systems are not relevant for the accepted command; * how the command should be evaluated against those systems. This distinction is important because the same command can affect different systems depending on the configured observation mode. Threshold based evaluation -------------------------- Some consistency decisions do not require every controlled system to satisfy the same condition. In these cases, the command semantics can also include the threshold to be applied by the consistency policy. A threshold defines the minimum condition that must be satisfied for the command or observation state to be considered consistent. Depending on the policy, this can represent, for example: * all required systems must satisfy the expected state; * all primary systems must satisfy the expected state; * a minimum number of required systems must satisfy the expected state; * a minimum number of primary systems must satisfy the expected state; * commensal systems may be evaluated separately from primary systems. The threshold is part of the command semantics because it gives meaning to the observed device state distribution. A distribution that is inconsistent for one observation mode can be valid for another if the configured mode requires a different set of systems or a different threshold. The consistency policy must therefore evaluate the current device states using the threshold stored in, or derived together with, the command context semantics, rather than applying a generic rule that is independent of the accepted command. Creation time ------------- Command semantics are created when the command context is created. This means that the interpretation of the command is fixed at command acceptance time. The observation supervisor and the consistency policies do not need to rebuild the meaning of the command from the current observation mode at every state evaluation. Instead, they use the semantics stored in the command context. The creation flow can be summarised as follows:: Command accepted -> current observation mode read CommandContext created -> command semantics derived from the observation mode -> required controlled systems identified -> system roles assigned -> threshold selected when required Observation state evaluated -> supervisor uses the active command context -> consistency policies use the stored command semantics -> threshold applied when required This ensures that the command is evaluated consistently with the observation mode that was active when the command was accepted.