Skip to content

[CTX-1361] feat(runtime): wire the ComponentBroker at the composition root - #2267

Merged
Xuepoo merged 3 commits into
mainfrom
ctx-1361/feat-component-broker
Oct 19, 2026
Merged

Xuepoo merged 3 commits into
mainfrom
ctx-1361/feat-component-broker

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Priority: P1 | Area: runtime | Labels: feat,P1,area:runtime | Milestone: 0.0.24 | RFC: DIR-030 | Task: CTX-1361

What shipped

  • Single broker at the composition root. ComponentHost owns exactly one existing ComponentBroker; Runtime owns the host and installs it on both the primary and headless-fallback startup paths. No second broker, protocol, or spawn path.
  • Installed-store loading. Components resolve only through the existing $XDG_DATA_HOME/bitty/extensions (user tier over system tier under the install rules); PATH is never consulted. Every spawn re-runs resolution and descriptor digest verification, so unknown components and digest tampering fail closed.
  • Capability and lifecycle gates. Requests require an Activated plugin, the caller's manifest hash to match the registered generation, a non-denied grant record bound to that hash, and each capability to pass the canonical GrantStore::is_granted (including denied_caps from an explicit revoke). PluginGrant is derived from declared [[network.egress]]; an offline grant denies before spawn.
  • Bounded lifecycle/event ownership. tick_at pumps broker lifecycle into a bounded event queue drained by poll_component_events / take_component_events; synchronous request retains other request ids' events for a later poll. Runtime shutdown stops recorded children before PTY teardown.
  • Proof. Fixture installed through the real bitty extension add implementation, request/response through the production host, plus a real bitty-net 0.0.1 HTTP 200 through the same host. Committed regressions cover absent host, revoked capability, non-active lifecycle, wrong/foreign manifest hash, denied record, undeclared capability, digest mutation, and tick_at lifecycle/delivery.

Gates

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo clippy -p bitty-terminal --features dev-tools --all-targets --locked -- -D warnings
  • cargo nextest run -p bitty-runtime -p bitty-terminal -p bitty-platform --locked — 3944 passed, 2 skipped
  • cargo check --workspace --all-targets --locked --target x86_64-pc-windows-msvc
  • ./scripts/check-scratch-paths.sh
  • Real bitty-net harness: 1 passed

Mutations M1–M7 each kill their test (roundtrip, absent host, offline grant, digest, tick_at pump, canonical is_granted, Activated state).

Non-claims

  • [0.0.24] Native components are installable but never executed: no production ComponentBroker host #2254 is NOT fully accepted by this PR. Bullet 1 (real add + fixture round-trip) is met; bullets 2 and 3 remain partial/unmet: the bitty-net proof is an #[ignore]d harness run with no headed run, and bitty extension list has no activation state.
  • No production request producer exists. Nothing outside tests submits a request, there is no non-test activate_plugin caller, and no Lua/IPC verb exists; installed components are therefore not yet reachable from a user action. That is a blocking follow-up.
  • Composition-root documentation in the canonical docs corpus is still pending.
  • The synchronous ComponentRequest path can block up to 310 s and must stay off the owner/UI thread; the async delivery surface is a prerequisite for the future Lua verb.
  • No claim for graphics/a11y/agent/execution extension wiring.

Refs #2254 (intentionally not Closes, per the non-claims above).

Summary by CodeRabbit

  • New Features
    • Added runtime support for native components, including authorized synchronous and asynchronous requests, response handling, status checks, and lifecycle events.
    • Native-component hosting is configured automatically from available component directories at startup.
  • Bug Fixes
    • Component requests now report clear failures for unavailable components, invalid or insufficient permissions, and untrusted component data.
    • Timed-out requests are cancelled, and event processing continues during runtime updates.

@Xuepoo Xuepoo added this to the 0.0.24 milestone Oct 19, 2026
@Xuepoo Xuepoo added feat Feature P1 Priority: high area:runtime Area: runtime orchestration labels Oct 19, 2026
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

📝 Walkthrough

The change adds a broker-backed component host to Runtime, including plugin authorization, request handling, and event delivery. Terminal startup installs the host when component roots are available. Integration tests cover request success, authorization failures, component lifecycle events, and optional network access.

Changes: Native component host

Layer / File(s) Summary
Component host request and event handling
crates/bitty-runtime/src/component/host.rs, crates/bitty-runtime/src/component/mod.rs
Adds response and error types, broker-backed submission, synchronous request handling, deferred event limits, polling, and shutdown APIs.
Runtime authorization and event lifecycle
crates/bitty-runtime/src/runtime.rs, crates/bitty-runtime/src/runtime/component_host.rs, crates/bitty-runtime/src/runtime/present.rs, crates/bitty-runtime/tests/component_host.rs
Runtime authorizes requests using plugin activation, manifest hashes, grants, and capabilities. It pumps broker events during ticks and exposes event and status APIs. Tests cover authorization denials, timeouts, and event delivery.
Terminal host installation and integration tests
crates/bitty-terminal/Cargo.toml, crates/bitty-terminal/src/lib.rs, crates/bitty-terminal/src/component_host.rs, crates/bitty-terminal/src/main.rs, crates/bitty-runtime/Cargo.toml, crates/bitty-runtime/tests/component_host.rs
Adds terminal component-root resolution and host installation for primary and fallback runtimes. Integration tests use the production add path and exercise successful requests and optional network access.

Priority: ⬇️ Low

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Runtime
  participant ComponentHost
  participant ComponentBroker
  participant PluginComponent
  Caller->>Runtime: submit_component_request(plugin_id, manifest_hash, component, request)
  Runtime->>Runtime: validate plugin activation, manifest, grant, and capability
  Runtime->>ComponentHost: submit(now, component, grant, request)
  ComponentHost->>ComponentBroker: submit request
  ComponentBroker->>PluginComponent: dispatch request
  PluginComponent-->>ComponentBroker: response events
  Caller->>Runtime: tick_at(now)
  Runtime->>ComponentHost: poll(now)
  ComponentHost->>ComponentBroker: poll(now)
  ComponentBroker-->>ComponentHost: broker events
  ComponentHost-->>Runtime: component events
Loading
Merge Risk: ⚪ Minimal · up to ee061

No concrete merge-blocking failure is established. The safe-mode concern remains unverified because installation alone does not execute an extension.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.36% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 69 functions across 9 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the primary change: integrating the existing ComponentBroker through the runtime composition root. It is specific, concise, and consistent with the changeset.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 75.36% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 69 functions across 9 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔇 Additional comments: 12
crates/bitty-runtime/src/component/host.rs: 1

1-342: LGTM!

crates/bitty-runtime/src/component/mod.rs: 1

78-78: LGTM!

Also applies to: 101-102

crates/bitty-runtime/src/runtime.rs: 1

134-134: LGTM!

Also applies to: 467-479, 1468-1473, 1718-1720, 1990-1992

crates/bitty-runtime/src/runtime/component_host.rs: 1

1-148: LGTM!

Also applies to: 173-221

crates/bitty-runtime/src/runtime/present.rs: 1

1807-1810: LGTM!

crates/bitty-runtime/tests/component_host.rs: 1

1-671: LGTM!

crates/bitty-terminal/Cargo.toml: 1

23-36: LGTM!

crates/bitty-terminal/src/lib.rs: 1

1-19: LGTM!

crates/bitty-terminal/src/component_host.rs: 1

1-95: LGTM!

crates/bitty-terminal/src/main.rs: 1

234-234: LGTM!

Also applies to: 1293-1316

crates/bitty-runtime/Cargo.toml: 1

103-108: LGTM!

crates/bitty-terminal/src/main.rs-927-933: 1

927-933: 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Do not install the component host when --safe is set.

install_component_host runs on the primary and fallback paths without checking args.safe. Under --safe, other code skips third-party execution: no plugin VM, no session restore, no config reload. The component host still gets a broker that can spawn installed native extension binaries. Those binaries are third-party code from the extension store. The repository guide requires: "Preserve a safe startup path with no third-party plugins."

No request producer exists today. Even so, the safe path should not hold the authority. Guard both calls:

🛡️ Proposed fix
-    install_component_host(&mut runtime);
+    if !args.safe {
+        install_component_host(&mut runtime);
+    }
-        install_component_host(&mut rt);
+        if !args.safe {
+            install_component_host(&mut rt);
+        }

Also fix the doc comment on install_component_host, Lines 1293-1297. It says missing data roots leave the runtime without a host. The comment at Lines 930-932 says the system tier always resolves. If the system tier always resolves, the "no component data root" log branch never runs.

As per coding guidelines: "Preserve a safe startup path with no third-party plugins."

Also applies to: 1262-1263

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f48b327b-5c30-4784-b0f6-9a3e9581755f
📥 Commits

Reviewing files that changed from the base of the PR and between a6a60c6 and ee0613e.

⛔ Files ignored due to path filters: 1
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing: 11
  • crates/bitty-runtime/Cargo.toml
  • crates/bitty-runtime/src/component/host.rs
  • crates/bitty-runtime/src/component/mod.rs
  • crates/bitty-runtime/src/runtime.rs
  • crates/bitty-runtime/src/runtime/component_host.rs
  • crates/bitty-runtime/src/runtime/present.rs
  • crates/bitty-runtime/tests/component_host.rs
  • crates/bitty-terminal/Cargo.toml
  • crates/bitty-terminal/src/component_host.rs
  • crates/bitty-terminal/src/lib.rs
  • crates/bitty-terminal/src/main.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@Xuepoo
Xuepoo merged commit f8aff84 into main Oct 19, 2026
17 checks passed
@Xuepoo
Xuepoo deleted the ctx-1361/feat-component-broker branch October 19, 2026 14:15
Xuepoo added a commit that referenced this pull request Oct 20, 2026
Cover the full `v0.0.23..main` range instead of the earlier partial passes:
all 71 merged commits are grouped under Added, Changed, Fixed, Security, and
Documentation, with PR numbers and the affected CTX tasks.

Explicit call-outs: copy keeps combining marks and ZWJ (#2266), multi-line
paste duplication and ghost fixed by the cursor clamp across wide spacers
(#2272), combining marks paint so decomposed `é` matches precomposed (#2279),
kitty font query and `bitty +show-font` (#2277), bounded native clipboard
acquisition path B (#2273), bounded `bitty.fs.list` (#2271), the
`bitty.history` Lua surface (#2268), the production ComponentBroker plus
activation state (#2267, #2276), Enter-confirm paste (#2269), the `fill` DPI
fix (#2283), landlock `no_new_privs` (#2284), and spawn descriptor
reservation (#2289).

Partials are marked honestly: #2254's request surface is still pending, the
#2213 disposition stays open, #2286 is feature-gated and unwired, the macOS
clipboard read stays a typed refusal, and the RC-1 fuel accounting fix is not
claimed because PR #2292 is unmerged. The heading reads `unreleased` because
the release is on hold; the tag date is set at tag time.

Docs-only: no code, scripts, workflows, or pins touched.
Xuepoo added a commit that referenced this pull request Oct 20, 2026
Cover the full `v0.0.23..main` range instead of the earlier partial passes:
all 71 merged commits are grouped under Added, Changed, Fixed, Security, and
Documentation, with PR numbers and the affected CTX tasks.

Explicit call-outs: copy keeps combining marks and ZWJ (#2266), multi-line
paste duplication and ghost fixed by the cursor clamp across wide spacers
(#2272), combining marks paint so decomposed `é` matches precomposed (#2279),
kitty font query and `bitty +show-font` (#2277), bounded native clipboard
acquisition path B (#2273), bounded `bitty.fs.list` (#2271), the
`bitty.history` Lua surface (#2268), the production ComponentBroker plus
activation state (#2267, #2276), Enter-confirm paste (#2269), the `fill` DPI
fix (#2283), landlock `no_new_privs` (#2284), and spawn descriptor
reservation (#2289).

Partials are marked honestly: #2254's request surface is still pending, the
#2213 disposition stays open, #2286 is feature-gated and unwired, the macOS
clipboard read stays a typed refusal, and the RC-1 fuel accounting fix is not
claimed because PR #2292 is unmerged. The heading reads `unreleased` because
the release is on hold; the tag date is set at tag time.

Docs-only: no code, scripts, workflows, or pins touched.
Xuepoo added a commit that referenced this pull request Oct 20, 2026
…s bitty-net (#2254) (#2296)

* [CTX-1380] feat(runtime): add the plugin component request surface (#2254)

The ComponentBroker wired by #2267 had no production request producer, so an
installed component was unreachable from any user action. This adds the
narrowest existing seam: a Lua host surface, because plugins are the intended
consumers and the accepted capability model already covers them.

- `bitty.component.request{ id, method, url, headers?, body?, timeout_ms? }`
  validates shape and bounds and enqueues one submission, returning a ticket.
  It never spawns, sends, or waits, so no Lua callback blocks on a component.
- `bitty.component.poll(ticket)` reads `nil` while in flight, a bounded
  response table on success, and raises the stable typed class on failure
  (`E_COMPONENT_CAPABILITY_DENIED`, `E_COMPONENT_NOT_ACTIVE`,
  `E_COMPONENT_BUDGET`, `E_COMPONENT_TIMEOUT`, ...).
- Bounds: 8 KiB request payload (the existing bridge ceiling), 8 KiB response,
  16 headers, 30 s deadline ceiling, 32 submissions, 4 held per plugin, and a
  32-entry completion window.
- Authorization is unchanged and canonical: the composition root mirrors each
  activated generation's manifest and grant into the runtime policy host, then
  `Runtime::submit_component_request` re-checks lifecycle, manifest generation,
  grant record, and the egress intersection before the broker resolves and
  digest-verifies the component. Denials fail closed before any spawn.
- Wiring: `pump_component_requests` drains submissions and delivers broker
  events once per cold tick; deadlines cancel abandoned broker requests and a
  suspended/reloaded/disposed generation's tickets are purged.

Evidence: `tests/component_request_surface.rs` installs the fixture through the
real `bitty extension add`, drives one request through the plugin surface
(200 + echoed body), and proves denied (`capability_denied`), over-bound
payload (rejected before enqueue), crashed component, and deadline failures.

* [CTX-1380] fix(runtime): register all mirrored generations before activating any (#2254)

register_plugin resolves dependencies against the runtime registry, so a
dependent plugin mirrored ahead of its dependency would be refused and stay
unmirrored. Snapshot the active generations, register every one, then grant and
activate; a refusal still warns and leaves that plugin failing closed.

---------

Co-authored-by: reviewer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:runtime Area: runtime orchestration feat Feature P1 Priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant