Skip to content

fix: Derive the agent manual's gate and tool count from declarations - #5209

Merged
Sinity merged 2 commits into
masterfrom
fix/agent-manual-derived-contracts
Sep 15, 2026
Merged

Sinity merged 2 commits into
masterfrom
fix/agent-manual-derived-contracts

Conversation

@Sinity

@Sinity Sinity commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Two beads, one commit each. Both replace restated facts with derived ones, because a restated fact in a generated manual is what drifted in the first place.

polylogue-4u79w — the manual prescribed a flow the handler rejects

The manual was wrong, not the handler. Evidence, rather than a preference:

  • The declaration owns the contract: the maintenance _ToolRow (mcp/declarations/registry.py:256-273) states "rebuild_insights and recovery_adjudicate require confirm=true and fail closed without it", and both the handler (server_cutover.py:2718-2745) and _dispatch_maintenance implement exactly that.
  • No preview/dry-run exists anywhere in the operation Literal, the dispatcher, or AuditRepository. recovery_status already is the read-only inspection route the prose wanted.
  • polylogue-2x6xu already adjudicated preview as phantom, removing the dry_run argument and the operation="preview" example from the generated contract. The prose was the last surviving remnant, not a competing intent. Growing the handler a preview operation would have invented a declared operation and a target-algebra entry to satisfy stale text.

The fix is not a reword: the gate is declared once as ConfirmationGate on the maintenance contract and the manual sentence is rendered from it, with the operation argument carrying derived enum_values. The remaining preview vocabulary the same defect left behind is purged too — the capability-table row, the "stale destructive preview" recovery bullet, a regeneration-checklist item, and a stale semantic:"preview-bound confirmation" example query.

Anti-vacuity, executed twice: adding "preview" to the handler's Literal failed both the declared-gate and manual-prose tests; restoring the hand-written prose line in place of the derived sentence failed. Both reverted.

Inherited failure fixed forward: test_generated_contract_arguments_match_the_live_mcp_signatures was already red at base — read: live but undocumented ['offset'], from #5184/#5202 adding the parameter. The read contract now documents it.

polylogue-nysan — "ten-tool surface" against twelve declared

The count is now derived: ALL_DECLARED_TOOLS comes from MCP_TOOL_DECLARATIONS, and the manual renders both its table rows and its spelled count word from that set. Every literal count is gone — renderer (5 sites), spec.py docstring and four ClientDelivery deltas, registry.py docstring, declared_tool_names' own "twelve-tool" docstring, tests/infra/mcp.py, verify_agent_integration.py, cli/commands/agent.py, and the test_assets_and_cli assertions.

record_work_event and emit_decision gained real manual contracts with live-signature-exact arguments; MCPToolDeclaration now carries result_semantics so a tool with no target transaction can still be described, and a new test keeps "outside the target algebra" distinct from "not a tool".

Anti-vacuity, executed: adding a 13th _ToolRow made devtools render agent-manual --check exit 1, failing closed with missing=['probe_thirteenth']; after adding its contract the manual rendered ## The thirteen tools and "thirteen tools, of which six are available by default". Reverted.

docs/atlas/mcp.md's DISCREPANCIES section documented both of these bugs and is now false — rewritten with re-resolved anchors.

Verification

devtools test tests/unit/agent_integration/test_manual_contract.py → PASSED exit 0
devtools test tests/unit/agent_integration/ tests/unit/mcp/        → PASSED exit 0
devtools render agent-manual --check → exit 0
devtools render all --check → exit 0, 0 "out of sync"
devtools verify --quick → exit 0, 21/21 gates
devtools gate atlas → ok

Every changed source file is out of the schema-identity closure. No devtools root verb added.

⚠ Overlaps operator work — do not lose it

A branch docs/mcp-tool-count exists with no commits ahead of master; the actual work is parked in stash@{0} ("mcp-tool-count-wip", authored by Sinity 2026-09-14) on the same topic as nysan. That stash was not touched, popped, or inspected beyond git stash list — it is operator WIP and the shared stash stack is unsafe to pop. This PR likely supersedes it, but that is the operator's call to confirm before dropping it.

Residual

## Normal invocations still renders worked examples for the six default read tools only; the privileged four-plus-two are covered by the table, capability section and contract JSON. Extending worked examples to privileged tools is a separate judgment call, deliberately not made here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

Sinity and others added 2 commits September 15, 2026 20:49
The standing agent manual told callers to "call maintenance with the
declared operation in preview/dry-run mode" and that "a legacy
confirm=true boolean is not the canonical gate". The live handler
declares exactly three operations (rebuild_insights, recovery_status,
recovery_adjudicate), has no preview or dry-run operation, and gates
full-effect execution precisely on confirm. An agent following the
manual's stated canonical flow was refused, and was told the one gate
that works should not be used.

The declaration is the intended contract: the maintenance tool row in
polylogue/mcp/declarations/registry.py states the confirm gate, the
handler and _dispatch_maintenance implement it, and polylogue-2x6xu
already removed the phantom dry_run argument and operation="preview"
example from the generated contract. The prose was the last remnant of
a flow that never existed, so the prose is the defect.

The gate is now declared once, as a ConfirmationGate on the maintenance
tool contract, and the manual sentence is rendered from it. Two tests
resolve that declaration and the rendered prose against the registered
MCP handler's signature.

Also documents the live `read` offset argument, which the generated
contract omitted; that mismatch was failing
test_generated_contract_arguments_match_the_live_mcp_signatures at the
base commit.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
The standing manual injected into agent sessions claimed a "ten-tool MCP
surface" and enumerated ten names, while declared_tool_names returns
twelve. record_work_event and emit_decision are live, registered,
write-gated handlers, so agents reading their own manual concluded two
capabilities they actually had were unavailable.

The count was hand-maintained in five places and had drifted in all of
them. It is now derived: ALL_DECLARED_TOOLS comes from
MCP_TOOL_DECLARATIONS, the manual's table and its spelled count render
from that set, and no docstring, comment, or prose restates a number.
Adding a tool row without a manual contract now fails closed at import
with a named error rather than silently undercounting.

The two event tools gain real manual contracts. Their target_visible=False
is preserved and explained where it is declared: they are outside the
target transaction algebra, which is not the same as not being tools.
MCPToolDeclaration carries result_semantics directly so a tool without a
target transaction can still be described.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 4ff371dc-ef70-4270-86bc-f27d2738e958

📥 Commits

Reviewing files that changed from the base of the PR and between ccec0d1 and 4d23980.

📒 Files selected for processing (18)
  • devtools/render_agent_manual.py
  • devtools/verify_agent_integration.py
  • docs/agent-integration-reference.md
  • docs/agent-manual.md
  • docs/atlas/mcp.md
  • polylogue/agent_integration/data/deep-reference.md
  • polylogue/agent_integration/data/integration-manifest.json
  • polylogue/agent_integration/data/integration-spec.json
  • polylogue/agent_integration/data/recipes.json
  • polylogue/agent_integration/data/standing-manual.md
  • polylogue/agent_integration/data/tool-contracts.json
  • polylogue/agent_integration/spec.py
  • polylogue/cli/commands/agent.py
  • polylogue/mcp/declarations/models.py
  • polylogue/mcp/declarations/registry.py
  • tests/infra/mcp.py
  • tests/unit/agent_integration/test_assets_and_cli.py
  • tests/unit/agent_integration/test_manual_contract.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-09-15T18:58:45.263868Z 4d23980 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Sinity
Sinity merged commit 70cc698 into master Sep 15, 2026
3 checks passed
@Sinity
Sinity deleted the fix/agent-manual-derived-contracts branch September 15, 2026 18:59
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.

1 participant