π Bug: agentMetadata.nodeName doesn't match node where interrupt originates
β»οΈ Reproduction Steps
- Clone open-research-ANA repo
- Upgrade @copilotkit versions to 1.6.0-next.11
- Add
enabledprop:
enabled: ({ agentMetadata }) => {
console.log(agentMetadata)
},
agentMetadata.nodeName is "call_model_node" instead of "process_feedback_node"
β Expected Behavior
agentMetadata.nodeName should be "process_feedback_node"
β Actual Behavior
agentMetadata.nodeName is "call_model_node"
π CopilotKit Version
js/ts: 1.6.0-next.11
python: 0.1.39
π Logs (Optional)
Hi @mlsimon734, thanks for creating this issue.
Have you tried this after upgrading to 1.6.0?
In version 1.8.6, the same bug exists: unless the node right before the interrupt node is also enabled, the interrupt UI wonβt show up. I have to make interrupt node and the pre node all be enabled in the "useLangGraphInterrupt" Hook
π Triage sweep. This was last confirmed on 1.8.6, which is well behind the current 1.63.x / v2 line. Could you confirm whether agentMetadata.nodeName still reports the wrong node for an interrupt's origin on the latest release? If we don't hear back we'll close this as stale in ~2 weeks β please reopen anytime with a repro.
Thanks for reporting this. The interrupt path has been substantially rewritten since this was filed β nodeName is now derived from the AG-UI STEP_STARTED stream (via useAgentNodeName), not the old coagent-metadata path. The useLangGraphInterrupt API and the agentMetadata.nodeName it exposes are still present, so this isn't obsolete β but we couldn't confirm whether the correct interrupt-origin node is reported on current main without a fresh repro.
Could you retest on the latest version and, if the reported nodeName still doesn't match the interrupt-originating node, share a minimal repro (a small graph with the interrupt node, plus which nodeName you expect vs. what you get) and your versions? Otherwise we'll close this for inactivity. Thanks!
Correcting my two earlier comments on this thread β the retest requests and the stale-close warning shouldn't have been there. This is still a real bug, and it's visible in the current code without needing anything further from you.
The interrupt path was rewritten since you filed, but the defect moved with it. useAgentNodeName tracks the current node in a ref, mutating nodeNameRef.current inside onStepStartedEvent, and returns nodeNameRef.current. A ref mutation doesn't schedule a render, so what callers receive is the value as of the last render rather than the live one. useLangGraphInterrupt then snapshots that into metadataRef during render (use-langgraph-interrupt.ts:45-54), and enabled() reads it at call time β so when no re-render lands between the STEP_STARTED for the interrupting node and the interrupt event, agentMetadata.nodeName ends up stale by exactly one step.
That matches what you reported (call_model_node where you expected process_feedback_node), and it also explains @lywaterman's observation that the node before the interrupt node has to be enabled as well.
One caveat worth stating: I've traced this in source but haven't reproduced it live, so whether a render lands in that gap will depend on the surrounding component. That's the first scoping step on our side. There's also no test coverage for the hook today, so a fix should bring one.
Hi! I traced #1426 on the current main branch. useAgentNodeName mutates a ref on STEP_STARTED, so useLangGraphInterrupt can retain the previous renderβs node in agentMetadata.
I propose making the hook reactive with state, while preserving the last active step when a run finalizes as an interrupt, including the legacy on_interrupt path. I would add regression coverage for the interrupt flow and the start/success/error transitions, and include nodeName in useCoAgentβs memo dependencies so both current consumers observe updates.
Would you be interested in this PR? Do you have a preferred semantic for nodeName while an interrupt is pending, or any existing work I should align with?
@guomengjia618-dot β thank you for this trace, and apologies for the week of silence. You deserved a reply much sooner, and there's a specific reason this one is overdue, which I'll be straight about.
Your reactivity analysis was correct, and that half is now fixed. useAgentNodeName did track the node in a ref and return nodeNameRef.current; mutating a ref schedules no render, so a component reading useCoAgent().nodeName kept showing whichever node was current at its last render and only appeared to update when something unrelated re-rendered it. It's now backed by state, with coverage for transitions, run-start reset, run-error, and unsubscribe on unmount β ffd15801d6, landed 2026-08-17, four days after your comment. That matches your first proposal exactly, and it went in without crediting you. That was my oversight and I'm correcting it here.
But I don't think the ref explains this issue, which is why #1426 is still open. useInterrupt only evaluates the enabled predicate from a useEffect/useMemo keyed on its pending state, so the interrupt's own state update always forces a render before the predicate runs β and even the pre-fix code reads the ref correctly at that point. So the reactivity bug was real, but it's a different bug from the one reported here.
Your second proposal is the one I think we actually need. You wrote: "preserving the last active step when a run finalizes as an interrupt, including the legacy on_interrupt path." That's unaddressed, and there's a plausible mechanism worth checking first:
use-interrupt.tsx:199drives the standard interrupt flow fromonRunFinishedEvent(params.outcome === "interrupt").useAgentNodeNamealso subscribes toonRunFinishedEvent, and unconditionally doessetNodeName("end").
Two subscribers on one event, one of which wipes the node at the exact moment the interrupt surfaces. I want to be clear that I have not reproduced this β it's the suspect I'd check first, not a confirmed diagnosis.
So yes, I'm interested in the PR β scoped to that second item rather than the ref change. The most useful first step would be a failing test that drives a run finishing with outcome: "interrupt" and asserts agentMetadata.nodeName is the originating node rather than "end" (or the previous node). If that reproduces, the fix shape you described β preserve the last active step on interrupt finalization, covering the legacy on_interrupt path too β is right, and I'll review it promptly.
If the test doesn't reproduce it, that's just as useful to know, and worth posting here before you build anything further.
On your third item, nodeName is already threaded through useCoAgent's returned object (use-coagent.ts:340 and :353), so I think that one's covered β but say if you're seeing otherwise.
Thanks for the detailed reply and the transparency, @BenTaylorDev.
I rebased #6488 on top of ffd15801d6, so the PR no longer contains the basic ref-to-state change. It is now scoped to the second item you identified.
The regression coverage drives exactly this sequence:
STEP_STARTED("process_feedback_node")RUN_FINISHED({ outcome: "interrupt" })- evaluate
useLangGraphInterrupt.enabled()
On current main, the unconditional run-finished transition makes that assertion receive "end"; with the patch it retains "process_feedback_node". There is separate coverage for the legacy on_interrupt path as well. The targeted file passes 7/7 with the patch.
On useCoAgent: agreed that nodeName is already present in the returned object. The remaining issue is that the object is wrapped in useMemo, but nodeName is absent from its dependency array. A node-name-only render can therefore keep returning the previous memoized object. #6488 keeps that as a separate one-line dependency fix.
The PR is mergeable and ready for review; its fork Actions are still awaiting approval.