Skip to content

Revert "[Workflows] Implement Workflows instance methods"#12872

Merged
edmundhung merged 1 commit intomainfrom
revert-12814-osilva/implement-workflows-instance-methods
Mar 13, 2026
Merged

Revert "[Workflows] Implement Workflows instance methods"#12872
edmundhung merged 1 commit intomainfrom
revert-12814-osilva/implement-workflows-instance-methods

Conversation

@edmundhung
Copy link
Member

@edmundhung edmundhung commented Mar 12, 2026

Reverts #12814

We are now seeing constant CI errors in the Tests (Windows) CI job (e.g. https://github.com/cloudflare/workers-sdk/actions/runs/23015495128/job/66849585138?pr=12840)

I am not 100% sure it's related to this change. We will see if the CI job pass in this PR.


Open with Devin

@changeset-bot
Copy link

changeset-bot bot commented Mar 12, 2026

⚠️ No Changeset found

Latest commit: 1a5eda5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ask-bonk
Copy link
Contributor

ask-bonk bot commented Mar 12, 2026

Good - both userTriggeredTerminate() and popTypeAll() pre-existed before PR #12814. The revert is faithfully restoring the prior state. There are no issues introduced by this revert.

LGTM

github run

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 12, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12872

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12872

miniflare

npm i https://pkg.pr.new/miniflare@12872

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12872

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12872

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12872

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12872

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12872

wrangler

npm i https://pkg.pr.new/wrangler@12872

commit: 8974f78

@edmundhung edmundhung marked this pull request as ready for review March 12, 2026 20:24
@edmundhung edmundhung requested review from a team as code owners March 12, 2026 20:24
@workers-devprod
Copy link
Contributor

workers-devprod commented Mar 12, 2026

Codeowners approval required for this PR:

  • @cloudflare/workflows
  • ✅ @cloudflare/wrangler
Show detailed file reviewers
  • packages/workflows-shared/README.md: [@cloudflare/workflows]
  • packages/workflows-shared/src/binding.ts: [@cloudflare/workflows]
  • packages/workflows-shared/src/context.ts: [@cloudflare/workflows]
  • packages/workflows-shared/src/engine.ts: [@cloudflare/workflows]
  • packages/workflows-shared/src/instance.ts: [@cloudflare/workflows]
  • packages/workflows-shared/src/lib/errors.ts: [@cloudflare/workflows]
  • packages/workflows-shared/src/lib/gracePeriodSemaphore.ts: [@cloudflare/workflows]
  • packages/workflows-shared/src/lib/timePriorityQueue.ts: [@cloudflare/workflows]
  • packages/workflows-shared/src/lib/validators.ts: [@cloudflare/workflows]
  • packages/workflows-shared/src/modifier.ts: [@cloudflare/workflows]
  • packages/workflows-shared/tests/binding.test.ts: [@cloudflare/workflows]
  • packages/workflows-shared/tests/context.test.ts: [@cloudflare/workflows]
  • packages/workflows-shared/tests/engine.test.ts: [@cloudflare/workflows]
  • packages/workflows-shared/tests/env.d.ts: [@cloudflare/workflows]
  • packages/workflows-shared/tests/test-entry.ts: [@cloudflare/workflows]
  • packages/workflows-shared/tests/tsconfig.json: [@cloudflare/workflows]
  • packages/workflows-shared/tests/utils.ts: [@cloudflare/workflows]
  • packages/workflows-shared/tests/validators.test.ts: [@cloudflare/workflows]
  • packages/workflows-shared/tsconfig.json: [@cloudflare/workflows]
  • packages/workflows-shared/vitest.config.ts: [@cloudflare/workflows]

@Caio-Nogueira
Copy link
Contributor

LGTM from the workflows team

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

View 6 additional findings in Devin Review.

Open in Devin Review

Comment on lines 472 to +474
await this.storeEventMap();
// TODO: persist eventMap - it can be over 2MiB
this.eventMap.set(event.type, eventTypeQueue);
Copy link
Contributor

Choose a reason for hiding this comment

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

🔴 receiveEvent calls storeEventMap before adding event type to eventMap, losing first events of new types

In receiveEvent(), the order of this.eventMap.set() and this.storeEventMap() was swapped compared to the original code (pre-PR #12814). When a new event type is first received, eventTypeQueue is a brand-new array ([] from the ?? [] fallback) that is NOT yet in this.eventMap. The event is pushed to this detached array, then storeEventMap() iterates this.eventMap.entries() — which doesn't include the new type — so the event is never persisted to storage. The this.eventMap.set() call only happens afterward. If the DO restarts before the event is consumed in-memory, the event is permanently lost, causing waitForEvent to hang until timeout.

Comparison with original code (pre-PR #12814)

Original order:

this.eventMap.set(event.type, eventTypeQueue);
await this.storeEventMap();

New (incorrect) order:

await this.storeEventMap();
this.eventMap.set(event.type, eventTypeQueue);
Suggested change
await this.storeEventMap();
// TODO: persist eventMap - it can be over 2MiB
this.eventMap.set(event.type, eventTypeQueue);
this.eventMap.set(event.type, eventTypeQueue);
await this.storeEventMap();
// TODO: persist eventMap - it can be over 2MiB
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines 91 to 97
public async status(): Promise<InstanceStatus> {
using instance = await this.getInstance();
const instance = (await this.binding.get(this.id)) as WorkflowInstance &
Disposable;
using res = (await instance.status()) as InstanceStatus & Disposable;
instance[Symbol.dispose]();
return structuredClone(res);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🟡 InstanceImpl.status() and sendEvent() leak RPC handle on exception path

In the miniflare wrapped binding, InstanceImpl.status() and InstanceImpl.sendEvent() replaced the original RAII using instance = await this.getInstance() pattern with manual instance[Symbol.dispose]() calls. If the intermediate operation (instance.status() or instance.sendEvent()) throws an exception, instance[Symbol.dispose]() is never reached, leaking the RPC handle. The original code at packages/miniflare/src/workers/workflows/wrapped-binding.worker.ts (pre-PR #12814) correctly used using declarations that guarantee disposal even on exception paths.

Suggested change
public async status(): Promise<InstanceStatus> {
using instance = await this.getInstance();
const instance = (await this.binding.get(this.id)) as WorkflowInstance &
Disposable;
using res = (await instance.status()) as InstanceStatus & Disposable;
instance[Symbol.dispose]();
return structuredClone(res);
}
public async status(): Promise<InstanceStatus> {
using instance = (await this.binding.get(this.id)) as WorkflowInstance &
Disposable;
using res = (await instance.status()) as InstanceStatus & Disposable;
return structuredClone(res);
}
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@edmundhung edmundhung added the skip-pr-description-validation Skip validation of the required PR description format label Mar 12, 2026
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

CI is green so it looks like this was the cause of our previous failures on main...

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Mar 13, 2026
@edmundhung edmundhung merged commit 22b51cd into main Mar 13, 2026
54 of 63 checks passed
@edmundhung edmundhung deleted the revert-12814-osilva/implement-workflows-instance-methods branch March 13, 2026 08:05
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 13, 2026
pombosilva added a commit that referenced this pull request Mar 13, 2026
pombosilva added a commit that referenced this pull request Mar 16, 2026
pombosilva added a commit that referenced this pull request Mar 17, 2026
pombosilva added a commit that referenced this pull request Mar 18, 2026
pombosilva added a commit that referenced this pull request Mar 18, 2026
pombosilva added a commit that referenced this pull request Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-pr-description-validation Skip validation of the required PR description format

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants