Phased Rollout Playbook
A reversible rollout plan for a LangChain 0.3 → 1.0 migration that touches production traffic. Designed so that any failure mode can be rolled back in under five minutes.
Phase 0 — Pre-flight (no production change)
- Run the pre-flight audit (see SKILL.md Step 1). Inventory every 0.3 usage and pick the owning team for each hit.
- Snapshot
pip freeze > requirements.lock.pre-1.0.txt— this is your rollback pin. - Snapshot the persistent chat-history store (if you have one) — RDS snapshot, Redis RDB dump, or S3 copy. The 1.0 LangGraph checkpointer uses a new schema; a rollback without this snapshot is data-lossy for in-flight conversations.
- Branch:
feat/langchain-1.0-migration. Merge nothing to main yet.
Phase 1 — Upgrade packages in a sandbox
On the migration branch only:
pip install --upgrade \
"langchain>=1.0,<2" \
"langchain-core>=0.3,<0.4" \
"langchain-openai>=1.0" \
"langchain-anthropic>=1.0" \
"langgraph>=1.0,<2" \
"anthropic>=0.40,<1"Run pytest -W error::DeprecationWarning — every DeprecationWarning is now a test failure, so any surviving 0.3 pattern surfaces immediately. Do not proceed to Phase 2 while the test suite is red.
Phase 2 — Codemod, one module at a time
Per-module order, lowest blast radius first:
- Pure-function chains (LLMChain → LCEL). Easiest. No state, no persistence.
- Embedding + vectorstore imports (P38). Import path changes only; no behaviour change.
- Stateless agents (initialize_agent → create_react_agent without memory).
- Streaming callers (astream_log → astream_events v2). Watch for payload-shape bugs — the event dict is typed.
- Stateful agents + memory (ConversationBufferMemory → LangGraph checkpointer). Highest risk — needs the dual-write below.
After each module: run its unit tests, commit with a pain-code reference (e.g. refactor: migrate P39 LLMChain in billing-summariser to LCEL).
Phase 3 — Dual-write for persistent chat histories
If conversations are persisted (Redis, Postgres, Dynamo) and you cannot drop existing threads, dual-write for the cutover window:
- Keep the 0.3 history writer running. Every turn, also write to the 1.0 LangGraph checkpointer table/keyspace under the same
thread_id. - Reads in 1.0 code path always go to the checkpointer. Reads in any surviving 0.3 code path keep their old source.
- Run dual-write for at least one full retention window (24h for most chat products).
- After promotion (Phase 5), stop the 0.3 writer and delete the old store on a delay (not immediately — keeps the rollback viable).
Phase 4 — Shadow traffic in staging
- Deploy the 1.0 branch to a staging environment that mirrors production traffic shape. A mirror proxy (e.g.
goreplay,tcpcopy, or a logged-request replayer) is ideal. - Compare outputs on a sample (100–1000 requests) against the 0.3 production behaviour. Diff on:
- Response content (fuzzy — LLM outputs vary; look for catastrophic drift, not token-level diffs).
- Tool-call counts per turn (should be within +/- 1 on average; a big delta means the ReAct prompt changed behaviour).
- Latency p50/p95 (LangGraph adds a small state-serialisation cost; watch for regressions > 20%).
- Error rate (target: zero new
ImportError,AttributeError, orKeyErroronintermediate_steps).
- Exit criteria for Phase 4: 24h of shadow traffic with no new error classes and no regression on the four metrics above.
Phase 5 — Feature-flagged production cutover
- Put the 1.0 entrypoint behind a feature flag (
LANGCHAIN_1_0_ENABLED). Default off. - Canary: flip on for 1% of traffic. Watch dashboards for 30 minutes.
- Ramp: 10% → 25% → 50% → 100% over 2–4 hours, with a 15-minute soak at each step.
- At each step, the on-call engineer owns the rollback call. Rollback is always "flip the flag off" — not a redeploy.
Phase 6 — Pin and clean up
- After 100% for at least one full day, remove the feature flag and the 0.3 code path.
- Pin
langchain,langchain-core,langgraph,langchain-openai,langchain-anthropic, andanthropicto exact versions inrequirements.txt. This prevents a drive-by dependency update from re-introducing a 0.3 compatibility shim or a breaking 1.1 change. - Delete the 0.3 dual-write path and, after the retention window, the 0.3 chat history store.
- Archive
requirements.lock.pre-1.0.txtin the repo for one release cycle; delete after that.
Rollback Plan
If Phase 5 reveals a regression:
- Flip the flag off. This is always step one. Traffic returns to the 0.3 code path within seconds.
- If the 0.3 code path has already been deleted (you are past Phase 6):
pip install -r requirements.lock.pre-1.0.txton the rollback branch, redeploy. This is a hard rollback and takes one deploy cycle. - If persistent chat histories are involved, restore from the Phase 0 snapshot if the schema drift corrupted any 0.3-readable data. In practice, dual-write (Phase 3) prevents this — do not skip dual-write if you have persisted histories.
Exit Criteria (Migration is Done)
- Zero hits on the verification greps in breaking-changes-matrix.md.
pytest -W error::DeprecationWarningis green.LANGCHAIN_1_0_ENABLEDflag is removed and all callers go through the 1.0 path.requirements.txtpins all six packages to exact 1.0.x versions.- Post-mortem note in the repo: what broke, what the grep audit missed, so the next major bump is cheaper.