Skip to content

Commit 32272f9

Browse files
committed
fix(daemon): log the effective auto_index_limit in daemon.autoindex.skipped
When daemon-backed auto-indexing refuses a repository, the daemon.autoindex.skipped warning reported the tracked-file count but not the limit that caused the refusal. The MCP autoindex.skip event already carries limit=<n> (DeusData#1466); add the same field to the daemon warning, using the auto_index_limit value the admission check already used. Admission behavior is unchanged. daemon_application_auto_index_honors_tracked_file_limit now captures the warning through a log sink and asserts reason=too_many_files, files=1 and limit=0 as whole fields. Fixes DeusData#1818 Signed-off-by: Gaurav Dubey <gauravdubey0107@gmail.com>
1 parent 10ab613 commit 32272f9

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

‎src/daemon/application.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2398,10 +2398,12 @@ static void application_background_initialize_impl(cbm_daemon_application_sessio
23982398
cbm_mcp_auto_index_within_file_limit(root_path, auto_index_limit, &tracked_files);
23992399
if (auto_index_candidate && !within_auto_index_limit) {
24002400
char files[32];
2401+
char limit[32];
24012402
(void)snprintf(files, sizeof(files), "%d", tracked_files);
2403+
(void)snprintf(limit, sizeof(limit), "%d", auto_index_limit);
24022404
cbm_log_warn("daemon.autoindex.skipped", "project", project, "reason",
24032405
tracked_files >= 0 ? "too_many_files" : "unsafe_or_unavailable_path", "files",
2404-
files);
2406+
files, "limit", limit);
24052407
}
24062408
bool args_required = auto_index_candidate && within_auto_index_limit;
24072409
char *args = args_required ? application_auto_index_args(application, root_path) : NULL;

‎tests/test_daemon_application.c‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "foundation/compat.h"
1313
#include "foundation/compat_fs.h"
1414
#include "foundation/compat_thread.h"
15+
#include "foundation/log.h"
1516
#include "foundation/platform.h"
1617
#include "foundation/sha256.h"
1718
#include "foundation/subprocess.h"
@@ -2884,6 +2885,38 @@ TEST(daemon_application_programmatic_index_forwards_set_doc_candidates) {
28842885
ASSERT_EQ(garbage, -1);
28852886
PASS();
28862887
}
2888+
2889+
/* #1818: the daemon.autoindex.skipped warning must name the effective limit,
2890+
* like the MCP autoindex.skip event does (#1466). The warning is emitted on the
2891+
* background-initialize thread, before the release increment of the
2892+
* background-initialize counter that the test waits for, so the captured line
2893+
* is complete once that wait returns. */
2894+
static char app_autoindex_skipped_line[1024];
2895+
static atomic_bool app_autoindex_skipped_seen = ATOMIC_VAR_INIT(false);
2896+
2897+
static void app_autoindex_skipped_sink(const char *line) {
2898+
if (!line || !strstr(line, "msg=daemon.autoindex.skipped") ||
2899+
atomic_load_explicit(&app_autoindex_skipped_seen, memory_order_acquire)) {
2900+
return;
2901+
}
2902+
(void)snprintf(app_autoindex_skipped_line, sizeof(app_autoindex_skipped_line), "%s", line);
2903+
atomic_store_explicit(&app_autoindex_skipped_seen, true, memory_order_release);
2904+
}
2905+
2906+
/* True when `line` carries the whole key=value field `field` (not a prefix of
2907+
* a longer value such as limit=00). */
2908+
static bool app_log_line_has_field(const char *line, const char *field) {
2909+
size_t length = strlen(field);
2910+
for (const char *at = strstr(line, field); at; at = strstr(at + 1, field)) {
2911+
bool starts = at == line || at[-1] == ' ';
2912+
char next = at[length];
2913+
if (starts && (next == '\0' || next == ' ' || next == '\n' || next == '\r')) {
2914+
return true;
2915+
}
2916+
}
2917+
return false;
2918+
}
2919+
28872920
TEST(daemon_application_auto_index_honors_tracked_file_limit) {
28882921
app_env_backup_t cache_environment;
28892922
bool cache_saved = app_env_backup_capture(&cache_environment, "CBM_CACHE_DIR");
@@ -2928,13 +2961,25 @@ TEST(daemon_application_auto_index_honors_tracked_file_limit) {
29282961
cbm_daemon_application_runtime_callbacks(application);
29292962
cbm_daemon_runtime_application_session_t *session =
29302963
application ? app_test_open(&callbacks, 4190) : NULL;
2964+
app_autoindex_skipped_line[0] = '\0';
2965+
atomic_store_explicit(&app_autoindex_skipped_seen, false, memory_order_release);
2966+
CBMLogLevel previous_log_level = cbm_log_get_level();
2967+
CBMLogFormat previous_log_format = cbm_log_get_format();
2968+
cbm_log_set_level(CBM_LOG_INFO);
2969+
cbm_log_set_format(CBM_LOG_FORMAT_TEXT);
2970+
cbm_log_set_sink_ex(app_autoindex_skipped_sink, CBM_LOG_SINK_REPLACE);
29312971
int bg_baseline = cbm_daemon_application_background_initializes_for_test();
29322972
bool initialized = app_test_initialize_profile(&callbacks, session, root,
29332973
CBM_MCP_TOOL_PROFILE_ALL, NULL, NULL);
29342974
bool admission_evaluated = app_wait_for_background_initializes(bg_baseline + 1);
29352975
bool limit_prevented_admission = initialized && admission_evaluated &&
29362976
atomic_load(&fake.starts) == 0 &&
29372977
cbm_daemon_application_active_jobs(application) == 0;
2978+
cbm_log_set_sink(NULL);
2979+
cbm_log_set_format(previous_log_format);
2980+
cbm_log_set_level(previous_log_level);
2981+
bool skip_logged = admission_evaluated &&
2982+
atomic_load_explicit(&app_autoindex_skipped_seen, memory_order_acquire);
29382983

29392984
if (session) {
29402985
callbacks.session_cancel(callbacks.context, session);
@@ -2954,6 +2999,10 @@ TEST(daemon_application_auto_index_honors_tracked_file_limit) {
29542999
ASSERT_TRUE(config_ready);
29553000
ASSERT_TRUE(initialized);
29563001
ASSERT_TRUE(limit_prevented_admission);
3002+
ASSERT_TRUE(skip_logged);
3003+
ASSERT_TRUE(app_log_line_has_field(app_autoindex_skipped_line, "reason=too_many_files"));
3004+
ASSERT_TRUE(app_log_line_has_field(app_autoindex_skipped_line, "files=1"));
3005+
ASSERT_TRUE(app_log_line_has_field(app_autoindex_skipped_line, "limit=0"));
29573006
ASSERT_TRUE(stopped);
29583007
ASSERT_TRUE(cache_restored);
29593008
PASS();

0 commit comments

Comments
 (0)