Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(daemon): replay the session within the startup budget

Martin Vogelbf30a1aaf01d
diff --git a/src/daemon/frontend.c b/src/daemon/frontend.c
index 123ec00e4..e76c920b6 100644
--- a/src/daemon/frontend.c
+++ b/src/daemon/frontend.c
@@ -120,6 +120,7 @@ static atomic_uint_fast64_t frontend_test_monitor_observation_count = ATOMIC_VAR
static atomic_uint_fast64_t frontend_test_worker_observation_count = ATOMIC_VAR_INIT(0);
static atomic_uint_fast64_t frontend_test_worker_idle_count = ATOMIC_VAR_INIT(0);
static atomic_uint_fast64_t frontend_test_routed_cancellation_count = ATOMIC_VAR_INIT(0);
+static atomic_uint_fast32_t frontend_test_replay_budget_ms = ATOMIC_VAR_INIT(0);
void cbm_daemon_frontend_test_observer_reset(bool hold_monitor) {
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) {
uint64_t cbm_daemon_frontend_test_routed_cancellations(void) {
return atomic_load_explicit(&frontend_test_routed_cancellation_count, memory_order_acquire);
}
+
+uint32_t cbm_daemon_frontend_test_replay_timeout_ms(void) {
+ return (uint32_t)atomic_load_explicit(&frontend_test_replay_budget_ms, memory_order_acquire);
+}
#endif
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_
static bool frontend_configure_client(cbm_daemon_runtime_client_t *client,
const cbm_daemon_frontend_session_config_t *session) {
- uint32_t timeout_ms = session->bootstrap.connect_timeout_ms;
+ /* The replay restores what startup set, so it waits within the startup
+ * budget like the first set_context and set_ui_config in main.c. The
+ * connect budget only bounds a probe (1 s in production): a replacement
+ * daemon whose UI save runs longer would end an otherwise good recovery. */
+ uint32_t timeout_ms = session->bootstrap.startup_timeout_ms;
+#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
+ atomic_store_explicit(&frontend_test_replay_budget_ms, timeout_ms, memory_order_release);
+#endif
if (cbm_daemon_application_client_set_context(
client, session->session_root, session->allowed_root, session->tool_profile, NULL, NULL,
timeout_ms) != CBM_DAEMON_RUNTIME_APPLICATION_OK) {
diff --git a/src/daemon/frontend.h b/src/daemon/frontend.h
index 8f59ec28b..8ee33d276 100644
--- a/src/daemon/frontend.h
+++ b/src/daemon/frontend.h
@@ -79,6 +79,10 @@ uint64_t cbm_daemon_frontend_test_worker_idle_cycles(void);
* Tests snapshot this monotonic
* count before sending a notification. */
uint64_t cbm_daemon_frontend_test_routed_cancellations(void);
+/* Budget in ms that the most recent session replay gave its context and UI
+ * settings requests. Recovery tests use distinct connect and startup budgets
+ * and compare. */
+uint32_t cbm_daemon_frontend_test_replay_timeout_ms(void);
#endif
/* Takes ownership of client and borrows cohort_manager for the complete call.
diff --git a/tests/test_daemon_frontend.c b/tests/test_daemon_frontend.c
index e4ed5e135..aa49bf4c7 100644
--- a/tests/test_daemon_frontend.c
+++ b/tests/test_daemon_frontend.c
@@ -250,6 +250,11 @@ enum {
* no-progress EOF
drain so shutdown deterministically overlaps recovery. */
FRONTEND_RECOVERY_EOF_RELEASE_MS = 16000,
+ /* Startup budget of the recovery bootstrap. It differs from the connect
+ * budget (FRONTEND_EOF_TEST_REQUEST_TIMEOUT_MS) so the recovery tests can
+ * tell which one the session replay waited on, and it is the larger one,
+ * as in production (1 s connect probe, 30 s startup). */
+ FRONTEND_RECOVERY_TEST_STARTUP_TIMEOUT_MS = 45000,
};
typedef enum {
@@ -818,7 +823,7 @@ static int frontend_recovery_child_run(const char *parent, frontend_recovery_mod
.identity = &fixture.identity,
.executable_path = "unused",
.connect_timeout_ms = FRONTEND_EOF_TEST_REQUEST_TIMEOUT_MS,
- .startup_timeout_ms = FRONTEND_EOF_TEST_REQUEST_TIMEOUT_MS,
+ .startup_timeout_ms = FRONTEND_RECOVERY_TEST_STARTUP_TIMEOUT_MS,
},
.session_root = parent,
.tool_profile = CBM_MCP_TOOL_PROFILE_ALL,
@@ -851,6 +856,14 @@ static int frontend_recovery_child_run(const char *parent, frontend_recovery_mod
bool input_closed = input && fclose(input) == 0;
bool output_closed = output && fclose(output) == 0;
bool fixture_closed = frontend_eof_fixture_finish(&fixture);
+#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
+ /* The replay restores what startup set within the startup budget. On the
+ * connect budget (a probe bound) a replacement daemon that answers slower
+ * than a probe would end an otherwise good recovery. Every mode replays. */
+ if (cbm_daemon_frontend_test_replay_timeout_ms() != FRONTEND_RECOVERY_TEST_STARTUP_TIMEOUT_MS) {
+ return 75;
+ }
+#endif
return replacement_ready && request_ready && result == 0 && response_exact &&
requests == expected_requests && writer_ok && input_closed && output_closed &&
fixture_closed