fix(EVO-1840): Set Variable node honors Increase/Decrease at runtime - #109
Merged
Conversation
The Set Variable config UI offers numeric Increase/Decrease (preview shows +40), but the runtime never read `operation` — SetVariableNodeInput.nodeData didn't even declare it — so every op was a plain SET and "increase lead_score by 40" never accumulated (silent-success family, EVO-1740/EVO-1757). - Declare operation/value/category on nodeData (removes the `as any` casts). - Add loadSessionVariables() (mirrors conditional.node.ts / EVO-1913) to read the current value. - For increase/decrease: base = Number(prior) (unset/non-numeric prior -> 0), delta = Number(value); write base +/- delta as a number (so downstream numeric comparisons keep working). A non-numeric amount throws -> visible failure (success:false) instead of a silent no-op (AC #3). Plain SET and all other ops are unchanged. Scope: increase/decrease only. - New set-variable.node.spec.ts (jest): increase from numeric/unset/non-numeric prior, decrease, plain set unchanged + doesn't read session, default set, non-numeric amount fails visibly. 7 tests pass; tsc clean.
Reviewer's GuideSetVariableNode now honors the Increase/Decrease operations at runtime by reading the current session variable value, performing numeric arithmetic, and failing visibly on invalid amounts, while preserving existing SET behavior and adding unit tests to lock the new semantics. Sequence diagram for SetVariableNode increase/decrease behaviorsequenceDiagram
participant Workflow
participant SetVariableNode
participant Database
participant JourneySessionRepository
Workflow->>SetVariableNode: execute(input)
SetVariableNode->>SetVariableNode: extract cleanName, value, operation
alt operation is increase or decrease
SetVariableNode->>SetVariableNode: loadSessionVariables(sessionId)
SetVariableNode->>Database: initializeDatabase()
Database-->>SetVariableNode: dataSource
SetVariableNode->>JourneySessionRepository: findOne({ id: sessionId })
JourneySessionRepository-->>SetVariableNode: session
SetVariableNode->>SetVariableNode: compute delta = Number(value)
SetVariableNode->>SetVariableNode: [delta not finite] throw Error
SetVariableNode->>SetVariableNode: compute base from session.variables[cleanName]
SetVariableNode->>SetVariableNode: variablesToSet[cleanName] = base ± delta
else operation is set or other
SetVariableNode->>SetVariableNode: variablesToSet[cleanName] = value
end
SetVariableNode-->>Workflow: { success, variables }
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new
loadSessionVariablesimplementation mirrors the logic inconditional.node.ts; consider extracting this into a shared helper/service to avoid duplication and keep behavior aligned across nodes. - For the
operationfield you now accept a fixed set of string literals; consider centralizing these into a shared enum/type used by both the UI and runtime to reduce the risk of them getting out of sync.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `loadSessionVariables` implementation mirrors the logic in `conditional.node.ts`; consider extracting this into a shared helper/service to avoid duplication and keep behavior aligned across nodes.
- For the `operation` field you now accept a fixed set of string literals; consider centralizing these into a shared enum/type used by both the UI and runtime to reduce the risk of them getting out of sync.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…riting a wrong number
Code review follow-up on the increase/decrease fix. The arithmetic worked, but
every way it could NOT be honored still wrote a wrong value and reported
success — the same silent-success class the card set out to close (EVO-1740).
- Failed/missing session read no longer degrades to {}. Rebasing to 0 on an
unreadable prior silently turned lead_score 500 into 40 with success:true.
The read moves to BaseNode.readSessionVariables() (it was duplicated verbatim
here and in conditional.node.ts) and throws; conditional keeps its local
degrade-to-{} policy, set-variable lets it propagate.
- Empty/null amount no longer counts as 0. Number('') and Number(null) are 0,
so an empty Amount was a silent "increase by 0" — while the panel renders 1
as the placeholder in that state.
- A {{variable}} amount is resolved against the session before parsing. The
panel's Amount field has a variable picker and the executor passes nodeData
raw, so {{bonus}} arrived literal and aborted the whole journey.
- A non-numeric CURRENT value now fails instead of being clobbered to the delta
(AC#3); genuinely unset/null/'' still starts at 0.
- The array input shape honors operation too — it kept degrading increase to a
plain SET, the exact bug being fixed, on the other half of the contract.
- The error path reports a duration instead of Date.now() (an epoch timestamp
was flowing into logNodeExecution/trackNodeExecution as the node's duration).
Tests: 17 in set-variable.node.spec.ts (was 7), covering accumulation across
runs, {{var}} amounts, the array shape, and each visible-failure case.
tsc clean; conditional/base specs unaffected (47 pass).
…tive Comments only, no behavior change. Each one kept the non-obvious decision and dropped the before/after story, which belongs in the PR, not the source.
gomessguii
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
EVO-1840 — Set Variable node honra Increase/Decrease no runtime
Root cause
A config UI do Set Variable oferece operações numéricas Increase/Decrease (o preview mostra
+40), mas o runtime nunca lia o campooperation— oSetVariableNodeInput.nodeDatasequer o declarava. Resultado: toda operação virava um SET plano e "increase lead_score by 40" nunca acumulava. Mesma família silent-success do EVO-1740/EVO-1757 (a UI promete algo que o runtime dropa).Correção (
src/modules/temporal/activities/nodes/set-variable.node.ts)operation/value/categorynonodeData(remove os castsas any).loadSessionVariables()(espelhaconditional.node.ts/ EVO-1913) para ler o valor atual.increase/decrease:base = Number(prior)(prior unset/não-numérico → 0),delta = Number(value); escrevebase ± deltacomo número (comparações numéricas a jusante seguem funcionando). Amount não-numérico → lança → falha visível (success:false), não no-op silencioso (AC feat(events): freeze EVENT_NAMES with @IsIn on track + identify DTOs #3). Plain SET e demais ops inalterados.Testes (
set-variable.node.spec.ts, novo — jest)increase de prior numérico (10+40→50) · de unset (→40) · de prior não-numérico (→40) · decrease (100-30→70) · plain SET inalterado + não lê a sessão · SET default · amount não-numérico falha visível. 7 tests pass ·
tsc --noEmitlimpo.Relacionado
Família silent-success: EVO-1740 / EVO-1757.
Summary by Sourcery
Honor the Set Variable node’s Increase/Decrease operations at runtime by reading the current session value and applying numeric arithmetic instead of always performing a plain SET.
New Features:
Bug Fixes:
Enhancements:
Tests: