Skip to content

fix: ignore yielded promise results after a task was restarted - #40

Merged
AlCalzone merged 2 commits into
claude/waddle-cancellation-bug-7e3f85from
claude/waddle-restart-promise-bug
Oct 6, 2026
Merged

AlCalzone merged 2 commits into
claude/waddle-cancellation-bug-7e3f85from
claude/waddle-restart-promise-bug

Conversation

@zwave-js-bot

@zwave-js-bot zwave-js-bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #39. Merge that first. This PR's diff only shows the change on top of it.

The issue: A task with interrupt: TaskInterruptBehavior.Restart can be reset by a higher-priority task while it waits for a yielded promise. The promise's then, catch and finally handlers did not check for that. If the old promise rejected after the restart, waitError was set and the next step() threw it into the fresh generator via gen.throw(waitError). The late finally also cleared the waitForPromise of the restarted run.

The fix: The yielded-promise handlers now use the same check as the subtask handlers from #39. then and catch only store the result or error if generator === gen. finally returns early when the generator has changed.

Test: A restarted task ignores a rejection of the promise it waited for before the restart interrupts a waiting Restart task and rejects the old promise while the restarted run waits for a new one. It failed with the old error before the fix. All 65 tests pass.

@zwave-js-bot zwave-js-bot changed the title claude/waddle restart promise bug fix: ignore yielded promise results after a task was restarted Oct 5, 2026
@zwave-js-bot
zwave-js-bot marked this pull request as ready for review October 5, 2026 09:56
@AlCalzone
AlCalzone added this pull request to stack #41 October 5, 2026 10:39
A task with the Restart interrupt behavior can be reset while it waits for a yielded promise. The promise handlers now check that the generator is still the same, so a late result or rejection no longer reaches the restarted run. The late finally handler also no longer clears the wait promise of the restarted run.
@AlCalzone
AlCalzone force-pushed the claude/waddle-restart-promise-bug branch from 5459d42 to aeeb22d Compare October 6, 2026 09:08
@AlCalzone
AlCalzone requested a balanced review from Copilot October 6, 2026 09:08

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.

Copilot review overview

🟡 Changes recommended

The regression test does not cover stale fulfillment or stale finally cleanup behavior.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Extends #39’s reset-safety logic to yielded promises.

Changes:

  • Ignores stale promise results, errors, and cleanup.
  • Adds a stale-rejection regression test.
  • Updates the changelog.
File Description
src/​Task.ts Guards promise handlers by generator identity.
src/​Task.test.ts Tests stale rejection after restart.
README.md Documents the fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Task.test.ts Resolved

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.

Copilot review overview

🟢 Approval recommended

The generator guards address all stale callback paths, with focused regression coverage for timing and outcomes.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@AlCalzone
AlCalzone merged commit ad3309f into main Oct 6, 2026
5 checks passed
@AlCalzone
AlCalzone deleted the claude/waddle-restart-promise-bug branch October 6, 2026 10:21
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.

3 participants