Repository navigation
docs(langgraph): document emit API to v2 hook mapping end-to-end - #5483
BenTaylorDev merged 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@nuthalapativarun is attempting to deploy a commit to the CopilotKit Team on Vercel. A member of the Team first needs to authorize it. |
|
Checking in on this one — tried to give the emit API to v2 hook mapping for langgraph a thorough end-to-end writeup since that mapping trips people up. The failing Vercel check is just the fork auth gate, not a real failure. Happy to adjust if needed. |
|
Thanks @nuthalapativarun — the new
Also note this is coupled with #5469 (its new section links here), so we'll land the pair together. |
BenTaylorDev
left a comment
There was a problem hiding this comment.
Nice page — it's correctly authored under showcase/shell-docs/, and the emit-API mapping checks out (copilotkit_emit_tool_call / copilotkit_customize_config signatures and the useFrontendTool/useComponent hooks all match current source; no equivalent page exists yet). Two fixes before merge:
- Drop the bundled
use-agent.tsxchange. The PR also editspackages/react-core/src/v2/hooks/use-agent.tsxto add anisReadyfield — butisReadyalready exists onmainwith a fuller implementation, so this reintroduces a conflicting, inferior duplicate (it's the source of the merge conflict) and is unrelated to the docs. The.mdxnever references it. - Fix the "See also" links. They use the
/langgraph/...prefix, but the docs route these under/integrations/langgraph/...— sofrontend-tools, the generative-UI display-only page, andadvanced/disabling-state-streamingall 404 as written. The/reference/v1/sdk/python/LangGraphlink has no target page at all — drop or replace it.
With the source edit removed and the links corrected, this is good to go.
Adds a new page under integrations/langgraph/advanced/ explaining how LangGraph SDK backend emit functions (copilotkit_emit_tool_call, copilotkit_customize_config) connect to React v2 frontend hooks (useFrontendTool, useComponent). Includes a mapping table, two concrete end-to-end examples, and a decision guide. Closes CopilotKit#3301
Point "See also" links at the /integrations/langgraph/ prefixed routes (the bare /langgraph/... links 404), drop the dead Python SDK reference link (no target page), and swap the placeholder "gpt-5.4" model string for a real one (gpt-4o) in both code samples. Addresses review feedback on CopilotKit#5483. The unrelated use-agent.tsx isReady change was dropped by rebasing this branch onto upstream/main and carrying forward only the docs commit — isReady already ships on main via CopilotKit#6041.
0a4ed31 to
9f7fef1
Compare
|
Thanks for catching both! Pushed a fix:
This should also unblock #5469, which links to this page's now-correct route. |
BenTaylorDev
left a comment
There was a problem hiding this comment.
Re-approving — both blockers are fixed: the conflicting use-agent.tsx edit is dropped (the PR is now just the .mdx), and the "See also" links are corrected to /integrations/langgraph/... (all three targets exist on main) with the invented python-reference link removed. Content matches the current emit-API signatures. One cosmetic nit (non-blocking): the at-a-glance table shows copilotkit_emit_tool_call(config, name, args) positionally while name/args are keyword-only — the step-by-step example below it uses the correct form.
I bless the code with a glad heart.
❌ Showcase Build FailedThe Docker build triggered by this PR's merge failed. Run: https://github.com/CopilotKit/CopilotKit/actions/runs/30162754730 @nuthalapativarun — please check the build logs and fix the issue. |
…hat it actually shipped (#6171) ## The hole A partially-cancelled showcase build was **indistinguishable from a clean one in both directions**: it emitted no alert, and it suppressed post-deploy verification — while having actually redeployed real images to staging. Three merges landed on `main` on 2026-07-25 with **zero post-deploy verification**. Reconstructed from the API, with run IDs: | # | build run | conclusion | what happened | |---|---|---|---| | #5483 | `30162754730` | cancelled | `shell-docs` killed at 10m04s. Alert **did** fire (all-failed path). No verify. | | — | `30162770765` | cancelled | `shell` killed at 10m04s. **Silent.** No verify. | | #6160 | `30162773601` | cancelled | 5 slots killed, **23 redeployed to staging**. **Silent.** No verify. | | #6168 | `30162784491` | success | clean — and its verify was then cancelled by a sibling. | ### The chain, for run `30162773601` 1. #6160's workflow edit forced a full-fleet rebuild. Five slots died — `shell`, `shell-docs`, `shell-dashboard`, `shell-dojo`, `showcase-aimock`. 2. The intersection guard correctly excluded them. `redeploy-staging` **succeeded** and uploaded `redeploy-summary`, redeploying the 23 that built. 3. The run concluded **`cancelled`** (5 legs cancelled, 0 failed → GitHub rolls the run up to `cancelled`). 4. `notify` was **skipped** → no Slack, no PR comment. 5. `showcase_deploy.yml` requires `conclusion == 'success'` → never started. 23 services redeployed, unverified. 6. The one legitimate verify — run `30163309977`, from #6168's successful build — started 15:17:13 and was **cancelled at 15:17:22** by run `30163312882`, which was triggered by a *different* partially-cancelled build and then skipped every job anyway. ## Which links I verified in the YAML, and where the brief was wrong | Link | Verdict | |---|---| | Intersection guard excludes cancelled slots | ✅ Confirmed — `showcase_build.yml` `redeploy-staging` intersects matrix ∩ `status == "success"`. | | Run concluded `cancelled`, not failure/success | ✅ Confirmed via API on all three runs. | | `showcase_deploy.yml` requires `conclusion == 'success'` | ✅ Confirmed verbatim on `resolve-matrix`. | | Global `showcase-verify-deploy` concurrency group preempted a sibling | ✅ Confirmed — group had no commit key, `cancel-in-progress: true`; timestamps above show the 9-second preemption. | | **`notify`'s condition is `if: failure()`** | ❌ **Wrong.** It is already `!cancelled() && (failure() \|\| any_success == 'false')`. | | **The suppressor is `failure()` not matching `cancelled`** | ❌ **Wrong, and the proposed fix would not have worked.** See below. | | **Depot `Step canceled by GitHub` is a flake** | ❌ **Wrong.** It is a `timeout-minutes` kill. See "Root cause". | ### Why `if: failure() || cancelled()` would NOT have fixed this I built a throwaway probe workflow on a scratch branch — a matrix with one leg killed by `timeout-minutes` and one green leg, plus dependent jobs guarded by each candidate expression. **Probe run [`30166429073`](https://github.com/CopilotKit/CopilotKit/actions/runs/30166429073)**: | probe | result | conclusion | |---|---|---| | killed leg's `job.status` | `cancelled` | a timeout kill reports as *cancelled* | | matrix rollup `needs.legs.result` | `cancelled` | | | `if: cancelled()` | **SKIPPED** | `cancelled()` evaluated **FALSE** | | `if: failure()` | **SKIPPED** | `failure()` evaluated **FALSE** | | pre-fix `notify` condition | **SKIPPED** | ← the bug, reproduced | | post-fix `notify` condition | **RAN** | ← the fix, proven | | workflow run conclusion | `cancelled` | matches production | `cancelled()` is **workflow-scoped**: ["Returns `true` if the workflow was cancelled."](https://docs.github.com/en/actions/reference/evaluate-expressions-in-workflows-and-actions) Individual legs dying does not cancel the *run*, so it is false. And `failure()` ["returns `true` if any ancestor job fails"](https://docs.github.com/en/actions/reference/evaluate-expressions-in-workflows-and-actions) — a **cancelled** ancestor did not *fail*, so it is false too. With 23 slots green, `any_success` is `'true'`. Every clause the old guard had went the wrong way. Independently corroborated in production: in run `30162773601`, both `!cancelled()`-guarded jobs (`aggregate-build-results`, `redeploy-staging`) **ran**, which is only possible if `cancelled()` was false. ## Root cause of the cancellations: a timeout, not a flake From the Depot log of the killed `shell` leg: ``` 15:04:03 depot build --file showcase/shell/Dockerfile ... --push 15:13:29 #25 [builder 15/15] RUN cd scripts && ... generate-registry.ts DONE 54.3s 15:13:32 failed to solve: Canceled: context canceled 15:13:32 ##[error]Step canceled by GitHub 15:13:32 BUILD_STATUS: cancelled ``` Started 15:03:28, killed 15:13:34 — **exactly `timeout-minutes: 10`**. Same for the other three shell slots; `showcase-aimock` died at exactly its 5. The build was making real but slow progress the whole time (repeated docker.io base-image pull stalls, `#9 ...` for seven minutes) and was 2 steps from done. So **a retry is the wrong lever twice over**: a cancelled job cannot run further steps, and the build was not erroring. The underlying cause is Depot builder contention — three full-fleet rebuilds ran concurrently (~84 simultaneous amd64 builds). Measured budgets: | slot | warm | contended | budget | |---|---|---|---| | shell / shell-docs / shell-dashboard / shell-dojo | 2–5 min | killed at 10 | **10 → 20** | | showcase-aimock | 2 min | killed at 5 | **5 → 12** | | showcase-pocketbase | — | **8.8 min** (near-miss) | **10 → 15** | | webhooks | 0.6 min | — | 5 (unchanged, `skip_build`) | The `context: "."` slots build the whole monorepo root and are the heaviest in the fleet, yet carried the *smallest* budgets — inverted. ## The design **1. Stop laundering the signal** (`build-outputs.ts`, per-slot writer). `cancelled` becomes a first-class `BuildOutcome` instead of being mapped to `skipped`. The per-slot result is the *only* place the cancellation survives, because the status functions can't see it. `successSet` still excludes it, so the redeploy intersection is unchanged — a slot that pushed no image still cannot enter the redeploy CSV. **2. Alert on it** — aggregator publishes `any_cancelled` + `cancelled_services`; `notify` gains an `any_cancelled == 'true'` clause (the exact expression proven by the probe), and its PR comment now distinguishes *incomplete* from *failed*. **3. Red the run, don't leave it `cancelled`** — new `notify-cancelled-builds` job exits non-zero, so the conclusion is `failure`. A slot killed by its timeout budget *is* a failure, and `cancelled` is precisely what suppressed everything downstream. **4. Verify the partial deploy anyway** — the `conclusion == 'success'` gate becomes a terminal-conclusion allowlist (`success|failure|cancelled|timed_out`). > **Tradeoff, stated plainly.** Relaxing the gate rather than only failing loudly is deliberate: a build that redeployed 23 services *needs* verifying, and gating on `success` guaranteed it never would. It is safe because the decision of *what* to verify never depended on the rollup — no `redeploy-summary` artifact still means `has_services=false` and verify is skipped, and the redeploy gate still narrows to the per-service success set, so a cancelled slot can never be probed against a stale `:latest` and reported healthy. The cost is one extra no-op deploy run for builds that die before redeploying. Note this *also* fixes the same hole for `conclusion == 'failure'`, which was equally unverified. **5. Key verification per commit** — `showcase-verify-deploy-${{ github.event.workflow_run.head_sha || github.sha }}`, so a later cancelled run can no longer destroy an earlier successful run's verification. `cancel-in-progress: true` is kept, so re-verifying the *same* commit still supersedes. (`github` context is [documented as available](https://docs.github.com/en/actions/reference/workflows-and-actions/contexts) in `concurrency`.) **6. Realistic timeout budgets** — separate commit, droppable independently. Mitigation, not the root fix; the durable lever is a non-cancelling concurrency queue on the build workflow, noted inline as a follow-up since this workflow deliberately has *no* concurrency group. ### On alerting for a genuine manual cancel It stays **silent**, and that is correct. `!cancelled()` is retained on both notify jobs as the flake-vs-intentional discriminator, and the probe proves it discriminates: a human cancelling the whole RUN makes `cancelled()` true → silent; a leg-level timeout leaves it false → alerts. Belt and braces — on a run-level cancel, `aggregate-build-results` is itself skipped by its own `!cancelled()` guard, so `any_cancelled` resolves to `''` rather than `'true'`. Two independent reasons for silence, zero manual-cancel noise. ## What I proved - **Real end-to-end red-green on GitHub Actions** — probe run [`30166429073`](https://github.com/CopilotKit/CopilotKit/actions/runs/30166429073), table above. Old condition skipped, new condition ran, on a genuinely timeout-killed matrix leg. Scratch branch deleted; the run is permanent. - **Local red-green on the TS layer** — 8 tests failing before the fix (`cancelledSet is not a function`, `invalid "status" (must be success|failure|skipped)`), 46 passing after. - **Local red-green on the live workflow expression.** `redeploy-guard.test.ts` parses the **actual `if:` strings out of the YAML** and evaluates them. Pointed at `origin/main`'s YAML, the new `GREEN: the live guard FIRES on the production partial-cancel` test fails (`expected false to be true`) and is the *only* failure; pointed at this branch, all 31 pass. The pre-fix guard is pinned as a literal so the test permanently encodes the difference rather than just the current behaviour. - **No new alert noise** — explicit tests that `notify` stays silent on a clean build, on a human run-cancel, and on a no-changes push. That last one exposed a latent inaccuracy in the test harness's own model (a skipped aggregator's outputs are `''`, not `'false'`), now fixed. - **Lint** — `actionlint` finding count unchanged at 10 vs the `origin/main` baseline (all pre-existing: the unknown `depot-ubuntu-24.04-4` label and shellcheck `info` notes on untouched scripts). `zizmor` with the repo's own config at `min-severity: low`: *No findings to report*. - **Suite** — 77 tests green across the three touched files. Full `showcase/scripts` suite has 5 pre-existing failing files (`emit-railway-envs-json`, `generate-catalog`, `generate-registry`, `integration-smoke-registry`); I reproduced the identical 5 files / 8 tests on a pristine `origin/main` worktree, so they are unrelated to this change. ## What remains unproven until it runs on `main` - The **production** partial-cancel path end-to-end. The probe reproduced the expression semantics on a synthetic matrix, not the real 28-slot fleet with real Depot builds; the Slack message and PR-comment rendering have not been exercised against a live webhook. - The relaxed deploy gate firing on a real `cancelled`/`failure` build — including the "no artifact → skipped, no noise" path. - The per-commit concurrency group under real rapid-fire merges. - Whether 20 minutes is actually enough for `shell` under peak Depot contention. It was ~3 steps from done at 10; 20 is inference from that, not measurement. `\n` handling in the new Slack payload follows the existing `fromJSON('"\n"')` convention in this file, but is not verified against a live webhook.
What does this PR do?
Adds end-to-end documentation showing how LangGraph SDK backend emit APIs (
copilotkit_emit_tool_call,copilotkit_customize_config) connect to React v2 frontend hooks (useFrontendTool,useComponent). Includes a mapping table and a concrete code example demonstrating the full wiring from a LangGraph node to a frontend tool handler. Addresses the documentation gap reported in #3301.Related PRs and Issues
useComponent,useFrontendTool, etc.) #3301Checklist