Address the Codex GPT-5.5 review of the standalone fake C++ gRPC Shard worker. Four root protocol defects fixed: - Fail closed before SessionOpen: a per-session `opened` flag gates chunk/decode so no activation bypasses lifecycle, cancellation, epoch or flow-control state (terminal ERROR_CODE_INTERNAL), even when an out-of-band Cancel created placeholder state. - Strict flow-control negotiation: NegotiateFlow takes the strictest of peer-vs-worker bounds (mirrors codec.negotiate_flow_control) and the negotiated per-session max_chunk_bytes is enforced on every bundle instead of trusting the peer proposal. - In-stream ReleaseSignal now erases session state immediately. - SessionOpen rejects incompatible schema, fingerprint, and shard-range identity and reports the worker's own served fingerprint rather than echoing the caller. Adds 9 regression tests (worker suite 18 -> 27). Real gates on the rebuilt pinned-gRPC binary: cmake build exit 0; ctest 2/2; worker pytest 27 passed; harness+protocol 63 passed; compileall 0; diff --check clean; ldd/nm show 0 llama/ggml linkage. DGR-033 passes -> true. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
15 KiB
DGR-033 evidence — standalone fake C++ gRPC Shard worker
Completed: 2026-07-25 (initial); repaired: 2026-07-26 after Codex
GPT-5.5 cross-review BLOCK (see "Cross-review repair" below).
Branch: ralph/distributed-gguf-opus
Authority: .scratch/distributed-gguf-runtime/prd.json
Dependencies: DGR-022 (lifecycle/status contract), DGR-024 (real generated
gRPC harness + shard_runtime_server.py reference semantics), DGR-032
(deterministic fake ShardEngine semantics).
Objective
Prove the standalone worker process, stream, lifecycle, and supervision shape before any llama.cpp integration: a real C++ executable that serves the whole ShardRuntime lifecycle/stream contract over gRPC using a model-free fake engine, driven end-to-end by Python integration tests over a real socket.
What was found live before changing code
packages/node/native/proto/shard_runtime.proto(DGR-021..023): the single semantic contract. ItsShardRuntimeservice has exactly five RPCs —GetCapability,Health,Session(bidi stream),Release,Cancel.packages/node/meshnet_node/shard_runtime_server.py(DGR-024): the reference Python servicer. It performs a bounded real forward (a CRC over the received bundle bytes) then echoes the chunk, and fails closed on stale epoch, expired deadline, corrupt/mis-tiled fragments, exhausted flow-control credit, duplicate idempotency step, and in-band/out-of-band cancellation, with per-route_session_idstate kept on the servicer so an out-of-bandCancelcan reach a live session. Key finding: despite the schema labelling the checksumCRC32C, this runtime computes it withzlib.crc32(standard CRC-32, not Castagnoli). The C++ worker mirrorszlib.crc32exactly so its checksum acceptance is byte-identical to the existing Python surface (the committed C++ conformance test, by contrast, uses true Castagnoli against separately-generated goldens — the two are unrelated code paths).packages/node/native/CMakeLists.txt(DGR-029/030): configures against the ignoredbuild/native-toolchainprefix (pinned Protobuf 33.1 + gRPC 1.82.1), always generates both message and service stubs, and registers a C++ conformance CTest. There was no worker executable and no Python worker integration test before this story (confirmed byls packages/node/native/worker→ absent, and grep forshard_worker).packages/node/meshnet_node/fake_shard_engine.py(DGR-032): the Python fake engine, deliberately not wired into the gRPC surface. DGR-033's worker is its native analogue — a separate executable, not a consumer of that module — so both fakes present identical behaviour to a client (deterministic, model-free bounded forward; per-session isolation; fail-closed lifecycle).
What was added (this story's change)
packages/node/native/worker/fake_engine.h (new)
meshnet::worker::FakeShardEngine — a header-only, model-free fixture engine.
Its only capability is to validate a TensorBundle (fragments tile exactly, the
uncompressed CRC-32 matches the declared checksum, the declared payload stays
within the negotiated max_chunk_bytes) and fold the fragment bytes through a
bounded forward. It links, loads, and dispatches to nothing — no llama.cpp,
no graph execution. Carries kEvidenceClass = "fixture" mirroring the Python
FakeShardEngine.EVIDENCE_CLASS for the later DGR-036 parity check.
packages/node/native/worker/shard_service.{h,cpp} (new)
ShardRuntimeServiceImpl : meshnet::shard::v1::ShardRuntime::Service — a faithful
C++ port of the DGR-024 Python servicer: the same per-route_session_id
identity/credit/dedup state guarded by a mutex, the same fail-closed negative
paths, and the same lifecycle (open → prefill/decode → flow-control top-up →
release/cancel). Each per-request response is computed under the lock and written
after releasing it, so a blocking Write can never deadlock the out-of-band
Cancel RPC that needs the same lock. Bounded messages are enforced two ways: a
per-tensor RESOURCE_EXHAUSTED app check against max_chunk_bytes, plus a hard
transport receive ceiling.
packages/node/native/worker/shard_worker_main.cpp (new)
The standalone shard_worker executable. Binds MESHNET_SHARD_LISTEN_ADDR
(or an argv address), prints one readiness line (ShardRuntime worker listening on <addr>), and serves until SIGTERM/SIGINT. Graceful shutdown uses a
self-pipe: the async-signal-safe handler writes one byte, a drain thread reads it
and calls server->Shutdown(), so in-flight sessions finish and the process
exits 0 printing ShardRuntime worker shut down cleanly. A --selftest mode
binds an ephemeral port and self-drives capability/health/fragmented-prefill/
decode/release over a real loopback gRPC channel, giving a pure-C++ CTest that
needs no Python.
packages/node/native/CMakeLists.txt (modified)
Adds the shard_worker executable (linking only shard_runtime_grpc +
gRPC::grpc++ — no llama.cpp) and registers shard_worker_selftest as a CTest.
tests/test_native_shard_worker.py (new)
18 integration tests that spawn the real compiled binary as a subprocess and
drive it with the committed generated stubs over a real localhost socket. When
the binary is not built they skip (the DGR-029/030 requires_cmake gating
pattern), locating it via MESHNET_SHARD_WORKER_BIN or build/native/shard_worker.
Acceptance criteria → evidence
- Standalone C++ executable serves the complete lifecycle/stream contract
using the fake engine —
shard_workerbuilds and serves all five RPCs; theshard_worker_selftestCTest drives open → fragmented prefill → decode → release over real gRPC; the 18 Python tests cover the same against the subprocess. - Python integration tests cover startup, health, capability, fragmented
prefill, decode, release, cancellation, graceful shutdown —
test_worker_startup_and_health,test_worker_capability,test_fragmented_prefill_echoes_reassembled_payload(3-fragment tiling),test_decode_step_is_served,test_release_is_terminal,test_in_band_cancel_of_single_work_item_does_not_end_stream,test_in_band_cancel_of_whole_session_is_terminal,test_out_of_band_cancel_rpc_races_ahead_of_open,test_graceful_shutdown_on_sigterm(SIGTERM → exit 0 + clean-shutdown line). - Bounded messages, deadlines, flow control, independent session
cancellation enforced —
test_bounded_message_is_rejected(RESOURCE_EXHAUSTEDon an over-ceiling tensor),test_expired_deadline_is_rejected,test_flow_control_violation_and_topup,test_independent_session_cancellation(cancelling session A leaves session B fully serviceable), plustest_stale_route_epoch_is_rejected,test_duplicate_idempotency_step_is_acked,test_malformed_fragment_tiling_is_rejected. - Exposes neither llama.cpp RPC nor arbitrary graph execution —
ldd build/native/shard_workershows no llama/ggml shared libs;nm -C build/native/shard_worker | grep -icE 'llama_|ggml_'→0; the proto exposes exactly one service with five lifecycle RPCs and no graph-exec entry. - Gates + this handoff — below.
Commands and results
Toolchain (ignored build/native-toolchain, pinned Protobuf 33.1 + gRPC 1.82.1):
bash scripts/bootstrap_native_toolchain.sh "$PWD/build/native-toolchain"
# ... gRPC 1.82.1 commit acccf84c0df20487d64101f528e5d426541ca4e5
# grpc_cpp_plugin sha256 43705cf26ae9ce98bbcee76b3408f5e171eec746b50bf0dd42dd68d132c6a533
Focused out-of-tree CMake build + CTest:
cmake -S packages/node/native -B build/native -DCMAKE_PREFIX_PATH="$PWD/build/native-toolchain"
cmake --build build/native -j"$(nproc)"
ctest --test-dir build/native --output-on-failure
1/2 Test #1: shard_worker_selftest ............ Passed 0.01 sec
2/2 Test #2: shard_protocol_conformance ....... Passed 0.00 sec
100% tests passed out of 2
Python integration tests against the real binary:
PYTHONPATH=packages/node:packages/tracker python -m pytest -q tests/test_native_shard_worker.py
18 passed in 3.96s
AC4 (no llama.cpp / no graph exec):
ldd build/native/shard_worker | grep -iE 'llama|ggml' # -> (no matches)
nm build/native/shard_worker | grep -icE 'llama_|ggml_' # -> 0
Shared gates + regression:
python -m compileall -q packages tests # exit 0
git diff --check -- packages/node/native tests/test_native_shard_worker.py # exit 0
PYTHONPATH=packages/node:packages/tracker python -m pytest -q \
tests/test_shard_runtime_harness.py tests/test_native_shard_protocol.py
# -> 61 passed, 2 skipped (DGR-024 harness + native protocol untouched)
Toolchain used: cmake/ctest from the distributed-gguf-runtime worktree's
.venv (PyPI cmake==4.4.0 wheel — no system cmake exists here, same as
DGR-029/030); the Python client uses that venv's grpcio==1.82.1,
grpcio-tools==1.82.1, protobuf, pytest. g++ (GCC) 15.2.1.
Limitations
- This is FIXTURE evidence only. The worker's "forward" is a CRC-over-wire-bytes echo, not real tensor compute; it proves process/stream/lifecycle/supervision shape, nothing about numerical correctness. Real engine binding is DGR-037 and numeric parity is DGR-036/052.
- The worker checksum path mirrors the DGR-024 runtime's
zlib.crc32(standard CRC-32 under aCRC32Clabel). Compressed-tensor tiling/checksum is not independently verified (no zstd decompressor in the fixture) — identical to the DGR-024 limitation. - Default
pytestruns skiptests/test_native_shard_worker.pyunless the worker binary is built (orMESHNET_SHARD_WORKER_BINis set); this session built it and ran all 18 for real (results above). Building requires the pinned gRPC C++ toolchain, which is not present by default and must be bootstrapped. - No CUDA/ROCm/GPU, no model download, no network at test time — all default tests are fixture-only and offline.
Dependency handoff
- DGR-036 (fixture vs real-model parity): the worker's
FakeShardEnginecarrieskEvidenceClass = "fixture"; diff it against DGR-037's real engine's equivalent marker, and reuse the same lifecycle/stream contract this worker serves to prove behavioural parity before numeric parity. - DGR-037 (bind llama.cpp): replace
FakeShardEngine's bounded forward with the real engine behind the sameShardRuntimeServiceImplsurface; the service's session/epoch/credit/dedup/cancel machinery and the graceful-shutdown supervision shape are reusable as-is. - DGR-040 (worker supervision):
shard_workeralready provides the supervision primitives — a readiness line for start detection,SIGTERMgraceful drain with a clean-exit line, and a--selftestliveness probe. A supervisor can start/monitor/restart the process around these.
Cross-review repair (2026-07-26)
An independent Codex GPT-5.5 review BLOCKED the initial implementation. Four
root protocol defects in the native worker were fixed in this worktree
(.claude/worktrees/distributed-gguf-opus); the fake-engine echo semantics and
supervision shape are unchanged.
Defects fixed
- Activation before SessionOpen bypassed all state. A chunk/decode whose
route_session_idhad no opened session fell through everyif (state && ...)guard and was echoed — bypassing lifecycle, cancellation, epoch and flow-control.SessionStatenow carries anopenedflag set only by a validSessionOpen; chunk and decode fail closed with a terminalERROR_CODE_INTERNALand end the stream when it is false. A placeholder state created by an out-of-bandCancelthat racesOpenhasopened == false, so it can never admit work either. - Flow control blindly trusted the peer proposal.
SessionOpencopied the proposedcredits/max_inflight/max_chunk_bytesverbatim into session state and the accepted reply. NewShardRuntimeServiceImpl::NegotiateFlowtakes the strictest bound of peer-vs-worker for every field (mirroringnegotiate_flow_controlinnative_protocol/codec.py), stores the negotiated ceilings on the session, and enforces the negotiated per-sessionmax_chunk_byteson every bundle (FakeShardEngine::Validatenow takes the ceiling as an argument instead of a fixed construction-time value). - In-stream
ReleaseSignalleaked session state. The streamreleasearm wrote a terminal status but never dropped the session. It now erases the session under the lock before responding, so KV/credits/dedup are freed immediately (the out-of-bandReleaseRPC already erased). SessionOpenechoed caller identity instead of validating it. The handshake now rejects an incompatibleschema_version(SCHEMA_UNSUPPORTED), a mismatched model/recipeFingerprint(FINGERPRINT_MISMATCH), and aShardRangeoutside the worker's served range (SHARD_RANGE_MISMATCH), each terminal;SessionAcceptednow reports the worker's own served fingerprint rather than a copy of the caller's.
Changed files (repair)
packages/node/native/worker/shard_service.h—opened+max_prefill_chunk_tokensonSessionState;NegotiateFlowdecl; engine now default-constructed.packages/node/native/worker/shard_service.cpp— worker-identity constants + fill helpers;NegotiateFlow;SessionOpenvalidation/negotiation; fail-closed chunk/decode; per-sessionmax_chunk_bytes; in-stream release erase.packages/node/native/worker/fake_engine.h—Validate(bundle, max_chunk_bytes).tests/test_native_shard_worker.py— extended_open(schema/fingerprint/range/ flow overrides); fixedtest_release_rpc_is_idempotentfor the new erase semantics; added 9 regression tests (chunk/decode before open, flow-control clamp, negotiated-ceiling cap, in-stream release erase, schema/fingerprint/range rejection, worker-fingerprint-not-caller).
Re-run gates (real, rebuilt binary)
Build driven through the pinned cmake (Unix Makefiles + gmake, gRPC 1.82.1):
cmake --build build/native --parallel 8 -> BUILD_EXIT 0
ctest --test-dir build/native --output-on-failure -> 100% (2/2) passed
shard_worker_selftest ....... Passed
shard_protocol_conformance .. Passed
python -m pytest -q tests/test_native_shard_worker.py -> 27 passed
python -m pytest -q tests/test_shard_runtime_harness.py \
tests/test_native_shard_protocol.py -> 63 passed
python -m compileall -q packages tests -> exit 0
git diff --check -> clean
ldd build/native/shard_worker | grep -iE 'llama|ggml' -> NONE
nm -C build/native/shard_worker | grep -cE 'llama_|ggml_' -> 0
The worker integration suite grew from 18 to 27 tests; all pass against the
freshly compiled binary. No .ralph-lane runtime artifacts were touched.