Skip to content

fix(EVO-1840): Set Variable node honors Increase/Decrease at runtime - #109

Merged
gomessguii merged 3 commits into
developfrom
fix/EVO-1840-set-variable-increment
Jul 24, 2026
Merged

fix(EVO-1840): Set Variable node honors Increase/Decrease at runtime#109
gomessguii merged 3 commits into
developfrom
fix/EVO-1840-set-variable-increment

Conversation

@pastoriniMatheus

@pastoriniMatheus pastoriniMatheus commented Jul 23, 2026

Copy link
Copy Markdown

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 campo operation — o SetVariableNodeInput.nodeData sequer 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)

  • Declara operation/value/category no nodeData (remove os casts as any).
  • Novo loadSessionVariables() (espelha conditional.node.ts / EVO-1913) para ler o valor atual.
  • increase/decrease: base = Number(prior) (prior unset/não-numérico → 0), delta = Number(value); escreve base ± delta como 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.
  • Escopo: só increase/decrease (as demais — clear/now/etc — ficam de fora, mesma família, follow-up).

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 --noEmit limpo.

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:

  • Support numeric increase/decrease operations for single-variable updates based on the current session value, defaulting to 0 when the prior value is unset or non-numeric.

Bug Fixes:

  • Ensure non-numeric amounts for increase/decrease cause a visible failure instead of silently no-oping.
  • Align the runtime with the Set Variable UI by declaring and consuming the operation/value/category nodeData fields so configured operations are no longer dropped.

Enhancements:

  • Add a helper to load session variables for the Set Variable node, mirroring the approach used in the conditional node and logging errors when loading fails.

Tests:

  • Add unit tests for Set Variable increase/decrease behavior, default SET behavior, avoidance of unnecessary session reads, and visible failure on non-numeric amounts.

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.
@sourcery-ai

sourcery-ai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Reviewer's Guide

SetVariableNode 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 behavior

sequenceDiagram
  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 }
Loading

File-Level Changes

Change Details Files
Support numeric increase/decrease operations in SetVariableNode using existing session values and explicit nodeData typing.
  • Add typed operation/value/category fields to nodeData instead of relying on casts.
  • Default operation to set and branch logic for increase/decrease vs other operations.
  • Implement numeric arithmetic for increase/decrease based on current session variable value, treating missing or non-numeric prior values as 0.
  • Throw an error when the amount is non-numeric to surface visible failures instead of silent no-ops.
  • Adjust logging to include the resolved operation and final value being set.
src/modules/temporal/activities/nodes/set-variable.node.ts
Introduce helper to load session variables for arithmetic operations with robust error handling.
  • Add private loadSessionVariables(sessionId) that initializes the database, loads JourneySession, and returns its variables.
  • Mirror conditional.node.ts behavior by degrading to an empty object on error but logging at error level with context.
src/modules/temporal/activities/nodes/set-variable.node.ts
Add Jest unit tests to lock SetVariableNode arithmetic behavior and default SET semantics.
  • Create tests for increase over numeric prior, unset prior, and non-numeric prior values.
  • Create tests for decrease behavior from a numeric prior value.
  • Verify plain SET does not read the session and remains unchanged, including default operation when omitted.
  • Add a test that a non-numeric amount for increase causes a visible failure (success:false).
  • Stub logger and error-reporting behaviors to keep tests isolated and deterministic.
src/modules/temporal/activities/nodes/set-variable.node.spec.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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
gomessguii merged commit 8154283 into develop Jul 24, 2026
6 checks passed
@gomessguii
gomessguii deleted the fix/EVO-1840-set-variable-increment branch July 24, 2026 23:57
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.

2 participants