feat(prototypes): campaign 3 — nine seam-risk prototypes, evidence folded into SPEC (#6)
44094afca6d7e914653b84cdb309a37b455ffc55
Oliver Jan Krylow <oliver@bugabinga.net> ·
SSH signature · not checked
- Parent 1: 57880ae2aaae
* docs: plan prototype campaign 3 — highest-risk unvalidated claims Nine prototypes (p15-p23) ranked by spec-impact x uncertainty, each targeting spec text with zero prototype evidence: 1. p15 async-lua-threading — architecture-fatal risk: all loop prototypes were synchronous; !Send Lua vs tokio hooks vs the "plugin thread" §9.18 assumes but §12 never defines, 2. p16 config-cascade-reload — §9.19 full contract, zero evidence; cross-layer merge granularity unpinned, 3. p17 bytecode-cache — disproof risk: §5.5 promises dump/load under vendored LuaJIT unverified; provenance rule needed, 4. p18 model-resolver — cheap, pure, cross-cutting (config, compaction, /model, failover all resolve through it), 5. p19 models-dev-schema-pin — the §7.3 translation has never run against the real api.json shape, 6. p20 trace-replay-contracts — replay validated only against the pre-consolidation design; new entry kinds unproven in traces, 7. p21 compaction-round — p12 proved the fold; the round that creates summaries (trigger math, livelock guard, re-entry) is unproven, 8. p22 input-queue-machine — §8.11 "best effort" reposition needs a proven rule, 9. p23 bus-delivery — §9.18 re-entrancy and teardown-mid-dispatch interaction with §9.16. Also records what is deliberately not prototyped (RPC catalog, release builds, CI wiring, UX prose) and why. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB * feat(prototypes): p16 config cascade + reload — PASS with findings Proves SPEC §5.6 five-layer cascade and the full §9.19 contract: atomic swap, rollback on eval/validation/resolution failure (active config byte-identical, no poisoned state), minimal changed-keypath diff, CLI persistence, plugin-reload cascade re-evaluation, restricted config env. Findings (1×P1, 3×P2, 2×P3): - §5.6 must pin leaf-field recursive merge for tables with lists/ scalars as wholesale-replace leaves — layer-replace wipes builtin ctrl+c=abort when a user overrides one binding and breaks alias resolution when a plugin contributes one alias (P1), - §9.19 diff must be computed over the post-CLI EFFECTIVE config (CLI-masked changes must not be reported), - cycle detection must be whole-alias-graph, not active-chain-only (a concrete CLI model otherwise masks latent cycles into config), - strict-vs-warn unknown-key contexts need naming; diff edge rules (lists as one path, add/remove as changes, empty-diff event) and all-errors rejection reporting need stating. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB * feat(prototypes): p15 async-lua threading — PASS with disproof THE campaign-3 top risk resolves positively: !Send mlua states integrate with a tokio multi-thread agent loop via one dedicated plugin thread running a channel actor (mpsc request, oneshot reply). No unsafe, no Send tricks — rustc refuses state movement (compile-fail evidence quoted in module docs). Measured: hook round-trip median 81µs / p99 142µs (N=10k, two states); 3 parallel 100ms tools with 6 hooks complete in 102ms (hooks serialize, tools overlap); a hostile 200ms busy-hook stalls only its turn + queued plugin dispatches while the UI heartbeat max gap stays 5.4ms < 16ms; abort unblocks the engine at +51ms of a 300ms hook. DISPROOF: §12 "every long operation observes abort" is false for in-flight Lua — LuaJIT hooks cannot be preempted (mlua set_interrupt is Luau-only; debug hooks don't fire in JIT traces). Abort abandons the dispatch; the hook always completes; hard cancellation is domain teardown (§9.16). Findings (2×P0, 2×P1): §12 must define the plugin thread §9.18 already assumes, the channel-actor dispatch rule, a SOFT hook budget with the head-of-line caveat, and the abort-abandons-dispatch carve-out. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB * feat(prototypes): p17 bytecode cache — DOUBLE DISPROOF The §5.5 bytecode cache is disproved on both premise and default behavior: 1. Performance premise dead: compile-from-source 1102µs vs full cache path (hash+read+verify+load) 818µs for a 2252-line module — net ~285µs saved per module; 50 plugins save ~15ms once at startup. Stripped bytecode is LARGER than source (107%). 2. Safety surface real: LuaJIT has no bytecode verifier — of 34 corrupted images, ~7 segfault the VM and 4 execute silently with WRONG results (worse than a crash for a file-editing agent). 3. mlua default load mode is "bt": a .lua file containing raw bytecode is auto-detected and ACCEPTED, violating "never loads bytecode it did not compile" by default — only explicit ChunkMode::Text rejects. Mechanics proven anyway (dump/load work; sha256+version-tag header provenance rejects tampered/foreign/stale entries before lua.load), so if the cache is ever revived the full key rule is recorded. Recommendation: drop the cache from §5.5; keep the mandatory text-mode-only rule for all source loads regardless. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB * feat(prototypes): p18 model resolver — PASS with findings Proves SPEC §5.7 + §7.5: pure multi-hop resolution (alias->alias-> group->bucket->model), load-time cycle detection with full paths (alias, transitive group, mixed), DAG diamonds without false positives, compaction_model through the same graph, exact §7.5 failover behavior per ProviderError kind with nested bucket rotation. Key finding (P1): "resolver is pure" + "groups rotate round-robin" is only satisfiable by exporting rotation state — resolve(config, name, &cursors) is pure; Mux owns the cursor map and advances one step per provider request per rotation node. Same cursors -> same plan. Six load-time rejection rules proven (P2/P3): cross-kind name shadowing, empty groups/buckets, dangling references (referrer named), in-group duplicates, bucket->concrete-model only; unknown-name is the sole resolve-time error. Open: DAG-duplicate candidates survive flattening — Mux dedupe vs attempt-twice needs deciding; §7.5 retry count needs its config key. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB * feat(prototypes): p19 models.dev schema pin — PASS with disproofs First execution of §7.3's translation claim against REAL data: committed snapshot of api.json (2026-07-16, sha256-recorded, 166 providers / 5666 models). The translated providers.schema.json validates the full snapshot (0 errors, non-vacuous); leaf-merge + catwalk gap-fill + semantic unknown-field preservation all hold on real shapes; 92.2% of models map cleanly into ModelMetadata. DISPROOFS: - boundary-1 "validate source data" as stated: gap-fill fragments are partial and required-clauses reject every legitimate fragment — fragments need type-only validation; required applies post-merge, - ambiguous-primary-source conflict class: unreachable post-parse (duplicate JSON keys collapse at the lexer), - the naive §7.3 field list: five loosenings with material counts (cost absent on 398 models — P1; limit.context=0 on image models — P1; tri-state capability flags; tiered pricing fields; api absent on gateway providers). Also P1: api.json has NO in-band version and models.dev publishes no standalone schema artifact — the pin procedure must be retrieval date + content sha256 (+ optional repo commit). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB * feat(prototypes): p20 trace/replay contracts — PASS with disproofs Proves §6.11 against the campaign-2 contracts: max-speed reconstruction deep-equals the live run (leaf, folded path, transcript, abort-time queues); abort dangling tail round-trips exactly; steering synthetics refuse re-execution; compare mode rehydrates from SESSION registration entries while the trace stays byte-verified masked; drifted tool caught as exactly one divergence. DISPROOFS: - §6.11's literal entry list rebuilds ZERO session entries — leaf switches, compaction spans, secret registrations, steer/follow-up deliveries are unrepresentable; "enough data to reconstruct session state" needs a SessionAppend trace kind (P1), - "small traces never exceed uncompressed size" verbatim: unachievable with any container header; achievable bound is raw + 9B/block, - per-entry-inflation as stated: it is about entry size, not trace size (mixed small traces can still net-compress per-entry). Pinned by measurement: block-level zstd, 4KiB blocks, 64B min-compress floor, per-block raw-fallback flag. Also: snapshots must carry queues + abort flag + leaf id (else §6.1 abort state is lost), registration redaction must be idempotent, and §6.11's compression citation must repoint from p11 to p20. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB * feat(prototypes): p22 input queue machine — PASS with findings Proves §8.11 via deterministic key-event scripts over a TestBackend widget with §17.7 styled-cell snapshots (byte-identical across process runs): visual order (follow-ups above steers, oldest->newest per kind, distinct styles), up-arrow newest->oldest cycling, edit temp-removal, empty-resend delete, cancel-pop-then-abort. Three §8.11 ambiguities forced into proven rules (3×P1, 1×P2): - RULE A: promote/demote lands the item at the NEWEST position of its new kind (cross-kind enqueue order is meaningless); consequence: promote->demote of a non-newest item does not restore order, - RULE B replaces "best effort": remember (kind, index-within-kind); clamp to current block length on re-send; kind-changed-while-away falls back to RULE A, - RULE C: cancel-pop follows ENQUEUE-TIME order across both kinds (undo semantics), which provably diverges from visual-bottom-first; promoted items keep their original enqueue time, - cancel-while-editing: edited item is outside the queue; empty-queue cancel discards the edit before it can abort. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB * feat(prototypes): p21 compaction round — PASS with findings Proves the §6.9 ROUND (the fold was p12's): trigger boundary exact at floor(fraction x window) - reserve with strict >, probed at ±1 token; trim ladder order with per-step token savings; ONE summary per pass; storage strict-prefix byte-compare; recency window untouched by every step; iteration limit terminates with monotone progress; summarizer cost tracked; nested-summary CREATION correct (prior summary is summarizer input, fold subsumes outermost-wins); secret registrations enter the summarizer masked. Findings (1×P1, 3×P2): - LIVELOCK IS REAL: §6.9 permits recency_budget >= threshold, where a triggered round can never fit and every request re-runs the full ladder forever. Pin strict recency_fraction + reserve_fraction < threshold_fraction, validated at config load; plus a runtime RecencyDominates guard and a no-progress abort, - iteration-limit behavior unstated: terminate + report via session_compact, request proceeds over budget, - re-entry needs wording: the summarizer IS a provider request — it must be exempt from the trigger check or the rule is self-referential; round is synchronous at the only trigger site, - threshold expression parses two ways (fraction x W - reserve vs fraction x (W - reserve)) — same path flips at the boundary. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB * feat(prototypes): p23 bus delivery — PASS with findings Proves SPEC §9.18 delivery semantics (implemented inline after the builder agent hit a session limit; its Lua fixtures were reused): registration-order synchronous delivery across two plugin domains, emit-during-delivery enqueues with max dispatch depth 1, subscriber error isolation (§9.17) with emitter returning normally, plain-data payload enforcement (functions/threads/function-keys/cycles rejected at the emit boundary; §9.2 topic charset on emit AND on), off() removal, structured payloads crossing Lua states as data copies. Rules pinned for §9.18/§9.16 (the plan's edge targets): - inner emits join ONE GLOBAL FIFO, delivered strictly after the current dispatch in emit order (cross-topic proven: b delivers before the re-emitted a), - teardown-mid-dispatch: the domain is CONDEMNED immediately (same- dispatch pending deliveries skip with a diagnostic) and the DROP is deferred to the drain epilogue — after all deliveries, before emit returns; self-teardown from inside a handler is therefore safe and the handler completes, - payload key rule: string keys only; array part or map, not mixed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB * docs: fold campaign-3 evidence into SPEC (p15-p23) All nine campaign-3 prototypes complete (digests in PLAN.md). The campaign targeted seams between validated subsystems; evidence-driven changes: §12 (p15, 2xP0): plugin thread DEFINED (one OS thread owns all !Send Lua states; the thread §9.18 always assumed), channel-actor dispatch rule (81µs median round-trip), soft hook budget with head-of-line caveat, and the abort carve-out — in-flight Lua cannot be preempted; abort abandons the dispatch, hard-kill is domain teardown. §5.5 (p17, disproof): bytecode cache DROPPED — ~285µs/module saving vs segfault/silent-misexecution surface (no LuaJIT verifier); every Lua load is text-mode-only (mlua's default accepts binary chunks). §4: bytecode/ removed from cache layout. §5.6/§9.19 (p16): leaf-merge pinned (lists/scalars replace wholesale), strict-vs-warn contexts named; reload diff over post-CLI effective config, whole-graph cycle validation, all-errors reporting, diff edge rules. §5.7/§7.5 (p18): purity reconciled with rotation via exported cursors (Mux owns them, one step per request); six load-time rejection rules; cycle diagnostic shape; Mux dedupes DAG-duplicate candidates; providers.retry_count named. §7.3 (p19, real-data): pin = date + sha256 (no in-band version exists); fragment validation is type-only with required post-merge; ambiguous-primary-source class dropped (undetectable post-parse); cost OPTIONAL (398/5666 real models) with priced-unknown rule; tri-state capability flags; tiered-cost fields named; chat-model mapping eligibility (text output + context>0). §6.11 (p20): session-entry-append trace kind added (the listed kinds rebuilt ZERO session entries); snapshots carry leaf+queues+abort flag; block zstd 4KiB/64B-floor/raw-fallback with corrected guarantee; stale citation fixed. §6.9 (p21): livelock arithmetic pinned (recency+reserve < threshold, validated at load, runtime guards); exact threshold expression with strict >; summarizer exempt from trigger; iteration-limit termination + session_compact outcomes. §8.11 (p22): RULES A/B/C replace ambiguity — promote lands newest of new kind, precise reposition rule replaces "best effort", cancel-pop by enqueue time; cancel-while-editing defined. §9.18/§9.16 (p23, p15): global-FIFO inner emits; teardown-mid-dispatch condemn-now/drop-deferred; teardown waits for in-flight hooks. §18: campaign record updated (22 prototypes across three campaigns). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB --------- Co-authored-by: Claude <noreply@anthropic.com>