Repository navigation
Deduplicate agent-runtime provider adapters and bridges - #1374
Conversation
|
🚨 SLOP COP 🚨 · I am the Slop Cop. I am now reviewing this pull request. I will check security, code quality, performance, architecture, and practical test coverage. |
SawyerHood
left a comment
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
ELI5: This PR puts repeated provider code into shared helpers. Future provider changes should need fewer edits and have fewer chances for drift.
I found no blocking issue.
The security review found no new command injection, permission bypass, cross-session response use, or secret transfer path.
The quality review found that the refactor preserves the reviewed provider behavior. It found no stale helper names or duplicate adapter implementations.
The performance review found no regression. The shared tool-response path removes one repeated session scan.
One small follow-up remains. ToolCallForwarder still has matching definitions in the shared registry, Claude proxy, and Pi proxy. A later cleanup can export one shared result contract.
I checked the full 31-file diff and relevant surrounding code. I also searched the repository for stale names and duplicate implementations.
The @bb/agent-runtime type check passed. The local package run passed 907 of 908 tests.
The unchanged stderr-tail test failed twice. This pull request does not change that test or its process lifecycle code.
GitHub CI passed all package, server, app, integration, and package-smoke checks.
I did not start the app or use a browser. This change has no user interface route, so the bridge and integration suites provide the relevant product coverage.
Motivation
The four provider adapters (claude-code, codex, pi, acp) and three bridges carry near-verbatim copies of the same machinery: stdio harness, session registry, adapter identity/command/translation boilerplate, turn lifecycle, item-id scoping, and tool item translation. That duplication has a measurable history of making cross-provider work slow and lossy:
ProviderRateLimitStateis referenced by claude-code and codex translation only — Pi and ACP have zero references. Duplication didn't just slow the change down; it silently dropped half the matrix.classifyExecutionSettingsChange(Apply Claude turn settings without replacing live sessions #1236) had to touch all four adapters to change one provider's behavior, because the member wiring is copied everywhere.After this PR, the shared machinery lives in
packages/agent-runtime/src/shared/and a cross-provider change of this kind is a one-place change.Honest accounting
Repo-wide this is roughly −300 lines net (2,204 insertions, 2,512 deletions, all inside
packages/agent-runtime). The ~1,640-line figure from the de-slop audit counts duplicated lines, not deletable ones — extracting a shared implementation still costs its one copy plus parameterization. The value of this PR is one-place-change for cross-provider behavior, not raw deletion.Commit-by-commit review guide
The 8 commits are logically staged; each is independently revertable and behavior-preserving:
fff1c494cshare bridge stdio harness — the three bridges' identical stdin/stdout JSON-RPC loop (readline wiring, dispatch, error replies) moves toshared/bridge-harness.ts.e1e7615bashare bridge session registry — the per-bridgeMap-of-sessions bookkeeping (create/get/stop/dispose) moves toshared/bridge-session-registry.ts.66fee1a30share bridge environment helpers — env-override construction/parsing dedup inshared/adapter-utils.ts(round-trip covered by a new test), plusshared/mime-types.ts.6e6e9fbc1share standard adapter members — the biggest one. Each adapter's copied identity/launch members,initializeplan, unsupported-command fallbacks, accepted-command translation, model-list parsing, and tool-call decoding collapse intocreateStandardAdapterMembers()(shared/standard-adapter-members.ts); adapters keep only their provider-specificbuildProviderCommandPlan. Review focus: confirm each adapter's per-command plans are unchanged (they are moved, not edited).4c6a3c65bcentralize provider turn hooks — per-adapterensureXTurnStartedwrappers and the copied error-envelope-to-events helper becomeonTurnStart/onTurnFinishhooks andbuildErrorEventson the shared turn-state registry;shared/provider-error-events.tsis deleted.276516e32share scoped item id factories — the copied open/completed scoped-item-id resolution moves toshared/scoped-item-ids.ts.fbd671c2ashare tool item translation — the copied toolUse/toolResult item builders move toshared/tool-item-translation.ts.86a313d7bremove dead exports and helpers — deletes exports and helpers made unreferenced by the extractions (verified by repo-wide typecheck).Wire compatibility (server ↔ host daemon)
No
HOST_DAEMON_PROTOCOL_VERSIONbump needed, and none is included. The diff is confined topackages/agent-runtime;packages/host-daemon-contract(session payloads, WS messages, host RPC commands/results) is untouched and the protocol version stays at 106 on both sides. The refactor changes where adapter/bridge code lives, not what crosses the wire: the 900+ adapter tests that assert exact translatedThreadEventoutput (ids, scopes, payloads) pass without any expectation changes, so the event stream the daemon posts to the server is byte-identical.Rebase provenance
This branch originated in archived thread
thr_jyia7bkdqnand was rebased onto current main (original authorship preserved in the commits). The rebase crossed #1280 (sent-message editing) and #1321 (provider-unhandled-event fix), both of which touched the same adapters; conflicts were resolved by preserving main's shipped behavior and re-grafting it into the extracted structure:thread/discardcommand plans re-added per provider (acp: noop, claude-code:thread/stop, pi:thread/discard) inside eachbuildProviderCommandPlan.latestProviderCheckpointIdreset moved into the sharedonTurnStarthook (fires only for newly opened turns, same guard as the removed wrapper).sourceProviderCheckpointIdforwarding re-added to the claude-code and pithread/forkplans.The rebase delta vs the original branch inside
packages/agent-runtimeis exactly the sum of #1280 + #1321 (+1,124/−36), i.e. nothing from main was lost and nothing beyond the refactor was introduced.Verification
pnpm exec turbo run typecheck— whole repo, 58/58 tasks pass.pnpm exec turbo run test --filter=@bb/agent-runtime— 907 passed, 1 failed:runtime.process-lifecycle.test.ts > bounds provider stderr while data arrives without a newline, which fails identically on unmodified origin/main (reproduced during this work; also documented as pre-existing in fix(host-daemon,db): stop one undeliverable event from wedging every thread #1321). The lifecycle suites (runtime.lifecycle.test.ts28/28,runtime.process-lifecycle.test.ts21/21 excluding the pre-existing failure) covering the Codex recovery paths pass.pnpm exec turbo run test --filter=@bb/host-daemon(the only dependent of@bb/agent-runtime) — 541/541 pass.🤖 Generated with Claude Code