Skip to content

fix(runtime): return the newest worker window from getApplicationLastProfile - #5023

Merged
mcollina merged 1 commit into
mainfrom
fix-get-last-profile-multiple-workers
Jul 28, 2026
Merged

fix(runtime): return the newest worker window from getApplicationLastProfile#5023
mcollina merged 1 commit into
mainfrom
fix-get-last-profile-multiple-workers

Conversation

@mcollina

Copy link
Copy Markdown
Member

Problem

Same family as #5022, different method: getApplicationLastProfile resolved a bare application id through the round-robin worker selector. With multiple workers, the live pull could land on a worker whose continuous profiler was never started, fail with PLT_PPROF_PROFILING_NOT_STARTED, find no preserved overload profile, and throw — intermittently, depending on where the rotor pointed. Even when it didn't fail, it could return an arbitrary worker's window instead of the application's most recent one.

Fix

There was already an asymmetry pointing at the right semantics: the preserved-overload-profile fallback (#getPreservedOverloadProfile) treats a bare application id as "scan all workers, return the newest", while the live path picked one arbitrary worker.

The live path now matches: for an application-level id, getLastProfile is pulled from every worker in parallel (new #pullLastProfiles helper), inside the existing single options.timeout budget, and the newest window wins.

  • Explicit application:workerIndex ids keep the current single-worker behavior.
  • Per-worker failures with codes in the fallback set (PROFILING_NOT_STARTED, NO_PROFILE_AVAILABLE, …) are ignored as long as at least one worker yields a profile; if all fail, the first error flows into the existing preserved-profile fallback exactly as before. Non-fallback errors still rethrow immediately.
  • The preserved-entry pruning (a strictly newer live window supersedes the preserved copy) now runs per responding worker.
  • Results without a timestamp (older capture modules) lose to timestamped ones when picking the newest.

This is independent of #5022 (which fixes start/stop pairing): here no pinning is needed because all workers are queried.

Testing

TDD from main: packages/runtime/test/get-last-profile-workers.test.js (new, 4 tests on a 2-worker fixture). The first test reproduced the reported intermittent failure before the fix (consecutive bare-id calls, one of which rotated onto the unprofiled worker) and passes after; the second asserts the newest-across-workers semantics.

  • new suite: 4/4
  • packages/runtime/test/extensions.test.js: 19/19
  • packages/wattpm-pprof-capture/test/watt-pprof-capture.test.js (covers preserved/overload/blocked-worker paths of this method): 36/36
  • lint clean

🤖 Generated with Claude Code

@ShogunPanda ShogunPanda 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.

LGTM!

…Profile

When an application ran multiple workers, getApplicationLastProfile
resolved a bare application id through the round-robin worker selector,
so the pull could land on a worker whose continuous profiler was never
started: the call failed intermittently even though another worker had
a live profile window.

For an application-level id the last profile is now pulled from every
worker in parallel, within the same timeout budget, and the newest
window is returned - mirroring the preserved overload profile fallback,
which already scanned all workers. Explicit application:workerIndex ids
keep addressing a single worker. Per-worker failures with fallback codes
are ignored as long as at least one worker yields a profile, while other
errors are still rethrown.

Assisted-by: Claude Code:claude-fable-5
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina
mcollina force-pushed the fix-get-last-profile-multiple-workers branch from ab5a47c to 3e8911a Compare July 27, 2026 14:12
@mcollina
mcollina merged commit ed9c0ca into main Jul 28, 2026
457 of 469 checks passed
@mcollina
mcollina deleted the fix-get-last-profile-multiple-workers branch July 28, 2026 10:59
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.

2 participants