Skip to content

Commit 70a9539

Browse files
authored
Merge pull request DeusData#1552 from DeusData/fix/batch2-regressions-and-determinism
fix: two self-inflicted regressions, evidence parity in json, and the quarantine verdict tests (v0.10.3)
2 parents 60a2bbf + 63f26f4 commit 70a9539

14 files changed

Lines changed: 611 additions & 47 deletions

‎scripts/memlab.sh‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,27 @@ if [[ "$BINARY" == *.exe ]] && command -v cygpath >/dev/null 2>&1 &&
3838
# Qualify with the domain: a bare name from coreutils `whoami` resolves
3939
# against the machine first, so on a host whose name equals the user's the
4040
# grant lands on an empty principal.
41-
ME="$(whoami | tr -d '\r')"
42-
if [ -n "${USERDOMAIN:-}" ]; then
43-
ME="${USERDOMAIN}\\${ME}"
44-
fi
41+
# Identify the account by SID, never by name. icacls resolves a bare name
42+
# against the machine first, so a host whose name equals the user's grants
43+
# to an empty principal (#1532); and a USERDOMAIN-qualified name is
44+
# UNRESOLVABLE on a workgroup machine — "WORKGROUP\test: No mapping between
45+
# account names and security IDs was done" — which fails the grant outright
46+
# and silently leaves the tree writable by Authenticated Users. A SID has
47+
# neither ambiguity, and the SYSTEM/Administrators grants below already use
48+
# this form. Name lookup remains only as a fallback where PowerShell is
49+
# unavailable.
50+
ME="$(powershell.exe -NoProfile -NonInteractive -Command \
51+
'[System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value' 2>/dev/null |
52+
tr -d '\r\n')"
53+
case "${ME}" in
54+
S-1-*) ME="*${ME}" ;;
55+
*)
56+
ME="$(whoami | tr -d '\r')"
57+
if [ -n "${USERDOMAIN:-}" ]; then
58+
ME="${USERDOMAIN}\\${ME}"
59+
fi
60+
;;
61+
esac
4562
MSYS2_ARG_CONV_EXCL='*' icacls "$WIN_ROOT_W" /reset /Q >/dev/null 2>&1 || true
4663
if ! MSYS2_ARG_CONV_EXCL='*' icacls "$WIN_ROOT_W" /inheritance:r \
4764
/grant:r "${ME}:(OI)(CI)F" '*S-1-5-18:(OI)(CI)F' '*S-1-5-32-544:(OI)(CI)F' \

‎scripts/run-tests-parallel.sh‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,27 @@ stamp_windows_build_dir() {
6464
# (COMPUTERNAME=BUILD, user build) the grant lands on an empty principal
6565
# (BUILD\) and, combined with /inheritance:r above, locks this script out
6666
# of its own log directory.
67-
me="$(whoami | tr -d '\r')"
68-
if [ -n "${USERDOMAIN:-}" ]; then
69-
me="${USERDOMAIN}\\${me}"
70-
fi
67+
# Identify the account by SID, never by name. icacls resolves a bare name
68+
# against the machine first, so a host whose name equals the user's grants
69+
# to an empty principal (#1532); and a USERDOMAIN-qualified name is
70+
# UNRESOLVABLE on a workgroup machine — "WORKGROUP\test: No mapping between
71+
# account names and security IDs was done" — which fails the grant outright
72+
# and silently leaves the tree writable by Authenticated Users. A SID has
73+
# neither ambiguity, and the SYSTEM/Administrators grants below already use
74+
# this form. Name lookup remains only as a fallback where PowerShell is
75+
# unavailable.
76+
me="$(powershell.exe -NoProfile -NonInteractive -Command \
77+
'[System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value' 2>/dev/null |
78+
tr -d '\r\n')"
79+
case "${me}" in
80+
S-1-*) me="*${me}" ;;
81+
*)
82+
me="$(whoami | tr -d '\r')"
83+
if [ -n "${USERDOMAIN:-}" ]; then
84+
me="${USERDOMAIN}\\${me}"
85+
fi
86+
;;
87+
esac
7188
# Normalize FIRST: some runner images stamp EXPLICIT (non-inherited)
7289
# Authenticated-Users ACEs onto the workspace tree, which /inheritance:r
7390
# cannot strip and /grant:r does not touch (it replaces only the granted

‎scripts/soak-test.sh‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,27 @@ soak_stamp_windows_dir() {
8080
# Qualify with the domain: a bare name from coreutils `whoami` resolves
8181
# against the machine first, so on a host whose name equals the user's the
8282
# grant lands on an empty principal.
83-
me="$(whoami | tr -d '\r')"
84-
if [ -n "${USERDOMAIN:-}" ]; then
85-
me="${USERDOMAIN}\\${me}"
86-
fi
83+
# Identify the account by SID, never by name. icacls resolves a bare name
84+
# against the machine first, so a host whose name equals the user's grants
85+
# to an empty principal (#1532); and a USERDOMAIN-qualified name is
86+
# UNRESOLVABLE on a workgroup machine — "WORKGROUP\test: No mapping between
87+
# account names and security IDs was done" — which fails the grant outright
88+
# and silently leaves the tree writable by Authenticated Users. A SID has
89+
# neither ambiguity, and the SYSTEM/Administrators grants below already use
90+
# this form. Name lookup remains only as a fallback where PowerShell is
91+
# unavailable.
92+
me="$(powershell.exe -NoProfile -NonInteractive -Command \
93+
'[System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value' 2>/dev/null |
94+
tr -d '\r\n')"
95+
case "${me}" in
96+
S-1-*) me="*${me}" ;;
97+
*)
98+
me="$(whoami | tr -d '\r')"
99+
if [ -n "${USERDOMAIN:-}" ]; then
100+
me="${USERDOMAIN}\\${me}"
101+
fi
102+
;;
103+
esac
87104
if ! output=$(MSYS2_ARG_CONV_EXCL='*' icacls "$dir_w" /reset /Q 2>&1); then
88105
echo "FAIL: soak DACL normalize failed (dir=$dir_w user=$me)" >&2
89106
printf '%s\n' "$output" >&2

‎src/cli/cli.c‎

Lines changed: 70 additions & 14 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

@@ -1232,12 +1255,17 @@ int cbm_replace_binary(const char *path, const unsigned char *data, int len, int
12321255
static const char skill_content[] =
12331256
"---\n"
12341257
"name: codebase-memory\n"
1235-
"description: Use the codebase knowledge graph for structural code queries. "
1258+
/* #1554: the value contains "Triggers on: " — a colon-space, which YAML
1259+
* reads as a nested-mapping indicator inside an unquoted scalar. Strict
1260+
* parsers (js-yaml's load, the frontmatter reader in `npx skills`) reject
1261+
* the whole file, so the skill silently fails to load rather than loading
1262+
* wrongly. Quoting the scalar is the fix; the text itself is unchanged. */
1263+
"description: \"Use the codebase knowledge graph for structural code queries. "
12361264
"Triggers on: explore the codebase, understand the architecture, what functions exist, "
12371265
"show me the structure, who calls this function, what does X call, trace the call chain, "
12381266
"find callers of, show dependencies, impact analysis, dead code, unused functions, "
12391267
"high fan-out, refactor candidates, code quality audit, graph query syntax, "
1240-
"Cypher query examples, edge types, how to use search_graph.\n"
1268+
"Cypher query examples, edge types, how to use search_graph.\"\n"
12411269
"---\n"
12421270
"\n"
12431271
"# Codebase Memory — Knowledge Graph Tools\n"
@@ -3250,8 +3278,22 @@ int cbm_upsert_codex_mcp(const char *binary_path, const char *config_path) {
32503278
return CLI_ERR;
32513279
}
32523280
char block[CLI_BUF_8K];
3281+
/* #1562: Codex sanitizes the environment of stdio MCP subprocesses, passing
3282+
* through only the names listed in env_vars. Without CBM_CACHE_DIR the
3283+
* Codex-spawned server silently falls back to the DEFAULT cache while the
3284+
* account daemon uses the configured one; the two disagree and the
3285+
* handshake closes during initialization, so Codex exposes no cbm tools at
3286+
* all.
3287+
*
3288+
* The name is listed unconditionally rather than only when the variable is
3289+
* set at install time: env_vars names variables to FORWARD IF PRESENT, so
3290+
* listing it costs nothing when unset and keeps working for someone who
3291+
* sets it after installing — which install-time detection would silently
3292+
* fail to cover. */
32533293
int written = snprintf(block, sizeof(block),
3254-
CODEX_CMM_SECTION "\ncommand = \"%s\"\nargs = []\n", escaped);
3294+
CODEX_CMM_SECTION "\ncommand = \"%s\"\nargs = []\n"
3295+
"env_vars = [\"CBM_CACHE_DIR\"]\n",
3296+
escaped);
32553297
if (written < 0 || (size_t)written >= sizeof(block) ||
32563298
cbm_remove_codex_legacy_mcp(config_path) != 0) {
32573299
return CLI_ERR;
@@ -11482,17 +11524,31 @@ int cbm_cmd_update(int argc, char **argv) {
1148211524

1148311525
bool dry_run = false;
1148411526
bool force = false;
11527+
bool legacy_variant_flag = false;
1148511528
for (int i = 0; i < argc; i++) {
1148611529
if (strcmp(argv[i], "--dry-run") == 0) {
1148711530
dry_run = true;
1148811531
} else if (strcmp(argv[i], "--force") == 0) {
1148911532
force = true;
11533+
} else if (strcmp(argv[i], "--ui") == 0 || strcmp(argv[i], "--standard") == 0) {
11534+
/* v0.10.2 deleted the ui/standard chooser and, with it, these flags —
11535+
* which turned `update --ui` from a working command into a hard
11536+
* error for everyone who had it in a script, an alias, or muscle
11537+
* memory (#1544). Removing a CHOICE is fine; removing the WORDS
11538+
* people type is a break we owe them nothing for. Accept both,
11539+
* ignore them, and say once why they no longer mean anything. */
11540+
legacy_variant_flag = true;
1149011541
} else if (strcmp(argv[i], "-y") != 0 && strcmp(argv[i], "--yes") != 0 &&
1149111542
strcmp(argv[i], "-n") != 0 && strcmp(argv[i], "--no") != 0) {
1149211543
(void)fprintf(stderr, "error: unknown update option: %s\n", argv[i]);
1149311544
return CLI_TRUE;
1149411545
}
1149511546
}
11547+
if (legacy_variant_flag) {
11548+
(void)fprintf(stderr, "note: --ui/--standard are accepted but no longer do anything; since "
11549+
"v0.10.0 there is one build per platform and it always includes the "
11550+
"graph UI.\n");
11551+
}
1149611552

1149711553
/* Updates run from the install script, not from this process — on every
1149811554
* platform.

‎src/cli/client_adapter.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,16 @@ char *cbm_client_adapter_pi(const char *binary_path) {
155155
"}\n\n");
156156

157157
/* Register every tool the registry advertises — never a hand-picked subset,
158-
* which is the drift this generator exists to prevent. */
159-
sb_append(&sb, "export function register(pi) {\n");
158+
* which is the drift this generator exists to prevent.
159+
*
160+
* DEFAULT export, and it must stay that way. Pi loads an extension via
161+
* jiti.import(path, { default: true }) and rejects anything that is not a
162+
* function, so a named `export function register(pi)` hands the loader the
163+
* module namespace object instead and every install fails with "Extension
164+
* does not export a valid factory function". A Pi extension that fails to
165+
* load takes EVERY pi command down with it — `pi doctor` included — not
166+
* just cbm's tools (#1550). */
167+
sb_append(&sb, "export default function (pi) {\n");
160168
for (int i = 0; i < count; i++) {
161169
const char *name = cbm_mcp_tool_name(i);
162170
if (!name || !name[0]) {

‎src/daemon/ipc.c‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,8 +1383,26 @@ static bool posix_directory_parent_secure(int directory_fd) {
13831383
!cbm_macos_extended_acl_fd_is_deny_only(directory_fd)) {
13841384
return false;
13851385
}
1386-
return (status.st_mode & 0022) == 0 ||
1387-
(status.st_uid == (uid_t)0 && (status.st_mode & S_ISVTX) != 0);
1386+
/* #1537: this ANCESTOR check refused any group-write bit, which is the same
1387+
* rule #1535 removed on the activation side — and the sibling that decision
1388+
* covers but that never got changed. A group-writable ~ or ~/.cache is
1389+
* ordinary (WSL2 ships 0775, so do several distro skeletons and any site
1390+
* with a shared primary group), and refusing it here made the daemon
1391+
* unusable with no way for the reader to see why.
1392+
*
1393+
* WORLD-writable is still refused: any local user could swap a path
1394+
* component. Group-writable is admitted for ancestors only — the private
1395+
* directory itself is chmod'd to 0700 and verified after this walk, so the
1396+
* thing that actually holds data stays owner-private either way. */
1397+
if ((status.st_mode & 0002) != 0) {
1398+
return status.st_uid == (uid_t)0 && (status.st_mode & S_ISVTX) != 0;
1399+
}
1400+
if ((status.st_mode & 0020) != 0) {
1401+
char mode_text[16];
1402+
(void)snprintf(mode_text, sizeof(mode_text), "%04o", (unsigned)(status.st_mode & 07777));
1403+
cbm_log_warn("daemon.private_dir_group_writable_ancestor", "mode", mode_text);
1404+
}
1405+
return true;
13881406
}
13891407

13901408
/* Validate a path transition only through the two already-open directory
@@ -1435,6 +1453,17 @@ static int private_directory_tree_open(const char *directory_path) {
14351453
ok = false;
14361454
} else {
14371455
ok = posix_directory_parent_secure(current_fd);
1456+
if (!ok) {
1457+
/* #1537: this branch used to leave the detail empty, so the
1458+
* caller fell back to printing errno — which NOTHING here sets.
1459+
* A reporter was handed "errno 2" (ENOENT) for a permission
1460+
* refusal and went looking for a missing file that existed.
1461+
* An unset errno is not a diagnosis; name the component. */
1462+
ipc_validation_detail_set("%s: ancestor '%s' is not a usable private-directory "
1463+
"parent (must be owned by you, not world-writable, and "
1464+
"carry no allow-ACL)",
1465+
directory_path, component);
1466+
}
14381467
bool created = ok && mkdirat(current_fd, component, 0700) == 0;
14391468
if (!created && errno != EEXIST) {
14401469
ok = false;

0 commit comments

Comments
 (0)