Skip to content

feat: resurrect all 99 cartridge adapters — 99/99 building and testing green - #114

Merged
hyperpolymath merged 8 commits into
feat/zig-016-ffi-sweepfrom
feat/adapter-resurrection
Aug 7, 2026
Merged

hyperpolymath merged 8 commits into
feat/zig-016-ffi-sweepfrom
feat/adapter-resurrection

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

PR D of the BoJ 0.16 campaign — the last, and largest, open item

Stacked on #109. Base is feat/zig-016-ffi-sweep, not main, because this depends on the shim compat layer that PR introduces. Merge #109 first.

The adapter layer had never compiled. zig-test.yml globbed only */ffi/, so 99 build files sat ungated since they were written, and just mint propagated the template's defects into every new cartridge.

Result: 99/99 adapters green on zig build && zig build test — the exact command CI now runs. Baseline was 3/99.

Why they were broken — mostly not Zig 0.16

Only two of the five defect classes were version-related. The other three are why these files had never built:

Defect Trees Zig 0.16?
Multiline string literal written with one backslash (\{{"success":…}} — not a token) 24 no
JSON object templates passed to bufPrint without doubling literal braces 19 no
Adapter called an init symbol absent from its own sibling FFI most no
Old build API (root_source_file in Executable/Test options) ~all yes
std.net → std.Io.net ~all yes

Corrections to the brief I gave

  • k9iser-mcp was not already-0.16-valid. Its zig build test passed only because a test build never analyses main(); zig build failed on std.net.Address. Same for bug-filing-mcp. This is why zig build — not zig build test — is the load-bearing gate here. The same lazy-analysis blind spot hid two live 0.16 breakages in 007-mcp's FFI (process.Child.init, FetchOptions.response_storage), which only surfaced when its adapter forced full analysis.
  • An over-broad brace fix on the first pass hit plain wire-body literals in four cartridges; caught, reverted from git, redone narrowly. local-coord's pre-existing doubled braces are legitimate format strings and were left alone.

⚠️ Security fix, flagged because it is a behaviour change

bsp, dap, lang and lsp bound 0.0.0.0 on three listeners each — 12 public ingresses. Their own READMEs and ADR-0004 state adapters are internal, loopback-only, behind the http-capability-gateway. They now bind loopback. Revert if that was deliberate, but it contradicted every document describing it.

The template

just mint copies it, so it got a real rebuild rather than a port. It was broken four ways — including that dispatch() never reached the FFI at all: it matched a tool name and returned a hand-written "<tool> forwarded" string, contradicting the "response passthrough" invariant in its own README. It now dispatches through ffi.boj_cartridge_invoke. It also had zero tests, so its test step could not fail; it now has 5, and failability was verified by breaking an assertion and watching the step go red.

What this does NOT fix — stated plainly

  • The 90 cloned adapters still fake their dispatch, exactly as the template did. They were ported semantics-preserving per the minimal-diff rule. Converting them to real boj_cartridge_invoke dispatch is scriptable (tool lists come from cartridge.json) but it is a wire-behaviour change across 90 cartridges — not something to do unilaterally in a port.
  • zig build test is vacuous for 95 of 99 adapters — only 4 declare inline tests. zig build is what makes the job failable, and the workflow header says so rather than implying coverage that doesn't exist. I did not fabricate tests for the 95: only 56 of 94 clones even route /status, so any generated assertion would have been wrong somewhere or weakened to fit. Adapter test coverage of 4/99 is now visible debt rather than a green step hiding it.

CI

zig-test.yml's detector and diff filter now match (ffi|adapter)/; the changed-cartridge job runs zig build && zig build test in <cart>/adapter; full-sweep gained a second pass over every */adapter/build.zig. Timeouts 15→25 and 60→120. The glob was wired only after its subject was green — the 99/99 sweep used the identical command.

Verification (re-run independently, not taken on trust)

check result
every */adapter/build.zig: zig build && zig build test 99 pass / 0 fail
every */ffi/build.zig: zig build test re-verified after 129 FFI files were touched
tools/sync_cartridge_shim.sh --check 117 copies, 0 drifted — no shim file appears in the diff

🤖 Generated with Claude Code

hyperpolymath and others added 7 commits August 7, 2026 13:58
`adapter/build.zig` imports the sibling FFI as a Zig module, but the FFI
sources declared bare `export fn`s and a private `const shim`. `export`
alone gives a symbol C linkage; it does NOT make the declaration visible
to another module through `@import`, so every adapter that referenced
`ffi.boj_cartridge_invoke` (or needed the shim's `std.Io`) failed to
compile. 2/118 FFI files had `pub export`; the other 116 did not.

Mechanical across 129 files: `export fn` -> `pub export fn` (568 sites),
and `const shim = @import("cartridge_shim.zig")` -> `pub const shim = ...`
so adapters can reach the ONE process-wide `std.Io` the shim owns rather
than standing up a second runtime alongside the cartridge.

No shim copy is touched: `tools/sync_cartridge_shim.sh --check` reports
117 copies, 0 drifted. All 118 `ffi/` trees still green on
`zig build test`.

Co-Authored-By: Claude Opus 5 <[email protected]>
…hape

The template adapter is what `just mint` copies, so every future cartridge
inherits whatever it leaves behind. It was broken three ways at once, none
of them fixable by a Zig version bump:

  * `main()` called `ffi.gossamer_init()` — a symbol that exists nowhere in
    the sibling `ffi/`;
  * `dispatch()` never reached the FFI at all. It matched a tool name and
    returned a hand-written `"<tool> forwarded"` string, which contradicts
    the adapter README's own "response passthrough" invariant;
  * `build.zig` used `root_source_file` inside Executable/Test options, and
    the listener used `std.net`, both removed in 0.16.

Rebuilt on the canonical unified-adapter shape documented in
`.claude/CLAUDE.md` and implemented by `k9iser-mcp`: ONE loopback listener,
protocol-classified (REST `/invoke`, SSE `/sse`, GraphQL `/graphql`,
gRPC-compat `/grpc/<Svc>/<Method>`), every request through the
`exposureSatisfied` transaction gate before a SINGLE dispatch into
`ffi.boj_cartridge_invoke`. The listener is ported to `std.Io.net` on the
shim's process-wide `std.Io`, and `build.zig` moves to
`createModule` + `.root_module`.

The adapter previously had zero tests, so its `test` step could not fail.
It now carries five: protocol classification, per-protocol tool extraction,
the dispatch funnel over every tool in `cartridge.json`, the
`exposureSatisfied` truth table, and `X-Trust-Level` parsing. Verified
failable — breaking one classification assertion turns the step red.

`zig build` and `zig build test` both green in `templates/gossamer-mcp/ffi`
and `templates/gossamer-mcp/adapter`.

Co-Authored-By: Claude Opus 5 <[email protected]>
Ninety `adapter/` trees are copies of one boilerplate. None of them built,
and no CI job ever ran them (`zig-test.yml` globbed only `*/ffi/`).

Per tree:

  * `build.zig` regenerated on the 0.16 build API — `b.createModule(...)`
    plus `.root_module`, replacing `root_source_file` inside
    `ExecutableOptions`/`TestOptions`. Adds the `run` and `test` steps to
    the trees that lacked them, and mirrors the sibling FFI library's
    `link_libc` onto the embedded module (74 trees), which is what the
    `undefined symbol` / `dependency on libc` failures were.
  * The listener tail is ported from `std.net` to `std.Io.net`: sockets now
    take an `io` handle, and it comes from the shared ADR-0006 shim
    re-exported by the FFI module, so the adapter and the cartridge behind
    it share ONE `std.Io.Threaded` rather than standing up two.
  * `main()` called `ffi.<cartridge>_init()`, absent from every sibling
    `ffi/`. Now `ffi.boj_cartridge_init()` with a matching `deinit`.

Two pre-existing format-string defects, independent of the version bump,
also had to go — both are why these files had never compiled at all:

  * 24 trees wrote a multiline string literal with ONE backslash
    (`\{{"success":…}}`), which is not a token;
  * 19 trees passed a JSON object template to `bufPrint` without doubling
    its literal braces, so `std.fmt` read the leading `{` as a placeholder.

The three-port REST/gRPC/GraphQL wire shape and every per-cartridge
dispatch table are left exactly as they were.

Co-Authored-By: Claude Opus 5 <[email protected]>
`k9iser-mcp` and `bug-filing-mcp` were the only adapters already on the
canonical unified shape, and `k9iser`'s `zig build test` was green — but
only because a test build never analyses `main()`. `zig build` failed on
both: `std.net` does not exist in Zig 0.16.

`writeHttp`, `writeSse`, `handleConnection` and `main` now take a
`std.Io` handle and use `std.Io.net`; the handle is the shim's
process-wide runtime, re-exported by the FFI module. Routing, the tool
catalogue, the dispatch funnel and the `exposureSatisfied` gate are
untouched, and all five inline tests still pass in each.

Co-Authored-By: Claude Opus 5 <[email protected]>
`bsp-mcp`, `dap-mcp`, `lang-mcp` and `lsp-mcp` drive `std.http.Server`
rather than parsing HTTP by hand, so they needed a different port from the
cloned boilerplate:

  * `std.http.Server.init` takes a `*Reader` and a `*Writer` in 0.16, not a
    `net.Server.Connection` plus a scratch buffer;
  * `Request.reader()` became `Request.readerExpectContinue(buffer)`;
  * `std.mem.trimLeft`/`trimRight` are now `trimStart`/`trimEnd`;
  * `{}` no longer formats an error value — `{t}` does;
  * `build.zig` moves to `createModule` + `.root_module`.

Three of them also carried 46 inline `\{{…}}` templates — a multiline
string literal written with one backslash, mid-expression, where a
multiline literal cannot appear at all. Rewritten as the quoted format
strings they were meant to be.

Corrects one thing that predates the migration: all four bound `0.0.0.0`.
A cartridge adapter is internal and sits behind the http-capability-gateway
(ADR-0004) — the adapter READMEs say so — so all three listeners in each
now bind loopback.

Co-Authored-By: Claude Opus 5 <[email protected]>
The last two adapters each used a removed stdlib API of its own.

local-coord-mcp:
  * `std.io.fixedBufferStream` is gone — `std.Io.Writer.fixed` replaces it
    at 8 sites, with `.pos` becoming `.end`;
  * `std.fmt.format(w, …)` folded into `Writer.print`;
  * `GeneralPurposeAllocator` renamed to `DebugAllocator`;
  * listener ported to `std.Io.net`. `build.zig` gains the `run`/`test`
    steps it lacked (it was the one tree with no `test` step at all).

007-mcp:
  * `std.process.getEnvMap` removed — reads `$OO7_WORKTREE` through the
    shim's libc-backed `getenv`, so the adapter module links libc;
  * `ArrayList.writer(gpa)` removed — `appendSlice`/`print` directly, and
    `std.Io.Writer.Allocating` where a `*Writer` is genuinely needed;
  * listener and `writeHttpResponse` ported to `std.Io.net`.

Building the 007 adapter also forced two 0.16 breakages out of
`007-mcp/ffi/oo7_mcp_ffi.zig` that the FFI's own `zig build test` never
reached, because nothing it analyses calls them:

  * `std.process.Child.init`/`spawn`/`collectOutput`/`wait` folded into
    `std.process.run(gpa, io, …)`, which takes the Io handle and enforces
    the capture limit itself. `Term`'s tags are lower-case now and
    `.signal` carries a `posix.SIG`;
  * `http.Client.FetchOptions.response_storage` replaced by
    `response_writer`; leaving it null discards the body, which is what
    this fire-and-forget POST wanted.

Co-Authored-By: Claude Opus 5 <[email protected]>
99 `adapter/` trees existed and no job ever built one — the changed-cartridge
detector and the diff filter both globbed `*/ffi/` only, and `full-sweep`
iterated `*/ffi/build.zig`.

  * the `changes` detector and the per-cartridge diff now match
    `(ffi|adapter)/`, and the cartridge root is derived by stripping either
    segment;
  * the changed-cartridge job runs `zig build && zig build test` in
    `<cart>/adapter`;
  * `full-sweep` gains a second step over every `*/adapter/build.zig`,
    reporting its own failure count. Its timeout goes 60 -> 120 minutes and
    the changed-cartridge job's 15 -> 25 to cover the extra compiles.

`zig build` is deliberately the load-bearing adapter gate: it compiles the
executable, so `main()` and the listener paths are analysed and the step
cannot pass vacuously. `zig build test` is run too, but only 4 of 99
adapters currently declare inline tests, so on its own it would be a check
that cannot fail — the workflow header says so rather than implying
coverage that is not there.

Verified before wiring: all 99 adapters pass `zig build && zig build test`,
and all 118 `ffi/` trees still pass `zig build test`.

Co-Authored-By: Claude Opus 5 <[email protected]>
hyperpolymath added a commit that referenced this pull request Aug 7, 2026
PR #114 takes the adapter layer from 3/99 to 99/99 green and wires it
into CI. Three things it deliberately leaves, now visible rather than
implied:

- A-4 (HIGH): the 90 cloned adapters still fake dispatch — they return
  "<tool> forwarded" without calling boj_cartridge_invoke, contradicting
  the response-passthrough invariant in their own READMEs. The template
  was fixed properly; converting 90 is a wire-behaviour change.
- A-5 (MEDIUM): adapter test coverage is 4 of 99, so `zig build test` is
  vacuous for 95 and `zig build` is what makes the job failable.
- A-6 (LOW, FIXED): bsp/dap/lang/lsp each bound 0.0.0.0 on three
  listeners — 12 public ingresses against ADR-0004 and their own
  READMEs. Now loopback.

Co-Authored-By: Claude Opus 5 <[email protected]>
@gitar-bot

gitar-bot Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Note

Automatic reviews are paused because your trial's included automatic processing has been used for this period. Upgrade now, or comment "Gitar review" to run a review anytime.
Learn more

Code Review ✅ Approved 2 resolved / 2 findings

Resurrects all 99 cartridge adapters to build and test green on Zig 0.16 by fixing build APIs, string literals, and network bindings. Consider restoring concurrent connection handling and implementing multi-read request buffering in the ported three-port adapters to prevent request truncation.

Auto-approved and auto-merge armed: No blocking issues found.
Please see Auto-approve Docs for details on setting custom approval criteria. — merges when pipeline and required approvals pass.

✅ 2 resolved
✅ Performance: Ported three-port adapters now handle connections serially

📄 cartridges/cross-cutting/agentic/agent-mcp/adapter/agent_adapter.zig:145-153 📄 cartridges/cross-cutting/fleet/fleet-mcp/adapter/fleet_adapter.zig:138-142 📄 cartridges/templates/gossamer-mcp/adapter/gossamer_adapter.zig:276-280
In the port, listenLoop was changed from spawning a detached thread per accepted connection to calling handleConnection(io, stream, proto) directly in the accept loop (agent_adapter.zig:150, fleet_adapter.zig:140-141, and the ~38 clones sharing this shape). Because handleConnection performs blocking socket reads/writes, one slow or half-open client now stalls the entire per-protocol listener until it times out/closes — a throughput and availability regression versus the pre-port thread-per-connection behavior. Notably this also diverges from the canonical template (gossamer_adapter.zig:277-279), which still spawns and detaches a thread per connection. Consider restoring thread-per-connection (matching the template) or documenting the intentional serialization.

✅ Edge Case: Adapter reads request with single fillMore(); body may truncate

📄 cartridges/templates/gossamer-mcp/adapter/gossamer_adapter.zig:217-231 📄 cartridges/domains/development/bug-filing-mcp/adapter/bug_filing_mcp_adapter.zig:201-215
handleConnection calls sr.interface.fillMore() once and then treats buffered() as the complete HTTP request (gossamer template, and the copied bug_filing/k9iser adapters). fillMore returns after a single fill, so a request whose body arrives in a later TCP segment — or exceeds REQ_BUF_LEN — is silently truncated. For REST/SSE the tool is parsed from that body via jsonStringField, so a split request yields a spurious 400 missing-tool instead of dispatching. On loopback this usually works because requests arrive in one segment, but as the canonical template copied by just mint it establishes the fragility in every new cartridge. Consider looping until \r \r is seen and Content-Length bytes are buffered (as oo7_adapter does for headers).

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Important

Your trial ends in 3 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more.

Was this helpful? React with 👍 / 👎 | Gitar

gitar-bot[bot]

This comment was marked as resolved.

@gitar-bot

gitar-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

⚠️ Gitar auto-approved this PR but could not enable auto-merge: the pull request is already mergeable, so there is nothing for auto-merge to wait on — add a required status check via branch protection, or merge it directly.

@gitar-bot gitar-bot Bot added the gitar-approved Added by Gitar label Aug 7, 2026

@gitar-bot gitar-bot 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.

Gitar has auto-approved this PR and enabled auto-merge (configure)

@gitar-bot
gitar-bot Bot dismissed their stale review August 7, 2026 14:40

✅ All code review findings resolved.

Configure merge blocking

@hyperpolymath
hyperpolymath merged commit afd4c9e into feat/zig-016-ffi-sweep Aug 7, 2026
2 checks passed
@hyperpolymath
hyperpolymath deleted the feat/adapter-resurrection branch August 7, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gitar-approved Added by Gitar

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant