Repository navigation
Serve hive tools over loopback MCP with per-turn call identity - #138
Conversation
Add tests pinning the wire form of call records on running turns and verifying that snapshots written before call records existed still load with an empty map and serialize without the field. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Running turns now carry a map of identified calls keyed by the caller's call id, each holding the tool, its arguments and the result, so a retry of the same call can be answered from the record instead of being repeated. The field defaults to empty so snapshots written before calls were identified still load. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Use the fully qualified std::collections::BTreeMap path in the retention test fixture so the test compiles without relying on an import that is no longer in scope. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The test name now says the loaded turn has no calls rather than none, matching what the assertion actually checks. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The retried-send test now holds only agent a and registers b as an immediately completing agent, so the second request no longer needs a manual finish notification. Teardown uses the held helper's end method instead of notifying and awaiting the drain by hand, and the calls test module is now declared so it is compiled. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
…r methods Move the hive creation, join, leave, and action staging logic out of the async methods into standalone functions that take the stored state directly, so the same validation can be exercised without going through the coordinator. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Simplify the equality check against the stored hive entry by comparing the value directly instead of taking an extra reference, with no change in behaviour. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The send path now delegates identifier validation to an `admissible` helper and the transactional body to an `accept_state` function, so the same logic can be reused outside the coordinator's update closure. Behaviour is unchanged. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
…ecks Introduce a TurnCall type that binds a state-changing call to an agent, its running turn, and a caller-chosen identity, so a retry with the same tool and arguments returns the recorded result while any other reuse is refused. Two new errors report calls that name a turn which is not the agent's running one and calls that reuse an identity with different tool or arguments. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Introduce a calls module under the coordinator to handle call-related coordination logic within the hive. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The holding helper now blocks only the turn a test actually receives, so later turns such as the conductor's nudges return immediately instead of stalling on a notification that is never signalled. The doc comment was updated to match the narrower behaviour. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Introduce a `RunningTurn::claimed` constructor that builds a turn with no staged actions and no recorded calls, and use it in the scheduler instead of assembling the struct inline. This keeps the initial state of a claimed turn defined in one place. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Replace the is_empty assertions on stored actions and side hive members with assert_eq against empty vectors so failures print the actual contents. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Adds README coverage for the `TurnCall` mechanism that lets out-of-process hosts distinguish transport retries from new actions, describing the `*_in_turn` entry points, how retries are answered from recorded results, and how stale turns and reused calls are refused. Also documents the new `RunningTurn::calls` record and its backward-compatible serialization, plus the corresponding test module. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Tool calls can now carry an optional turn and call identity, and management actions such as creating a hive, joining, or leaving are dispatched through the coordinator's in-turn variants when that identity is present. This lets the coordinator enforce that a turn is running and apply at-most-once semantics per call, while unidentified calls keep the existing behaviour. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add a test asserting that a runner reports whether any hook matches a given tool name, covering wildcard and exact matchers as well as the case where only a stop hook is present. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Added a matches_tool method to HookRunner that reports whether any pre_tool_use or post_tool_use hook names the given tool, letting callers skip work when a tool call would run no hook. The matcher test was reformatted to fit the new hook construction. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Register the new tinyhivemind-mcp member and declare the dependencies its Streamable HTTP server needs: hyper with server and HTTP/1 only, hyper-util for tokio I/O and graceful shutdown, http-body-util for bounded and fixed bodies, subtle for constant-time bearer comparison, and getrandom for per-seat tokens. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Introduce a common support module that integration tests can share, so setup and helper code no longer has to be duplicated across test files. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add integration tests covering the MCP HTTP transport, exercising request handling and response behaviour end to end. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The test harness now keeps the coordinator drain task so a new settle helper can wait for the turn to end and the coordinator to go idle, and a written helper counts transcript messages by sender and body. The old posts helper was replaced since it only counted staged rows in one hive rather than the full transcript. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add helpers to the MCP test support module that construct executable tool and hook fixtures from concise arguments, so call tests can declare them without repeating the full JSON shape. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add integration tests covering the MCP server's program and seat handling along with an end-to-end suite, so the server's behaviour is exercised through its public interface rather than only in unit tests. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The Hive test fixture no longer stores the turn request receiver, since only the first turn is consumed during setup and later turns such as the conductor's nudges are not held. The receiver is now dropped explicitly after the initial receive. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Introduce an error enum for the MCP crate so tool handlers can return structured failures instead of ad-hoc strings. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Introduce a bearer token based seat implementation so clients can authenticate with a static token. This provides a simpler alternative to the existing seat authentication mechanisms. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The admission path now returns a response directly instead of wrapping it in a Result that callers immediately unwrapped, removing a redundant match at the call site. A test variable was renamed for clarity and the protocol version comment was reworded. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The test helper now constructs the tool declaration as a mutable JSON value and assigns the args field afterwards, so the caller-supplied arguments are inserted without being captured inside the json! macro. This keeps the fixture valid when args contain values the macro would otherwise interpolate incorrectly. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Reorders the unused patch entries in Cargo.lock and adds tinyinference-decisions 0.5.0 to the list. No dependency versions actually changed; the lockfile was regenerated. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Reordered the unused patch entries in Cargo.lock, moving the tinyinference-decisions and tinytools-std records to the end of the list. No dependency versions changed. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Added a unit test module for the seat bearer covering generation, constant-time comparison and redaction, plus an integration test for the host send policy refusing a send and for secrets and Services debug output. The READMEs now list the new test files. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Renamed the local binding in the send policy test to `delivered` so the assertion reads more clearly. No behaviour change. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add integration tests asserting that a send or join refused by the host policy runs no hooks and records nothing, while an allowed call runs each hook once and its retry runs none. A strict authorizer is introduced to exercise both refusal paths. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The host belt gains an `authorize` method that runs the same send and management policy as `call` without any effect, so the MCP server can check policy before running package hooks and still have dispatch re-check it. The approval docs and harness spec now describe the tool server asking about effectful executable tools of a supervised seat. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Added README entries for the authorize and identified test modules in the host tools tests, and noted the new pre-hook policy refusal coverage in the MCP calls test table. The authorized helper in dispatch was reflowed to one parameter per line with no behaviour change. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The test harness now arms a per-agent slot so a runner only holds a turn when its slot is populated, letting tests start and hold a fresh turn on demand. A new next_turn helper settles the current turn and then triggers another via a host message, so multi-turn scenarios can be exercised. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add tests for sends answered after the policy changes, idle unauthenticated sockets not blocking a seat, and a lowered seat's tool allow list, and document the new review suite in the tests README. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The belt now asks the coordinator whether an identified call is already recorded on its running turn and, if so, skips the send and management authorizers, since a retry is answered from the record and acts on nothing. A new `Coordinator::call_recorded` reports whether a call matches its turn's recorded tool and arguments, and the MCP error module gains tests alongside updated call, review, and seat coverage. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Introduce a schema tool that returns the JSON input schema for a named MCP tool so clients can discover parameters at runtime. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The ledger now enforces per-seat limits on record count and bytes, refusing calls past either bound instead of evicting existing records, and records a call only after the coordinator confirms under the lock that its turn is still the seat's running turn. This prevents a held call from running or overwriting a newer turn's records, and adds purge and forget to drop records for ended turns and withdrawn seats. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
…s early Read-only tools now have their arguments checked against the tool's declaration before they run, and program tools are validated the same way hive tools already were. State-changing calls are recorded as pending before the approver is asked so a retry while it decides is refused, and the turn is re-checked after approval in case it ended while the approver deliberated. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Seats now serve only the tools named by a non-empty tools.allow list plus their executable tools, matching the linked path, and refuse argument schemas using keywords the server cannot check. Bearer secrets are zeroed on drop, and in-flight calls are bounded across and per seat rather than by connection count. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
…r order Update the crate READMEs and harness spec to match the server's current behaviour: per-seat and global in-flight call bounds, record limits, the argument schema check for executable tools, and the reordered ledger and access-gate steps. The new tools test module is also listed in the tools README. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Renamed the internal Turn struct to Records since it holds a seat's records for its running turn rather than the turn itself, making the name match what the type actually represents. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The call_message helper now takes its arguments by reference, and the two call sites pass a borrow of the identified payload. This avoids moving the value so it can be reused after building the request. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Adds a test asserting that a tool call with no arguments is treated as an empty object and succeeds, while a non-object argument payload and an unknown argument are both rejected even for a read-only tool, with nothing logged when the call fails. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Brings in #137 (harness schema). The one conflict is the "Implemented so far" paragraph of docs/specs/harnesses.md, now covering steps 1, 2 and 3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #137 (harness schema) and #138 (hive tool server). Conflicts: - Cargo.toml: both new members, and both dependency blocks (hyper and its helpers for tinyhivemind-mcp, reqwest for this crate). - assert-pure.sh: host_crates now guards tinyhivemind-host, tinyhivemind-mcp and tinyhivemind-openhuman-process. - docs/specs/harnesses.md: "Implemented so far" covers steps 1, 2, 3 and 4b. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Step 2 of the process harness plan. An out-of-process seat reaches the hive's tools through a loopback MCP server, and a retried tool call acts once.
Coordinator (
tinyhivemind-hives).RunningTurn.callsrecords each identified call with its result. A new*_in_turnentry point exists for post, ask, broadcast, complete, send, and create, join and leave hive. It checks the turn, looks up the call, acts and records in one transaction, so a failed commit leaves neither. Older snapshots still load, the serde form is pinned, and the existing entry points are unchanged. New errors:StaleTurnandCallReused.tinyhivemind-mcp. A Streamable HTTP server on 127.0.0.1 with a random port. In the order the spec requires:Hostnaming the listener; anyOriginrefused; per-seat bearer compared in constant time and zeroed on drop; body, header and timeout bounds; no redirects. Idle unauthenticated sockets cannot hold a seat's slot.turncheck against the coordinator; the call record; send and management policy (Belt::authorize, before any hook); theread_only/supervisedgate with the host's approver; then hooks and dispatch.turnandcallare added to the served schema of every state-changing tool and stripped before hooks see the arguments. A hooked call counts as state-changing, reads included.create_agentand hooked calls get an in-memory started/finished record. It is turn-scoped, bounded in count and bytes, and cleared at turn end. A call held across a turn change runs nothing.tools.allowis applied: a tool outside it is neither listed nor callable.Two independent reviews were run. The first found the allowlist dropped and stale calls able to run and erase the current turn's records. Every finding is fixed with a test that failed on the old code.
Stacked on #136.
Related issue
None. Refs #136.
API or behavior changes
tinyhivemind-mcp.tinyhivemind-hives:TurnCall,CallRecord, the*_in_turnmethods,running_turnandcall_recorded, plus the two error variants.tinyhivemind-host(additive):ToolCall::in_turn,Belt::authorize,Error::Refused.tinyhivemind-exec:HookRunner::matches_tool.Dependencies
All were already in the lockfile; only the new crate's entry is added.
Validation
At
e50ade12:cargo fmt --all -- --check: passcargo clippy --all-targets --all-features -- -D warnings: passcargo build --all-targets --all-features: passcargo test --all-features: 1944 passed, 0 failed, 0 ignoredassert-pure.sh(now also guardstinyhivemind-mcp), rustdoc-D warnings: passcargo +1.96 check -p tinyhivemind-mcp -p tinyhivemind-hivesandcargo denylicenses, bans and sources: pass (run by the implementing agent)dispatch.rs); mcp total 96.57%CI will show the same red checks as #136, all already on
main.Tests
Every acceptance case in the spec's "Call identity", "Runtime gates" and step 2 list has a test against a real loopback HTTP client, mapped in
crates/tinyhivemind-mcp/tests/README.md. One end-to-end test lists tools and posts as seat a, then is refused as seat b.Deliberately untested: a turn ending during hooks, a poisoned coordinator lock, and the race between the turn check and the record insert, which need a fault hook. Program output over 1 MiB is also untested.
Error::Listen,RandomandStoppedare covered by message tests only.Known trade-off: accepts are no longer capped, so that idle sockets cannot block a seat. Idle connections close after 5 s. A same-user process could still exhaust file descriptors; the spec does not defend against hostile same-user processes, and built-in tools are off.
Documentation
Crate, src and module READMEs, crate overview with doctest,
AGENTS.md,docs/crate-dependencies.md, anddocs/specs/harnesses.md("What the server settled").Checklist
#[allow(...)],#[ignore], or relaxed lints.envcontents in the diff or the descriptionCo-authored-by: Medulla medulla@tinyhumans.ai