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

Function cli_activation_diagnostic

src/cli/cli.c:232–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

230static bool g_cli_activation_scope_cache_unreadable_for_test = false;
231
232static void cli_activation_diagnostic(const cbm_cli_activation_ops_t *ops, const char *message) {
233 const char *diagnostic = message ? message : CLI_ACTIVATION_REFUSED_MESSAGE;
234 /* #1416: when the transaction recorded a concrete refusal (an ACL or
235 * filesystem safety check), say THAT. The generic text blames "active CBM
236 * sessions" for what is a validation refusal - reporters rebooted, killed
237 * every process, and hunted phantom handles because the message pointed at
238 * sessions that did not exist. The sessions wording remains for genuine
239 * stop/reservation failures, which record no refusal note. */
240 char attributed[CBM_SZ_1K];
241 const char *note = cbm_activation_transaction_refusal_note();
242 /* A recorded refusal is more specific than EITHER generic message, so it
243 * wins over both the busy and the reservation-failure wording. */
244 if ((diagnostic == CLI_ACTIVATION_REFUSED_MESSAGE ||
245 diagnostic == CLI_ACTIVATION_BUSY_MESSAGE) &&
246 note && note[0]) {
247 (void)snprintf(attributed, sizeof(attributed),
248 "error: activation was refused by a filesystem safety check before any "
249 "change was made: %s\n"
250 "error: this is not a session problem. If the flagged directory is one you "
251 "trust, remove the flagged permission grant (icacls <dir> /remove:g <sid>; "
252 "an INHERITED grant needs icacls <dir> /inheritance:r /grant:r "
253 "\"%%USERNAME%%\":(OI)(CI)F instead, because /remove:g cannot delete one) "
254 "or use an owner-private directory for --dir/CBM_CACHE_DIR, then retry.",
255 note);
256 diagnostic = attributed;
257 } else if (diagnostic == CLI_ACTIVATION_REFUSED_MESSAGE) {
258 /* #1537/#1416: the reservation-failure message told the reader to
259 * "check the errors above" — and nothing was above. The detail that
260 * names the failing component is recorded on the daemon side and was
261 * only ever surfaced by `daemon status`, so the CLI replaced a message
262 * that blamed the wrong thing with one that blamed nothing. Two
263 * reporters were left with no way forward. Print it here. */
264 const char *detail = cbm_daemon_ipc_validation_detail();
265 if (detail && detail[0]) {
266 (void)snprintf(attributed, sizeof(attributed),
267 "error: activation could not reserve exclusive access; no activation "
268 "was committed.\n"
269 "error: this is NOT a running-session problem — nothing needs to be "
270 "closed. The check that refused was: %s",
271 detail);
272 diagnostic = attributed;
273 }
274 }
275 if (ops && ops->visible_diagnostic) {
276 ops->visible_diagnostic(ops->context, diagnostic);
277 return;
278 }
279 (void)fprintf(stderr, "%s\n", diagnostic);
280}
281
282int cbm_cli_activation_guard_with_ops(const cbm_cli_activation_ops_t *ops,
283 cbm_cli_activation_mutation_fn mutation,

Callers 2

Tested by

no test coverage detected