MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / tf_index_worker_probe

Function tf_index_worker_probe

tests/test_main.c:367–469  ·  view source on GitHub ↗

Fast real-process probes for the async index-supervisor contract. They run * only in a child admitted by the exact build-bound worker grammar. */

Source from the content-addressed store, hash-verified

365/* Fast real-process probes for the async index-supervisor contract. They run
366 * only in a child admitted by the exact build-bound worker grammar. */
367static void tf_index_worker_probe(const char *args_json, const char *response_out) {
368 if (!args_json || !strstr(args_json, "\"__cbm_test_worker\"")) {
369 return;
370 }
371 if (strstr(args_json, "\"clean\"")) {
372 FILE *response = response_out ? cbm_fopen(response_out, "wb") : NULL;
373 if (response) {
374 (void)fputs("{\"probe\":\"clean\"}", response);
375 (void)fclose(response);
376 }
377 (void)fprintf(stderr, "async worker clean probe\n");
378 fflush(NULL);
379 _Exit(response ? 0 : 1);
380 }
381 if (strstr(args_json, "\"heartbeat\"")) {
382 FILE *response = response_out ? cbm_fopen(response_out, "wb") : NULL;
383 if (response) {
384 (void)fputs("{\"probe\":\"heartbeat\"}", response);
385 (void)fclose(response);
386 }
387 cbm_log_info("pipeline.discover", "files", "1");
388 (void)fprintf(stderr, "async worker heartbeat probe ready\n");
389 fflush(NULL);
390 _Exit(response ? 0 : 1);
391 }
392 if (strstr(args_json, "\"silent-exit\"")) {
393 /* #1300: reach a phase, then exit 0 without writing the response. The
394 * trailing plain-text line must not be mistaken for a phase. */
395 cbm_log_info("incremental.edge_snapshot", "captured", "3");
396 (void)fprintf(stderr, "async worker silent-exit probe\n");
397 fflush(NULL);
398 _Exit(0);
399 }
400 if (strstr(args_json, "\"crash\"")) {
401 (void)fprintf(stderr, "async worker crash probe\n");
402 fflush(NULL);
403 abort();
404 }
405 if (strstr(args_json, "\"buffered-kill\"")) {
406 /* The 0-byte-worker-log repro. tf_maybe_run_index_worker has already
407 * put stderr into the FULL buffering a redirected stderr gets from the
408 * Windows CRT (see there), so this line only reaches the log if the
409 * production worker-log entry made the stream crash-durable.
410 *
411 * Then die the way the reports die. NOT abort(): Darwin's abort() runs
412 * the stdio cleanup handler, so it flushes the very buffer this probe
413 * exists to strand — under abort the reverted build still produced a
414 * populated log and the repro was silently toothless. SIGKILL cannot be
415 * caught, blocked or handled, so no cleanup of any kind runs. It is
416 * also literally #1070's death (`signal=9`) and how #1130's hung worker
417 * is terminated. */
418 cbm_log_info("index.worker.buffered_kill_probe", "phase", "before_kill");
419#ifdef _WIN32
420 TerminateProcess(GetCurrentProcess(), 9);
421#else
422 (void)raise(SIGKILL);
423#endif
424 _Exit(2); /* unreachable: neither primitive returns */

Callers 1

Calls 5

cbm_fopenFunction · 0.85
_ExitFunction · 0.85
abortFunction · 0.85
signalFunction · 0.85
cbm_mem_budgetFunction · 0.85

Tested by

no test coverage detected