Skip to content

fix: settle traceScenario as success when the consumer unsubscribes after a value - #27

Open
lukasmatta wants to merge 6 commits into
mainfrom
26-tracescenario-records-successful-requests-as-abandoned-when-used-with-firstvaluefrom-take1-or-first
Open

lukasmatta wants to merge 6 commits into
mainfrom
26-tracescenario-records-successful-requests-as-abandoned-when-used-with-firstvaluefrom-take1-or-first

Conversation

@lukasmatta

Copy link
Copy Markdown
Collaborator

traceScenario recorded abandoned instead of success when the stream was consumed with firstValueFrom, or when take(1) / first() came after it. These unsubscribe upstream once they have a value, before the source's complete arrives, so the operator only saw a teardown and called cancel(). The outcome mapper never ran either.

Changes

  • An unsubscribe after the stream has emitted now settles as success and runs the outcome mapper. An unsubscribe before any value is still abandoned, so switchMap superseding an in-flight request and takeUntilDestroyed behave as before.
  • New option valueThenTeardown: 'complete' | 'cancel' (default 'complete'). Multi-value streams such as polling can opt back into treating a teardown after a value as abandonment.
  • Specs now run against a real UwtScenario and cover firstValueFrom, lastValueFrom, take(1) / first() before and after the operator, switchMap superseding before and after a value, and retry placement.

Behaviour change

Code that relied on the old behaviour, a teardown after a value recorded as abandoned, will now record success. Use valueThenTeardown: 'cancel' to keep the old behaviour.

Closes #26

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

St.❔
Category Percentage Covered / Total
🟢 Statements
97.06% (-0.06% 🔻)
1286/1325
🟢 Branches
95.32% (+0.05% 🔼)
713/748
🟢 Functions 96.95% 318/328
🟢 Lines
97.41% (-0.06% 🔻)
1243/1276
Show files with reduced coverage 🔻
St.❔
File Statements Branches Functions Lines
🟢
... / uwt-scenario-operators.ts
96.15% (-3.85% 🔻)
95.83% (+2.08% 🔼)
100%
96.15% (-3.85% 🔻)

Test suite run success

753 tests passing in 24 suites.

Report generated by 🧪jest coverage report action from 6cca207

Copilot AI 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.

🟢 Approval recommended

The focused implementation and regression coverage support the intended behavior, with only a non-blocking documentation inconsistency remaining.

1 open issue
What changed in this PR

Fixes traceScenario settlement for consumers that unsubscribe after receiving a value, addressing the incorrect abandonment reporting described in #26.

Changes:

  • Treats teardown after a value as success and runs the outcome mapper.
  • Adds valueThenTeardown: 'cancel' to preserve abandonment behavior for multi-value streams.
  • Adds real-scenario regression coverage for promise consumers, operator ordering, supersession, and retries.
File Description
projects/​ngx-ui-watchtower/​src/​lib/​scenario/​uwt-scenario-operators/​uwt-scenario-operators.ts Updates teardown settlement and adds the cancellation opt-out.
projects/​ngx-ui-watchtower/​src/​lib/​scenario/​uwt-scenario-operators/​uwt-scenario-operators.spec.ts Adds real-scenario tests for consumption and teardown behavior.

Review effort: Balanced

@lukasmatta
lukasmatta marked this pull request as ready for review October 26, 2026 19:48
…-as-abandoned-when-used-with-firstvaluefrom-take1-or-first
…-as-abandoned-when-used-with-firstvaluefrom-take1-or-first
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.

traceScenario records successful requests as "abandoned" when used with firstValueFrom, take(1) or first()

3 participants