The effect is computed once in closeLastFrame; the same number is stored in the EM frame and in the automatism’s Usefulness update — without recalculations and mismatches.
effect = clamp(Δdiff)
addUsefulnessSample(id, effect)
If feedbackAutomatizmId is set on the frame (waiting after an automatism), the sample goes into it; otherwise it goes into Automatizms_getDefaultAutomatizmForBranch(perceptionNodeId).
EpisodicMemory_setLastFrameActionFromActionId registers OD in the frame and calls Automatizms_createAutomatizm(branchId, actionsImageId). The record is unique by the pair (branch, OD). The first automatism on a branch is set as default (setDefaultAutomatizm).
startAction → the frame stores the reaction (OD) → an automatism is created with zero usefulness and count = 0 until the first close.effect from the EM frame is averaged into usefulness — this is the “first” numeric estimate of utility for the (branch + action) pair.