Skip to content

Commit 6f7a4af

Browse files
authored
Merge branch 'main' into fix/swift-nested-url-constructor
2 parents aa3627d + ffb5ebe commit 6f7a4af

24 files changed

Lines changed: 1011 additions & 105 deletions

‎.github/workflows/_test.yml‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,14 @@ jobs:
311311
steps:
312312
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
313313

314+
# Pinned: the unversioned `llvm` formula tracks Homebrew stable, so the
315+
# leg's compiler changed under us when stable moved 22 -> 23 (a new
316+
# -Wunused-but-set-global under -Werror broke the build on whichever
317+
# runner drew the 23 bottle, and passed on the ones that drew 22). A
318+
# test verdict must be a function of the code, not of the image snapshot;
319+
# moving to a newer major is a deliberate one-line bump here.
314320
- name: Install LSan-capable toolchain
315-
run: brew install llvm ccache
321+
run: brew install llvm@22 ccache
316322

317323
- name: Compiler cache (content-verified, restore)
318324
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
@@ -327,7 +333,7 @@ jobs:
327333
env:
328334
ASAN_OPTIONS: "detect_leaks=1:halt_on_error=1"
329335
run: |
330-
LLVM_PREFIX="$(brew --prefix llvm)"
336+
LLVM_PREFIX="$(brew --prefix llvm@22)"
331337
scripts/test.sh CC="$LLVM_PREFIX/bin/clang" CXX="$LLVM_PREFIX/bin/clang++"
332338
333339
- name: Compiler cache (save)

‎internal/cbm/extract_calls.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,17 @@ static char *extract_objc_callee(CBMArena *a, TSNode node, const char *source, c
529529
return ts_node_is_null(selector) ? NULL : cbm_node_text(a, selector, source);
530530
}
531531

532+
/* tree-sitter-elixir gives a call's arguments node no field name, so it is
533+
* found positionally. Mirrors elixir_call_args() in extract_defs.c, which the
534+
* definition side has always used for the same reason. */
535+
static TSNode elixir_call_arguments_fallback(TSNode node) {
536+
TSNode args = ts_node_child_by_field_name(node, TS_FIELD("arguments"));
537+
if (ts_node_is_null(args) && ts_node_child_count(node) > 1) {
538+
args = ts_node_child(node, 1);
539+
}
540+
return args;
541+
}
542+
532543
// Erlang: extract callee from call node's first child.
533544
static char *extract_erlang_callee(CBMArena *a, TSNode node, const char *source, const char *nk) {
534545
if (strcmp(nk, "call") != 0 || ts_node_child_count(node) == 0) {
@@ -3749,6 +3760,21 @@ CBMInvocationDescriptor handle_calls(CBMExtractCtx *ctx, TSNode node, const CBML
37493760
}
37503761

37513762
TSNode args = ts_node_child_by_field_name(node, TS_FIELD("arguments"));
3763+
/* tree-sitter-elixir attaches NO field name to a call's arguments
3764+
* node — its whole field set is key, left, operand, operator,
3765+
* quoted_start, quoted_end, right, target, value — so the lookup
3766+
* above is always null for Elixir and first_string_arg was never
3767+
* populated for ANY Elixir call. That silently disabled every
3768+
* downstream signal keyed off a call's string argument: Phoenix
3769+
* route paths, HTTP/async service URLs, and config keys.
3770+
* cbm_elixir_call_args is the shared second-child fallback the
3771+
* definition side already uses. Restricted to `call` nodes —
3772+
* Elixir's other call kinds (`dot`, the `|>` binary_operator) have
3773+
* no arguments node in that position. */
3774+
if (ts_node_is_null(args) && ctx->language == CBM_LANG_ELIXIR &&
3775+
strcmp(ts_node_type(node), "call") == 0) {
3776+
args = elixir_call_arguments_fallback(node);
3777+
}
37523778
// ObjectScript stores args under oref_method/method_args, not the
37533779
// generic "arguments" field; macro arguments add one wrapper.
37543780
if (ts_node_is_null(args) && is_objectscript_language(ctx->language)) {

‎internal/cbm/extract_defs.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,13 @@ static int collect_bases_from_field(CBMArena *a, TSNode field_node, const char *
24452445
* dotted base like `mod.Base`). Without these the raw-text fallback
24462446
* below captured the whole "(Base)" field text, which never
24472447
* resolved -> zero INHERITS edges for Python subclasses. */
2448-
strcmp(ck, "identifier") == 0 || strcmp(ck, "attribute") == 0) {
2448+
strcmp(ck, "identifier") == 0 || strcmp(ck, "attribute") == 0 ||
2449+
/* Ruby `class C < Base` wraps the base in a `superclass` node whose
2450+
* child is a `constant` (or `scope_resolution` for `A::B`). Without
2451+
* these the raw-text fallback captured "< Base" (operator included),
2452+
* which never resolves — breaking INHERITS and the Ruby LSP's
2453+
* superclass chain. */
2454+
strcmp(ck, "constant") == 0 || strcmp(ck, "scope_resolution") == 0) {
24492455
char *t = cbm_node_text(a, child, source);
24502456
if (t) {
24512457
char *angle = strchr(t, '<');

‎scripts/smoke-test.sh‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,35 @@ if command -v node >/dev/null 2>&1; then
23392339
PI_NODE=$(command -v node)
23402340
PI_PROBE_DIR="$TMPDIR/pi-node-probe"
23412341
mkdir -p "$PI_PROBE_DIR"
2342+
# The extension is loaded by the Pi host, not by bare Node, so the probe
2343+
# provides what that host provides: Node's builtins plus the packages Pi
2344+
# ships to extensions (`typebox` — Pi's schema library for tool
2345+
# parameters). Every import the generated file makes must come from that
2346+
# set, otherwise it loads in this probe and fails in a real install with
2347+
# ERR_MODULE_NOT_FOUND. The typebox stub is a Proxy: any Type.X(...) call
2348+
# returns a descriptor, so the probe never depends on which helpers the
2349+
# emitter uses; it only exercises the tool lifecycle.
2350+
PI_HOST_PACKAGES="typebox"
2351+
mkdir -p "$PI_PROBE_DIR/node_modules/typebox"
2352+
cat >"$PI_PROBE_DIR/node_modules/typebox/package.json" <<'PITYPEBOXPKG'
2353+
{ "name": "typebox", "version": "0.0.0-smoke-stub", "type": "module", "exports": "./index.mjs" }
2354+
PITYPEBOXPKG
2355+
cat >"$PI_PROBE_DIR/node_modules/typebox/index.mjs" <<'PITYPEBOXSTUB'
2356+
export const Type = new Proxy({}, {
2357+
get: (_target, helper) => (...args) => ({ smokeStubHelper: String(helper), args }),
2358+
});
2359+
export default { Type };
2360+
PITYPEBOXSTUB
2361+
PI_FOREIGN_IMPORTS=$(grep -oE "^import .* from '[^']+'" "$PI_EXTENSION" |
2362+
sed -E "s/.* from '([^']+)'/\1/" | grep -vE '^node:' |
2363+
grep -vxF -f <(
2364+
# shellcheck disable=SC2086
2365+
printf '%s\n' $PI_HOST_PACKAGES
2366+
) || true)
2367+
if [ -n "$PI_FOREIGN_IMPORTS" ]; then
2368+
echo "FAIL 8al-node: generated Pi extension imports packages the Pi host does not provide: $(echo "$PI_FOREIGN_IMPORTS" | tr '\n' ' ')"
2369+
exit 1
2370+
fi
23422371
python3 - "$PI_EXTENSION" "$PI_PROBE_DIR/cbmem.mjs" <<'PYPIADAPTER'
23432372
import pathlib
23442373
import sys

‎src/cli/cli.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,13 @@ char *cbm_hook_augment_lifecycle_json_for(const char *input, const char *forced_
525525
/* Thin daemon frontend support: preserve the hook's bounded stdin read and
526526
* hard fail-open deadline without constructing a local MCP/store instance. */
527527
void cbm_hook_augment_arm_deadline(void);
528+
529+
/* The in-process deadline in milliseconds, as CBM_HOOK_DEADLINE_MS resolves it.
530+
* Exposed so a test can check what an unreadable value falls back to. POSIX
531+
* only: the Windows path arms a fixed timer and reads no environment value. */
532+
#ifndef _WIN32
533+
int cbm_hook_augment_deadline_ms_for_testing(void);
534+
#endif
528535
char *cbm_hook_augment_read_stdin(void);
529536
/* Pure no-op gate for the hook-client fast path (see hook_augment.c). */
530537
bool cbm_hook_augment_input_is_noop_bash(const char *input);

‎src/cli/hook_augment.c‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "foundation/compat_fs.h"
2121
#include "foundation/constants.h"
2222
#include "foundation/mem.h"
23+
#include "foundation/platform.h"
2324
#include "mcp/mcp.h"
2425
#include "pipeline/pipeline.h"
2526
#include "yyjson/yyjson.h"
@@ -70,18 +71,21 @@
7071
* hook "timeout" remains the outer backstop (and alone governs Windows,
7172
* where this whole in-process deadline block is compiled out). */
7273
static int ha_deadline_ms(void) {
73-
const char *env = getenv("CBM_HOOK_DEADLINE_MS");
74-
if (!env || !env[0]) {
74+
/* A value this reader cannot read gets the DEFAULT, never the floor. atoi
75+
* used to answer 0 for a typo, 0 is below the minimum, and the clamp then
76+
* handed back the shortest deadline the setting allows — the opposite of
77+
* what somebody raising CBM_HOOK_DEADLINE_MS is asking for. */
78+
long v = 0;
79+
if (!cbm_env_long("CBM_HOOK_DEADLINE_MS", &v)) {
7580
return HA_DEADLINE_DEFAULT_MS;
7681
}
77-
int v = atoi(env);
7882
if (v < HA_DEADLINE_MIN_MS) {
7983
return HA_DEADLINE_MIN_MS;
8084
}
8185
if (v > HA_DEADLINE_MAX_MS) {
8286
return HA_DEADLINE_MAX_MS;
8387
}
84-
return v;
88+
return (int)v;
8589
}
8690

8791
static int g_ha_crumb_fd = -1;
@@ -123,6 +127,10 @@ static void ha_open_crumb_log(int deadline_ms) {
123127
g_ha_crumb_len = (n > 0 && n < (int)sizeof(g_ha_crumb_msg)) ? (size_t)n : 0;
124128
}
125129

130+
int cbm_hook_augment_deadline_ms_for_testing(void) {
131+
return ha_deadline_ms();
132+
}
133+
126134
void cbm_hook_augment_arm_deadline(void) {
127135
int ms = ha_deadline_ms();
128136
ha_open_crumb_log(ms);

‎src/cypher/cypher.c‎

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,8 +1802,16 @@ static int parse_return_or_with(parser_t *p, cbm_return_clause_t **out, bool is_
18021802
/* Projection is materialized per row into fixed-width stack arrays sized at
18031803
* CBM_SZ_32 columns (execute_return_simple and its siblings). Bound the
18041804
* parsed item count to that width so an over-wide RETURN is rejected here
1805-
* instead of writing past those arrays downstream. */
1806-
if (r->count > CBM_SZ_32) {
1805+
* instead of writing past those arrays downstream.
1806+
*
1807+
* WITH is bounded tighter, by CYP_MAX_VARS. Every item a WITH projects
1808+
* becomes one variable of the binding that carries the rest of the query,
1809+
* and binding_t holds exactly CYP_MAX_VARS variables. A wider WITH used to
1810+
* parse, then lose every alias past the 16th in with_add_vbinding_var and
1811+
* answer with silently blank columns. Refuse it here, the same way an
1812+
* over-wide RETURN is refused, so the caller sees an error instead of a
1813+
* short or empty result. */
1814+
if (r->count > (is_with ? CYP_MAX_VARS : CBM_SZ_32)) {
18071815
free_return_clause(r);
18081816
return CBM_NOT_FOUND;
18091817
}
@@ -4193,17 +4201,34 @@ static void execute_with_clause(cbm_query_t *q, binding_t **bindings_ptr, int *b
41934201

41944202
/* Project RETURN * — all bound variable properties */
41954203
/* Collect all variable names from query patterns */
4204+
/* Has this variable already been collected? A query may name the same variable
4205+
* in more than one pattern, and RETURN * must give it one set of columns. */
4206+
static bool star_var_seen(const char **vars, int vc, const char *name) {
4207+
for (int i = 0; i < vc; i++) {
4208+
if (strcmp(vars[i], name) == 0) {
4209+
return true;
4210+
}
4211+
}
4212+
return false;
4213+
}
4214+
4215+
/* Collect the variables a RETURN * projects, in the order the query names them
4216+
* and with no repeats. Without the repeat check, `MATCH (f) OPTIONAL MATCH
4217+
* (f)-[:CALLS]->(g)` names f in two patterns and f gets its four columns
4218+
* twice. */
41964219
static int collect_pattern_vars(cbm_query_t *q, const char **vars, int max_vars) {
41974220
int vc = 0;
41984221
for (int pi = 0; pi < q->pattern_count; pi++) {
41994222
for (int ni = 0; ni < q->patterns[pi].node_count && vc < max_vars; ni++) {
4200-
if (q->patterns[pi].nodes[ni].variable) {
4201-
vars[vc++] = q->patterns[pi].nodes[ni].variable;
4223+
const char *var = q->patterns[pi].nodes[ni].variable;
4224+
if (var && !star_var_seen(vars, vc, var)) {
4225+
vars[vc++] = var;
42024226
}
42034227
}
42044228
for (int ri = 0; ri < q->patterns[pi].rel_count && vc < max_vars; ri++) {
4205-
if (q->patterns[pi].rels[ri].variable) {
4206-
vars[vc++] = q->patterns[pi].rels[ri].variable;
4229+
const char *var = q->patterns[pi].rels[ri].variable;
4230+
if (var && !star_var_seen(vars, vc, var)) {
4231+
vars[vc++] = var;
42074232
}
42084233
}
42094234
}
@@ -4255,8 +4280,43 @@ static void project_star_row(binding_t *b, const char **vars, int vc, const char
42554280
}
42564281
}
42574282

4283+
/* RETURN * after a WITH.
4284+
*
4285+
* The pattern's variables are out of scope by this point — the WITH replaced
4286+
* them with the names it made. Each of those names holds one value, not a
4287+
* node, so each is ONE column rather than the four a node variable gets.
4288+
*
4289+
* Reading the pattern here instead is the fault this function exists to avoid:
4290+
* it named variables the bindings no longer hold, found nothing for every one
4291+
* of them, and answered a full result of empty strings with no error. */
4292+
static void execute_return_star_after_with(cbm_query_t *q, binding_t *bindings, int bind_count,
4293+
int max_rows, result_builder_t *rb) {
4294+
cbm_return_clause_t *wc = q->with_clause;
4295+
char name_bufs[CYP_MAX_VARS][CBM_SZ_128];
4296+
const char *cols[CYP_MAX_VARS];
4297+
/* parse_return_or_with refuses a WITH wider than CYP_MAX_VARS, so this
4298+
* clamp cannot fire. It stays as the bound this function relies on. */
4299+
int col_n = wc->count < CYP_MAX_VARS ? wc->count : CYP_MAX_VARS;
4300+
for (int i = 0; i < col_n; i++) {
4301+
cols[i] = resolve_item_alias(&wc->items[i], name_bufs[i], sizeof(name_bufs[i]));
4302+
}
4303+
rb_set_columns(rb, cols, col_n);
4304+
for (int bi = 0; bi < bind_count && rb->row_count < max_rows; bi++) {
4305+
const char *vals[CYP_MAX_VARS];
4306+
for (int i = 0; i < col_n; i++) {
4307+
cbm_node_t *vn = binding_get(&bindings[bi], cols[i]);
4308+
vals[i] = vn && vn->name ? vn->name : "";
4309+
}
4310+
rb_add_row(rb, vals);
4311+
}
4312+
}
4313+
42584314
static void execute_return_star(cbm_query_t *q, binding_t *bindings, int bind_count, int max_rows,
42594315
result_builder_t *rb) {
4316+
if (q->with_clause) {
4317+
execute_return_star_after_with(q, bindings, bind_count, max_rows, rb);
4318+
return;
4319+
}
42604320
const char *vars[CBM_SZ_32];
42614321
int vc = collect_pattern_vars(q, vars, CBM_SZ_32);
42624322
build_star_columns(rb, vars, vc);

‎src/daemon/version_cohort.c‎

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "foundation/platform.h"
88
#include "foundation/private_file_lock_internal.h"
99

10+
#include <stdatomic.h>
1011
#include <stdbool.h>
1112
#include <stdint.h>
1213
#include <stdio.h>
@@ -414,11 +415,10 @@ static cbm_version_cohort_status_t version_cohort_claim_new(
414415
CBM_PRIVATE_FILE_LOCK_SH, deadline_ms, &lease->lifetime));
415416
}
416417

417-
cbm_version_cohort_status_t cbm_version_cohort_acquire(cbm_version_cohort_manager_t *manager,
418-
const cbm_daemon_build_identity_t *identity,
419-
uint64_t deadline_ms,
420-
cbm_version_cohort_lease_t **lease_out,
421-
cbm_daemon_conflict_t *conflict_out) {
418+
static cbm_version_cohort_status_t version_cohort_acquire_once(
419+
cbm_version_cohort_manager_t *manager, const cbm_daemon_build_identity_t *identity,
420+
uint64_t deadline_ms, cbm_version_cohort_lease_t **lease_out,
421+
cbm_daemon_conflict_t *conflict_out) {
422422
if (lease_out) {
423423
*lease_out = NULL;
424424
}
@@ -569,6 +569,77 @@ cbm_version_cohort_status_t cbm_version_cohort_acquire(cbm_version_cohort_manage
569569
return CBM_VERSION_COHORT_OK;
570570
}
571571

572+
#ifdef CBM_ENABLE_TEST_SEAMS
573+
/* #2046 test seam: counts conflict retries so a test can prove the waiting
574+
* participant actually met the mismatched holder before that holder left —
575+
* without it, "admitted after release" is indistinguishable from "arrived
576+
* after release" and the test passes vacuously. */
577+
static atomic_uint_fast64_t version_cohort_conflict_retry_seam;
578+
uint64_t cbm_version_cohort_conflict_retries_for_testing(void) {
579+
return atomic_load_explicit(&version_cohort_conflict_retry_seam, memory_order_acquire);
580+
}
581+
static void version_cohort_note_conflict_retry(void) {
582+
(void)atomic_fetch_add_explicit(&version_cohort_conflict_retry_seam, 1, memory_order_release);
583+
}
584+
#else
585+
static void version_cohort_note_conflict_retry(void) {}
586+
#endif
587+
588+
static const char *version_cohort_conflict_kind(const cbm_daemon_conflict_t *conflict) {
589+
switch (conflict->status) {
590+
case CBM_DAEMON_HELLO_VERSION_CONFLICT:
591+
return "version";
592+
case CBM_DAEMON_HELLO_BUILD_CONFLICT:
593+
return "build";
594+
case CBM_DAEMON_HELLO_PROTOCOL_ABI_CONFLICT:
595+
return "protocol_abi";
596+
case CBM_DAEMON_HELLO_STORE_ABI_CONFLICT:
597+
return "store_abi";
598+
case CBM_DAEMON_HELLO_FEATURE_ABI_CONFLICT:
599+
return "feature_abi";
600+
case CBM_DAEMON_HELLO_CACHE_CONFLICT:
601+
return "cache_root";
602+
default:
603+
return "unknown";
604+
}
605+
}
606+
607+
/* A mismatched live holder is not necessarily a peer that will stay: an
608+
* internal daemon keeps its lifetime SH lock for the few hundred milliseconds
609+
* between its last client leaving and its teardown finishing, and a CLI under
610+
* another CBM_CACHE_DIR arriving inside that window used to be refused with a
611+
* cache-root conflict although nothing was running any more (#2046; the
612+
* refusal was masked only by the local CLI's own slow startup). host.c already
613+
* waits out the same handoff for the daemon claim marker. Admission therefore
614+
* retries a conflict until the caller's deadline, holding NO guard between
615+
* attempts so compatible peers and activations are never queued behind the
616+
* wait. On deadline the last observed conflict is reported exactly as before;
617+
* an indefinite deadline keeps failing fast because a mismatched holder may
618+
* never leave. */
619+
cbm_version_cohort_status_t cbm_version_cohort_acquire(cbm_version_cohort_manager_t *manager,
620+
const cbm_daemon_build_identity_t *identity,
621+
uint64_t deadline_ms,
622+
cbm_version_cohort_lease_t **lease_out,
623+
cbm_daemon_conflict_t *conflict_out) {
624+
bool retry_logged = false;
625+
for (;;) {
626+
cbm_version_cohort_status_t status =
627+
version_cohort_acquire_once(manager, identity, deadline_ms, lease_out, conflict_out);
628+
if (status != CBM_VERSION_COHORT_CONFLICT || deadline_ms == UINT64_MAX ||
629+
cbm_now_ms() >= deadline_ms) {
630+
return status;
631+
}
632+
if (!retry_logged) {
633+
retry_logged = true;
634+
cbm_log_info("version_cohort.conflict_retry", "reason",
635+
version_cohort_conflict_kind(conflict_out), "active_build",
636+
conflict_out->active_build_fingerprint);
637+
}
638+
version_cohort_note_conflict_retry();
639+
version_cohort_retry_sleep();
640+
}
641+
}
642+
572643
static cbm_version_cohort_status_t version_cohort_reserve_for_mutation_internal(
573644
cbm_version_cohort_manager_t *manager, uint64_t deadline_ms,
574645
cbm_version_cohort_quiesce_fn quiesce, void *quiesce_context,

0 commit comments

Comments
 (0)