Commit b30a3a2
committed
D2.3 /v1/shader/token-agreement handler wiring (Phase 2 surface complete)
Final Phase 2 surface deliverable — routes WireTokenAgreement requests
through the D2.1 TokenAgreementHarness stub. End-to-end flow:
WireTokenAgreement (JSON at ingress)
↓ serde_json deserialize (Rule F: edge only)
Handler validates candidate: WireCodecParams → CodecParams
↓ precision-ladder + overfit guard fire here (ingress) NOT deeper
ReferenceModel::load(&req.model_path) when path exists
OR ReferenceModel::stub(hash(model_path), 0) fallback
↓ deterministic stub keyed on model_path string for regression tests
TokenAgreementHarness::new(ref, baseline, candidate, n_tokens)
↓
.measure_stub() → WireTokenAgreementResult { stub:true, backend:"stub" }
↓ serde_json serialize (Rule F: edge only)
HTTP 200 Json response
crates/cognitive-shader-driver/src/serve.rs — ~70 LOC:
- token_agreement_handler async fn
- new imports: ReferenceModel, TokenAgreementHarness,
WireTokenAgreement, WireTokenAgreementResult, CodecParams,
StdPath (aliased to avoid collision with axum::extract::Path)
- new route: POST /v1/shader/token-agreement
Errors typed at handler boundary:
- BAD_REQUEST + "invalid CodecParams: <CodecParamsError display>"
for precision-ladder / overfit guard failures
- BAD_REQUEST + "model load: ModelPathMissing { path }" when
real path is specified but does not exist
- BAD_REQUEST + stringified TokenAgreementError for harness errors
(EmptyPromptSet when n_tokens = 0)
Stub-fallback behavior (when model_path does not exist on fs):
Deterministic hash of the path string keys the ReferenceModel stub.
Same model_path → same stub fingerprint → test harnesses get
repeatable results without needing a real safetensors file. D2.2
replaces with strict path validation once the real loader lands.
Why the `stub:true` wall matters end-to-end:
Client sends WireTokenAgreement over HTTP → handler returns 200 OK
with WireTokenAgreementResult. Without the `stub` flag, a client
pipeline could silently treat 0.0 rates as real measurements. With
the flag, any `assert!(!result.stub)` fails the pipeline loudly —
the Phase 0/D2.1 anti-#219 discipline extends through the HTTP
surface.
Phase state:
Phase 0 ✅ complete
Phase 1 scaffold ✅ (D1.1 / D1.2 / D1.3 shipped; D1.1b queued)
Phase 2 scaffold ✅ — D2.1 harness + D2.3 handler (this PR)
⏳ D2.2 real decode-and-compare loop queued
Tests: 117/117 cognitive-shader-driver --features serve pass
(unchanged; handler's logic is a thin pass-through and the
harness it delegates to is already covered by 13 D2.1 tests).
Board hygiene:
STATUS_BOARD.md D2.3 Queued → In PR
Rules honored:
Rule F — serde_json::from at ingress (Json<WireTokenAgreement>),
serde_json::to at egress (Json<WireTokenAgreementResult>);
in between: CodecParams + ReferenceModel + Harness are all
in-memory Rust objects, zero re-serialisation
https://claude.ai/code/session_01SbYsmmbPf9YQuYbHZN52Zh1 parent 3ee739a commit b30a3a2
2 files changed
Lines changed: 67 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | | - | |
| 54 | + | |
54 | 55 | | |
| 56 | + | |
| 57 | + | |
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
| |||
87 | 90 | | |
88 | 91 | | |
89 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
90 | 99 | | |
91 | 100 | | |
92 | 101 | | |
| |||
219 | 228 | | |
220 | 229 | | |
221 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
222 | 287 | | |
223 | 288 | | |
224 | 289 | | |
| |||
0 commit comments