SIGN IN SIGN UP

refactor(core): resolve the platform once and modernize trait signatures (#1986)

* refactor(core): resolve the platform once and modernize trait signatures

Construct the OS platform once per process (PlatformFactory::shared,
OnceLock) instead of per tick and per command, and inject the resolved
Arc<dyn Platform> into the collector cycle. The sampling module gains
collect_snapshot(store, &PlatformHandle), which also removes the
duplicated prime/loop sampling blocks in system_monitor and gives the
collector an injection seam, covered by new FakePlatform tests.

Replace the hand-rolled Pin<Box<dyn Future>> signatures on the platform
traits and implementations with #[async_trait] async fns (the dependency
was declared but unused until now). Per-cycle behavior on platform
initialization failure is preserved: sensor samples report unavailable
with the error as reason, GPU samples stay empty, and power falls back
to the default.

PlatformFactory::create() is removed from the public API; all callers
use the shared instance. Generated bindings are verified unchanged via
the export_bindings bin.

* refactor: serialize platform construction and retry failed resolution

Review corrections (PR #1986):

- PlatformFactory::shared() now serializes construction behind an init
  mutex with a double-check, so racing first callers cannot run the
  platform constructor twice and discard an instance that may hold
  provider handles. The fast path stays lock-free; a panicking
  constructor does not permanently poison resolution.
- The collector re-resolves the platform on each tick while resolution
  is failing, so a transient startup failure cannot pin the loop to
  degraded samples for the process lifetime. On success the resolved
  Arc is retained as before.
S
shm committed
84a8e3140e9b0fc48ef86fa41be4fc69d2781b87
Parent: 7f82d94
Committed by GitHub <noreply@github.com> on 8/22/2026, 5:10:52 PM