Skip to content

Lazy state errors#1312

Merged
josephjclark merged 5 commits intorelease/nextfrom
lazy-state-errors
Mar 17, 2026
Merged

Lazy state errors#1312
josephjclark merged 5 commits intorelease/nextfrom
lazy-state-errors

Conversation

@josephjclark
Copy link
Collaborator

@josephjclark josephjclark commented Mar 17, 2026

Short Description

Fixes an issue in the compiler (and slightly improves CLI reporting) where lazy state error do not report their position, much to the annoyance of users.

Fixes #1307

AI Usage

Please disclose whether you've used AI anywhere in this PR (it's cool, we just
want to know!):

  • I have used Claude Code
  • I have used another model
  • I have not used AI

You can read more details in our
Responsible AI Policy

@github-project-automation github-project-automation bot moved this to New Issues in Core Mar 17, 2026
@josephjclark josephjclark merged commit c687ef5 into release/next Mar 17, 2026
6 checks passed
@github-project-automation github-project-automation bot moved this from New Issues to Done in Core Mar 17, 2026
@josephjclark josephjclark deleted the lazy-state-errors branch March 17, 2026 16:41
josephjclark added a commit that referenced this pull request Mar 17, 2026
* Fix worker crash caused by async promise antipattern and event ordering (#1311)

* fix(ws-worker): remove async promise antipattern in run-log.ts

The non-batch log path wrapped an async function in `new Promise(async
(resolve) => { ... })`. If sendEvent rejected (e.g. channel timeout),
the outer Promise never settled and the rejection was unhandled. This
was the direct cause of the worker crash: LightningTimeoutError on
run:log became an uncaught exception that killed the container.

The function is already async so the wrapper was unnecessary — replaced
with a plain for-loop that properly propagates rejections.

* fix(ws-worker): remove async promise antipattern in try-with-backoff.ts

Same `new Promise(async ...)` antipattern as run-log.ts. If the
isCancelled callback or any other code in the catch block threw, the
error became an unhandled rejection instead of propagating to the
caller.

Replaced with an inner async function that returns its promise
directly. setTimeout retry replaced with awaited promise to keep the
flow async-native.

* fix(ws-worker): remove async promise antipattern in destroy.ts

Same `new Promise(async (resolve) => { ... })` pattern — if
engine.destroy() or waitForRunsAndClaims rejected, the outer promise
never settled. Replaced with an async IIFE so errors propagate through
Promise.all to the caller.

* fix(engine-multi): emit compilation log before workflow-error

During a compilation failure, engine-multi emitted WORKFLOW_ERROR
(from the worker:error handler) before the "Error occurred during
compilation" WORKFLOW_LOG (from the .catch handler). The ws-worker
tears down the channel on WORKFLOW_ERROR, so the subsequent log push
had nowhere to go — triggering the LightningTimeoutError that crashed
the container.

Moved the compilation log into the worker:error handler so it emits
before the error event. Guarded the .catch handler's log with
!didError to avoid duplication. Added COMPILE_START/COMPLETE events
to mock-run.ts to match real worker behavior.

* chore: add changesets for worker crash fixes

* chore: exclude engine-multi tmp from pnpm workspace

Test fixture directories under packages/engine-multi/tmp/ were being
picked up as workspace packages by the packages/** glob, pulling in
phantom dependencies (ava@6.x and its full transitive tree) that
caused persistent lockfile churn.

* remove duplicate log, tidy types

* update changelogs

* tidy test

* revert diff on destroy

* keep destroy change after all and fix test

* relax runtime test

it just went flaky

---------

Co-authored-by: Joe Clark <jclark@openfn.org>

* Compile errors step name (#1313)

* engine: report compile errors with step name, not id

* changeset

* remove debug code

* Lazy state errors (#1312)

* compiler: improve error messages for lazy state

* compiler: report position on lazy state reporting

* update extra errors

* update changeset

* types

* versions

---------

Co-authored-by: Stuart Corbishley <corbish@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants