Skip to content

[PHP] Hold pooled workers until streamed responses finish#3553

Merged
adamziel merged 2 commits into
trunkfrom
codex/object-pool-streamed-responses
Apr 28, 2026
Merged

[PHP] Hold pooled workers until streamed responses finish#3553
adamziel merged 2 commits into
trunkfrom
codex/object-pool-streamed-responses

Conversation

@adamziel

Copy link
Copy Markdown
Collaborator

What it does

Keeps a borrowed pooled worker checked out until a streamed result finishes.

Rationale

ObjectPoolProxy released instances as soon as the proxied method returned. For streamed responses, the method returns before the stream is consumed, so another caller could reuse the same worker while the previous response was still active.

Implementation

If the proxied result exposes a finished promise, release the instance only after that promise settles. The new test covers the streamed-result lock behavior.

Testing instructions

Run npx nx test:vite php-wasm-universal -- object-pool-proxy.spec.ts, or use the CI matrix.

@adamziel adamziel force-pushed the codex/object-pool-streamed-responses branch from 7bd3012 to f950217 Compare April 28, 2026 18:21
@adamziel adamziel force-pushed the codex/file-lock-manager-test-cleanup branch 2 times, most recently from 13c1cb4 to dfa2a4b Compare April 28, 2026 18:29
@adamziel adamziel force-pushed the codex/object-pool-streamed-responses branch 2 times, most recently from 9f5b24e to fe9b9c4 Compare April 28, 2026 18:38
@adamziel adamziel force-pushed the codex/file-lock-manager-test-cleanup branch 2 times, most recently from c2a6cd2 to af2730f Compare April 28, 2026 19:37
@adamziel adamziel force-pushed the codex/object-pool-streamed-responses branch 2 times, most recently from 7788ed1 to 1507232 Compare April 28, 2026 19:46
@adamziel adamziel force-pushed the codex/file-lock-manager-test-cleanup branch from af2730f to 2aaf83d Compare April 28, 2026 19:46
Base automatically changed from codex/file-lock-manager-test-cleanup to trunk April 28, 2026 22:27
@adamziel adamziel force-pushed the codex/object-pool-streamed-responses branch from 1507232 to 27303d6 Compare April 28, 2026 22:29
@adamziel adamziel changed the title Hold pooled workers until streamed responses finish [PHP] Hold pooled workers until streamed responses finish Apr 28, 2026
@adamziel adamziel added the [Type] Bug An existing feature does not function as intended label Apr 28, 2026
@adamziel adamziel marked this pull request as ready for review April 28, 2026 22:48
@adamziel adamziel requested review from a team, Copilot and zaerl April 28, 2026 22:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Prevents pooled PHP wasm workers from being returned to the pool while a streamed response is still being consumed by delaying release() until the stream’s finished promise settles.

Changes:

  • Add finished-aware release logic in ObjectPoolProxy so instances remain checked out during streaming.
  • Add a unit test ensuring a second borrower blocks until the first streamed result finishes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/php-wasm/universal/src/lib/object-pool-proxy.ts Delays releasing pooled instances until a returned streamed result’s finished promise settles.
packages/php-wasm/universal/src/lib/object-pool-proxy.spec.ts Adds a regression test verifying the pool remains locked while a streamed result is unfinished.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +70 to +73
Promise.resolve(finished).then(
() => release(instance),
() => release(instance)
);

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

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

The Promise.resolve(finished).then(...) is intentionally not awaited/returned; in repos that use no-floating-promises, this will be flagged and can also make it easy to miss that errors inside release() would surface as an unhandled rejection. Consider explicitly marking it as intentionally detached (e.g., prefix with void) and using finally to avoid duplicating the release(instance) callback for both success and failure.

Suggested change
Promise.resolve(finished).then(
() => release(instance),
() => release(instance)
);
void Promise.resolve(finished).finally(() => release(instance));

Copilot uses AI. Check for mistakes.
Comment thread packages/php-wasm/universal/src/lib/object-pool-proxy.spec.ts
@adamziel adamziel merged commit 93b59e1 into trunk Apr 28, 2026
47 of 48 checks passed
@adamziel adamziel deleted the codex/object-pool-streamed-responses branch April 28, 2026 23:13
pento added a commit to pento/claudaborative-editing that referenced this pull request Jun 6, 2026
#101)

The vendored @wp-playground/cli + @php-wasm/universal tarballs (a build of
WordPress/wordpress-playground#3494) worked around a worker-pool bug that
returned PHP workers to the pool before their streamed response finished,
causing intermittent 500s under concurrent e2e requests. That bug was fixed
upstream (WordPress/wordpress-playground#3553) and shipped in the 3.1.2x
line, so depend on the released package instead.

- @wp-playground/cli: file:./vendor/...-pr3494.tgz -> ^3.1.36
- drop the @php-wasm/universal file: override (now resolves transitively)
- remove the vendor/ tarballs
- run the e2e Playground server with --workers=auto

Verified: e2e 23/23 on 4 workers (no 5xx), php 140/140.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] PHP.wasm [Package][@php-wasm] Universal [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants