Repository navigation
[0.0.28] feat(plugin): per-plugin execution budgets (#2304) - #2622
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 17 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Add optional [limits] fuel_instructions, wall_ms, memory_bytes, and warning_ms to bitty-plugin.toml, validated in 1..=the compiled RC-1/RC-2 ceilings with typed field-path errors. Add an optional data-only $XDG_CONFIG_HOME/bitty/plugin-budgets.lua with a global default and per-plugin overrides; every layer is an upper bound and the effective budget is the per-dimension minimum, so no manifest or user file can widen another layer. Production activation now builds VmBudgets from the resolved values instead of always VmBudgets::default(); absent declarations keep the existing defaults. Safe mode ignores both tightening layers and runs host defaults. A rejected user file fails activation closed rather than silently falling back. bitty plugin config show prints host, manifest, user, effective values and the deciding source layer. Closes #2304
beb20bf to
f159076
Compare
Xuepoo
left a comment
There was a problem hiding this comment.
INDEPENDENT REVIEW (guard tick, agent: guard-1024) — head f1590761c8a5c7777e81a01908da50859449fc37
Scope: independent review of the 2518-line diff across bitty-plugin-host (budgets.rs, manifest.rs, event.rs, error.rs), bitty-runtime (manifest_toml.rs, plugin_runtime/mod.rs), bitty-terminal (plugin.rs, plugin_runtime.rs) + tests/CHANGELOG. Areas: fail-closed budget validation, user-layer plugin-budgets.lua safety, production VmBudgets wiring, manifest-hash stability, security invariants, test honesty. All findings below verified with fresh runs on the head, not the implementer's artifacts. Note: base drifted (base 6d82a69, earlier than main head) — mergeable=MERGEABLE at review time.
(a) Fail-closed validation — PASS
budgets.rs:143-186(BudgetValues::validate) +budgets.rs:188-211(check_range_u64): every present value must be1..=ceiling; zero and above-ceiling rejected withPluginError::Budgetcarrying the exact field path (limits.fuel_instructions,plugin-budgets.default.wall_ms, cross-layerplugin-budgets.plugins["id"].warning_ms). No clamping, no silent ignore.warning_ms >= wall_msrejected within the same layer (budgets.rs:174-181); the cross-layer case is handled by the advisory cap (warning = min(warning, wall-1),resolve_budgetsatbudgets.rs:278-287) withwarning_capped_by_wallreported.- Manifest dimension:
manifest.rs:844-867adds fourOptionfields;manifest.rs:927-928re-runs budget validation insidePluginLimits::validate, soparse_manifestfails closed even before acceptance checks (manifest_toml.rs:584callsvalidate()). - TOML subset:
parse_limit_u64/parse_limit_uint(manifest_toml.rs:712-741) accept bare ASCII digits only — quoted strings,-1,4.0,true, empty, >u64 all rejected; duplicates caught byseen_keys.insertbefore the key match (manifest_toml.rs:406-410), so the earlycontinuearms of the new budget keys do not bypass duplicate detection (verified in code;limit_budgets_parse_and_reject_escalationcovers it). - Tests:
budgets.rs:781-811sweeps zero/above-ceiling for all four dimensions throughresolve_budgets;manifest.rs:4589-4685covers zero/escalation/typed-error/warning-vs-wall at the manifest layer;manifest_toml.rstests cover wrong types, signs, floats, empty, duplicate keys.
(b) User-layer Lua file — PASS
- Loader (
bitty-terminal/src/plugin_runtime.rs:621-654): absent file →Ok(None);symlink_metadata+!file_type().is_file()refuses symlinks, directories, and special files; size checked pre-read and re-checked post-read byparse_budget_file, closing the widen TOCTOU window. - Parser (
budgets.rs:243-255): UTF-8 only, ≤16 KiB / 256 lines / 512 B per line / ≤256 plugin records; hand-rolled bounded byte parser — accepts onlyreturn { default = {...}, plugins = { ["id"] = {...} } }with bare non-negative integers and--comments; fails closed on strings, floats, negatives, booleans, function calls,local x, duplicate keys/values, unknown keys, trailing content (budgets.rs:560-592tests). No Lua VM is constructed anywhere; no host/IO access from file content. - Malformed file ⇒
set_budget_file_error(mod.rs:1171-1180) ⇒ activation refuses with typedPluginRuntimeError::Budget(mod.rs:1226-1231);--safecheckssafe_modefirst (mod.rs:1221-1226), so recovery always runs host defaults. Tests:rejected_user_file_fails_closed_but_safe_mode_still_works,budget_file_loader_refuses_symlinks_and_special_files(unix-only, symlink exercised directly — nit below on the FIFO case). - Minor:
parse_string(budgets.rs:496-532) maps non-ASCII bytes viachar::from(byte)(Latin-1), mangling multibyte plugin ids beforePluginId::newvalidation; sincePluginIdis ASCII-only (manifest.rs:86-141), this fails closed — cosmetic diagnostic staleness only.
(c) Production wiring — PASS
- Activation actually constructs
VmBudgetsfrom resolved values (mod.rs:2966-2971):instruction_budget/wall/warning/memory_limitall fromeffective_budgets; the oldVmBudgets::default()fallback path is gone; the test-only harness override touches only the wall dimension. - No layer can raise: per-dimension minimum across manifest/user layers (
budgets.rs:245-275), range capped at1..=ceiling, and ceilings are derived from the actualVmBudgets::default()(budget_ceilings,mod.rs:2180-2189) so host/VM constant drift fails closed.host_ceilings_match_the_vm_defaultspins RC-1 (10^7 fuel, 50 ms wall) / RC-2 (32 MiB) parity in the runtime crate. - Constants re-pointed to the single authority:
event.rs:1063-1087now aliasesbudgets::HOST_*(no duplicate ownership). - Manifest bytes/hash: budget keys appended to canonical bytes only when at least one is declared (
manifest.rs:2715-2739), so absent declarations keep pre-existing bytes —manifest_hash_covers_budgets_only_when_declaredasserts no budget keys in the canonical string when nothing is declared, and distinct values change the hash. Absent-declaration grant pins stay valid. - Effective budgets recorded per entry, cleared on teardown and on failure (
entry.budgets = Nonehunks); rollback happens before any VM exists when resolution fails (mod.rs:2944-2955).
(d) Security invariants — PASS
- Tighten-only monotonic min across layers; user layers cannot widen manifest/host (explicit tests
user_layers_cannot_widen_manifest_or_hostatbudgets.rs:860-878,user_layers_tighten_and_cannot_widen). - No plugin execution on render/input hot path: the diff touches only startup discovery (
discover_with_roots— file read per process start, no VM), activation, and theplugin config showCLI report path. The budget file is data-only and never instantiated as code, so it cannot alter Terminal Truth; no new Terminal Truth writes anywhere in the diff.
(e) Test honesty — PASS
My independent runs on the PR head: bitty-plugin-host full suite ok (incl. 12 budgets::tests + 2 manifest budget tests), --test plugin_budgets 8/8 ok (end-to-end: manifest values reach the production VM; runaway command terminated by tight fuel, not default; rejected-file fail-closed with safe-mode recovery; VM-level fuel/wall/memory suspend contrast), bitty-runtime manifest_toml incl. limit_budgets_parse_and_reject_escalation ok, bitty-terminal --bins 4 budget tests ok, cli_plugin malformed-budget-file fail-closed (exit 4, BudgetRejected on stderr) ok. GitHub CI green on this exact head (Linux Wayland/X11, Windows, macOS, MSRV 1.85, CodeQL, supply chain).
Nits (non-blocking)
crates/bitty-terminal/src/plugin_runtime.rs:655— replaced doc comment leaves a stray///glued to the first line (...(CTX-1115 test seam).///), merging two rustdoc paragraphs; formatting regression only.budget_rows(bitty-terminal/src/plugin.rs:4511) displaysBudgetCeilings::HOSTconstants while the runtime derives ceilings fromVmBudgets::default(); parity is pinned by tests, but on hypothetical drift theconfig showreport could disagree with effective enforcement.budget_file_loader_refuses_symlinks_and_special_filesexercises only the symlink case on unix; a FIFO/named-pipe case would close the special-files evidence gap directly.parse_budget_table's unknown-key path reports the input-typed error ("expected a bare non-negative integer") instead of "unknown budget key" when a string follows an unknown key; fail-closed either way, message quality only.
VERDICT: PASS-WITH-NITS — fail-closed validation, data-only user file, resolved VmBudgets wiring, hash stability, hot-path neutrality, and genuine fail-path tests all verified against head f159076; four cosmetic nits only.
|
Independent review verdict recorded by blitz guard tick (agent guard-1024, completed 2026-10-24 17:13 CST). INDEPENDENT REVIEW ✓ (agent: guard-1024)PR: #2622 "[0.0.28] feat(plugin): per-plugin execution budgets (#2304)" · Head SHA (fetched fresh): Scope: independent review of fail-closed budget validation, user-layer (a) Fail-closed validation — PASS
(b) User-layer Lua file — PASS
(c) Production wiring — PASS
(d) Security invariants — PASS
(e) Test honesty — PASSMy independent runs on the PR head: Nits (non-blocking)
I made no changes to GitHub (no approval, comment, merge, push). Housekeeping leftovers from my verification: VERDICT: PASS-WITH-NITS — fail-closed validation, data-only user file, resolved |
Summary
Implements bitty#2304: per-plugin execution budgets that can only tighten the
compiled RC-1/RC-2 ceilings.
bitty-plugin.toml[limits]accepts optionalfuel_instructions,wall_ms,memory_bytes, andwarning_ms. Values validate in1..=host_ceiling; zero, above-ceiling, negative, wrong-typed, duplicate,unknown, and
warning_ms >= wall_msdeclarations fail closed with themanifest field path.
<config-dir>/plugin-budgets.lua: a globaldefaulttable plus per-plugin
plugins["owner.name"]entries. Data-only Lua parsedwithout a VM or host access (16 KiB, 256 lines, 512 B/line, 256 plugins,
UTF-8 only, duplicate/unknown keys fail, symlinks/special files refused).
VmBudgetsfrom the resolved valuesinstead of always
VmBudgets::default(). Absent declarations keep theexisting defaults exactly (canonical manifest bytes are unchanged when no
budget is declared, so existing manifest hashes and grant pins stay valid).
bitty plugin config show <id>prints host ceiling, manifest value, userlayers, effective value, and the deciding source layer, in table and JSON.
Design choice: layers are upper bounds, effective = minimum
All four layers are upper bounds; the effective value is the per-dimension
minimum across host ceiling, manifest, user global, and user per-plugin. This
is monotone by construction: a later layer that declares a larger number is
inert, never a widening, even when it is inside the host ceiling. It also
avoids a global user default being rejected because some other plugin declared
a tighter manifest value. The advisory
warning_msis capped atwall_ms - 1when a tighter wall leaves no room; it never suspends.
Failure posture: a malformed user file fails generation activation closed with
a typed budget error (no silent fallback).
--safeignores both tighteninglayers and runs host defaults, so the recovery path cannot be blocked by a bad
local file. Safe mode also ignores manifest declarations for bundled plugins.
Tests
crates/bitty-plugin-host: budget resolution (accepted tightening, absent =defaults, min precedence, user cannot widen, zero/above-ceiling/warning
rejection), user-file parser (happy path, wrong types, negatives, unknown
and duplicate keys, oversize/non-UTF-8), manifest validation and
hash coverage.
crates/bitty-runtime/tests/plugin_budgets.rs: production activation appliesmanifest budgets to
VmBudgets; absent keys keep host defaults; user layerstighten and cannot widen; safe mode ignores both layers; rejected file fails
closed while safe mode still activates; deterministic VM-level proof that a
tighter fuel suspends where the default completes, plus wall/memory
observation.
crates/bitty-terminal: loader tests (absent/valid/malformed/oversize/symlink) and
plugin config showbudget rows, precedence, and rejected-fileexit behavior.
Gates run
cargo fmt --all -- --checkcargo clippy -p bitty-plugin-host -p bitty-runtime -p bitty-terminal --all-targets -- -D warningscargo check --workspace --all-targetscargo test -p bitty-plugin-hostcargo test -p bitty-configcargo test -p bitty-runtime --test plugin_budgetscargo test -p bitty-runtime --test plugin_runtimecargo test -p bitty-runtime --test plugin_settings_filecargo test -p bitty-terminal --test cli_plugin plugin_config_showjust fmt-check+just verify-schema+ targeted markdownlint(bitty-manual),
just fmt-check+ targeted markdownlint +just language(bitty-terminal-docs);
just markdownlint/just linksstill reportpre-existing
recording/issues unrelated to this PR.Docs: bitty-manual plugin manifest/config pages, bitty-terminal-docs
configuration options, bitty-plugins-docs isolation RFC amendment, and the
bitty-docs OQ-014 note are updated in their own repositories.
Closes #2304