Trace LangGraph agents across Vercel Sandbox webhooks through a correlation record your application owns. A webhook should annotate a run or request reconciliation; it should never, by itself, mark a graph complete or resume it. Vercel’s lifecycle-webhook announcement documents session signals, while LangChain’s LangSmith documentation documents LangGraph tracing. No cited source documents a native session-to-run identifier mapping. Treating correlation as built in would require evidence not supplied here: a full Vercel payload schema and ordering/retry policy, LangSmith documentation for attaching and querying your chosen identifier, and integrated replay tests showing that duplicate notifications cannot repeat run transitions or external effects.
The supportable procedure is therefore a practitioner design assembled from separately documented primitives, not a vendor-documented connection between the products. Its central rule is simple: reconcile session state against LangGraph checkpoint state, inspect the LangSmith trace for the run-plane record, and make every resulting action idempotent.
A sandbox session and an agent run occupy different state planes
Vercel’s webhooks report the lifecycle of the execution environment. According to the Sandbox documentation, persistent sandboxes auto-save state on stop and resume where they left off, persistence is the default, and no manual snapshot management is required. That is useful session-plane persistence. It does not establish that a LangGraph graph reached a terminal node, that a particular checkpoint exists, or that an external write occurred only once.
LangGraph has a separate state model. A paper describing LangGraph workflows identifies typed shared state, graph nodes and edges, conditional routing, durable checkpoints, and interrupt/resume as control-plane primitives. It says workflows can persist through failures and pauses and resume from the last checkpoint, with humans able to inspect or modify state at interrupt points.
LangSmith supplies a third surface: the trace. LangChain says it supports tracing LangGraph agents in Python and JavaScript, whether they use LangChain modules or other SDKs. The tracing documentation does not establish webhook handling, checkpoint persistence, or a Vercel correlation key.
I would assign each surface a distinct job:
- Sandbox session state answers whether the environment is ready, nearing expiry, stopped, or available for session-level restoration.
- LangGraph checkpoint state answers where graph execution can resume and whether the application considers the graph complete.
- The LangSmith trace helps operators reconstruct what the run recorded before they choose cleanup, extension, or recovery.
- The webhook delivers a notification. It is not a run outcome or a recovery transaction.
Neither persistence description establishes a ledger of side effects outside the sandbox or graph. That missing distinction matters when a tool call has already changed a customer record, sent a message, or modified another external system.
Read the three events as signals, not commands
Vercel names three events, subscribed through team webhook settings: sandbox.session.started, sandbox.session.expiring, and sandbox.session.stopped. The following responses are proposed reconciliation logic; the event facts come from Vercel’s announcement, while the agent-side actions are inference from the checkpoint and tracing model.
| Event | What Vercel documents | Recommended run-plane response |
|---|---|---|
sandbox.session.started | The sandbox session is ready. | Create or confirm the session-to-run correlation record. If this event launches work, route that launch through an idempotent launcher; otherwise annotate the existing run. Do not treat session readiness as graph progress. |
sandbox.session.expiring | The session is approaching its timeout. Vercel sends the warning 1 minute before timeout, or at the time configured by expiryNotificationLeadTime. | Deduplicate on session ID and sandbox.expiresAt, inspect current run and checkpoint state, and apply a predetermined extension policy. Expiry alone does not show that the graph is stuck or still has useful work. |
sandbox.session.stopped | The session stopped. The event includes a stop reason plus session duration, active CPU time, and network transfer. | Store the session telemetry, inspect checkpoint and trace state, and separate sandbox cleanup from graph completion. No stop reason, by itself, proves that the agent run finished. |
Extension handling deserves a concrete policy because the default warning may leave only 1 minute for a decision. Vercel says each extension produces another warning 1 minute before the new timeout. A handler that deduplicates only on session ID could mistakenly discard that new warning; including sandbox.expiresAt distinguishes a new expiry from repeated delivery of the old one.
If your reconciliation process needs more decision time, expiryNotificationLeadTime is the documented configuration point to evaluate. The announcement does not supply its permitted range or promise that manual investigation will finish within the configured interval. For a long-running graph, decide extension eligibility in advance rather than improvising after the warning arrives. A graph already known to be terminal should not be extended merely because an expiry notification was delivered.
Build the correlation and delivery record yourself
A useful implementation can remain small, but it must make ownership explicit. The following is a design pattern derived from Vercel’s duplicate-delivery warning and LangGraph’s checkpoint model, not a published reference architecture.
1. Create the association before you need to recover
When your orchestrator creates or attaches a sandbox session, record the Vercel session ID alongside the LangGraph thread or run identifier your application already uses. Add an internal delivery-attempt identifier if your system can make multiple attempts within one thread, and retain the current sandbox.expiresAt value when available.
Keep a reference that lets an operator find the corresponding LangSmith trace. That might be a correlation field in your own datastore rather than metadata inside LangSmith. No cited source establishes that LangSmith accepts or indexes an arbitrary Vercel session field, so any metadata-based design needs verification against current LangSmith documentation before it becomes a dependency.
This record gives the webhook receiver something to look up without inferring run identity from arrival order or assuming that one sandbox always represents exactly one graph attempt.
2. Deduplicate before performing an action
Vercel explicitly states that an event can be delivered more than once. Its recommended keys are the session ID and, for expiring events, sandbox.expiresAt.
Apply that key within the relevant event handler and store the processing result with it. A repeated delivery should return or reproduce the recorded decision, not execute cleanup, extension, launch, or resume again. For expiring, a changed sandbox.expiresAt must be treated as a new decision point rather than collapsed into an earlier warning.
Handler-level idempotency does not prove that the agent’s own tool calls are idempotent. Those are separate problems, which is why deduplicating the webhook is necessary but insufficient for safe recovery.
3. Reconcile current state instead of trusting event sequence
The supplied Vercel material documents duplicate delivery but not ordering guarantees or retry timing. Do not claim that started will always be observed before expiring, or that a delayed stopped notification represents the latest run condition.
Store each observation for diagnosis, then read the current correlation record, checkpoint state, and trace before making a transition. If those sources disagree or one is unavailable, leave the run in an internal “unknown” or “needs review” category rather than guessing. Those category names are application choices, not statuses documented by either vendor.
This also gives duplicate events a harmless role: once the original decision has been recorded, subsequent copies become annotations or no-ops.
4. Separate cleanup ownership from run ownership
Assign the webhook handler responsibility for session-plane bookkeeping and whatever sandbox cleanup your application owns. Give the graph runner or supervising service responsibility for declaring a run terminal or resumable.
A graph should be considered complete only when its own execution and checkpoint state support that conclusion. If stopped arrives after that point, annotate the late session observation and perform session cleanup. If it arrives while the graph is incomplete, route the run through interruption and recovery logic instead of closing it as a successful or failed run solely from the webhook.
Stop reasons narrow the session story, not the run outcome
Vercel lists five stop reasons: requested, snapshot, timeout, exited, and error. The same announcement says stopped events also carry duration, active CPU time, and network transfer. It does not map any reason to a LangGraph terminal state.
Use the reasons to choose what to inspect next:
| Stop reason | Proposed routing |
|---|---|
requested | Check your own request or audit record if your application initiated the stop, then confirm graph state. A requested environment stop does not prove that the graph completed before it stopped. |
snapshot | Keep sandbox persistence and LangGraph checkpoints separate in the audit record. The label does not establish which graph checkpoint, if any, is resumable. |
timeout | Check whether the graph was terminal, interrupted, or still active. Do not automatically restart it, and do not mark it complete merely because its time budget ended. |
exited | Inspect the checkpoint and trace before assigning a run outcome. The supplied source does not define this label deeply enough to infer which graph node failed or whether any node failed at all. |
error | Treat this as a session-plane error indication until run-plane evidence identifies the consequence. Preserve the session telemetry and require the same recovery checks as any other interrupted run. |
This routing is deliberately less automatic than a mapping such as “error means failed” or “requested means complete.” The documented reason taxonomy does not support those transitions.
Why checkpoint resume still needs a side-effect check
LangGraph’s documented ability to resume from the last checkpoint is preferable to blindly starting the entire graph again, but it is not blanket permission to resume after every notification. The strongest counter-evidence in the brief comes from Agent Recovery Gone Wrong, an AppWorld study rather than a test of Vercel webhooks or this integrated stack.
In its stratified random sample of 200 candidate episodes across ten models, 145 were confirmed as partial executions through database state. Among 143 confirmed partial executions with a determinable outcome, 30 were followed by a harmful recovery; the authors report a stratification-weighted estimate of 24.6%. Two thirds of those harmful recoveries duplicated an effect, while the rest deleted user data or made a wrong first-time write. The harm also tended to persist: 49 of 51 continuations with a harmful action still had the violation at the end of the run.
A broader static analysis in the same paper examined 13,988 AppWorld runs and identified 1,897 failed blocks containing at least one write call before the failing line. In 70.6% of those cases, the agent rewrote the code and issued those writes again.
Those percentages cannot estimate the failure rate of a LangGraph run resumed after a Vercel webhook. They concern agent task recovery in a different benchmark. They do, however, directly challenge the assumption that re-execution after partial progress is benign.
For an automatic checkpoint resume, I would therefore require four conditions: an unambiguous session-to-run association, a resumable checkpoint, duplicate-delivery handling that cannot launch another attempt, and an application-specific account of external effects since the checkpoint. If the last condition is unknown, resume should pause for inspection or use an application-approved recovery path rather than proceeding blindly.
The choice can differ by workload. In a hypothetical read-only evaluation where repeated tool calls have no external effects, automatic checkpoint resume may be reasonable after replay tests pass. For an agent that may already have updated a customer account, a missing effect ledger is a reason to require reconciliation or human review, not merely a caveat under an otherwise automatic design.
What to verify before shipping
The sources leave specific gaps that tests and current documentation need to close:
- Payload and delivery behavior: Confirm the full event schemas, available identifiers, extension interface, ordering guarantees, and retry timing. Do not infer any of these from the three event names alone.
- Trace correlation: Verify how your chosen session, thread, or run identifier can be attached to and retrieved through LangSmith. If that mechanism is unavailable or unsuitable, retain the mapping in your own datastore.
- Checkpoint survival: Test that the checkpoint your recovery path needs remains accessible after sandbox stop and restoration. Vercel’s default sandbox persistence does not establish this for your LangGraph deployment.
- Duplicate and extension handling: Replay identical
startedandstoppedevents, repeat anexpiringevent with the samesandbox.expiresAt, and then deliver one with a changed expiry. Acceptance means no repeated side effect and no discarded new expiry warning. - Partial-execution recovery: In a controlled test, interrupt a run after a countable test write. Verify that the recovery path reviews or deduplicates that write instead of issuing it again.
I would roll this out in stages: first use the webhooks for correlation and trace annotations, then enable policy-controlled session extension, and enable automatic run resumption only for workloads whose checkpoint and side-effect behavior have passed those tests. That keeps Vercel’s notifications useful without allowing session lifecycle state to impersonate agent run state.
Frequently Asked Questions
What are the three Vercel sandbox session lifecycle webhook events?
Vercel names three events, subscribed through team webhook settings: sandbox.session.started, sandbox.session.expiring, and sandbox.session.stopped.
How should a handler deduplicate Vercel webhook events?
Vercel explicitly states that an event can be delivered more than once. Its recommended keys are the session ID and, for expiring events, sandbox.expiresAt.
What stop reasons does Vercel list for sandbox sessions?
Vercel lists five stop reasons: requested, snapshot, timeout, exited, and error.
Join the discussion
Share a useful perspective or ask a question about this article.