docs: integrate cargo-pup gate
96ef3c2742e757883d7664de83c0b9d482067c16
Oliver Jan Krylow <oliver@bugabinga.net> ·
SSH signature · not checked
- Parent 1: f3af9036447e
There are many coding harnesses - but this one is fast
96ef3c2742e757883d7664de83c0b9d482067c16
Oliver Jan Krylow <oliver@bugabinga.net> ·
SSH signature · not checked
+313 / −60 text lines
+28 / −3 text lines
- `cargo run -p xtask -- arch` checks stable metadata/source invariants.- `cargo run -p xtask -- check` includes both gates.Root `pup.ron` exists and is required. Initial rules enforce:Crate-boundary module match patterns must include the crate root. Use`^crate($|::.*)`, not only `^crate::.*`. Cargo-pup sees root-owned items in`lib.rs`/`main.rs` under the crate name itself.Required boundary patterns:```ronmatches: Module("^smith_core($|::.*)")matches: Module("^smith_ai($|::.*)")matches: Module("^smith_tui($|::.*)")````cargo pup print-modules` is not a complete module inventory. It can omit crateroots and can emit synthetic `unknown_crate` for crates with no child `mod`items. Developer-facing module inventory uses `cargo run -p xtask -- print-modules`,which prefixes crate roots from stable Cargo metadata and then printscargo-pup-discovered submodules.| `print-modules` | module inventory: Cargo metadata crate roots + cargo-pup submodules |+285 / −57 text lines
1. `p01-pup-gate`2. `p02-lua-interface-descriptor`3. `p03-subagent-ecosystem-simulation`4. `p04-plugin-install-uninstall`5. `p05-provider-fetch-normalize`6. `p06-session-codec-recovery`7. `p07-streamfn-agent-loop`8. `p08-tui-testbackend`1. `p02-lua-interface-descriptor`2. `p03-subagent-ecosystem-simulation`3. `p04-plugin-install-uninstall`4. `p05-provider-fetch-normalize`5. `p06-session-codec-recovery`6. `p07-streamfn-agent-loop`7. `p08-tui-testbackend`8. `p09-memory-arena-allocation`9. `p10-lua-plugin-heap-limit`10. `p11-plugin-memory-domain-reload`## P01 — `p01-pup-gate`### SPEC claims- `cargo-pup` can be a required architecture gate on pinned nightly.- Stable product build and pinned-nightly architecture gate can coexist.- `pup.ron` can enforce crate-boundary and module-hygiene rules.### Risk`cargo-pup` may be too unstable, too slow, or unable to express the requiredSmith architecture rules.### Minimal artifactTiny Rust workspace:```textp01-pup-gate/ Cargo.toml pup.ron smith/ smith-core/ smith-ai/ xtask/```Include one passing case and one intentionally failing case gated by file renameor feature flag.### Verify```bashcd prototypes/p01-pup-gatecargo +stable check --workspacecargo +nightly-2026-01-22 pup```### Pass evidence- stable check passes,- pup passes on valid crate graph,- pup fails with useful diagnostic when forbidden import is enabled.### SPEC impactIf pup cannot express needed rules, change SPEC to keep `xtask arch` as the hardarchitecture gate and redefine pup scope.## P09 — `p09-memory-arena-allocation`### SPEC claimsNo current SPEC claim requires arenas. This prototype tests whether memorypressure justifies a future SPEC policy.Candidate claims:- Smith can load/replay large sessions without arena allocation.- Smith can discover many sessions without fully loading them.- Virtual scroll bounds per-frame allocations by visible rows, not total entries.- Phase-local scratch allocation may reduce render/request allocation pressure.- Phase-local scratch allocation may reduce allocator-call/syscall pressure.- Phase-local scratch allocation may produce a flatter post-warmup memory profile.- `bumpalo` can support scratch buffers without unsafe project code if measured wins justify it.- Persisted/session data must use stable IDs, not `&'arena` references.### Empirical sizing targetUse `../docs/research/SMITH-MEMORY-ALLOCATION-PROFILE.md` as the workloadbaseline. Pi sessions treated as Smith-shaped sessions showed:- 535 sessions, 395 MiB JSONL total,- p50 session 88 KiB / 36 entries,- p95 session 3.1 MiB / 822 entries,- p99 session 9.2 MiB / 1,930 entries,- max session 29.2 MiB / 5,157 entries,- max single message line 4.6 MiB,- compaction around 247k–282k tokens,- dominant bytes: tool results + assistant/thinking text.### RiskArena allocation may optimize the wrong layer. Persisted text dominates memory,while arenas mainly help repeated short-lived scratch allocation. Allocationcount reduction alone is insufficient; the real win may be fewer global allocatorcalls, less allocator/syscall pressure, and more stable peak/RSS behavior. Arenause may still add lifetime complexity, skipped destructors, async/threadfriction, and unnecessary dependency surface.### Minimal artifact```textp09-memory-arena-allocation/ Cargo.toml fixtures/session-small.jsonl fixtures/session-p95.jsonl fixtures/session-p99.jsonl fixtures/session-pathological.jsonl src/main.rs```Fixtures are synthetic and content-free but match measured shapes:- small: 36 entries, 88 KiB,- p95: 822 entries, 3.1 MiB,- p99: 1,930 entries, 9.2 MiB,- pathological: 5,157 entries, 29 MiB, one 4.6 MiB message.Implement five workloads:1. `discover`: scan 535 session headers/metadata without full load,2. `load-replay`: decode full sessions into Smith-like `SessionEntry` values,3. `render-window`: render visible rows from small/p95/p99/pathological sessions,4. `request-build`: assemble provider request near 250k token context,5. `arena-scratch`: compare baseline `Vec`/`String` vs `bumpalo` for render and request scratch only.Use a counting global allocator. Measure allocations, allocated bytes, allocatorcalls, peak live bytes where feasible, post-warmup live-memory plateau, elapsedtime, and Linux RSS via `/proc/self/statm` when available. Treat allocator callsas syscall-pressure proxy; optional local strace/malloc tracing may be noted butmust not be required. Do not prototype `arena-allocator`; prior research flags ittoo sharp for Smith.### Verify```bashcd prototypes/p09-memory-arena-allocationcargo run -- discovercargo run -- load-replaycargo run -- render-windowcargo run -- request-buildcargo run -- arena-scratchcargo run -- all```### Pass evidence- discovery allocation is O(session count + metadata), not O(total corpus bytes),- full-load memory estimates stay within target bands from research,- render-window allocation is O(visible rows) for p95/p99/pathological sessions,- request-build reports peak allocation near compaction-size contexts,- post-warmup render/request memory profile is reported across repeated phases,- `bumpalo` keep/drop decision considers allocated bytes, allocation count, allocator calls, elapsed time, RSS/peak-live stability, and complexity,- no arena reference crosses async/thread/persistent boundaries,- output prints keep/drop recommendation for `bumpalo` per workload.### SPEC impactIf baseline is sufficient, record “no arena allocation in v1” and keep normalownership.If arenas win on allocator calls, elapsed time, or memory stability, add a SPECpolicy:- arenas only for phase-local scratch memory,- `bumpalo` allowed only in measured hot paths,- keep/drop gates include allocator-call pressure and stable memory profile, not only allocation reduction,- persisted/session data uses stable IDs and owned bytes/strings,- no custom unsafe arena implementation.If session discovery/load/render exceeds targets, SPEC must clarify lazy loading,virtual-scroll cache boundaries, max retained render state, and provider-requestpeak-memory behavior.## P10 — `p10-lua-plugin-heap-limit`### SPEC claimsSmith's Lua plugin sandbox can enforce per-plugin heap limits.Candidate claims:- `mlua + LuaJIT` supports `Lua::used_memory()` and `Lua::set_memory_limit()` in Smith's locked feature set.- A plugin exceeding its configured heap limit fails with a recoverable Lua memory error.- Heap limit failure does not corrupt the host runtime or other plugins.- Host-created values exposed to Lua have clear accounting semantics.### RiskLua heap accounting may not include all host-side allocations, may behavedifferently under LuaJIT, or may make plugin isolation require one Lua state perquota domain. Shared Lua state + per-plugin quota may be impossible.### Minimal artifact```textp10-lua-plugin-heap-limit/ Cargo.toml plugins/small.lua plugins/oom_table.lua plugins/oom_string.lua plugins/host_value.lua src/main.rs```Use Smith's planned `mlua = { features = ["luajit", "vendored", "serialize"] }`shape.Implement four scenarios:1. `small`: plugin stays below limit,2. `oom-table`: table growth hits limit,3. `oom-string`: string/buffer growth hits limit,4. `isolation`: one plugin OOMs, another plugin still runs.Test one-state-per-plugin first. If shared-state quotas are attempted, reportwhether they are enforceable or impossible.### Verify```bashcd prototypes/p10-lua-plugin-heap-limitcargo run -- smallcargo run -- oom-tablecargo run -- oom-stringcargo run -- isolationcargo run -- all```### Pass evidence- `used_memory()` reports nonzero growth,- `set_memory_limit()` rejects table/string growth with recoverable error,- host process survives OOM scenario,- isolated plugin state still works after another plugin OOMs,- output states whether per-plugin quota requires one Lua state per plugin.### SPEC impactIf viable, SPEC should add plugin heap quota fields and define quota domain:per-plugin Lua state or shared runtime.If not viable, SPEC should avoid promising plugin heap limits and instead definecoarser process/session limits.## P11 — `p11-plugin-memory-domain-reload`### SPEC claimsSmith can make plugin reload/unload memory management simple by assigning eachplugin instance a memory domain and dropping the whole domain on reload.Candidate claims:- A plugin runtime can own all reloadable plugin state behind one domain object: Lua state, registry handles, hook/tool descriptors, render caches, interface adapters, and host-side plugin scratch memory.- Reload is `drop(old_domain) -> construct(new_domain)` with no per-resource cleanup graph.- Arena-backed or domain-owned host allocations produce stable memory behavior across repeated reloads.- Plugin heap quota and plugin memory-domain teardown are complementary: Lua heap limit bounds VM allocations; domain teardown bounds/reclaims host-side plugin allocations.### RiskSome plugin resources may escape the domain through async tasks, event bussubscriptions, registry keys, UI caches, or shared host registries. If escape ispossible, reload can leak memory or leave stale callbacks even with an arena.### Minimal artifact```textp11-plugin-memory-domain-reload/ Cargo.toml plugins/grow.lua plugins/register_many.lua src/main.rs```Model a `PluginDomain` that owns:- one `mlua::Lua`,- plugin metadata/descriptors,- hook/tool registries,- render/layout cache,- host scratch/domain arena or bump allocator,- cancellation token for async tasks,- subscription tokens dropped with the domain.Run repeated load/use/reload cycles. Include one intentionally escaped resourcescenario that must fail validation.### Verify```bashcd prototypes/p11-plugin-memory-domain-reloadcargo run -- reload-loopcargo run -- reload-with-heap-limitcargo run -- escaped-callback-failscargo run -- all```### Pass evidence- repeated reloads plateau in RSS/live bytes after warmup,- old hooks/tools/render caches disappear after reload,- Lua heap is reclaimed by dropping the domain,- domain arena/scratch is reclaimed or reset on reload,- escaped callback/task/subscription is rejected or cancelled with clear error,- no stale plugin callback can run after reload.### SPEC impactIf viable, SPEC should define `PluginDomain`/reload ownership:- one reloadable domain per plugin instance,- all plugin-owned host memory/resources live inside that domain,- reload is whole-domain replacement,- no plugin callback/resource may outlive its domain,- optional per-domain arena for host-side plugin state,- Lua heap limit remains separate quota enforcement.If not viable, SPEC must define explicit cleanup registries and leak/stale-callbackfailure modes for plugin reload.