Repository navigation
fix(angular): resolve human-in-the-loop results without the bus envelope - #6586
Conversation
0f98a7b to
053c5a6
Compare
HumanInTheLoop.onResult resolved with the whole rxjs bus event
({toolCallId, toolName, result}) instead of the bare result, because
lastValueFrom was not mapped. The bound tool handler returns that promise
directly as the tool's result, and run-handler JSON.stringifies a non-string
return into the tool message content, so agents received
{"toolCallId":...,"toolName":...,"result":{...}} where React sends the bare
value.
A LangGraph agent gating a side effect on a field of the human's answer
therefore reads that field off the envelope, finds nothing, and falls through
silently while the model still reports the action succeeded.
The existing tests asserted the envelope as expected behaviour, which is why
this went unnoticed; they now pin the bare result, plus a case that fails if
the routing keys leak again.
Reported in CopilotKit#6571, which attributes the envelope to @ag-ui/langgraph. It
originates here. The missing ToolMessage.name in that issue is a separate
defect and is not addressed by this change.
053c5a6 to
53f856a
Compare
@copilotkit/a2ui-renderer
@copilotkit/agentcore-runner
@copilotkit/angular
@copilotkit/channels
@copilotkit/channels-core
@copilotkit/channels-discord
@copilotkit/channels-intelligence
@copilotkit/channels-slack
@copilotkit/channels-teams
@copilotkit/channels-telegram
@copilotkit/channels-ui
@copilotkit/channels-whatsapp
@copilotkit/core
@copilotkit/react-core
@copilotkit/react-native
@copilotkit/react-textarea
@copilotkit/react-ui
@copilotkit/runtime
@copilotkit/runtime-client-gql
@copilotkit/sdk-js
@copilotkit/shared
@copilotkit/sqlite-runner
@copilotkit/voice
@copilotkit/vue
@copilotkit/web-components
@copilotkit/web-inspector
commit: |
BenTaylorDev
left a comment
There was a problem hiding this comment.
Thanks for this — the diagnosis is right, and the writeup on #6571 that separated this
half from the upstream half saved us real time. I verified the fix independently rather
than taking the tests at their word:
- Reverting only
human-in-the-loop.tsto main's version while keeping your three specs
fails all three (Received: "request_page_oncall"on the leak guard). They bind to the
mechanism — not self-fulfilling. onResulthas exactly one production consumer (packages/angular/src/lib/copilotkit.ts:530),
so the change is complete in code.- I read React and Vue directly to check the direction of the parity claim: both resolve the
bare result, so this moves Angular toward them. - Full Angular suite is 290/291 with the fix; the one failure reproduces on clean
main
without your branch.
One change needed before merge
The envelope is documented as behavior, so merging as-is leaves three sentences actively
wrong in showcase/shell-docs/src/content/reference/angular/functions/registerHumanInTheLoop.mdx:
- line 8 — "resolves the tool with the serialized result envelope described below"
- line 112 — "The current implementation resolves the internal handler with
{ toolCallId, toolName, result }; core serializes that object to JSON for the tool result." - line 178 — "sends
\"confirmed\"or\"rejected\"in the serialized result envelope
described above"
This matters more than a stale doc usually would. onResult returns Promise<unknown>, so
TypeScript cannot catch a consumer that assumed the envelope — the doc is the only thing
telling Angular users what shape to expect, and after this change it would steer them into
result.result, which is the same class of bug the PR fixes.
It's hand-written MDX, not generated, so it won't self-correct. Once those three read as the
bare result, this is good to go from my side.
registerHumanInTheLoop.mdx documented the { toolCallId, toolName, result }
envelope as intended behavior. After the fix the tool result is the value
passed to respond(), so the three sentences describing the envelope would
steer readers toward result.result.
|
Good catch on the docs — agreed that with Pushed the fix: all three sentences in Thanks for reverting the source to confirm the specs bind to the mechanism — that's the check I'd want too. |
BenTaylorDev
left a comment
There was a problem hiding this comment.
The docs ask is resolved — thank you for going past what I asked. All three sentences read as the bare value now, and line 112 additionally spells out the serialization rule (string stored as-is, anything else JSON.stringify'd by core) and states the parity with React and Vue. Since onResult returns Promise<unknown> and TypeScript can't catch a consumer that assumed the envelope, that paragraph is now doing the work the type system can't. The only remaining mention of the envelope in the file is the correct negation.
I re-verified against the current tree rather than trusting the earlier round, since main has moved twice under this branch:
- Mutation check still holds. Reverting only
human-in-the-loop.tsto main's version, with everything else at your head, fails all three specs — including the leak guard. Restore it and they pass. They bind to the mechanism, not to themselves. - Differential full-suite run, with and without the fix: zero regressions. The fix flips exactly your three specs from red to green and moves nothing else.
tsc --noEmit: no errors in anything this PR touches.- No drift. Main hasn't touched any of the three files since your last merge, and there are no conflicts against current main.
One note for whoever writes the release line: this is a behavior change, not just a fix. Any app that had worked around the leak by reading .result off the envelope itself will need to drop that workaround. Worth calling out explicitly, since the failure mode on the other side is silent.
Nice diagnosis on this one — separating the Angular half from the upstream ToolMessage.name half on #6571 is what made it tractable, and the comment you left on the map explaining that toolCallId/toolName are routing keys for that bus only is the kind of thing that stops this regressing in a year.
I bless the code with a glad heart.
|
The CI timeouts are a known issue predating this PR, and the tests covering these changes are green. |
|
## What's broken
Every GitHub Release this repo has ever cut has a body of `Release
<tag>` and nothing else — `v1.70.0`, `v1.69.3`, `channels/v0.6.0`,
`angular/v0.4.0`, all of them. The `#engr` Slack announcement links
"Release notes" at that page, so that link has always pointed at a blank
release.
The notes *were* being generated. The `angular/v0.5.0` create-pr run
logged:
```
Raw release notes written to release-notes.md
Generating AI-enhanced release notes...
AI-enhanced release notes written to release-notes.md
```
They just never left the runner. `release-notes.md` was gitignored
(`.gitignore:72-73`), so `peter-evans/create-pull-request` skipped it,
the file never reached the release branch, and `publish-release.yml`'s
`readFileSync("./release-notes.md")` missed and fell through to `body =
\`Release ${name}\``.
The same ignore rule severed the Notion round-trip:
`release-notes-notion.json` was ignored too, so the publish job could
never read an edited draft back. That path had never run either.
Meanwhile the repo carried **29 changelog files that no tooling had
written since April**. They are changesets-era leftovers, and nothing in
`scripts/` or `.github/` reads or writes them:
```
$ git grep -n "CHANGELOG" -- 'scripts/**' '.github/**' '*.json' ':!*/CHANGELOG.md'
(no matches)
```
They stopped at `1.55.2` while the monorepo lane shipped `1.69.3`, and
`packages/angular/CHANGELOG.md` still claimed `1.54.3` — a version from
before angular split onto its own `0.x` line. So the only changelog a
reader could find in the tree named the wrong version for the wrong
lane.
## What this changes
**1. The notes become a source-controlled changelog, one file per
release lane.**
| lane | file |
|---|---|
| `monorepo` | `CHANGELOG.md` |
| `angular` | `packages/angular/CHANGELOG.md` |
| `channels` | `packages/channels/CHANGELOG.md` |
Per lane rather than one root file because the lanes version
independently: a shared file would interleave `1.70.0`, `angular/0.5.0`
and `channels/0.9.0` into one sequence where no reader can follow any
single line. (Concurrent writes are *not* the reason —
`stable-release.yml` already fails if any release PR is open.)
The flow: `prepare-release.ts` writes the raw notes,
`generate-ai-release-notes.ts` polishes them, **`write-changelog.ts`**
prepends them as this version's section, `create-pull-request` commits
the changelog (a tracked file, so `git add -A` always stages it), and
**`extract-release-notes.ts`** reads that section back in the publish
job as the GitHub Release body.
The changelog is therefore both the durable record and the review
surface: edit the top section on the release PR to change what ships.
`release-notes.md` goes back to being gitignored scratch, so the same
notes never exist as two editable copies with no rule about which one
wins.
**2. The 29 stale changelogs are deleted**, and a test pins the tracked
changelog set to exactly the three lane files, so they cannot creep back
and contradict the real versions again. Their content stays recoverable
from git history (`git show v1.69.3:packages/core/CHANGELOG.md`).
**3. Notes are selected per PR, scoped to the lane.** Selection was
`--no-merges` over every commit since the scope's tag. Two bugs:
- *No path filter* — a scope inherited every other lane's work.
- *`--no-merges` is backwards here* — this repo merges PRs as merge
commits, so the merge **is** the unit of change and the only commit
carrying `(#1234)`. `--no-merges` dropped every PR boundary and kept the
intermediate branch commits.
Now: `--first-parent` over the scope's package directories, minus
commits no consumer would read about (`test`/`ci`/`style`, `chore`
except `chore(deps)`, and the release commit itself).
| scope | before | after |
|---|---|---|
| `angular` v0.5.0 | 159 entries | **4** |
| `channels` (unreleased) | 600+ entries | **9** |
**4. Breaking-change footers still survive.** `--first-parent` alone
silently dropped `BREAKING CHANGE:` footers written on branch commits
rather than in the PR description — measured at **2 of 2 lost** across
`v1.60.0..HEAD`. Each merge's branch messages are now folded into its
body before extraction, so the entry list stays one-per-PR while the
footer scan sees the whole PR. Re-measured: **0 lost**.
**5. The AI prompt is scoped and the API call is correct.** It was
passing a repo-wide `git log -50` as "context" and asserting the release
was "CopilotKit vX.Y.Z, an open-source AI agent framework for React
applications" — wrong commits, wrong framing, and wrong release title
for any non-monorepo lane. Now it gets the lane's own commits, the names
of the packages actually being published, and an instruction to write
about nothing else. Also fixed in the same call: `max_tokens: 2048`
(truncates a large release mid-section, and the truncated text is what
ships as the body), and a response reader that took `content[0].text`
rather than selecting the text block by type. The model pin is left
alone — `main` already carries a current, undated id.
**6. Notion is removed**, not repaired — the release PR is already the
review surface.
### Failure behavior on the publish side
`extract-release-notes.ts` runs **after** `npm publish`, so it never
exits non-zero: failing there would leave the packages published and the
tag unpushed. A missing section prints a `::error::` annotation and
falls through to the workflow's existing `Release <tag>` fallback. Worst
case is the blank body we have today, never a half-finished release.
## Testing
Baseline on `main`: `15 files / 162 tests`. On this branch: **`16 files
/ 197 tests`**.
```
$ npx vitest run --config scripts/release/vitest.config.mts
Test Files 16 passed (16)
Tests 197 passed (197)
```
**The whole lane round-trips end to end.** A real `prepare-release.ts
--scope channels --bump minor` run (versions reverted afterward), then
the two new halves:
```
$ pnpm tsx scripts/release/write-changelog.ts 0.10.0 channels
Recorded 0.10.0 in packages/channels/CHANGELOG.md
$ rm release-notes.md
$ pnpm tsx scripts/release/extract-release-notes.ts 0.10.0 channels
Release body written to release-notes.md from packages/channels/CHANGELOG.md (861 chars)
```
The extracted body is the 9 PR-numbered entries under Features / Fixes /
Other, with **no duplicated version heading** (`grep -c '^## '
release-notes.md` → `0`) — the raw generator's own `## v0.10.0
(channels)` line is stripped when the section heading is written. The
miss path was exercised too:
```
$ pnpm tsx scripts/release/extract-release-notes.ts 9.9.9 channels
::error title=Release notes::No section for 9.9.9 in packages/channels/CHANGELOG.md. ...
exit: 0
```
**The staging behavior is verified against the pinned action, not
assumed.** `peter-evans/create-pull-request@5f6978f` stages with `git
add -A` when `add-paths` is unset. In-repo, after a real notes run:
```
$ git add -A --dry-run | grep -iE "changelog|release-notes"
add 'packages/channels/CHANGELOG.md'
$ git check-ignore -v release-notes.md
.gitignore:77:release-notes.md release-notes.md
```
The changelog is staged; the scratch file is invisible to the commit.
The publish job checks out `ref: main` at `fetch-depth: 0`, and the
release PR merges the changelog into main, so the section is present
when the extractor runs.
**The selection reproduces a hand-curated list exactly.**
`angular/v0.5.0`'s release body was written by hand from its four real
PRs. Running the new selection over that same range returns exactly
those four, release commit correctly dropped:
```
#6098 feat(runtime): use managed Intelligence authority (#6098)
#6756 chore(deps): bump @ag-ui/* to 0.0.59 (#6756)
#6773 feat(angular): add registerComponent ... (refs OSS-1034) (#6773)
#6586 fix(angular): resolve human-in-the-loop results without the bus envelope (#6586)
```
**Breaking-change regression measured, not assumed** — differential
comparison of extracted notes, old selection vs new, over two ranges:
```
range v1.60.0..HEAD old: 2 new: 2 LOST: 0
range v1.50.0..HEAD old: 2 new: 2 LOST: 0
```
(Before the fold was added, the same probe reported `LOST: 2` — that is
how the bug was caught.)
**Every new test was mutation-checked** — the mechanism was broken and
the test confirmed failing:
| mutation | result |
|---|---|
| `--first-parent` → `--no-merges` | 2 failed |
| drop the pathspec filter | 2 failed |
| `isNoiseCommit` always false | 2 failed |
| `parsePrNumber` always null | 2 failed |
| `withBranchMessages` → no-op | 1 failed |
| code-fence tracking disabled | 1 failed |
| `stripVersionHeading` → no-op | 3 failed |
| `prependSection` appends instead | 1 failed |
| `extractSection` keeps the heading | 5 failed |
| `upsertSection` stops replacing | 1 failed |
| re-ignore a lane changelog | 1 failed |
| re-ignore all `packages/*/CHANGELOG.md` | 2 failed |
| an orphan changelog creeps back | 1 failed |
| a lane changelog goes missing | 1 failed |
| *(restored)* | **all green** |
One of those mutations found a bug **in the test itself**: `git
check-ignore <path>` reports nothing for a path that is already tracked,
so the ignore assertion passed against a rule that would still strand
the next lane's file. It now runs `git check-ignore --no-index`, and the
mutation fails as it should. The flagless form is why the row above
exists at all.
Also run: `verify-release-scope-dropdowns.sh` (all OK), YAML parse of
both edited workflows, `oxfmt` (no-op after formatting), `oxlint` (0
warnings, 44 files).
**Not verified:** the live Claude API call. No `ANTHROPIC_API_KEY` was
available locally, so only the no-key fallback path (raw changelog) and
the CLI arg validation were exercised. A generation failure is already
caught and falls back to the raw notes, so the worst case is un-polished
notes rather than a blank body.
The commit is `--no-verify`: the pre-commit nx lane cannot run in this
worktree (`packages/core` and `packages/channels-ui` have no
`node_modules`, and `nx run @copilotkit/core:build` fails identically
with the tree clean). The only change under `packages/**` is deleting
orphan markdown that no build or test reads. CI on this PR runs the real
lane.
## Not in this PR
Slack-side drafting/massaging in a dedicated channel, with write-back to
the release body. Deliberately separate — that lane needs its own
channel and webhook, and must not run through `#engr`. The `notify` job
and the `#engr` announcement are untouched here.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Release notes are now organized by release lane and recorded in
dedicated changelogs.
* GitHub Releases can automatically use the matching lane changelog
section.
* Release notes are scoped to packages included in each release lane.
* **Documentation**
* Added guidance for supported release lanes and changelog workflows.
* **Changes**
* Historical package and example changelog entries were removed or
replaced with the lane-based format.
* Notion-based release-note drafting and PR links are no longer used.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
|
Checked the build logs. This isn't a build failure, and it isn't All 19 slots died at the same instant, 20:51:44-50, exactly 15 minutes after they started at 20:36:43. The per-slot budgets in the matrix are 25 and 30 minutes, so nothing had come close to its own timeout. The log ends with: An external cancellation of the run, not a slot exceeding its budget. Nothing in the diff could have caused it: this PR touched one Angular Nothing to fix here, and nothing is stale on staging. Every Two things worth doing separately, if anyone wants to pick them up:
|
…Kit#7327) Picks up the second half of CopilotKit#6571, the part CopilotKit#6586 deliberately left alone. ## The bug `convertMessageToLangChainMessage` builds a `ToolMessage` from a `ResultMessage` and drops the tool's identity on the floor: ```ts // packages/runtime/src/v1-deprecated/service-adapters/langchain/utils.ts (before) } else if (message.isResultMessage()) { return new ToolMessage({ content: message.result, tool_call_id: message.actionExecutionId, }); } ``` `ResultMessage` already carries `actionName`. It just never gets passed. The two halves of the same round trip disagree about this. The `ActionExecutionMessage` branch twenty lines up already passes `name` through onto the `AIMessage`'s tool call, so a chain sees the name on the way out and then loses it on the way back. ## Why it matters `ToolMessage.name` is the field LangChain consumers route on. With it unset, a chain behind `LangChainAdapter` that matches on tool identity falls through silently. Nothing throws, nothing logs, the branch just never runs and the model carries on as if it had. That is the same failure shape CopilotKit#6571 describes: the evidence of a working gate and the evidence of a gate that never fired are identical from inside the app. The only workaround available to a consumer is to walk back through the message list to the `ActionExecutionMessage` whose id matches `tool_call_id` and read the name off that. That is work the adapter is better placed to do, and it is exactly the lookup `sdk-python/copilotkit/copilotkit_lg_middleware.py:840` already does on the Python side, where `name` is set correctly from the matching tool call. This brings the TypeScript adapter in line with it. ## The fix One field, plus a comment saying why it's there. ## Tests New `utils.test.ts`, four specs. Two pin the name, two guard against collateral damage: - name is carried onto the `ToolMessage` - `tool_call_id` and `content` are untouched - the name round-trips: `convertedResult.name` equals the `name` on the `AIMessage`'s tool call produced from the matching `ActionExecutionMessage` - text messages still convert to `HumanMessage` Reverting only `utils.ts` and keeping the specs fails the two that pin the name (`expected undefined to be 'request_page_oncall'`) and passes the other two, so they bind to the mechanism rather than to themselves. Differential full-suite run on `packages/runtime`, with and without the change: identical failure set either way (105 files / 8 tests, all pre-existing and all from workspace deps that aren't built in a fresh checkout — `Cannot find module '@copilotkit/shared/...'` and friends). The change adds exactly one passing file and four passing tests and moves nothing else. `tsc --noEmit` reports no errors in either touched file; the 35 it does report are the same unbuilt-dependency errors and are present on clean `main`. ## Scope `convertMessageToLangChainMessage` has one caller, `langchain-adapter.ts:106`. Nothing reads `ToolMessage.name` inside this repo, so nothing here depended on it being unset. This is a behavior change for anyone downstream who had worked around the gap by reading the name out of the message list themselves. Their workaround keeps working, since it reads the `ActionExecutionMessage`, not this field. Worth a release note anyway. ## Still not addressed The upstream half. `@ag-ui/langgraph`'s `aguiMessagesToLangChain()` omits `name` in its `case "tool"`, and the root cause is that `ToolMessageSchema` in `@ag-ui/core` is the only message role without a `name` field. That is not fixed in `0.0.43` — that release only added `status` — so bumping the `0.0.42` pin in `packages/runtime/package.json` and `packages/sdk-js/package.json` will not help. It needs a change in those packages, not this one. One correction to a note I left on CopilotKit#6586: I flagged `examples/showcases/scene-creator/agent/agent.py:743` as a live instance of this bug. It isn't. The tools it routes on are backend tools executed by LangGraph's `ToolNode`, which sets `name` itself, so that read is fine. My mistake. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Tool results now retain the originating action name when converted to LangChain messages. - Consumers can identify which tool produced a result directly from the converted message. - Added coverage to verify tool identifiers, content, and text message conversions remain intact. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Fixes the Angular half of #6571.
The bug
HumanInTheLoop.onResultpipes the rxjs bus throughfilter+take(1)but never maps, solastValueFromresolves with the whole bus event rather than the result the human supplied:toolCallIdandtoolNameare routing keys for this bus only. Leaking them turns the tool result into an envelope, and the chain carries it all the way to the agent:copilotkit.ts:534— the bound HITL tool handler returnsonResult(...)directly as the tool's result.packages/core/src/core/run-handler.ts— a non-string handler return isJSON.stringify'd into the tool messagecontent.So a LangGraph agent receives:
{"toolCallId": "call-1", "toolName": "request_page_oncall", "result": {"approved": true}}where React sends the bare
{"approved": true}—use-human-in-the-loop.tsx:24resolves the handler promise withresultitself. This is a cross-framework inconsistency as much as a bug: the same agent cannot serve both adapters.Why it matters
An agent gating a side effect on a field of the human's answer reads
approvedoff the envelope, finds nothing, and the gate silently never fires — while the model still reports the action succeeded. That is the failure #6571 describes: the gated node never runs, so the side effect's audit trail stays clean, and a clean audit trail is exactly what a correctly working gate looks like from inside the application.The fix
Map to the bare result:
Tests
The two existing tests asserted the envelope as correct behaviour, which is why this survived:
They now pin the bare result, and a third test fails if the routing keys leak back in. Verified that all three fail with the fix reverted and pass with it.
nx run @copilotkit/angular:test→ 304 passed;check-typesandbuildclean.Scope
onResultis called only from#bindHumanInTheLoopTool(copilotkit.ts:534); the sole other spec that touches it mocks the method wholesale, so nothing else depends on the old shape. Any app that had worked around the leak by reading.resultitself would need to drop that workaround — worth a line in release notes.Not addressed here
#6571's primary claim — that
ToolMessage.nameis unset — is a separate defect and is untouched by this PR. For the record, since the issue attributes both symptoms to@ag-ui/langgraph:{toolName, result}envelope does not come from@ag-ui/langgraph. It originates in this file. Grepping that package for it turns up nothing, which risks the whole report being discounted.nameis in@ag-ui/langgraph—aguiMessagesToLangChain(),case "tool"omits it. It is not fixed in 0.0.43; that release only addedstatus, so bumping the pin from0.0.42will not help. The root cause is thatToolMessageSchemain@ag-ui/coreis the only message role without anamefield. The adapter can still recover it by matchingtoolCallIdagainst the preceding assistant message'stoolCalls[]in the same loop —sdk-python/copilotkit/copilotkit_lg_middleware.py:809andlanggraph.py:129already do exactly that lookup.Two related spots worth separate fixes:
packages/runtime/src/service-adapters/langchain/utils.ts:45builds aToolMessageand discardsmessage.actionName, which is already in scope; andexamples/showcases/scene-creator/agent/agent.py:741readsmsg.name, which isNonefor frontend and HITL results — a live instance of the bug sitting in an example.