Skip to content

MCP-04: typed working-set memory and exact llama-server preflight (CPU contracts) - #18

Merged
patrickdugan merged 57 commits into
gym/mcp-local-retrieval-20261119from
research/mcp04-stateful-preflight-20261121
Nov 22, 2026
Merged

patrickdugan merged 57 commits into
gym/mcp-local-retrieval-20261119from
research/mcp04-stateful-preflight-20261121

Conversation

@patrickdugan

Copy link
Copy Markdown
Contributor

Scope

Sibling experiment to MCP-03-RU01, based on the existing MCP parent feature branch (#14). Implements the first MCP-04 admission gate from issue #15:

  • New MCP/hubrun/mcp04.py strict /apply-template plus /tokenize preflight, including the full message history and tool schema in the applied template. Reject unsupported endpoints rather than estimating.
  • Adaptive raw-first selection, typed history compaction only for prompts above the actual context_window - completion_reserve - safety_margin.
  • Immutable tool-result handles, preservation of user constraints and applied edit anchors, and rejection of unpaired tool-call history.
  • Separate mcp04 relay arm in MCP/hubrun/proxy.py. Raw and v1 Goblin paths remain available.
  • Model prompt-token usage vs upstream exact preflight discrepancy logged.
  • Stdlib tests with fake pinned-format upstream and local HTTP integration.

Required gates before promotion

  • Existing MCP and relay regressions green
  • Verify /apply-template and /tokenize response schemas against the actual pinned llama-server fork
  • Preserve no-overflow 5/5 event-recon, and match/exceed raw doc-edit 5/8 without increasing total tokens (fresh replay)
  • Keep zero unpaired tool turns and ensure original task/edits survive compaction

No model-based compaction improvement is claimed here; this is protocol/CPU implementation. Related issue #15.

Copy link
Copy Markdown
Contributor Author

MCP-04 CPU implementation now includes strict raw-first /apply-template plus /tokenize admission, a no-tools control that rejects silently ignored tool schemas, immutable per-task-tag handles, full edit-anchor and user-constraint retention, and a one-shot remeasured retry after provider context errors. The latest protocol note is MCP/hubrun/MCP04_PROTOCOL.md. The real pinned llama-server fork's template/tool serialization and Bonsai 27B doc-edit/event-recon comparisons remain unverified; leave the PR draft pending those admission gates. The documented llama.cpp endpoint response supports prompt/tokens, while tools is not advertised under the upstream /apply-template options, so the defensive schema-difference check is essential.

Copy link
Copy Markdown
Contributor Author

CPU-only MCP-04 preflight hardening added to this draft: lossless edit-site strings (large anchors reject compaction rather than silently truncating), original edit arguments preserved by content-addressed task-scoped handle, synthetic numeric-output/token preflight tests, and python -m MCP.hubrun.preflight_probe for a zero-inference check of the pinned local llama-server's /apply-template + /tokenize tool-schema contract. This deliberately prevents the 27B run from starting before exact preflight compatibility is established. The native Bonsai run remains for the local executor.

MCP-05T: audited historical read-repetition and stale-edit baseline
MCP-05: query-aware ECAN-style working-set attention over MCP-04
@patrickdugan
patrickdugan marked this pull request as ready for review November 22, 2026 02:57
@patrickdugan
patrickdugan merged commit 6a97cfa into gym/mcp-local-retrieval-20261119 Nov 22, 2026
2 checks passed
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