Skip to content

Commit ff853ac

Browse files
committed
fix(cli): stop blaming sessions for a failure that has none (DeusData#1537)
A reporter ran `uninstall`, then could not install again: every attempt said "active CBM sessions and operations could not be stopped safely". A reboot proved no such session existed, and the remedy line v0.10.2 added made it worse — it told them to run `codebase-memory-mcp daemon status`, a binary they had just uninstalled. Both halves were wrong for their case: The guard funneled two unrelated outcomes into one message. A cohort that is BUSY means real sessions hold it and closing something is the fix. A reservation that FAILED — lock I/O, leftover coordination state, permissions — means nothing is running at all, and telling that reader to close sessions sends them after processes that do not exist. Same misattribution class as DeusData#1416 and DeusData#1535: a non-session failure wearing a session costume. They are now separate messages, and the failure one says plainly that nothing needs to be closed. The remedy also has to survive the situation it prints in. Install, and any retry after uninstall, runs with no cbm on PATH; advice that starts with `codebase-memory-mcp ...` is unusable exactly when it is needed. The busy message now leads with the actionable step (close the editor/agent holding it) and mentions the command only as an aid where a binary still exists; the failure message asks for a cache listing, which needs no cbm at all. A recorded transaction refusal still outranks both generic messages, so the DeusData#1416 attribution is unchanged. This does NOT yet explain why their reservation fails with nothing running — that needs their environment, which is being requested on the issue. What it does is stop sending them after the wrong thing while we find out. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 98aff5b commit ff853ac

2 files changed

Lines changed: 69 additions & 11 deletions

File tree

‎src/cli/cli.c‎

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,31 @@ int cbm_cli_exit_status_after_maintenance(int exit_status, bool maintenance_canc
152152
return maintenance_cancelled && exit_status == EXIT_SUCCESS ? EXIT_FAILURE : exit_status;
153153
}
154154

155-
/* #1537: the refusal is correct, but "sessions could not be stopped" gives the
156-
* reader nothing to act on — which sessions? The daemon already knows every
157-
* client pid and `daemon status` prints them, so name that remedy here rather
158-
* than leaving people to guess (one reporter uninstalled first and still hit
159-
* this, with no way to see what was holding on). */
160-
static const char CLI_ACTIVATION_REFUSED_MESSAGE[] =
155+
/* #1537. Two very different failures reached this one message: the cohort was
156+
* BUSY (real sessions are running — the reader can close them), or the
157+
* reservation failed outright (lock I/O, stale coordination state, permissions
158+
* — nothing the reader can close, because nothing is running). Reporting both
159+
* as "active sessions" sent someone hunting processes that a reboot proved did
160+
* not exist.
161+
*
162+
* The remedy line must also survive the situation it prints in: an install or
163+
* a retry after `uninstall` has no cbm on PATH, so "run codebase-memory-mcp
164+
* daemon status" was advice the reader could not follow at exactly the moment
165+
* they needed it. Each message now names its own condition and stays runnable. */
166+
static const char CLI_ACTIVATION_BUSY_MESSAGE[] =
161167
"error: active CBM sessions and operations could not be stopped safely; "
162168
"no activation was committed.\n"
163-
"error: run 'codebase-memory-mcp daemon status' to list the client "
164-
"processes still holding the daemon (MCP servers started by your editor or "
165-
"agent are the usual holders), close them, then retry.";
169+
"error: something is still using CBM. If an editor or agent is running an "
170+
"MCP server, close it and retry; 'codebase-memory-mcp daemon status' lists "
171+
"the holders when a cbm binary is still installed.";
172+
static const char CLI_ACTIVATION_REFUSED_MESSAGE[] =
173+
"error: activation could not reserve exclusive access; no activation was "
174+
"committed.\n"
175+
"error: this is NOT a running-session problem — the reservation itself "
176+
"failed (coordination lock, leftover state, or permissions). Nothing needs "
177+
"to be closed. Check the errors above, and report this with the output of "
178+
"'ls -la \"${CBM_CACHE_DIR:-$HOME/.cache/codebase-memory-mcp}\"' if it "
179+
"persists.";
166180
static const char CLI_ACTIVATION_PARTIAL_MESSAGE[] =
167181
"error: activation stopped after one or more agent configuration or "
168182
"cleanup operations failed; the published/current executable was kept, "
@@ -211,7 +225,11 @@ static void cli_activation_diagnostic(const cbm_cli_activation_ops_t *ops, const
211225
* stop/reservation failures, which record no refusal note. */
212226
char attributed[CBM_SZ_1K];
213227
const char *note = cbm_activation_transaction_refusal_note();
214-
if (diagnostic == CLI_ACTIVATION_REFUSED_MESSAGE && note && note[0]) {
228+
/* A recorded refusal is more specific than EITHER generic message, so it
229+
* wins over both the busy and the reservation-failure wording. */
230+
if ((diagnostic == CLI_ACTIVATION_REFUSED_MESSAGE ||
231+
diagnostic == CLI_ACTIVATION_BUSY_MESSAGE) &&
232+
note && note[0]) {
215233
(void)snprintf(attributed, sizeof(attributed),
216234
"error: activation was refused by a filesystem safety check before any "
217235
"change was made: %s\n"
@@ -245,7 +263,12 @@ int cbm_cli_activation_guard_with_ops(const cbm_cli_activation_ops_t *ops,
245263
if (mutation_lease) {
246264
ops->mutation_lease_release(ops->context, mutation_lease);
247265
}
248-
cli_activation_diagnostic(ops, CLI_ACTIVATION_REFUSED_MESSAGE);
266+
/* 0 means the cohort was BUSY: real sessions hold it and closing them
267+
* is the remedy. Anything else is the reservation itself failing, and
268+
* telling that reader to close sessions sends them after processes
269+
* that do not exist (#1537). */
270+
cli_activation_diagnostic(ops, reserve_status == 0 ? CLI_ACTIVATION_BUSY_MESSAGE
271+
: CLI_ACTIVATION_REFUSED_MESSAGE);
249272
return CLI_TRUE;
250273
}
251274

‎tests/test_cli.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,40 @@ TEST(cli_activation_refusal_note_reaches_diagnostic_issue1416) {
682682
PASS();
683683
}
684684

685+
/* #1537: a reservation that FAILED (lock I/O, leftover coordination state,
686+
* permissions) is not a reservation that was BUSY. Reporting both as "active
687+
* CBM sessions could not be stopped" sent a reporter hunting processes that a
688+
* reboot proved did not exist — and the remedy we printed told them to run a
689+
* cbm binary they had just uninstalled. Each condition now names itself. */
690+
TEST(cli_activation_distinguishes_busy_from_reservation_failure_issue1537) {
691+
cbm_activation_transaction_note_refusal_for_testing(NULL, 0UL);
692+
693+
/* BUSY (0): real sessions hold the cohort — closing something is the fix. */
694+
cli_activation_fake_t busy = {
695+
.participants_active = true,
696+
.mutation_reserve_result = 0,
697+
};
698+
cbm_cli_activation_ops_t ops = {
699+
.context = &busy,
700+
.reserve_for_mutation = cli_activation_fake_reserve_mutation,
701+
.mutation_lease_release = cli_activation_fake_release_mutation,
702+
.visible_diagnostic = cli_activation_fake_diagnostic,
703+
};
704+
ASSERT_EQ(cbm_cli_activation_guard_with_ops(&ops, cli_activation_fake_mutation, &busy), 1);
705+
ASSERT_NOT_NULL(strstr(busy.diagnostic, "could not be stopped safely"));
706+
707+
/* FAILURE (-1): nothing is running, so the reader must not be told to close
708+
* sessions — and must not be handed a command that may not be installed. */
709+
cli_activation_fake_t failed = {
710+
.mutation_reserve_result = -1,
711+
};
712+
ops.context = &failed;
713+
ASSERT_EQ(cbm_cli_activation_guard_with_ops(&ops, cli_activation_fake_mutation, &failed), 1);
714+
ASSERT_NOT_NULL(strstr(failed.diagnostic, "NOT a running-session problem"));
715+
ASSERT_NULL(strstr(failed.diagnostic, "could not be stopped safely"));
716+
PASS();
717+
}
718+
685719
TEST(cli_activation_refuses_unsafe_cohort_reservation) {
686720
cli_activation_fake_t fake = {
687721
.mutation_reserve_result = -1,
@@ -12138,6 +12172,7 @@ SUITE(cli) {
1213812172
RUN_TEST(cli_activation_quiesces_active_cohort_before_mutation);
1213912173
RUN_TEST(cli_activation_refuses_when_cohort_does_not_drain);
1214012174
RUN_TEST(cli_activation_refusal_note_reaches_diagnostic_issue1416);
12175+
RUN_TEST(cli_activation_distinguishes_busy_from_reservation_failure_issue1537);
1214112176
RUN_TEST(cli_activation_refuses_unsafe_cohort_reservation);
1214212177
RUN_TEST(cli_activation_releases_maintenance_lease_after_success);
1214312178
RUN_TEST(cli_activation_releases_maintenance_lease_when_mutation_fails);

0 commit comments

Comments
 (0)