Skip to content

LangGraph re-checks the role of the agent a turn resumes in (1.6.0, item 7) - #302

Merged
antiv merged 1 commit into
mainfrom
ccr-9eba0dfd-0u60sa
Oct 24, 2026
Merged

antiv merged 1 commit into
mainfrom
ccr-9eba0dfd-0u60sa

Conversation

@antiv

@antiv antiv commented Oct 24, 2026

Copy link
Copy Markdown
Owner

What and why

1.6.0 item 7 (#276), found in the review of #278.

Every turn checked only the agent requested

On AGENT_FRAMEWORK=langgraph, a multi-agent graph starts each turn at the checkpointed current_agent:

  • transfer_to_agent sets current_agent, and route_entry routes the next turn to it.
  • A paused tool call resumes inside that agent's node.

But execute_run called check_rbac only for app_name, the root agent. After a transfer, a user kept talking to the sub-agent even when the role check would refuse them there:

  • the user's role for the sub-agent was taken away;
  • the sub-agent's allowed roles changed so they no longer match.

ADK checks the agent that answers on every model call (before_model_callback), so it refuses there.

execute_run now reads the agent the turn resumes in (_resumed_agent: current_agent from the checkpoint, or the root when it is not in the tree, which is also where route_entry sends it). When that agent is not the root, it runs check_rbac for it too.

  • The check covers all three kinds of turn: a message, a confirmation resume and a client-tool resume. It runs before any side effect: before the user event is stored, before guardrails and before the graph runs.
  • A refused turn returns the same RBAC_ACCESS_DENIED event as the root check, with the audit entry and the ACCESS_DENIED usage row from check_rbac.
  • A checkpoint that cannot be read refuses the turn. The check cannot know which agent would answer.
  • A session stuck in a refused sub-agent stays refused. Nothing resets current_agent, so the user starts a new conversation. ADK behaves the same.

A transfer without a run context was let through

transfer_to_agent checked roles only when it had a run context, and transferred without a check when it had none. It now refuses, because there is no user to check.

Production never runs without one: execute_run and the eval LangGraphSnapshotAgent both set it. The graph built for LangGraph Studio has no MATE user, so it is the one exception: AgentBuilder(require_run_context=False), used only in studio_graph.py. The shared builder and the eval builder keep the default.

How it was tested

  • python -m unittest discover -s shared/test -p "test_*.py": 1635 tests pass, except test_browser_tools.test_real_headless_navigation. That test needs outbound network and fails the same way on main in my environment.

    • New: test_langgraph_resumed_agent_rbac.py (8 tests). It builds a real multi-agent graph through AgentBuilder.build_for_config, with plain nodes instead of models and an in-memory checkpointer, and runs execute_run against it. It covers:

      • after a transfer, a user without the sub-agent's role is refused and the sub-agent does not run;
      • a user with both roles goes on in the sub-agent;
      • a turn at the root is checked once;
      • an unreadable checkpoint refuses;
      • a current_agent outside the tree starts at the root;
      • a transfer without a run context is refused;
      • the Studio graph transfers without one;
      • only the Studio builder drops the requirement.

      7 of the 8 fail on main. The one that passes is the root-only case, which behaves the same. In the first test the sub-agent's node ran on main.

    • Updated: test_langgraph_agent_builder.py::test_transfer_returns_parent_command now sets a run context. It relied on a transfer passing without one.

  • python -m pytest shared/test/test_sessions_api.py passes.

  • python scripts/gen_docs.py --check is clean.

  • Independent security review of the diff: no findings.

    • It traced every path that runs a built graph: /run_sse, eval snapshots and Studio.
    • It covered the three kinds of turn and the resume loop.
    • It covered whether a caller can point a run at another user's or app's thread: the proxy checks user_id, and /run_sse requires the session to belong to that user and app.
    • It confirmed the root fallback agrees with route_entry.

    It also raised a pre-existing issue, not touched here: deleting a LangGraph session does not delete its checkpoint thread, so a recreated session with the same id would load the old history. That needs the old session's UUID.

Checklist

  • Tests added or updated in shared/test/, and python -m unittest discover -s shared/test -p "test_*.py" passes
  • Schema changes have a migration for all three dialects (shared/sql/migrations/{postgresql,mysql,sqlite}/) (no schema change)
  • Changed a route, env var, model or the tool registry: ran python scripts/gen_docs.py and committed docs/reference/ (nothing to regenerate)
  • Ran python scripts/gen_docs.py drift --base origin/main and updated the guides it lists (or say below why they still hold)
  • New user-facing feature: a guide in docs/user/ (and docs/dev/ if it has internals worth knowing) (a fix; dev guides updated)
  • No API keys, tokens or credentials in code, logs or tests

Guides updated:

  • docs/dev/langgraph-runtime.md:
    • when roles are checked in a multi-agent tree;
    • the refused-session behaviour;
    • the transfer without a run context and the Studio exception;
    • the new test in the test list.
  • docs/dev/agent-runtime.md: the LangGraph role check runs per turn, not per model call.
  • docs/dev/auth-and-access.md: the LangGraph hook's coverage.

Guide drift lists that still holds: docs/dev/releases.md, for a CHANGELOG entry only.


Generated by Claude Code

…tem 7)

A multi-agent graph starts each turn at the checkpointed current_agent,
but execute_run checked the user's roles only for the agent requested.
A user who lost a sub-agent's role, or whose sub-agent's allowed roles
changed after a transfer, kept talking to it. execute_run now reads the
agent the turn resumes in and checks it too when it is not the root,
refusing as ADK does on the sub-agent's model call. A checkpoint that
cannot be read refuses the turn.

The transfer tool let a transfer through when it had no run context to
check. It now refuses, except in the graph built for LangGraph Studio,
which runs with no MATE user.
@antiv
antiv merged commit 84df829 into main Oct 24, 2026
2 checks passed
@antiv
antiv deleted the ccr-9eba0dfd-0u60sa branch October 24, 2026 15:59
@antiv antiv mentioned this pull request Oct 24, 2026
24 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants