Skip to content

MCP-01: add local retrieval gym and architecture sweeps - #14

Merged
patrickdugan merged 119 commits into
masterfrom
gym/mcp-local-retrieval-20261119
Nov 22, 2026
Merged

patrickdugan merged 119 commits into
masterfrom
gym/mcp-local-retrieval-20261119

Conversation

@patrickdugan

Copy link
Copy Markdown
Contributor

Why

HybridTRMLDT needs an executable retrieval gym for comparing MCP discovery layouts and locally served model architectures. The local controller can spend a generous inference budget while the evidence packet sent onward has its own size limit.

Changes

  • Add MCP/ with paired synthetic records, a private exact judge, and deterministic public-observation reference control.
  • Compare flat catalogs, metadata search, layered indices, and checked LDT filtering through the existing strict membrane.
  • Provide MCP 2025-06-18 stdio initialization and tool methods, with independent replay of tool results.
  • Add a loopback chat-completions adapter using strict JSON actions, model provenance fields, counted repair attempts, and observed usage accounting.
  • Sweep catalog width and index depth while preserving the task and required evidence across configurations.
  • Record Data Goblin's longer-term retrieval specialization, additional Transformer adapters, and the later frozen comparison protocol.

Verification

  • 83 tests and 55 subtests pass locally, including existing strict-membrane regressions.
  • All 360 deterministic reference episodes pass across four arms, catalog sizes 8/32/128, and depths 1/3/6.
  • Actual subprocess MCP responses match in-process replay.
  • Compressed raw episodes, summaries, source hashes, publication tree equality, and test output are preserved under MCP/results/mcp01/ (about 0.4 MB).

The recorded sweep uses deterministic reference control. Local HTTP fixture tests validate the model adapter; trained-model retrieval and downstream frontier-token savings await runs against a real local model.

The dedicated CI workflow runs contract tests and a 192-episode deterministic stdio pilot. Local model inference remains an explicitly separate command.

patrickdugan and others added 20 commits November 19, 2026 22:56
…refinement

Add MCP/mcp02 beside the unchanged MCP-01 gym:
- world.py: seven-server worlds, eight task families (ambiguous names,
  multi-hop joins, nested sections, moved records, mid-episode epoch
  change, replica conflicts, missing values, pagination) with a hidden
  oracle and split-disjoint name pools and request templates.
- env.py: flat, search, layered and layered_ldt arms; facet layouts over
  server, collection, kind, provenance, bucket and entity; per-node
  candidate sets bound to the catalog epoch, with every exclusion passed
  through certify_and_apply_verified; private judge.
- agent.py: one observation/action boundary for every router, public
  plan tracker, deterministic, BM25, sham and oracle policies, decision
  tapes for torch-free replay.
- models.py/train.py: dense, Transformer, looped, TRM, TRM+LDT and HRM
  routers with measured parameters, recurrent depth and FlopCounterMode
  FLOPs; imitation training from train worlds only.
- run.py/economics.py: evaluation grid with depth, deliberation and
  layout sweeps; failure-inclusive cost per accepted task; replay.
- llm.py/hf_server.py: LLM controller through MCP.local_model.LocalModel
  and a loopback Transformers server reporting measured identity.
- CI: MCP-02 control smoke, summary and replay; replay of committed tapes.

Verified: python -m pytest -q MCP/test_mcp02.py -> 23 passed, 1 skipped
(torch test); the torch architecture test passes in a torch 2.11 venv.
Stdio episodes match in-process replay in all four arms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…erer

A tool-transport artifact had turned the CRLF-normalisation escapes in
run.py into literal line breaks, which made run.py unparsable on import.
report.py renders comparative tables from summarized runs.

Verified in Ubuntu 24.04 (WSL, Python 3.12.3): python -m pytest -q MCP
tests/test_cca_verified_membrane.py tests/test_hybrid_membrane.py ->
106 passed, 1 skipped, 55 subtests passed; MCP-02 control smoke replay
96/96 episodes, 0 mismatches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mendment

features.py gains encoder 'match': tokens shared by needs and candidate get
segment ids 2/3 (template glue excluded); 'tokens' is unchanged and stays
the default, so existing checkpoints load as before. models.py and train.py
thread the encoder through. run.py gains 'publish' (gzip, history dropped,
compact tapes) and replays compact tapes. PROTOCOL.md records why and where
the encoder changed: CPU pilot stays tokens-only plus an ablation pair, GPU
pilot uses match plus a tokens-only anchor.

Verified: python -m pytest -q MCP/test_mcp02.py -> 23 passed, 1 skipped;
torch architecture and encoder tests pass in the torch venv. Same smoke data
and model: dev top-1 0.40 (tokens) vs 0.77 (match).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Goose GDK app

- MCP/mcp03: snapshots of SWE-bench repositories from bare clones, ast
  symbol tables cached per blob, gold files and functions from the patch
  (hidden); a code MCP surface (BM25 code_search, layered index over
  directories, modules and symbols, read_symbol, certified test/doc path
  exclusions); the MCP-02 routers behind the same observation; token-
  budgeted packets (ranked file map plus snippets) under a named
  tokenizer; the SWE-bench BM25 whole-file baseline; repo-grouped splits
  (train django+sympy, test ten held-out Lite repositories).
- goblin_server.py: MCP stdio server with compact_context and
  read_symbol over a live working tree, loadable by Goose as an extension.
- MCP/goose_gdk_app: goblin-gdk, a Rust app on goose-agent and
  goose-providers 0.1.0-alpha.14. A GDK Operation contributes the packet
  as a prompt part; InferenceRunner calls an OpenAI-compatible provider.
  ci_smoke.py checks it end to end against a scripted endpoint.
- train.py receipts record process peak RSS and CUDA peak memory.

Verified: python -m pytest -q MCP/test_mcp02.py MCP/test_mcp03.py -> 33
passed, 1 skipped (torch test). cargo build --release in Ubuntu 24.04
(WSL) succeeds; ci_smoke.py passes all five checks: the packet reaches
the provider request, stays within its 1024-token budget, the router read
11.5K tokens to produce it, and provider usage is recorded with and
without the packet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…baseline, paper scaffold

peak_rss_bytes called GetProcessMemoryInfo with an untyped pseudo-handle and
returned None on Windows; it now uses K32GetProcessMemoryInfo with argtypes.
train.py gains 'trainprobe' (peak RSS after dataset and torch load, peak RSS
and CUDA peak over N training steps, seconds per step). MCP-03 baselines add
BM25 ranked path maps (top 5/12/25 paths) so the whole-file baseline gets the
same pointer channel as router packets; 'run.py baselines' recomputes them.
swebench_demo.py runs goblin-gdk on SWE-bench Lite with and without packets.
papers/mcp_data_goblin holds the LaTeX scaffold and table/figure generators.

Verified: python -m pytest -q MCP/test_mcp02.py MCP/test_mcp03.py -> 33
passed, 1 skipped; peak_rss_bytes returns the process peak on Windows and
memprobe reports a 13 MB forward delta for the smoke TRM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
run.py dataset --shard k/n builds every n-th instance of the split, and
run.py merge concatenates shard files with summed metadata, so the
training set can be built in parallel processes.

Verified: python -m compileall MCP/mcp03 succeeds; four training shards are
running from this code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ter snippets)

The held-out control run showed that a whole-file BM25 ranking listed as
its top 12 paths (113 tokens) reaches gold-file recall 0.76, above the
router-derived file map (0.725), while carrying no symbol evidence. The
code MCP surface gains file_search (BM25 over whole files, paths only).
With evaluation.composed_packets, each episode issues one counted
file_search after exploration and also reports packets whose file map is
that ranking and whose snippets are the router's reads (keys cNNN).
goblin_server accepts compose=true. Paper tables and macros report both
packet types and the path-map baseline.

Verified: python -m pytest -q MCP/test_mcp02.py MCP/test_mcp03.py -> 34
passed, 1 skipped (new composed-packet test included).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Under full CPU contention one CPU inference of the 0.5B model ran past
goose-providers' default 600 s request timeout and the run returned an
empty answer with no usage. The app now sets ModelConfig max_tokens and the
ApiClient timeout from flags and records both in its receipt. The demo
passes --max-tokens 200 --timeout-secs 3600, keeps completed runs on
restart, retries runs that produced no output tokens, and keeps the earlier
timeout receipts under earlier_provider_timeouts.

Verified: cargo build --release in Ubuntu 24.04 (WSL) succeeds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MCP/results/mcp03/gdk_demo: goblin-gdk (goose-agent 0.1.0-alpha.14) with
Qwen2.5-0.5B-Instruct on CPU in WSL, 11 SWE-bench Lite tasks from requests,
flask and seaborn, each run with and without the goblin packet. With the
1.5K-token packet the model named a gold file in 5/11 tasks and a gold
function in 3/11 (provider input 2,012 tokens on average); without it, 1/11
and 2/11 (503 tokens). Server identity (494,032,768 parameters, weight
SHA-256) and the one provider timeout from the contended period are kept.

run.py evaluate --shard k/n and merge-runs let the held-out evaluation run
in parallel processes. Paper: abstract, resources section, aggregated GDK
table.

Verified: python -m pytest -q MCP/test_mcp03.py -> 11 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ADME

make_tables.py writes macro_defaults.tex (providecommand fallbacks for
every data macro) and wraps generated tables in adjustbox. A dry run on
partial results compiles with pdflatex (MiKTeX) to a 209 KB PDF.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rom data

MCP/results/mcp02/pilot_gpu (8,064 episodes, width-128 routers with the
exact-match encoder, 256 and 1024 resources, depth/deliberation/layout
sweeps): learned routers accept 22-32 of 32 layered episodes at 256
resources against 7-22 for BM25 and the rules, and 14-23 against 1-6 on the
kind-first index at 1024; looped and TRM cores match the four-layer
Transformer with a quarter of its non-embedding parameters; the looped block
improves with more passes at test time while TRM/HRM stay flat; no certified
exclusion removed a required record. Replay of 202 sampled episodes from
the published tapes: 0 mismatches.

MCP/results/mcp03/swebench_lite (109 SWE-bench Lite tasks from ten held-out
repositories, 13 routers x 3 arms, composed packets, BM25 whole-file and
path-map baselines, training/inference memory probes): the four-pass looped
router reaches gold-file recall 0.86 in a 308-token packet, against 0.53
for 27K-token BM25 whole files; BM25 reading plus the BM25 path map gives
the best function recall (0.41 at 2K tokens).

papers/mcp_data_goblin: generated tables, figures and number macros;
results, resources and next-experiment sections written from them. The paper
compiles with pdflatex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MCP/results/mcp02/llm_pilot: Qwen2.5-0.5B-Instruct (494,032,768
parameters, server-measured; bf16 on the RTX 5080) as an end-to-end
JSON-action controller through MCP.local_model.LocalModel on six MCP-02
search-arm test worlds: 0/6 accepted, 39.8 calls and 78.5K tokens per
episode; five episodes read invented URIs 40 times without searching. The
stage was stopped after six episodes to stay within its VRAM lease on a
shared card; Qwen3-1.7B was not run. Replay of all six from the recorded
responses: 0 mismatches.

Paper: LLM controller table and section, abstract revised to the measured
SWE-bench result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ampled MCP-03 episodes

PROTOCOL.md records how the pilots were split, paused and resumed on the
shared machine, why the LLM stage stopped after six episodes, and where
training memory comes from. MCP-03 README records that file_search and
composed packets were added after the first control-only run and that all
published numbers come from the later full evaluation. MCP/README.md points
to MCP-03, the GDK app, results and the paper. run.py replay now replays
only the sampled episodes instead of every episode of a sampled instance.

Verified: python -m pytest -q MCP/test_mcp03.py -> 11 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d training-set count

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MCP/results/mcp02/pilot_cpu (7,488 episodes): width-48 routers trained and
run on CPU. The tokens-only routers stay below BM25 and the rules on layered
discovery; the matched exact-match pair (same data, width, epochs) lifts dev
ranking accuracy from 0.62 to 0.88 (Transformer-L2) and 0.61 to 0.86 (TRM),
and layered acceptance at 256 resources from 17/4/5 to 31/29/26 and from
20/7/5 to 30/29/28. Replay of 188 sampled episodes: 0 mismatches.

papers/mcp_data_goblin: final tables (MCP-02 pilots, MCP-03 packets and
receipts, LLM controllers, GDK demo), redrawn figures (SWE-bench tokens
against file recall; layout sweep), encoder-ablation paragraph, and the
compiled main.pdf (pdflatex, 17 pages, no undefined references).

CI replays committed MCP-02 tapes every 15th episode.

Verified: python -m pytest -q MCP tests/test_cca_verified_membrane.py
tests/test_hybrid_membrane.py -> 115 passed, 1 skipped, 55 subtests; the
2 failures are the MCP-01 Windows-only timing tests that pass on Ubuntu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MCP/mcp03/swebench_e2e.py runs goblin-gdk per task and context condition,
converts search/replace edits into git diffs at the base commit, and writes
harness predictions with token receipts. Run on the 26 SWE-bench Lite tasks
from requests, flask and pytest (repositories the routers never trained
on), with Qwen3-4B-Instruct-2507 in bf16 on the RTX 5080 under WSL, scored
by the official harness (swebench 5.0.2, Docker):

- gold patches: 21/26 resolved on this host (the 5 failures are requests
  tasks whose tests need network access)
- issue only: 0 applicable patches, 0 resolved
- BM25 whole files, 13K tokens: 14 patches, 0 resolved, 13,430 input tokens
- goblin packet, 4K tokens: 12 patches, 1 resolved (pytest-dev__pytest-7373),
  4,039 input tokens

Paper (19 pages): end-to-end section, table and abstract item; limitations
now describe the small-model resolve rates instead of an unmeasured gap.

Verified: python -m pytest -q MCP/test_mcp03.py -> 11 passed; harness
reports are in MCP/results/mcp03/swebench_e2e.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MCP/hubrun adds an OpenAI-compatible relay with a raw arm and a goblin
packet arm, the packet compaction for long agent histories (MCP-02 BM25
plus the MCP-03 exact-match terms), a summarizer for vf-eval and
verifiers v1 outputs, and the WSL scripts that pin verifiers per
environment and run the overnight queue.

Verified: python -m unittest MCP.test_hubrun (8 tests) passes on Windows
Python 3.12 and WSL Python 3.12; smoke runs of all seven environments
completed through the relay against Bonsai 27B.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…blin packet

One night on the RTX 5080: Ternary Bonsai 2 27B PTQ1_0 (llama-server, two
32K slots) through the MCP/hubrun relay.

Storyworlds (held-out splits only): jinn-beast-metta cross-frame 0.80 on
80 dev tasks, constructs 0.88, moral reasoner 0.87, control mesh v2 0.93
with the target action on 48/48, no critical actions.
storyworld-constitution scores 0/15: the model answers <option_id> with
angle brackets, as the prompt's format line shows, and the strict parser
rejects them; bracket-stripped choices match 3/15.

Agentic sets: feishu-office hard 7/7 and expert 7/7 (raw),
durable-notebook 6/8, mcp-sqlite 22/57 exact match. event-recon tier 1
scores 0 in every arm: raw overflows 32K in 5/5 episodes, the goblin
packet prevents overflow but never files a report, and late compaction
(18K estimated) still overflows 5/5. On doc-edit the early packet lowers
success from 5/8 to 1/8.

Adds publish.py (summary, public traces, call logs, manifest), context
overflow counts and late-arm pairing in summarize.py, the paper section,
tables and abstract/limitations entries.

Verified: python -m pytest -q MCP/test_hubrun.py MCP/test_mcp03.py
(19 passed); python -m pytest -q MCP has only the two MCP-01 timing
tests that fail on Windows; pdflatex builds main.pdf (20 pages, no
undefined references).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Contributor Author

Review of MCP-01/02/03 + Bonsai Hubrun at PR #14 head 1e526b0, also reading Carbon's newer docs/mcp-looped-mesh-retrieval-strategies-20261121 (72aee28). The strategy document's proposed SetTRM-LDT with persistent typed state and separate expand/read heads is a reasonable next experiment. Please keep the following scientific and execution boundaries explicit:

  1. The bottleneck is symbol acquisition. On MCP-03's 109 SWE-bench Lite test instances, search/looped_p4_d64 at a 512-token packet has 94/109 all-gold-file hits (mean file recall 0.8624, mean packet 307.55 tokens) but mean gold-symbol recall only 0.1116. layered_ldt/lexical_bm25 at 2048 tokens with composed packet has mean gold-symbol recall 0.4141; the layered_ldt oracle at 1024 is 0.9281. These are different packet/arm budgets and the oracle is private-gold-assisted, so they are diagnostic targets, not a single fair leaderboard. Train a separate read_symbol marginal-utility head and measure actual symbol-body admission before adding model scale.
  2. Keep SWE-bench outcomes distinct from localization. The official end-to-end 26-task campaign resolved 1/26 with Goblin packet and 0/26 with BM25-13K. Gold patches were harness-resolved for 21/26, with multiple no_tests_collected ambiguous predictions. Report the 26 assigned denominator and a pre-audited gold-valid subset separately; these 109/26 inspected instances should remain development data after iterative strategy selection.
  3. Verifier scope for learned LDT. Current MCP/mcp03/env.py certifies test_path and doc_path exclusions only. The new strategy text proposes already-covered symbol subtree and complete subgoal satisfaction as pruning/stop predicates. Require an exact, host-owned proof of the relevant coverage state before these become exclusion certificates. Until then, treat coverage as a soft rank/VOI feature.
  4. Compaction regression is substantive. Hubrun doc-edit falls from raw 5/8 to compacted 1/8, with more total prompt tokens; event-recon prevents five context overflows yet scores 0/5 in both arms. Issue MCP-04: token-aware, state-preserving compaction for the generic MCP mesh #15 already specifies a good v2 plan: exact model-tokenizer preflight, an append-only mutable-edit/negative-evidence ledger, stable read handles, and raw-history when context fits. The new MCP/TRAINING_STRATEGIES.md should keep this as a distinct admission gate.
  5. Live Goose snapshot correctness: MCP/mcp03/goblin_server.py cached source/AST by directory forever, and some bad symbol reads came back with isError: false. I opened review PR #16 against the gym feature branch with revision-aware cache invalidation, error-channel propagation and edit/delete/add regression tests. It does not alter pretrained-model scores.

Recommended next CPU-first campaign: freeze the exact 109-instance baseline as development, generate new repo-rooted platformer defects and validation tasks for DAgger/read-aware training, compare BM25, existing looped router, and read-aware SetTRM with one fixed budget and intact gold labels offline. Follow with a fresh independent externally curated SWE cohort for downstream patch-resolution tests; keep native SWE graders unchanged.

MCP-05T: audited historical read-repetition and stale-edit baseline
MCP-05: query-aware ECAN-style working-set attention over MCP-04
MCP-03-RU01: CPU read-aware expand/read utility heads and packet-marginal supervision
MCP-04: typed working-set memory and exact llama-server preflight (CPU contracts)
@patrickdugan
patrickdugan merged commit 0d331ce into master Nov 22, 2026
10 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