Repository navigation
Add daemon-ready tasks and channel-rebuilt hooks to AppExtensions - #3405
Conversation
Automated pragmatic-code-review (medium) — PR #3405 @ 6925893Review Type: Initial Review Requirements Check (issue #3307)
Deviations, judged on their merits:
Other things I traced and found fine:
Code Review Findings🔴 Critical: none. 🟡 Important: none. 🟢 Suggestion — document the gap between reading the channel and caching a client built on it. The scenario:
The window is narrow: a wedge during startup, while the frontend's steady-state poll is probing. It is also the same shape as core's existing probe-then- But this bullet is the extension contract, and the issues that move the cloud client onto this seam will inherit it. Add one sentence: a task should read Principle: an API contract should state the concurrency obligations it places on callers. Nit: Nit: Nit: Recommendation: APPROVEThe change is tight and correct, and it matches the issue's design. Concurrency and lifecycle hold up against tokio and Tauri semantics. The tests prove what they claim; I confirmed by running them, including the real-daemon wedge test. The Suggestion is a one-line doc addition, and the Nits are optional polish. None of them blocks merging. |
mstomar125
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review (medium): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above: no Critical or Important findings, one Suggestion and three Nits.
Address review: PR #3405, review of 6925893Addressed in 94c7bdb. Every finding was checked against the code before it was acted on. Addressed (4 of 4)
SkippedNone. Checks after the fixes
No test was added, so no mutation check is new. The 22 mutation results in the PR body still hold, because these edits change only docs, a log line and an import. Re-Review DecisionDecision: NO RE-REVIEW NEEDED Rationale: The review was APPROVE with no Critical or Important findings. The fixes are:
None of them changes behaviour that a test or a reviewer has already judged. 🤖 Generated with Claude Code |
AppExtensions gains on_daemon_ready and on_channel_rebuilt. assemble
manages their state as ExtensionHooks, empty for AppExtensions::none().
- spawn_daemon_ready_tasks takes the tasks once and spawns each with a
DaemonReady { app, grpc, shutdown }, where shutdown is the task's own
child token. run's startup task calls it after the watcher and token
stream are wired and does not await it.
- run_channel_rebuilt_hooks runs the hooks in order, each as a spawned
task under CHANNEL_REBUILT_HOOK_TIMEOUT. A timeout aborts the task and
a panic is logged; the next hook runs either way.
- probe_and_recover_channel's body moves to probe_and_recover, generic
over the runtime, which runs the hooks after reconnect() and before
the re-probe.
- The GrpcClient channel docs describe extensions instead of a product.
- TauriTestApp::connect_assembled builds a mock app through assemble.
- Unit tests on a mock runtime, source-order tests for run and
probe_and_recover, and seam tests against a real nodespaced for the
shared channel and a wedged-channel rebuild.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- on_daemon_ready's contract says a task that caches a client reads the channel and stores the client under the lock its channel-rebuilt hook uses, and that tasks are spawned, not started, in order. - A panicking daemon-ready task's log line carries the panic message. - The wedge seam test imports Arc and Mutex itself, so the file has no import that is unused on Windows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
94c7bdb to
92fa402
Compare
Closes #3307
Part of the Pro-boundary epic (#3298) and the Tauri extension points (#3322).
What this adds
Two daemon-side hooks on
AppExtensions(ADR-082 sections 3.4 and 3.5). Later boundary issues use them to move the startup probe and the cloud client's rebind out of core.AppExtensions::on_daemon_ready(task). Each task is spawned once per process withDaemonReady { app, grpc, shutdown }. Core's startup task spawns it after the daemon start attempt finishes and the watcher and token stream are wired, and never awaits it.grpcis a clone of the managed client.shutdownis the task's own child of core's shutdown token. A task that panics is logged, and the other tasks are unaffected.AppExtensions::on_channel_rebuilt(hook). Awaited inprobe_and_recover, afterGrpcClient::reconnect()and before the re-probe. Hooks run in registration order. Each runs as its own spawned task underCHANNEL_REBUILT_HOOK_TIMEOUT(2 s). A hook that times out is aborted and logged, a hook that panics is logged, and recovery continues either way.assemblealways manages the hook state, empty fornone(), so an app with no extension behaves as before.ChannelandCancellationTokenare re-exported fromextensions.probe_and_recover_channel's body moves intopub async fn probe_and_recover<R: Runtime>(app, client) -> bool, so a mock app can drive it. The command is nowOk(probe_and_recover(&app, client.inner()).await).GrpcClient'schannelfield,channel()andreconnect()now describe extensions generically and name no product.TauriTestApp::connect_assembled(daemon, timeout, extensions).This PR leaves the startup Pro probe and the
ProClientrebind alone. Their own issue removes them.Deviations from the issue text
BASELINES not lowered. Step 5 of the issue says to lower
BASELINESto the printed counts. The standing instruction for this batch is the opposite, because parallel PRs collide on those lines and the closing issue tightens everything at once. This PR edits no baseline, and no count rises.The
daemon:data-plane-readyblock from Add a neutral daemon:data-plane-ready event and stop reloading on pro:tier-detected #3318 has not landed.spawn_daemon_ready_taskstherefore sits directly afterstart_token_stream_subscription, as the issue specifies for that case. If Add a neutral daemon:data-plane-ready event and stop reloading on pro:tier-detected #3318 lands first, the call moves below its block.The wedge seam test and the connect mutex. The issue says to hold the connect mutex for the whole test.
TauriTestApp::connect_assembled, likeconnect, takes that mutex itself, so holding it across the call would deadlock. The test holds it in two sections instead:hold_connect_mutex_and_socket_env, from after the app is built to the end, so the rebuild resolves the real daemon's socket.Each section's guard restores the environment variable when it drops.
tokiotest-utilis added tonodespace-app-lib's dev-dependencies for thestart_pausedtimeout tests. No new crate enters the lockfile.EXTENSION_API_VERSIONstays(1, 0). It must equal the TypeScript constant. The sibling additions to the extension API (lifecycle hooks) also left both at 1.0, because the API is unreleased.Ratchet
bun run scripts/check-pro-boundary.tspasses. Current counts move fromproProtocol95 to 93 and fromproWording274 to 272, and every other count is unchanged. Both drops come from the rewordedGrpcClientdocs. No count rises,BASELINESis not edited, and no added line carries a Pro marker.Tests
Unit tests in
extensions/fixture_tests.rs(mock runtime, aconnect_lazy()client, no daemon):daemon_ready_tasks_are_spawned_not_awaiteddaemon_ready_task_gets_the_app_the_client_and_a_child_shutdown_tokendaemon_ready_tasks_each_get_their_own_shutdown_tokena_panicking_daemon_ready_task_does_not_stop_the_othersdaemon_ready_tasks_run_oncechannel_rebuilt_hooks_run_in_registration_ordera_hanging_channel_rebuilt_hook_times_out_and_the_next_still_runsa_panicking_channel_rebuilt_hook_does_not_stop_recoveryhooks_are_a_no_op_without_extension_stateSource-text tests:
lib.rs, onrun: the spawn comes after the token stream and before the reachability check, the call is not awaited, and the shutdown token is a child of core's.nodes.rs: the hooks run afterreconnect()and before the final probe.Seam tests in
tests/it/extension_hooks_test.rs, against a realnodespaced:DatabaseService.Listonready.grpc.channel()succeeds.probe_and_recoverreturntrue, with the hook'sListon the rebuilt channel already completed. The wedge comes from a silent socket that accepts connections and never replies.Mutation checks
Each new test was checked by breaking the code path it covers and confirming the test fails, then restoring the code.
All 22 mutations below were killed: each made its test fail.
block_oninstead of spawning itdaemon_ready_tasks_are_spawned_not_awaiteddaemon_ready_task_gets_the_app_the_client_and_a_child_shutdown_tokendaemon_ready_tasks_each_get_their_own_shutdown_tokendaemon_ready_task_gets_the_app_the_client_and_a_child_shutdown_tokena_panicking_daemon_ready_task_does_not_stop_the_othersdaemon_ready_tasks_run_oncechannel_rebuilt_hooks_run_in_registration_ordera_hanging_channel_rebuilt_hook_times_out_and_the_next_still_runsa_panicking_channel_rebuilt_hook_does_not_stop_recoverystateinstead oftry_state)hooks_are_a_no_op_without_extension_staterunbefore the watcher and token streamrun_spawns_daemon_ready_tasks_once_the_watcher_and_token_stream_are_wiredrunrun's extension token a fresh token, not a child of the shutdown tokenrun_derives_the_daemon_ready_shutdown_from_the_shutdown_tokenprobe_and_recover_runs_the_channel_rebuilt_hooks_between_the_rebuild_and_the_reprobeGrpcClient::channel()return a channel that doesn't reach the daemondaemon_ready_task_reaches_the_daemon_on_the_shared_channel(seam)a_wedged_channel_rebuild_runs_the_hooks_before_recovery_returns(seam)probe_and_recoverEach task runs at most once because the tasks are
FnOnceand are taken out of the state, so the type system already rules out running a task twice. Mutation 6 covers the other way the run-once check can break: a second call that panics instead of doing nothing.Commands run
🤖 Generated with Claude Code