Repository navigation
feat(module): support per-instance setup factories - #48
Conversation
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reached
This review includes 4 billable files and costs up to $1.00. Or wait 31 minutes for your next included review. View limit details
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 30a777cc11
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Tiny Sweeper reviewTiny Sweeper completed its review; deterministic results follow. State: Ready for maintainer review Review snapshot
Completeness: Complete What changedThe diff adds a `setup_factory` alternative to the configured `setup` form: `crates/tinybus-module/src/lib.rs#macro_rules! module_export {` gains an arm rewriting `setup_factory = $factory:path, config = $config:ty` into a configured export started by `start_reconfigurable_module_with_factory`, and `module_export_static!` gains a matching arm routing to a linked factory starter. Two new `#[doc(hidden)]` public starters (`start_reconfigurable_module_with_factory`, `start_linked_reconfigurable_module_with_factory`) delegate to a shared `start_reconfigurable_module_factory_mode` that invokes the factory under `catch_unwind(AssertUnwindSafe(factory))` after configuration parses, returning `TB_PANICKED` on panic and otherwise cloning the result into the initial setup and moving it into the reinitialize closure. A `#[cfg(test)]` module is registered for a new `setup_factory_tests.rs`, the optional static-link fixture is converted from `setup` to `setup_factory` with a new `Config` type, and `docs/modules/module/README.md` documents the per-instance state behavior. Features
Tests
FindingsNo active actionable findings. Before mergeNone. How this fits togetherflowchart LR
n0["Connection"]:::impacted
n1["start_module_runtime"]:::impacted
n2["Result"]:::impacted
n3["Output"]:::impacted
n4["TbHostVtable"]:::impacted
n5["start_reconfigurable_module_factory_mode"]:::impacted
n1 -->|uses| n0
n1 -->|uses| n2
n1 -->|uses| n3
n1 -->|uses| n4
n5 -->|uses| n0
n5 -->|calls| n1
n5 -->|uses| n2
n5 -->|uses| n3
n5 -->|uses| n4
classDef changed fill:#0d4429,stroke:#238636,color:#e6edf3
classDef impacted fill:#161b22,stroke:#6e7681,color:#c9d1d9
classDef flagged fill:#5a1e02,stroke:#d93f0b,color:#ffffff
classDef blocking fill:#67060c,stroke:#f85149,color:#ffffff
Agent review detailscritique
security
tests
commits
description
Evidence and run details
|
There was a problem hiding this comment.
tinysweeper found nothing blocking, but could not review everything, so this is not an approval: crates/tinybus-module/src/lib.rs, crates/tinybus-module/src/setup_factory_tests.rs, crates/tinybus-module/src/static_link_tests.rs, tinysweeper/tests.
$0.0023 · 218,637 in / 30,375 out · 29,824 cached (14%) · ladder/vectors-oai3, deepseek-v4.1-flash · 492 embedded
critique: $0.0006 · 87,944 in / 8,540 out · 19,584 cached (22%) · deepseek-v4.1-flash
security: $0.0009 · 84,589 in / 13,242 out · 6,400 cached (8%) · deepseek-v4.1-flash
description: $0.0004 · 38,702 in / 4,294 out · 3,840 cached (10%) · deepseek-v4.1-flash
There was a problem hiding this comment.
tinysweeper found nothing blocking. Approving.
$0.0022 · 305,529 in / 33,637 out · 54,641 cached (18%) · ladder/vectors-oai3, deepseek-v4.1-flash, · 492 embedded
critique: $0.0019 · 144,827 in / 29,373 out · 30,961 cached (21%) · deepseek-v4.1-flash,
security: $0.0000 · 41,672 in / 189 out · 3,712 cached (9%) · deepseek-v4.1-flash
tests: $0.0001 · 61,817 in / 809 out · 6,272 cached (10%) · deepseek-v4.1-flash
description: $0.0001 · 39,093 in / 936 out · 13,696 cached (35%) · deepseek-v4.1-flash
Summary
Add an optional
setup_factory = factoryform to configured native, static and optional-static module exports. The safe factory runs once after complete ABI argument validation and valid initial configuration parsing. The same setup callback is shared by reference throughout the instance lifecycle and reused on reinitialization; separate ABI instances receive separate captured state.This lets a module seal an admitted runtime mode in its own captured state and refuse incompatible reinitialization before replacing the served interface. It avoids self-calls during setup, which cannot complete before module readiness, and avoids process-wide registries. The downstream use is TinyConnectors restricted concurrent reads (tinyhumansai/openhuman#7433); this PR adds the generic owning seam only.
Existing
setup = functionbehavior, per-instance reinitialization serialization, configuration parsing, deadlines and native ABI error mapping are preserved. Factory panic is contained asTB_PANICKED. No wire protocol, ABI layout, connection/responder/stream changes or new dependencies.Regression evidence
Two actual compiled ModuleHost tests failed against legacy setup: the factory was never created, and changing the sealed mode during reinitialization succeeded. After the seam and review corrections, fourteen focused factory/lifecycle tests pass on current-thread/in-memory fixtures:
Legacy configured callback tests stay green. Optional-static exports compile in both default and all-feature configurations.
Verification
-D warnings, full build, slim no-default check, rustdoc-D warnings, fmt and diff checks passed.Canonical base is merged PR46 at
8a4d8ca; this branch is independent of PR47 and touches only module export/runtime factory delegation, sibling tests and module docs. Downstream module and host consumption will wait for upstream availability. No real services are called.Review correction runs used serial test execution. One earlier default run hit the existing 20ms Echo timeout under machine load; its unchanged focused rerun and the complete default suite passed. One Clippy process exited137 without a diagnostic; the fresh complete strict run passed. Neither unrelated test nor resource behavior was changed.