@@ -45,6 +45,10 @@ enum {
4545 MAIN_MAX_PORT = 65536 ,
4646 MAIN_PATH_CAP = 4096 ,
4747 MAIN_CONNECT_TIMEOUT_MS = 1000 ,
48+ /* #2277: the conflict-remedy STATUS probe runs only after a refusal, so it
49+ * gets the same budget as `daemon status`: the daemon hashes the peer's
50+ * (~300 MB) image before answering, which can exceed a 1 s connect budget. */
51+ MAIN_CONFLICT_STATUS_PROBE_TIMEOUT_MS = 3000 ,
4852 MAIN_STARTUP_TIMEOUT_MS = 10000 ,
4953 /* Backstop for waiting out a held startup transition — see
5054 * main_local_transition_acquire. Not a budget for healthy contention: a busy
@@ -1698,6 +1702,10 @@ static bool main_semver_newer(const char *candidate, const char *active) {
16981702 return false;
16991703}
17001704
1705+ /* A conflict refusal plus its remedy (#2277), joined by one space. */
1706+ #define MAIN_CLIENT_FAILURE_DETAIL_CAP \
1707+ (CBM_DAEMON_CONFLICT_MESSAGE_SIZE + CBM_DAEMON_CONFLICT_REMEDY_SIZE + 1U)
1708+
17011709/* A client that cannot reach the daemon must SAY SO, in the caller's own
17021710 * protocol. An MCP client speaks JSON-RPC over stdout, and the old path
17031711 * returned EXIT_FAILURE having written nothing at all: agents saw a transport
@@ -1721,7 +1729,7 @@ static bool main_semver_newer(const char *candidate, const char *active) {
17211729 * just the one that happened to be fixed first. */
17221730static void main_report_client_failure (cbm_daemon_process_role_t role , const char * detail ) {
17231731 if (cbm_daemon_process_role_requires_client (role )) {
1724- char escaped [CBM_DAEMON_CONFLICT_MESSAGE_SIZE * 2 ];
1732+ char escaped [MAIN_CLIENT_FAILURE_DETAIL_CAP * 2 ];
17251733 size_t out = 0 ;
17261734 for (size_t i = 0 ; detail [i ] && out + 2 < sizeof (escaped ); i ++ ) {
17271735 unsigned char c = (unsigned char )detail [i ];
@@ -1746,10 +1754,35 @@ static void main_report_client_failure(cbm_daemon_process_role_t role, const cha
17461754
17471755static void main_report_client_bootstrap_failure (cbm_daemon_process_role_t role ,
17481756 const cbm_daemon_bootstrap_result_t * result ) {
1749- main_report_client_failure (role , (result && result -> message [0 ])
1750- ? result -> message
1751- : "CBM daemon connection failed before the session was "
1752- "established" );
1757+ const char * message = (result && result -> message [0 ])
1758+ ? result -> message
1759+ : "CBM daemon connection failed before the session was "
1760+ "established" ;
1761+ char detail [MAIN_CLIENT_FAILURE_DETAIL_CAP ];
1762+ (void )snprintf (detail , sizeof (detail ), "%s%s%s" , message ,
1763+ (result && result -> remedy [0 ]) ? " " : "" , result ? result -> remedy : "" );
1764+ main_report_client_failure (role , detail );
1765+ }
1766+
1767+ /* #2277: a conflict is a legitimate refusal (another build owns the account
1768+ * daemon), but it must name that daemon and the way out. known_active is a
1769+ * STATUS answer the caller already holds; without one this probes STATUS
1770+ * (cross-build by design) itself. When nothing answers, the remedy falls
1771+ * back to pointing at `daemon status`. */
1772+ static void main_conflict_remedy_probe (const cbm_daemon_ipc_endpoint_t * endpoint ,
1773+ const cbm_daemon_build_identity_t * identity ,
1774+ const cbm_daemon_runtime_status_t * known_active , char * out ,
1775+ size_t out_size ) {
1776+ cbm_daemon_runtime_status_t probed ;
1777+ const cbm_daemon_runtime_status_t * active = known_active ;
1778+ if (!active && endpoint && identity &&
1779+ cbm_daemon_runtime_request_status (endpoint , identity , MAIN_CONFLICT_STATUS_PROBE_TIMEOUT_MS ,
1780+ & probed )) {
1781+ active = & probed ;
1782+ }
1783+ if (!cbm_daemon_conflict_remedy_format (active , out , out_size )) {
1784+ out [0 ] = '\0' ;
1785+ }
17531786}
17541787
17551788/* Client bootstrap with the upgrade policy: a CONFLICT against a PERMANENT
@@ -1766,10 +1799,13 @@ static cbm_daemon_bootstrap_status_t main_client_bootstrap_with_upgrade(
17661799 return status ;
17671800 }
17681801 cbm_daemon_runtime_status_t active ;
1769- if (! cbm_daemon_runtime_request_status (config -> endpoint , config -> identity ,
1770- MAIN_CONNECT_TIMEOUT_MS , & active ) ||
1771- !active .permanent ||
1802+ bool active_known = cbm_daemon_runtime_request_status (config -> endpoint , config -> identity ,
1803+ MAIN_CONNECT_TIMEOUT_MS , & active );
1804+ if (! active_known || !active .permanent ||
17721805 !main_semver_newer (config -> identity -> semantic_version , active .semantic_version )) {
1806+ main_conflict_remedy_probe (config -> endpoint , config -> identity ,
1807+ active_known ? & active : NULL , result -> remedy ,
1808+ sizeof (result -> remedy ));
17731809 return status ;
17741810 }
17751811 if (report_lifecycle ) {
@@ -1786,9 +1822,16 @@ static cbm_daemon_bootstrap_status_t main_client_bootstrap_with_upgrade(
17861822 !drain .accepted ) {
17871823 (void )fprintf (stderr , "codebase-memory-mcp: the active daemon did not accept the "
17881824 "upgrade drain; run `codebase-memory-mcp daemon stop`\n" );
1825+ main_conflict_remedy_probe (config -> endpoint , config -> identity , & active , result -> remedy ,
1826+ sizeof (result -> remedy ));
17891827 return status ;
17901828 }
1791- return cbm_daemon_bootstrap_execute (config , result );
1829+ status = cbm_daemon_bootstrap_execute (config , result );
1830+ if (status == CBM_DAEMON_BOOTSTRAP_CONFLICT ) {
1831+ main_conflict_remedy_probe (config -> endpoint , config -> identity , NULL , result -> remedy ,
1832+ sizeof (result -> remedy ));
1833+ }
1834+ return status ;
17921835}
17931836
17941837/* One-shot CLI commands execute through the shared daemon, exactly like MCP
@@ -1825,6 +1868,9 @@ static char *main_local_cli_daemon_execute(const char *tool_name, const char *ar
18251868 (void )fprintf (stderr , "error: %s\n" ,
18261869 bootstrap .message [0 ] ? bootstrap .message
18271870 : "no CBM daemon connection for CLI execution" );
1871+ if (bootstrap .remedy [0 ]) {
1872+ (void )fprintf (stderr , "hint: %s\n" , bootstrap .remedy );
1873+ }
18281874 return NULL ;
18291875 }
18301876 if (bootstrap .daemon_spawned && cbm_log_get_level () <= CBM_LOG_INFO ) {
@@ -2870,13 +2916,17 @@ int main(int argc, char **argv) {
28702916 char message [CBM_DAEMON_CONFLICT_MESSAGE_SIZE ];
28712917 bool formatted = cohort_status == CBM_VERSION_COHORT_CONFLICT &&
28722918 cbm_daemon_conflict_format (& cohort_conflict , message , sizeof (message ));
2919+ char remedy [CBM_DAEMON_CONFLICT_REMEDY_SIZE ] = "" ;
28732920 if (cohort_status == CBM_VERSION_COHORT_CONFLICT ) {
28742921 (void )cbm_version_cohort_log_conflict (& cohort_conflict );
2922+ main_conflict_remedy_probe (local_endpoint , & local_identity , NULL , remedy ,
2923+ sizeof (remedy ));
28752924 }
2876- (void )fprintf (stderr , "codebase-memory-mcp: %s\n" ,
2925+ (void )fprintf (stderr , "codebase-memory-mcp: %s%s%s \n" ,
28772926 formatted ? message
28782927 : "CLI exact-build admission could not be verified; retry "
2879- "after active CBM operations exit" );
2928+ "after active CBM operations exit" ,
2929+ remedy [0 ] ? " " : "" , remedy );
28802930 goto local_cli_cleanup ;
28812931 }
28822932 main_local_maintenance_context_init (& maintenance_context );
@@ -3198,11 +3248,17 @@ int main(int argc, char **argv) {
31983248 bool formatted =
31993249 client_cohort_status == CBM_VERSION_COHORT_CONFLICT &&
32003250 cbm_daemon_conflict_format (& client_cohort_conflict , message , sizeof (message ));
3251+ char remedy [CBM_DAEMON_CONFLICT_REMEDY_SIZE ] = "" ;
32013252 if (client_cohort_status == CBM_VERSION_COHORT_CONFLICT ) {
32023253 (void )cbm_version_cohort_log_conflict (& client_cohort_conflict );
3254+ /* Hooks fail open on a tight budget; they skip the extra probe. */
3255+ if (role != CBM_DAEMON_PROCESS_HOOK_CLIENT ) {
3256+ main_conflict_remedy_probe (endpoint , & identity , NULL , remedy , sizeof (remedy ));
3257+ }
32033258 }
3204- (void )fprintf (stderr , "codebase-memory-mcp: %s\n" ,
3205- formatted ? message : "client exact-build admission failed" );
3259+ (void )fprintf (stderr , "codebase-memory-mcp: %s%s%s\n" ,
3260+ formatted ? message : "client exact-build admission failed" ,
3261+ remedy [0 ] ? " " : "" , remedy );
32063262 if (role == CBM_DAEMON_PROCESS_HOOK_CLIENT &&
32073263 client_cohort_status == CBM_VERSION_COHORT_CONFLICT ) {
32083264 main_hook_report_conflicted_daemon (hook_dialect );
0 commit comments