Skip to content

Fix the Go Guardian follow-ups from the #619 review - #765

Open
President wants to merge 10 commits into
GenAI-Security-Project:integrationfrom
disciplinedware:refimpl/go-701-followups
Open

President wants to merge 10 commits into
GenAI-Security-Project:integrationfrom
disciplinedware:refimpl/go-701-followups

Conversation

@President

@President President commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

This pull request fixes the seven Go Guardian items that issue #701 lists. Each item has its own commit. The pull request also includes one test fix.

  1. When the Guardian returns ASK or DEFER for the response to an MCP tools/call request, it keeps the call open. The agent can then send the response again. The Guardian closes the call only after a final ALLOW, MODIFY or DENY on the response.
  2. In MCP 2026-07-28 and later, the Guardian closes the call that a notifications/cancelled message names. When the list of open calls is full, the Guardian closes the oldest calls. It records this as an mcp_calls_evicted event in its own audit log. This event is not in the ACS event catalog.
  3. When no policy checks tool results, the Guardian now allows an MCP tool result that it cannot read. When a policy checks tool results, the Guardian still denies such a result.
  4. An MCP server can return a task in place of the tool output. The Guardian now reads a task object (MCP 2025-11-25) and resultType: "task" (the MCP Tasks extension). No policy checks the task's output, which arrives later in a tasks/result or tasks/get response or a notifications/tasks message. So when a policy checks tool results, the Guardian denies the task and its output. When no policy checks tool results, it allows them. Issue [RefImpl] Go Guardian: check MCP task results and other server content #766 tracks checking a task's output with its tool's policy.
  5. The Guardian again returns a signed DENY for a tools/call request whose tool name is not a string, as it did before Fix the Go Guardian items from the #169 review #619. The same signed DENY now also applies to a request with no tool name, a request with no ID, and a request whose arguments is not a JSON object or null.
  6. changesMCPCall now reports no change when the modification data is missing. This could not cause a crash before, because disposition.Check already rejects such a MODIFY before changesMCPCall runs. The new check protects future callers of changesMCPCall.
  7. The Guardian rejects a numeric MCP ID that has a fractional part or whose absolute value is 2^53 or more. Above that limit, the Guardian could treat two different IDs as the same ID. I-JSON (RFC 7493, section 2.2) sets the same limit.
  8. Issue Go Guardian: follow-ups from the #619 review #701 does not list the test fix. The guardiantest store tests gave each entry a placeholder entry_hash. A store that verifies entry hashes rejected those entries, so 11 tests could not run on that store. The tests now use the correct hash for each entry. I can move this fix to a separate pull request if you prefer.

Please check these two points:

  • Item 2 closes a call on cancellation only in MCP 2026-07-28 and later. In MCP, both the client and the server send requests, and each side assigns IDs to its own requests. So the client's tools/call and a server request can both be open with ID 7. A notifications/cancelled message names the request to cancel by its ID. In MCP 2025-11-25 and earlier, either side may cancel its own request, so the Guardian cannot tell from the ID alone whether "cancel 7" is for the client's call or the server's request. It closes nothing. In MCP 2026-07-28, a cancellation can name only a client request, so the Guardian closes the client's call 7. In the older versions, only the size limit closes an old call that never gets a final decision.
  • Item 2 changes how stores save Session.MCPCalls, the session's list of open calls. Stores saved a JSON object with call IDs as keys. Stores now save a JSON array, oldest call first, because the Guardian closes the oldest calls first and a JSON object has no defined order.

Which issue does this implement

Closes #701

  • This is an editorial correction (typo, grammar, link, formatting) with no change in
    meaning, so it needs no issue

Base branch

  • integration. Every pull request targets integration, documentation included.
    Only a promotion targets main (see CONTRIBUTING.md)
  • release/0.2, because this changes normative specification text, a schema, or a
    conformance requirement for 0.2, or carries out such a change in code

Type of change

  • Specification change (schema, hooks, events, AgBOM)
  • Reference implementation or adapter
  • Documentation
  • Tooling or CI
  • Governance (licensing, security policy, contributor docs)

I tested this

  • I synced my branch with the base branch before opening this
  • uv run pytest -v passes on my machine
  • uv run mkdocs build --strict passes on my machine

In reference-implementations/agt-go, make check and make test-race pass on Linux and on macOS. make load passes on macOS.

I also sent test events to this Guardian through the Claude Code, Cursor and NAT adapters. The Guardian returned the same answers as on integration. These adapters do not send MCP messages wrapped in ACS messages, so only the Go tests cover the MCP changes.

Checklist

  • Commits are signed off with git commit -s (required by the DCO)
  • Prose follows STYLE.md
  • No secrets, tokens, or internal URLs in the diff

Security

  • This change has no security impact

Items 3 and 4 change some DENY decisions to ALLOW, but only when no policy checks tool results. Item 5 returns a signed DENY in place of an error: before, an agent configured to proceed could treat that error as permission to continue. Item 7 stops the Guardian from matching two different IDs to the same call.

After an ASK or a DEFER on a tools/call response, the Observed Agent
can send the same response again. The Guardian had already closed the
call, so the second send got DENY mcp_call_not_open.

The call now closes only on a final ALLOW, MODIFY or DENY.

Part of GenAI-Security-Project#701

Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
Two cases left a call open for good. A cancelled request usually gets
no response, so its call stayed open. And the only bound on the open
calls denied new ones: once the calls filled
limits.max_policy_state_bytes, every new tools/call in the session was
denied.

A notifications/cancelled now closes the call it names. It does so only
from MCP 2026-07-28 on, where only the client's requests can be
cancelled. The version comes from the method, or else from the one MCP
version the client declared. Under MCP 2025-11-25 and earlier a cancel
closes nothing, because its id can name a request of the MCP server;
there only eviction bounds the record.

When a new call does not fit in limits.max_policy_state_bytes, the
oldest calls close, and an mcp_calls_evicted event names them. This is
an event of this Guardian's own audit log, not of the specification.

Session.MCPCalls is now MCPCalls, an ordered record saved as a JSON
list. A Conclusion names the call it opens (OpenMCPCall) and the calls
it closes (CloseMCPCalls), and a store applies both with MCPCalls.Apply.
The engine still reads SessionContext.MCPCalls as a map.

This changes the store format. A store cannot load the earlier form, a
JSON object by id, so end those sessions before the upgrade. The record
is per ACS session, so MCP ids in flight must be unique across the
session's connections.

The cancel is the third place that asks whether a method wraps an MCP
message, so method.WrappedMethod now answers it once, case-insensitive
as before, for the cancel, the Guardian's tools/call and the bridge.
Example: "protocols/mcp/notifications/cancelled" names MCP.

Part of GenAI-Security-Project#701

Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
With a manifest that has no result policy, the bridge still denied an
MCP result it could not decode. The denial named a policy that does not
exist.

Decide now allows such a result when no policy governs
steps/toolCallResult, and denies it as before when one does.

Part of GenAI-Security-Project#701

Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
A server may answer a tools/call with a task instead of the tool's
output. The bridge refused that answer as unreadable. It now accepts a
task in both forms: a task object (MCP 2025-11-25) and resultType "task"
(the MCP Tasks extension). checkResult reports which results acknowledge
a task.

A task acknowledgement with no outputs is allowed without asking the
result policy. The stock AGT policy reads outputs[0], so it would deny
the empty result with runtime_error:path_missing. An acknowledgement
that carries content or _meta is decided like any result.

A server that answers with a task skips the result policy: the tool's
output arrives later, in tasks/result or tasks/get, which no policy
reads. Neither does a task's statusMessage. The docs state this gap.

The result reader no longer carries a branch for an MCP error object it
cannot decode: mcp.Read has already refused such a response, for
example {"error":{"code":1,"message":7}}, so no input reached it.

Part of GenAI-Security-Project#701

Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
The MCP handler read a tools/call with ReadToolCall and refused such a
call with -32602 before the Guardian could read it. The handler now
checks a tools/call as it checks every MCP message, with Read. The
Guardian's own read then refuses it: a signed DENY evaluation_failed,
as before GenAI-Security-Project#619. Example: {"jsonrpc":"2.0","id":3,"method":"tools/call",
"params":{"name":42}}.

The same DENY now covers three neighbours of this case:
- a null or missing name ("name":null) reached the policy as the tool "";
- a request without an id (MCP requires one) reached the policy, and
  its call was not tracked;
- arguments that are neither an object nor null ("arguments":[])
  reached the engine; the AGT bridge failed to translate them, so the
  step was denied as an engine failure, and another engine got them.

The reasoning of this DENY now names what was refused, such as "the
wrapped tools/call has no tool name that is a string".

Part of GenAI-Security-Project#701

Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
changesMCPCall read its modifications without a nil check. At d315da3
too, disposition.Check (called from fit in decide) refused a MODIFY
without modifications before changesMCPCall, so no panic could occur.
The guard only protects a future caller. It reads nil as no change,
which its own test covers. An end-to-end test pins the case of item 6:
such a MODIFY on a wrapped tools/call gets DENY evaluation_failed, no
panic.

Part of GenAI-Security-Project#701

Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
RFC 8785 writes every number as a double. Two numeric ids that differ
beyond a double's precision, such as 9007199254740992 and
9007199254740993, canonicalize to one id and share one call.

A numeric id is now unreadable, and its call a signed DENY
evaluation_failed, when it is not an integer or is 2^53 or more in
magnitude. I-JSON (RFC 7493 section 2.2), which RFC 8785 builds on, sets
the same bound for an exact integer.

Reading an id exactly is cheap for an ordinary number, but an exponent
such as 1e-999999 makes a huge integer; the 64-character and exponent
bounds keep that read cheap. An id beyond the range of a double is not
I-JSON and fails envelope parsing first, so its request gets -32700.

Part of GenAI-Security-Project#701

Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
The SessionContextStore contract in guardiantest gave every test entry a
made-up entry_hash: digest(n) was the number n padded to 64 hex digits, so
entry 1 carried 000...0001. A store may check each entry's entry_hash
before it keeps it; such a store refused every entry, and the 11 cases
that append one could not test it.

Steps to reproduce: run guardiantest.TestSessionContextStore against a
store whose Append checks chain.EntryHash(a.Entry) == a.Entry.EntryHash.
Expected: the contract runs and passes. Actual: every Append fails with
"entry 1 carries entry_hash 000...0001, its content gives b253...".

entry now seals each entry with chain.Seal, as the Guardian seals it, and
digest(n) is the entry_hash of entry n in the chain 1, ..., n. The case
that gives entry 2 the step id of entry 1 seals it again after the change.

TestTheStoreContractHoldsForAStoreThatChecksEntryHashes runs the contract
against the memory store wrapped by such a check: it fails before this
change and passes after it.

Signed-off-by: Konstantin Trunin <konstantin@trunin.com>

@rocklambros rocklambros left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Konstantin. Six of the seven items are good, and the store test fix is good too. make test passes in every package at d00fcc7, including TestRecordingIsCurrent and TestRecordedCases, and go vet is clean.

One thing blocks the merge. It's the first point you asked us to check: item 4 lets a tool's output reach the agent without a result check, even when a policy checks tool results.

In agtbridge/bridge.go (lines 148 to 151), the bridge answers ALLOW to a task acknowledgement before it asks whether the result point is governed. The real output then comes back in a tasks/result or tasks/get response, and project() in agtbridge/mcp.go maps neither one to a policy point, so the bridge allows those too. I tested this through the Guardian with the stock AGT policy and a ghp_ token in the tool output:

Step integration (905f124) This PR (d00fcc7)
Direct result with the token MODIFY redaction_applied MODIFY redaction_applied
Task acknowledgement (task object or resultType: "task") DENY mcp_result_unreadable ALLOW
tasks/result or tasks/get response with the token ALLOW ALLOW

The last row is ALLOW on integration too, but today the DENY on the acknowledgement stops the agent before it learns the task ID. This PR removes that DENY, so the token reaches the agent without redaction. ACS says the agent can't get around the control, so the fix has to be part of this PR.

Please make this change:

  1. When the result point is governed, answer DENY with mcp_result_unreadable to a task acknowledgement and to every tasks/result or tasks/get response. When no result policy exists, keep ALLOW. Use the same check as line 136 in bridge.go.
  2. Add tests for both cases (result policy governed, and no result policy) for the acknowledgement and for the tasks/result and tasks/get responses.
  3. Update docs/conformance.md line 29 to say that a task's output is denied while a result policy is set.

The full fix would record which tool each task ID belongs to, and then check the later tasks/result output with that tool's result policy. That's a bigger change, so I'd like to keep it for a separate issue. The change above is enough for this PR.

If you use an AI coding tool, this prompt covers it:

In reference-implementations/agt-go/agtbridge/bridge.go, Engine.Decide currently returns
ALLOW for an MCP task acknowledgement (p.task && len(p.outputs) == 0) before it checks the
result policy. Change it so that, when the steps/toolCallResult point is governed (the same
check as the errMCPResultUnreadable branch: e.mapping.point(acs.StepToolCallResult) and
e.evaluator.Governs(point)), the bridge returns DENY with reason code
mcp_result_unreadable for (a) a task acknowledgement and (b) any MCP response to a
tasks/result or tasks/get request. When the result point is not governed, keep ALLOW. Add
Go tests in agtbridge/bridge_test.go for both cases, with both task forms (a task object and
resultType "task") and both follow-up methods. Update docs/conformance.md line 29 to match.
Then run `make test` and `go vet ./...` in reference-implementations/agt-go.

One optional follow-up that can wait for a later PR: in guardian/step.go (line 714), a response answered ASK or DEFER keeps its call open with no time limit, and only eviction closes it. Eviction goes by age only, so it can close a call that is still waiting for its approver. Closing the call when the ASK or DEFER is answered or times out would fix that.

When the fix is in, this PR can merge into integration in the next batch, together with other PRs for release 0.1.6.

@acs-board-reconciler acs-board-reconciler Bot moved this from Needs triage to In progress in ACS Project Tracker Dec 3, 2026
Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
Item 4 let a task's acknowledgement through, but no policy reads the
output that follows: the bridge maps tasks/result, tasks/get and
notifications/tasks to no policy point. So with a result policy, a
secret in a task's output reached the agent unredacted. Before item 4,
the Guardian denied the acknowledgement, and the agent never got the
output.

Steps to reproduce: with the stock AGT policy, send a wrapped tools/call
that asks for a task, its acknowledgement, a tasks/result request, and
the response, whose content holds a ghp_ token.
Expected: the token does not reach the agent.
Actual: each step is ALLOW.

While the manifest has a result policy, the bridge now answers DENY
mcp_result_unreadable to a task's acknowledgement, to every response to
tasks/result or tasks/get, and to notifications/tasks, in which the MCP
Tasks extension pushes the same task with its output. Without a result
policy it allows them, as before. The tasks/result and tasks/get
requests carry no output and stay allowed.

TestWrappedMCPTaskAcknowledgement and TestWrappedMCPTaskOutput cover
both forms of a task, the three messages, the stock policy, which has
a result policy, and a policy that checks only tool calls. They fail
before this change.

Signed-off-by: Konstantin Trunin <konstantin@trunin.com>
@President

Copy link
Copy Markdown
Collaborator Author

Thanks, Rock. Fixed in e6d15da.

With a result policy set, the bridge now denies the task acknowledgement and the task output: tasks/result, tasks/get, and notifications/tasks, where the Tasks extension pushes the same output. Without a result policy, all of them stay allowed. Your scenario now gives DENY at each task step.

Checking task output with its tool's policy is #766.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

Go Guardian: follow-ups from the #619 review

2 participants