repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

docs: integrate cargo-pup gate

96ef3c2742e757883d7664de83c0b9d482067c16

Oliver Jan Krylow <oliver@bugabinga.net> ·

SSH signature · not checked

Browse filesCompare with HEAD

Changed files (2)

+313 / −60 text lines

Diff layout

docs/SPEC.md

Modified

+28 / −3 text lines

6868Architecture gates:
70- `cargo run -p xtask -- arch` checks stable metadata/source invariants.
70- `cargo run -p xtask -- arch` checks stable Cargo metadata and source
71 invariants not covered by pup.
7172- `cargo run -p xtask -- pup` runs `cargo +nightly-2026-01-22 pup`.
72- `cargo run -p xtask -- check` includes both gates.
73- `cargo run -p xtask -- print-modules` prints crate roots from Cargo metadata
74 plus cargo-pup submodule output.
75- `cargo run -p xtask -- check` includes `arch` and `pup`.
7477### 2.3 Workspace Manifest
247250### 3.5 cargo-pup
249Root `pup.ron` exists and is required. Initial rules enforce:
252Root `pup.ron` exists and is required. Cargo-pup is the pinned-nightly source
253architecture lint gate. `xtask arch` remains the stable Cargo metadata gate.
255Initial pup rules enforce:
251257- hygienic `mod.rs`,
252258- no wildcard imports,
254260- `smith-ai` imports no `smith-core`, `smith-tui`, `smith-harness`, `smith-cli`,
255261- `smith-tui` imports no `smith-core`, `smith-ai`, `smith-harness`, `smith-cli`.
263Crate-boundary module match patterns must include the crate root. Use
264`^crate($|::.*)`, not only `^crate::.*`. Cargo-pup sees root-owned items in
265`lib.rs`/`main.rs` under the crate name itself.
267Required boundary patterns:
269```ron
270matches: Module("^smith_core($|::.*)")
271matches: Module("^smith_ai($|::.*)")
272matches: Module("^smith_tui($|::.*)")
273```
275`cargo pup print-modules` is not a complete module inventory. It can omit crate
276roots and can emit synthetic `unknown_crate` for crates with no child `mod`
277items. Developer-facing module inventory uses `cargo run -p xtask -- print-modules`,
278which prefixes crate roots from stable Cargo metadata and then prints
279cargo-pup-discovered submodules.
257281Required setup:
259283```bash
14331457| `spec-verify` | verify SPEC links and project invariants |
14341458| `arch` | stable architecture checks |
14351459| `pup` | pinned-nightly cargo-pup gate |
1460| `print-modules` | module inventory: Cargo metadata crate roots + cargo-pup submodules |
14361461| `audit` | cargo-deny + cargo-audit |
14371462| `bench` | criterion benchmarks |
14381463| `coverage` | tarpaulin coverage |

prototypes/PLAN.md

Modified

+285 / −57 text lines

1414## Execution Order
161. `p01-pup-gate`
172. `p02-lua-interface-descriptor`
183. `p03-subagent-ecosystem-simulation`
194. `p04-plugin-install-uninstall`
205. `p05-provider-fetch-normalize`
216. `p06-session-codec-recovery`
227. `p07-streamfn-agent-loop`
238. `p08-tui-testbackend`
161. `p02-lua-interface-descriptor`
172. `p03-subagent-ecosystem-simulation`
183. `p04-plugin-install-uninstall`
194. `p05-provider-fetch-normalize`
205. `p06-session-codec-recovery`
216. `p07-streamfn-agent-loop`
227. `p08-tui-testbackend`
238. `p09-memory-arena-allocation`
249. `p10-lua-plugin-heap-limit`
2510. `p11-plugin-memory-domain-reload`
2527Run in order unless a later prototype is needed to answer an active SPEC dispute.
27## P01 — `p01-pup-gate`
29### SPEC claims
31- `cargo-pup` can be a required architecture gate on pinned nightly.
32- Stable product build and pinned-nightly architecture gate can coexist.
33- `pup.ron` can enforce crate-boundary and module-hygiene rules.
35### Risk
37`cargo-pup` may be too unstable, too slow, or unable to express the required
38Smith architecture rules.
40### Minimal artifact
42Tiny Rust workspace:
44```text
45p01-pup-gate/
46 Cargo.toml
47 pup.ron
48 smith/
49 smith-core/
50 smith-ai/
51 xtask/
52```
54Include one passing case and one intentionally failing case gated by file rename
55or feature flag.
57### Verify
59```bash
60cd prototypes/p01-pup-gate
61cargo +stable check --workspace
62cargo +nightly-2026-01-22 pup
63```
65### Pass evidence
67- stable check passes,
68- pup passes on valid crate graph,
69- pup fails with useful diagnostic when forbidden import is enabled.
71### SPEC impact
73If pup cannot express needed rules, change SPEC to keep `xtask arch` as the hard
74architecture gate and redefine pup scope.
7629## P02 — `p02-lua-interface-descriptor`
7831### SPEC claims
393346Clarify theme schema, widget test strategy, and snapshot normalization.
348## P09 — `p09-memory-arena-allocation`
350### SPEC claims
352No current SPEC claim requires arenas. This prototype tests whether memory
353pressure justifies a future SPEC policy.
355Candidate claims:
357- Smith can load/replay large sessions without arena allocation.
358- Smith can discover many sessions without fully loading them.
359- Virtual scroll bounds per-frame allocations by visible rows, not total entries.
360- Phase-local scratch allocation may reduce render/request allocation pressure.
361- Phase-local scratch allocation may reduce allocator-call/syscall pressure.
362- Phase-local scratch allocation may produce a flatter post-warmup memory profile.
363- `bumpalo` can support scratch buffers without unsafe project code if measured
364 wins justify it.
365- Persisted/session data must use stable IDs, not `&'arena` references.
367### Empirical sizing target
369Use `../docs/research/SMITH-MEMORY-ALLOCATION-PROFILE.md` as the workload
370baseline. Pi sessions treated as Smith-shaped sessions showed:
372- 535 sessions, 395 MiB JSONL total,
373- p50 session 88 KiB / 36 entries,
374- p95 session 3.1 MiB / 822 entries,
375- p99 session 9.2 MiB / 1,930 entries,
376- max session 29.2 MiB / 5,157 entries,
377- max single message line 4.6 MiB,
378- compaction around 247k–282k tokens,
379- dominant bytes: tool results + assistant/thinking text.
381### Risk
383Arena allocation may optimize the wrong layer. Persisted text dominates memory,
384while arenas mainly help repeated short-lived scratch allocation. Allocation
385count reduction alone is insufficient; the real win may be fewer global allocator
386calls, less allocator/syscall pressure, and more stable peak/RSS behavior. Arena
387use may still add lifetime complexity, skipped destructors, async/thread
388friction, and unnecessary dependency surface.
390### Minimal artifact
392```text
393p09-memory-arena-allocation/
394 Cargo.toml
395 fixtures/session-small.jsonl
396 fixtures/session-p95.jsonl
397 fixtures/session-p99.jsonl
398 fixtures/session-pathological.jsonl
399 src/main.rs
400```
402Fixtures are synthetic and content-free but match measured shapes:
404- small: 36 entries, 88 KiB,
405- p95: 822 entries, 3.1 MiB,
406- p99: 1,930 entries, 9.2 MiB,
407- pathological: 5,157 entries, 29 MiB, one 4.6 MiB message.
409Implement five workloads:
4111. `discover`: scan 535 session headers/metadata without full load,
4122. `load-replay`: decode full sessions into Smith-like `SessionEntry` values,
4133. `render-window`: render visible rows from small/p95/p99/pathological sessions,
4144. `request-build`: assemble provider request near 250k token context,
4155. `arena-scratch`: compare baseline `Vec`/`String` vs `bumpalo` for render and
416 request scratch only.
418Use a counting global allocator. Measure allocations, allocated bytes, allocator
419calls, peak live bytes where feasible, post-warmup live-memory plateau, elapsed
420time, and Linux RSS via `/proc/self/statm` when available. Treat allocator calls
421as syscall-pressure proxy; optional local strace/malloc tracing may be noted but
422must not be required. Do not prototype `arena-allocator`; prior research flags it
423too sharp for Smith.
425### Verify
427```bash
428cd prototypes/p09-memory-arena-allocation
429cargo run -- discover
430cargo run -- load-replay
431cargo run -- render-window
432cargo run -- request-build
433cargo run -- arena-scratch
434cargo run -- all
435```
437### Pass evidence
439- discovery allocation is O(session count + metadata), not O(total corpus bytes),
440- full-load memory estimates stay within target bands from research,
441- render-window allocation is O(visible rows) for p95/p99/pathological sessions,
442- request-build reports peak allocation near compaction-size contexts,
443- post-warmup render/request memory profile is reported across repeated phases,
444- `bumpalo` keep/drop decision considers allocated bytes, allocation count,
445 allocator calls, elapsed time, RSS/peak-live stability, and complexity,
446- no arena reference crosses async/thread/persistent boundaries,
447- output prints keep/drop recommendation for `bumpalo` per workload.
449### SPEC impact
451If baseline is sufficient, record “no arena allocation in v1” and keep normal
452ownership.
454If arenas win on allocator calls, elapsed time, or memory stability, add a SPEC
455policy:
457- arenas only for phase-local scratch memory,
458- `bumpalo` allowed only in measured hot paths,
459- keep/drop gates include allocator-call pressure and stable memory profile, not
460 only allocation reduction,
461- persisted/session data uses stable IDs and owned bytes/strings,
462- no custom unsafe arena implementation.
464If session discovery/load/render exceeds targets, SPEC must clarify lazy loading,
465virtual-scroll cache boundaries, max retained render state, and provider-request
466peak-memory behavior.
468## P10 — `p10-lua-plugin-heap-limit`
470### SPEC claims
472Smith's Lua plugin sandbox can enforce per-plugin heap limits.
474Candidate claims:
476- `mlua + LuaJIT` supports `Lua::used_memory()` and `Lua::set_memory_limit()` in
477 Smith's locked feature set.
478- A plugin exceeding its configured heap limit fails with a recoverable Lua
479 memory error.
480- Heap limit failure does not corrupt the host runtime or other plugins.
481- Host-created values exposed to Lua have clear accounting semantics.
483### Risk
485Lua heap accounting may not include all host-side allocations, may behave
486differently under LuaJIT, or may make plugin isolation require one Lua state per
487quota domain. Shared Lua state + per-plugin quota may be impossible.
489### Minimal artifact
491```text
492p10-lua-plugin-heap-limit/
493 Cargo.toml
494 plugins/small.lua
495 plugins/oom_table.lua
496 plugins/oom_string.lua
497 plugins/host_value.lua
498 src/main.rs
499```
501Use Smith's planned `mlua = { features = ["luajit", "vendored", "serialize"] }`
502shape.
504Implement four scenarios:
5061. `small`: plugin stays below limit,
5072. `oom-table`: table growth hits limit,
5083. `oom-string`: string/buffer growth hits limit,
5094. `isolation`: one plugin OOMs, another plugin still runs.
511Test one-state-per-plugin first. If shared-state quotas are attempted, report
512whether they are enforceable or impossible.
514### Verify
516```bash
517cd prototypes/p10-lua-plugin-heap-limit
518cargo run -- small
519cargo run -- oom-table
520cargo run -- oom-string
521cargo run -- isolation
522cargo run -- all
523```
525### Pass evidence
527- `used_memory()` reports nonzero growth,
528- `set_memory_limit()` rejects table/string growth with recoverable error,
529- host process survives OOM scenario,
530- isolated plugin state still works after another plugin OOMs,
531- output states whether per-plugin quota requires one Lua state per plugin.
533### SPEC impact
535If viable, SPEC should add plugin heap quota fields and define quota domain:
536per-plugin Lua state or shared runtime.
538If not viable, SPEC should avoid promising plugin heap limits and instead define
539coarser process/session limits.
541## P11 — `p11-plugin-memory-domain-reload`
543### SPEC claims
545Smith can make plugin reload/unload memory management simple by assigning each
546plugin instance a memory domain and dropping the whole domain on reload.
548Candidate claims:
550- A plugin runtime can own all reloadable plugin state behind one domain object:
551 Lua state, registry handles, hook/tool descriptors, render caches, interface
552 adapters, and host-side plugin scratch memory.
553- Reload is `drop(old_domain) -> construct(new_domain)` with no per-resource
554 cleanup graph.
555- Arena-backed or domain-owned host allocations produce stable memory behavior
556 across repeated reloads.
557- Plugin heap quota and plugin memory-domain teardown are complementary: Lua heap
558 limit bounds VM allocations; domain teardown bounds/reclaims host-side plugin
559 allocations.
561### Risk
563Some plugin resources may escape the domain through async tasks, event bus
564subscriptions, registry keys, UI caches, or shared host registries. If escape is
565possible, reload can leak memory or leave stale callbacks even with an arena.
567### Minimal artifact
569```text
570p11-plugin-memory-domain-reload/
571 Cargo.toml
572 plugins/grow.lua
573 plugins/register_many.lua
574 src/main.rs
575```
577Model a `PluginDomain` that owns:
579- one `mlua::Lua`,
580- plugin metadata/descriptors,
581- hook/tool registries,
582- render/layout cache,
583- host scratch/domain arena or bump allocator,
584- cancellation token for async tasks,
585- subscription tokens dropped with the domain.
587Run repeated load/use/reload cycles. Include one intentionally escaped resource
588scenario that must fail validation.
590### Verify
592```bash
593cd prototypes/p11-plugin-memory-domain-reload
594cargo run -- reload-loop
595cargo run -- reload-with-heap-limit
596cargo run -- escaped-callback-fails
597cargo run -- all
598```
600### Pass evidence
602- repeated reloads plateau in RSS/live bytes after warmup,
603- old hooks/tools/render caches disappear after reload,
604- Lua heap is reclaimed by dropping the domain,
605- domain arena/scratch is reclaimed or reset on reload,
606- escaped callback/task/subscription is rejected or cancelled with clear error,
607- no stale plugin callback can run after reload.
609### SPEC impact
611If viable, SPEC should define `PluginDomain`/reload ownership:
613- one reloadable domain per plugin instance,
614- all plugin-owned host memory/resources live inside that domain,
615- reload is whole-domain replacement,
616- no plugin callback/resource may outlive its domain,
617- optional per-domain arena for host-side plugin state,
618- Lua heap limit remains separate quota enforcement.
620If not viable, SPEC must define explicit cleanup registries and leak/stale-callback
621failure modes for plugin reload.
395623## Reporting Template
397625Each completed prototype updates this plan with a result block: