Skip to content

fix(laya-ts): end batch request contexts in reverse start order - #1339

Merged
NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
thread3d:fix/laya-ts-end-order
Oct 24, 2026
Merged

NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
thread3d:fix/laya-ts-end-order

Conversation

@thread3d

Copy link
Copy Markdown
Contributor

What

Router._endContexts dispatches onPredictEnd in reverse start order (elapsed/usage stamping stays forward).

Why

Every per-request context of a checkpoint group starts before any of them ends, so the ends must unwind LIFO: a hook that opens in start and closes in end (a tracing span, an AsyncLocalStorage frame, an in-flight counter) otherwise closes the wrong frame, and every request after the first inherits a corrupted context. Python's Router.predict_batch ends its contexts in reverse and its docstring states the reason.

How it was verified

cd laya-ts && npx vitest run tests/router-batch.test.ts

Checklist

  • Focused on one change (split unrelated work into another PR)
  • Rebased on the latest main (branch cut from upstream/main at 0.4.14)
  • Tests pass locally
  • Docs or examples updated when the public API changed

Every per-request context of a checkpoint group starts before any of them ends, so the end
hooks must unwind LIFO: a hook that opens something in start and closes it in end (a
tracing span, an AsyncLocalStorage frame, an in-flight counter) otherwise closes the wrong
frame, and every request after the first inherits a corrupted context. Python's
Router.predict_batch ends its contexts in reverse and its docstring states the reason;
this runtime ended them in start order.

The three tests that asserted the forward order now assert the reverse one (including a
three-request case, which is the smallest shape where the rule is visible rather than
merely different); before the change six order assertions fail.
@NandhaKishorM
NandhaKishorM merged commit 1958921 into NandhaKishorM:main Oct 24, 2026
46 of 50 checks passed
NandhaKishorM added a commit that referenced this pull request Oct 24, 2026
33 PRs. Server hardening (#1331, #1332, #1333), TypeScript parity
(#1330, #1336, #1337, #1338, #1339, #1340, #1341, #1342, #1343),
fail-closed input handling in evals and the integrations (#1317, #1318,
#1319, #1320, #1321, #1322, #1326, #1335), exact and faster script
detection (#1334, #1349), JVM and .NET resource handling (#1327, #1328,
#1329, #1346), port goldens and clipping (#1324 excluded, #1325, #1344,
#1345), CI (#1323, #1347, #1348).

Verified before tagging: all 92 suites pass, 610 tests. ruff clean on
both lists. laya-ts 1247 tests across 44 files, tsc --noEmit clean.
Version agrees across pyproject.toml, laya.__version__ and nix/package.nix.
README carries 0.4.15 only.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@thread3d
thread3d deleted the fix/laya-ts-end-order branch October 28, 2026 10:37
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