Skip to content

[codex] redesign MCP contracts and recovery - #514

Merged
morluto merged 9 commits into
mainfrom
codex/redesign-mcp-contracts
Sep 19, 2026
Merged

morluto merged 9 commits into
mainfrom
codex/redesign-mcp-contracts

Conversation

@morluto

@morluto morluto commented Sep 19, 2026

Copy link
Copy Markdown
Owner

Problem

The MCP catalog embedded every capability-specific analysis and capture model, then recursively embedded the analysis request again in continuation outputs. That made tools/list large and ambiguous while malformed nested arguments escaped into raw validation diagnostics. Capture-complete failures were also hidden under details.partial_evidence, recovery metadata used provider-specific prose keys, repository queries could not distinguish an absent inventory from an empty or unmatched one, and captured analysis sources were reconstructed from path and digest metadata during publication.

For agents, these behaviors made tool selection expensive, recovery difficult to compose, and failed workload evidence easy to mistake for a failed MCP call. Path reconstruction also broke preservation when equivalent filesystem aliases referred to the same captured source.

Root cause

The high-level SDK registration surface owned too much of the public schema. Capability matrices were projected into recursive unions during catalog construction, while transport validation and domain recovery were split across SDK behavior, runtime exceptions, descriptions, and provider-specific detail dictionaries. Repository publication did not retain the relational identity already known during capture.

Changes

  • replace high-level MCP registration with the supported low-level SDK Server and a declarative, typed ToolContract registry;
  • keep seven broad workflow tools and add discriminated inspect_capabilities list/get discovery;
  • replace recursive capability unions with compact analyze and capture_and_analyze envelopes backed by registry validation;
  • normalize validation failures into typed Flameox failures with field paths, accepted values, retryability, and executable next actions;
  • return complete, partial, retryable, and unavailable product states as composable structured results;
  • type capture outcomes, evidence query rows, repository inventory state, and continuation calls;
  • propagate domain retryability and remediation instead of emitting provider-specific recovery keys;
  • preserve ordered captured-source indices through CachedAnalysis and repository publication instead of rematching path strings;
  • share compact capability descriptors between CLI and MCP, add minimal examples, and clarify SARIF routing boundaries;
  • update architecture and interface documentation and remove the obsolete generated capability-union module.

A fresh stdio client reports seven tools and a 94,447-byte rendered catalog, down from the previous 275,296-byte baseline (about 65.7%). Invalid discovery calls now return INVALID_REQUEST with field_path: ["mode"] and accepted values list and get.

Validation

  • uv run ruff check src tests tools
  • uv run mypy src tests tools
  • uv run --extra dev pytest -q — 398 passed, 1 skipped, 206 deselected
  • targeted real-stdio and process regressions — 5 passed
  • fresh SDK stdio initialization, catalog rendering, capability list/get, and structured validation measurement

The skipped test requires the optional Memray provider. The targeted process tests cover the changed preservation, capture-partial, collector-failure, and real-stdio paths.

Closes #500
Closes #501
Closes #502
Closes #503
Closes #504
Closes #505
Closes #506
Closes #507
Closes #508
Closes #509
Closes #510
Closes #511
Closes #512
Closes #513

@morluto
morluto marked this pull request as ready for review September 19, 2026 09:26
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 19, 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
📝 Code Review ✅ Completed 2026-09-19T17:30:28.700589Z 076b657 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ccb56fabcd

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/flameox/runtime.py Outdated
Comment thread src/flameox/mcp/server.py
Comment thread src/flameox/mcp/server.py Outdated
Comment thread src/flameox/mcp/request_contracts.py
Comment thread src/flameox/mcp/tool_registry.py
Comment thread src/flameox/mcp/server.py Outdated
Comment thread src/flameox/runtime.py Outdated
@morluto

morluto commented Sep 19, 2026

Copy link
Copy Markdown
Owner Author

Addressed all seven review findings in 2f42550:

  • removed the Darwin ordinary-path fallback and moved descriptor-backed rescue capability validation into preflight;
  • included workload-interpreter prerequisites in provider preparation summaries;
  • made analysis/query summaries distinguish bounded and paginated evidence;
  • allowed historical capability IDs in evidence queries;
  • generated discovery examples at each capability minimum source cardinality;
  • separated workload-only preservation guidance from analysis-failure reanalysis;
  • stripped unsafe worker diagnostics while retaining typed code, retryability, and remediation.

Validation: Ruff format/check, strict mypy, and full pytest (395 passed, 7 skipped). The rescue destination remains agent-selected; descriptor paths are internal safety machinery, not a user-facing path requirement.

@morluto

morluto commented Sep 19, 2026

Copy link
Copy Markdown
Owner Author

Follow-up cleanup pushed in 7ce4403 and f5c298b. The Linux-only deterministic failure was an idempotent re-rescue regression after session rescue metadata was cleared; existing valid rescue repositories are now recognized through a descriptor-relative marker check. I also removed prescriptive agent workflow policy from server instructions, tool descriptions, request-field copy, and workload-failure guidance. The remaining restrictions are enforced correctness/safety invariants, not repo/workspace policy: explicit inputs, bounded execution, compatible contracts, non-overwriting publication, and immutable-evidence integrity.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 461138d2b3

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/flameox/mcp/server.py Outdated
Comment thread src/flameox/runtime.py Outdated
Comment thread src/flameox/mcp/server.py Outdated
Comment thread src/flameox/mcp/request_contracts.py Outdated
Comment thread src/flameox/runtime.py
@morluto
morluto merged commit cab2f6b into main Sep 19, 2026
10 checks passed
@morluto
morluto deleted the codex/redesign-mcp-contracts branch September 19, 2026 17:26

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 076b657d5b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +86 to +89
class McpPathSource(PathSource):
format: ArtifactFormat | None = Field(
default=None,
description="Explicit native artifact format. Omission requires unambiguous detection.",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Admit resolved preview formats in continuation requests

When artifact.preview reads a directory or an extensionless file with format omitted, runtime detection records the source format as directory or unknown and emits that value in the exact next_page request. Neither value is in this closed enum, so any preview requiring a second page is rejected by MCP validation even though the first page succeeded. Keep the preview source format open enough to accept runtime-generated handoffs, or avoid serializing a format that the transport cannot read back.

AGENTS.md reference: AGENTS.md:L44-L48

Useful? React with 👍 / 👎.

Comment thread src/flameox/runtime.py
Comment on lines +2053 to +2056
parent_descriptor = os.open(selected.parent, os.O_RDONLY)
try:
stage.rename(selected)
os.fsync(parent_descriptor)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep rescue publication usable on Windows

On Windows, os.open(selected.parent, os.O_RDONLY) cannot open a directory for _commit/os.fsync, so every new rescue reaches this statement after staging the evidence and then returns REPOSITORY_IO_FAILURE instead of publishing it. The former Windows preflight rejection was removed and the interface now presents rescue as ordinary filesystem publication, which also means a CLI capture can execute before discovering this failure; use a Windows-compatible directory durability path or continue rejecting the operation before execution.

AGENTS.md reference: AGENTS.md:L48-L48

Useful? React with 👍 / 👎.

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