Skip to content

Commit bf30a1a

Browse files
committed
fix(daemon): replay the session within the startup budget
The recovery path replays the session context and UI settings on the replacement daemon. It waited on the bootstrap connect budget, which only bounds a probe (1 s in production), while main.c gives the first set_context and set_ui_config the startup budget since eb29429. A replacement daemon whose UI save runs longer than a probe would end an otherwise good recovery. frontend_configure_client now waits on startup_timeout_ms. A test seam records the budget the replay used, and the recovery fixture gives the bootstrap distinct connect and startup budgets and exits 75 when the replay waited on the wrong one. With the old budget exactly the three recovery tests fail with exit 75; with the fix daemon_frontend is 17/17. Signed-off-by: Martin Vogel <[email protected]>
1 parent e6874f0 commit bf30a1a

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎src/daemon/frontend.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ static atomic_uint_fast64_t frontend_test_monitor_observation_count = ATOMIC_VAR
120120
static atomic_uint_fast64_t frontend_test_worker_observation_count = ATOMIC_VAR_INIT(0);
121121
static atomic_uint_fast64_t frontend_test_worker_idle_count = ATOMIC_VAR_INIT(0);
122122
static atomic_uint_fast64_t frontend_test_routed_cancellation_count = ATOMIC_VAR_INIT(0);
123+
static atomic_uint_fast32_t frontend_test_replay_budget_ms = ATOMIC_VAR_INIT(0);
123124

124125
void cbm_daemon_frontend_test_observer_reset(bool hold_monitor) {
125126
atomic_store_explicit(&frontend_test_monitor_observation_count, 0, memory_order_release);
@@ -152,6 +153,10 @@ uint64_t cbm_daemon_frontend_test_worker_idle_cycles(void) {
152153
uint64_t cbm_daemon_frontend_test_routed_cancellations(void) {
153154
return atomic_load_explicit(&frontend_test_routed_cancellation_count, memory_order_acquire);
154155
}
156+
157+
uint32_t cbm_daemon_frontend_test_replay_timeout_ms(void) {
158+
return (uint32_t)atomic_load_explicit(&frontend_test_replay_budget_ms, memory_order_acquire);
159+
}
155160
#endif
156161

157162
static cbm_version_cohort_maintenance_presence_t frontend_observe_maintenance(
@@ -528,7 +533,14 @@ static cbm_daemon_runtime_cancel_result_t frontend_cancel_active(frontend_state_
528533

529534
static bool frontend_configure_client(cbm_daemon_runtime_client_t *client,
530535
const cbm_daemon_frontend_session_config_t *session) {
531-
uint32_t timeout_ms = session->bootstrap.connect_timeout_ms;
536+
/* The replay restores what startup set, so it waits within the startup
537+
* budget like the first set_context and set_ui_config in main.c. The
538+
* connect budget only bounds a probe (1 s in production): a replacement
539+
* daemon whose UI save runs longer would end an otherwise good recovery. */
540+
uint32_t timeout_ms = session->bootstrap.startup_timeout_ms;
541+
#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
542+
atomic_store_explicit(&frontend_test_replay_budget_ms, timeout_ms, memory_order_release);
543+
#endif
532544
if (cbm_daemon_application_client_set_context(
533545
client, session->session_root, session->allowed_root, session->tool_profile, NULL, NULL,
534546
timeout_ms) != CBM_DAEMON_RUNTIME_APPLICATION_OK) {

‎src/daemon/frontend.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ uint64_t cbm_daemon_frontend_test_worker_idle_cycles(void);
7979
* Tests snapshot this monotonic
8080
* count before sending a notification. */
8181
uint64_t cbm_daemon_frontend_test_routed_cancellations(void);
82+
/* Budget in ms that the most recent session replay gave its context and UI
83+
* settings requests. Recovery tests use distinct connect and startup budgets
84+
* and compare. */
85+
uint32_t cbm_daemon_frontend_test_replay_timeout_ms(void);
8286
#endif
8387

8488
/* Takes ownership of client and borrows cohort_manager for the complete call.

‎tests/test_daemon_frontend.c‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ enum {
250250
* no-progress EOF
251251
drain so shutdown deterministically overlaps recovery. */
252252
FRONTEND_RECOVERY_EOF_RELEASE_MS = 16000,
253+
/* Startup budget of the recovery bootstrap. It differs from the connect
254+
* budget (FRONTEND_EOF_TEST_REQUEST_TIMEOUT_MS) so the recovery tests can
255+
* tell which one the session replay waited on, and it is the larger one,
256+
* as in production (1 s connect probe, 30 s startup). */
257+
FRONTEND_RECOVERY_TEST_STARTUP_TIMEOUT_MS = 45000,
253258
};
254259

255260
typedef enum {
@@ -818,7 +823,7 @@ static int frontend_recovery_child_run(const char *parent, frontend_recovery_mod
818823
.identity = &fixture.identity,
819824
.executable_path = "unused",
820825
.connect_timeout_ms = FRONTEND_EOF_TEST_REQUEST_TIMEOUT_MS,
821-
.startup_timeout_ms = FRONTEND_EOF_TEST_REQUEST_TIMEOUT_MS,
826+
.startup_timeout_ms = FRONTEND_RECOVERY_TEST_STARTUP_TIMEOUT_MS,
822827
},
823828
.session_root = parent,
824829
.tool_profile = CBM_MCP_TOOL_PROFILE_ALL,
@@ -851,6 +856,14 @@ static int frontend_recovery_child_run(const char *parent, frontend_recovery_mod
851856
bool input_closed = input && fclose(input) == 0;
852857
bool output_closed = output && fclose(output) == 0;
853858
bool fixture_closed = frontend_eof_fixture_finish(&fixture);
859+
#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
860+
/* The replay restores what startup set within the startup budget. On the
861+
* connect budget (a probe bound) a replacement daemon that answers slower
862+
* than a probe would end an otherwise good recovery. Every mode replays. */
863+
if (cbm_daemon_frontend_test_replay_timeout_ms() != FRONTEND_RECOVERY_TEST_STARTUP_TIMEOUT_MS) {
864+
return 75;
865+
}
866+
#endif
854867
return replacement_ready && request_ready && result == 0 && response_exact &&
855868
requests == expected_requests && writer_ok && input_closed && output_closed &&
856869
fixture_closed

0 commit comments

Comments
 (0)