You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(vtex): read MESH_REQUEST_CONTEXT per-request, not from cached factory env (#431)
* fix(vtex): bump @decocms/runtime to ^1.6.2 to restore state propagation
The kubernetes-bun rollback in #429 dropped @decocms/runtime from ^1.6.2
back to 1.3.1. With 1.3.1, requests reach the pod with a populated
MESH_REQUEST_CONTEXT envelope (token/connectionId/meshUrl all set) but
state arrives as an empty object — so state.accountName is null and
every tool call fails with "VTEX accountName is missing".
Confirmed in the deployed pod logs:
hasMeshContext: true, hasToken: true, hasConnectionId: true,
hasMeshUrl: true, stateKeys: [], stateAccountNamePresent: false
The Workers latency that prompted the revert was startup-CPU-budget
specific to Cloudflare Workers, not a Bun problem, so this only bumps
the runtime/bindings/sdk versions and keeps the kubernetes-bun deploy
and serve()-style entrypoint intact.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(vtex): read MESH_REQUEST_CONTEXT from runtimeContext, not factory closure
Every tool was capturing `env` in its factory closure and reading
`env.MESH_REQUEST_CONTEXT` from inside execute. The @decocms/runtime
caches tool registrations after the first request (see tools.ts:
`let cached: Registrations | null`) and creates a fresh `bindings` env
per request — so the captured env is the FIRST request's snapshot,
frozen for the lifetime of the pod.
When a pod's first request happened to carry an `x-mesh-token` with
populated state, every subsequent call reused that captured state
(seemingly worked). When the first request was an unauthenticated
`tools/list` (e.g. just after a Knative scale-up), every later call
saw `state: {}` and failed with "VTEX accountName is missing" — even
though studio was correctly forwarding the JWT with the connection's
configuration_state. Verified end-to-end: studio's `buildRequestHeaders`
mints a JWT containing `state: { accountName, appKey, appToken }` for
this connection, the JWT reaches the pod, but the cached tool closure
ignores it.
The runtime expects `execute` to read per-request env from
`runtimeContext.env` (filled from AsyncLocalStorage on every call) — see
the comment in @decocms/runtime tools.ts:821 ("Tool *execution* reads
per-request context from State (AsyncLocalStorage), so reusing
definitions is safe"). Switch all four execute paths
(createToolFromOperation + the three custom tools) to read from
`runtimeContext.env` and discard the captured factory env.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
"Replace all specifications for a product. Pass the complete set — values not included are removed. Caller does GET → merge → POST for partial updates. Counterpart of VTEX_GET_PRODUCT_SPECIFICATIONS.",
0 commit comments