Files
codebase-memory-mcp/src/daemon/application_internal.h
T
Martin Vogel 87f7c0d784 daemon: deterministic job interleavings and queued explicit index admission
Two changes to the index coordinator, developed together and validated as
one state:

Determinism seams. A cancel racing a worker start was only observable on a
loaded runner; now the interleaving is forced by construction: a test hold
parks every job thread before its first pre-start cancel check, and a
background-initialize completion counter turns sleep-then-assert negatives
into positive-signal waits. The cancel-before-worker-start case is pinned
by a dedicated test; three auto-index admission tests now wait for the
admission tail instead of sleeping through it.

Queued admission. An explicit index_repository request that hits the
physical job limit used to surface a raw busy error. The request thread
already blocks for the whole index, so it now queues: a cancellable,
shutdown-aware wait-and-resubscribe loop replaces the error path, with a
wait counter as the parked-state observable. The programmatic coordinator
API keeps its non-blocking busy answer for callers with their own retry
policy (watcher, auto-index). The job-limit test asserts the new contract:
parked without a second worker start, admitted and completed once the
occupying job finishes.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-07-23 17:35:23 +02:00

39 lines
1.8 KiB
C

/*
* application_internal.h — Private daemon application test seams.
*/
#ifndef CBM_DAEMON_APPLICATION_INTERNAL_H
#define CBM_DAEMON_APPLICATION_INTERNAL_H
#include "daemon/application.h"
#include <stdbool.h>
/* Read-only test diagnostic for a live session. The caller must serialize
* this check with request, cancellation, and close callbacks. */
bool cbm_daemon_application_session_retains_store_for_test(
const cbm_daemon_runtime_application_session_t *session);
/* Fail exactly one physical index supervisor-thread admission before any
* worker starts. This keeps the otherwise OS-dependent thread-create failure
* path deterministic and verifies that its linked job reservation is rolled
* back rather than retained as terminal background state. */
void cbm_daemon_application_fail_next_job_thread_start_for_test(void);
/* Park every new job thread before its first pre-start cancel check while
* held. This makes the cancel-wins-before-worker-start interleaving — which
* otherwise needs a descheduled thread on a loaded runner — reproducible by
* construction: hold, subscribe, cancel, observe CANCELLED, release, then
* assert the worker was never started and its ops were never invoked. */
void cbm_daemon_application_hold_job_before_start_for_test(bool hold);
/* Completed background-initialize passes (auto-index admission tail).
* Waiting for a delta here replaces sleep-then-assert negatives. */
int cbm_daemon_application_background_initializes_for_test(void);
/* Iterations of the explicit-index busy-queue wait (request parked behind
* the physical job limit). Waiting for a delta here is the positive signal
* that a request QUEUED rather than erroring or starting. */
int cbm_daemon_application_busy_queue_waits_for_test(void);
#endif /* CBM_DAEMON_APPLICATION_INTERNAL_H */