Skip to content

Commit 22506b9

Browse files
authored
Merge branch 'main' into codex/issue-860-test-tsan
2 parents 3d5af94 + dafec04 commit 22506b9

19 files changed

Lines changed: 908 additions & 40 deletions

‎.github/workflows/_smoke.yml‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,24 @@ jobs:
4040
# Broad legs reuse existing goos/goarch artifacts on newer/older OS
4141
# versions (e.g. ubuntu-22.04 = older glibc) to widen the run-anywhere
4242
# signal without building new targets.
43+
# Broad legs are REQUIRED gates (no optional / continue-on-error):
44+
# every smoke leg must pass. No `optional` flags anywhere.
4345
BROAD_UNIX='[
44-
{"os":"ubuntu-22.04","goos":"linux","goarch":"amd64","optional":true},
45-
{"os":"ubuntu-22.04-arm","goos":"linux","goarch":"arm64","optional":true},
46-
{"os":"macos-15","goos":"darwin","goarch":"arm64","optional":true}
46+
{"os":"ubuntu-22.04","goos":"linux","goarch":"amd64"},
47+
{"os":"ubuntu-22.04-arm","goos":"linux","goarch":"arm64"},
48+
{"os":"macos-15","goos":"darwin","goarch":"arm64"}
4749
]'
4850
CORE_WIN='[{"os":"windows-latest"}]'
4951
# windows-11-arm runs the shipped x86_64 binary under emulation —
5052
# verifies the Windows artifact still launches on ARM hardware.
51-
BROAD_WIN='[{"os":"windows-2025","optional":true},{"os":"windows-11-arm","optional":true}]'
53+
BROAD_WIN='[{"os":"windows-2025"},{"os":"windows-11-arm"}]'
5254
CORE_PORTABLE='[
5355
{"arch":"amd64","runner":"ubuntu-latest"},
5456
{"arch":"arm64","runner":"ubuntu-24.04-arm"}
5557
]'
5658
BROAD_PORTABLE='[
57-
{"arch":"amd64","runner":"ubuntu-22.04","optional":true},
58-
{"arch":"arm64","runner":"ubuntu-22.04-arm","optional":true}
59+
{"arch":"amd64","runner":"ubuntu-22.04"},
60+
{"arch":"arm64","runner":"ubuntu-22.04-arm"}
5961
]'
6062
if [ "$BROAD" = "true" ]; then
6163
UNIX=$(jq -cn --argjson a "$CORE_UNIX" --argjson b "$BROAD_UNIX" '$a + $b')
@@ -66,17 +68,26 @@ jobs:
6668
WIN=$(jq -cn --argjson a "$CORE_WIN" '$a')
6769
PORTABLE=$(jq -cn --argjson a "$CORE_PORTABLE" '$a')
6870
fi
69-
echo "unix={\"variant\":[\"standard\",\"ui\"],\"include\":$UNIX}" >> "$GITHUB_OUTPUT"
70-
echo "windows={\"variant\":[\"standard\",\"ui\"],\"include\":$WIN}" >> "$GITHUB_OUTPUT"
71-
echo "portable={\"variant\":[\"standard\",\"ui\"],\"include\":$PORTABLE}" >> "$GITHUB_OUTPUT"
71+
# Expand each OS entry over both variants into a FLAT include list so
72+
# every {os,variant} runs as its own job. A {variant:[...],include:$LIST}
73+
# matrix collapses under GitHub's include-merge (later os entries
74+
# overwrite the variant combos last-wins), which silently dropped every
75+
# OS except the last — e.g. only windows-11-arm ran, never windows-latest.
76+
# Building the cartesian explicitly avoids that.
77+
VARIANTS='["standard","ui"]'
78+
UNIX_M=$(jq -cn --argjson a "$UNIX" --argjson v "$VARIANTS" '{include:[$a[] as $o | $v[] as $t | ($o + {variant:$t})]}')
79+
WIN_M=$(jq -cn --argjson a "$WIN" --argjson v "$VARIANTS" '{include:[$a[] as $o | $v[] as $t | ($o + {variant:$t})]}')
80+
PORTABLE_M=$(jq -cn --argjson a "$PORTABLE" --argjson v "$VARIANTS" '{include:[$a[] as $o | $v[] as $t | ($o + {variant:$t})]}')
81+
echo "unix=$UNIX_M" >> "$GITHUB_OUTPUT"
82+
echo "windows=$WIN_M" >> "$GITHUB_OUTPUT"
83+
echo "portable=$PORTABLE_M" >> "$GITHUB_OUTPUT"
7284
7385
smoke-unix:
7486
needs: setup-matrix
7587
strategy:
7688
fail-fast: false
7789
matrix: ${{ fromJSON(needs.setup-matrix.outputs.unix) }}
7890
runs-on: ${{ matrix.os }}
79-
continue-on-error: ${{ matrix.optional == true }}
8091
timeout-minutes: 15
8192
steps:
8293
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
@@ -153,7 +164,6 @@ jobs:
153164
fail-fast: false
154165
matrix: ${{ fromJSON(needs.setup-matrix.outputs.windows) }}
155166
runs-on: ${{ matrix.os }}
156-
continue-on-error: ${{ matrix.optional == true }}
157167
timeout-minutes: 15
158168
steps:
159169
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
@@ -220,7 +230,6 @@ jobs:
220230
fail-fast: false
221231
matrix: ${{ fromJSON(needs.setup-matrix.outputs.portable) }}
222232
runs-on: ${{ matrix.runner }}
223-
continue-on-error: ${{ matrix.optional == true }}
224233
timeout-minutes: 15
225234
steps:
226235
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

‎.github/workflows/pr.yml‎

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010

1111
permissions:
1212
contents: read
13+
pull-requests: read
1314

1415
# A new push to the PR supersedes the running validation — cancel it
1516
# instead of stacking zombie pipelines.
@@ -35,10 +36,91 @@ jobs:
3536
# dry runs and releases where a flaky red does not block a merge.
3637
skip_perf: true
3738

39+
# ── Which files changed? Gate the (heavier) build+smoke on product code so
40+
# docs / CI / test-only PRs stay fast. ──
41+
changes:
42+
runs-on: ubuntu-latest
43+
timeout-minutes: 5
44+
outputs:
45+
product: ${{ steps.f.outputs.product }}
46+
steps:
47+
- name: Detect product-code changes
48+
id: f
49+
env:
50+
GH_TOKEN: ${{ github.token }}
51+
PR: ${{ github.event.pull_request.number }}
52+
REPO: ${{ github.repository }}
53+
run: |
54+
FILES=$(gh pr diff "$PR" --repo "$REPO" --name-only)
55+
printf '%s\n' "$FILES"
56+
if printf '%s\n' "$FILES" | grep -qE '^(src/|internal/|scripts/build\.sh|scripts/smoke-test\.sh|scripts/env\.sh|Makefile\.cbm)'; then
57+
echo "product=true" >> "$GITHUB_OUTPUT"
58+
else
59+
echo "product=false" >> "$GITHUB_OUTPUT"
60+
fi
61+
62+
# ── Light smoke: build the PRODUCTION binary and run the core smoke on the
63+
# three RELIABLE NATIVE platforms. Catches built-binary regressions at PR
64+
# time (e.g. the Windows CreateProcess argv-quoting class that previously
65+
# only surfaced in the release dry run). The full broad/emulated smoke stays
66+
# in the dry run. Only product-code PRs pay this; every leg gates.
67+
# SMOKE_DOWNLOAD_URL is intentionally unset — the download/update phases of
68+
# smoke-test.sh self-skip; the core index/search/trace phases still run. ──
69+
pr-smoke:
70+
needs: [changes]
71+
if: ${{ !cancelled() && needs.changes.outputs.product == 'true' }}
72+
strategy:
73+
fail-fast: false
74+
matrix:
75+
os: [ubuntu-latest, macos-14, windows-latest]
76+
runs-on: ${{ matrix.os }}
77+
timeout-minutes: 30
78+
steps:
79+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
80+
81+
- name: Install deps (Ubuntu)
82+
if: matrix.os == 'ubuntu-latest'
83+
run: sudo apt-get update && sudo apt-get install -y zlib1g-dev
84+
85+
- uses: msys2/setup-msys2@66cd2cce69caa17b53920067426061ca1de3a884 # v2
86+
if: matrix.os == 'windows-latest'
87+
with:
88+
msystem: CLANG64
89+
path-type: inherit
90+
install: >-
91+
mingw-w64-clang-x86_64-clang
92+
mingw-w64-clang-x86_64-zlib
93+
mingw-w64-clang-x86_64-python3
94+
make
95+
coreutils
96+
97+
- name: Build prod + smoke (Ubuntu)
98+
if: matrix.os == 'ubuntu-latest'
99+
run: |
100+
scripts/build.sh CC=gcc CXX=g++
101+
scripts/smoke-test.sh "$(pwd)/build/c/codebase-memory-mcp"
102+
103+
- name: Build prod + smoke (macOS)
104+
if: matrix.os == 'macos-14'
105+
run: |
106+
scripts/build.sh CC=cc CXX=c++
107+
codesign --sign - --force build/c/codebase-memory-mcp
108+
scripts/smoke-test.sh "$(pwd)/build/c/codebase-memory-mcp"
109+
110+
- name: Build prod + smoke (Windows)
111+
if: matrix.os == 'windows-latest'
112+
shell: msys2 {0}
113+
run: |
114+
scripts/build.sh CC=clang CXX=clang++
115+
BIN="$(pwd)/build/c/codebase-memory-mcp"
116+
[ -f "${BIN}.exe" ] && BIN="${BIN}.exe"
117+
scripts/smoke-test.sh "$BIN"
118+
38119
ci-ok:
39120
# The one required context (besides dco) — fails unless every PR stage
40-
# succeeded, so matrix renames can never silently deadlock merges.
41-
needs: [security, lint, test]
121+
# succeeded, so matrix renames can never silently deadlock merges. `skipped`
122+
# is OK: pr-smoke skips on docs/CI/test-only PRs (changes.product == false).
123+
needs: [security, lint, test, changes, pr-smoke]
42124
if: ${{ always() }}
43125
runs-on: ubuntu-latest
44126
timeout-minutes: 5
@@ -50,7 +132,7 @@ jobs:
50132
echo "$RESULTS" | python3 -c "
51133
import json, sys
52134
needs = json.load(sys.stdin)
53-
bad = {k: v['result'] for k, v in needs.items() if v['result'] != 'success'}
135+
bad = {k: v['result'] for k, v in needs.items() if v['result'] not in ('success', 'skipped')}
54136
if bad:
55137
print('CI NOT OK:', bad)
56138
sys.exit(1)

‎src/cypher/cypher.c‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "cypher/cypher.h"
99
#include "store/store.h"
1010
#include "foundation/platform.h"
11+
#include "foundation/limits.h"
12+
#include "foundation/log.h"
1113

1214
enum {
1315
CYP_BUF_16 = 16,
@@ -22,7 +24,6 @@ enum {
2224
CYP_MAX_VARS = 16, /* max Cypher variables in a query */
2325
CYP_MAX_EDGE_VARS = 8, /* max edge variables */
2426
CYP_GROWTH_10 = 10, /* binding growth factor */
25-
CYP_MAX_DEPTH = 10, /* max variable-length path depth */
2627
CYP_CHAR_IDX1 = 1, /* second character index (e.g. op[1]) */
2728
CYP_EBUF_MASK = 7,
2829
CYP_NODE_COLS = 4, /* columns per node var: name, qn, label, file */
@@ -2886,7 +2887,20 @@ static void expand_var_length(cbm_store_t *store, cbm_rel_pattern_t *rel,
28862887
cbm_node_pattern_t *target_node, binding_t *b, cbm_node_t *src,
28872888
const char *to_var, binding_t *new_bindings, int *new_count,
28882889
int max_new, int *match_count) {
2889-
int max_depth = rel->max_hops > 0 ? rel->max_hops : CYP_MAX_DEPTH;
2890+
/* Clamp BOTH the explicit (`*1..N`) and unbounded (`*`, `*..m`) forms to the
2891+
* engine ceiling: an explicit N above the cap was previously honoured
2892+
* verbatim, driving cbm_store_bfs to an unbounded hop count (#887). WARN on
2893+
* clamp — never a silent truncation. */
2894+
int depth_cap = cbm_cypher_max_depth();
2895+
int max_depth = rel->max_hops > 0 ? rel->max_hops : depth_cap;
2896+
if (max_depth > depth_cap) {
2897+
char req_buf[16];
2898+
char cap_buf[16];
2899+
snprintf(req_buf, sizeof(req_buf), "%d", max_depth);
2900+
snprintf(cap_buf, sizeof(cap_buf), "%d", depth_cap);
2901+
cbm_log_warn("cypher.depth_capped", "requested", req_buf, "cap", cap_buf);
2902+
max_depth = depth_cap;
2903+
}
28902904
cbm_traverse_result_t tr = {0};
28912905
const char *dir = rel->direction ? rel->direction : "outbound";
28922906
cbm_store_bfs(store, src->id, dir, rel->types, rel->type_count, max_depth, CBM_PERCENT, &tr);

‎src/foundation/limits.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "foundation/limits.h"
55

66
#include <errno.h>
7+
#include <limits.h>
78
#include <stdlib.h>
89

910
long cbm_max_file_bytes(void) {
@@ -24,3 +25,32 @@ long cbm_max_file_bytes(void) {
2425
}
2526
return default_cap;
2627
}
28+
29+
/* Shared env-int parser: a positive integer in [1, INT_MAX], else the fallback.
30+
* Read fresh each call (see cbm_max_file_bytes rationale — cheap, test-friendly,
31+
* no stale memoized copy across runs). */
32+
static int env_positive_int(const char *name, int fallback) {
33+
const char *raw = getenv(name);
34+
if (raw && raw[0]) {
35+
errno = 0;
36+
char *end = NULL;
37+
long v = strtol(raw, &end, 10);
38+
if (errno == 0 && end != raw && *end == '\0' && v > 0 && v <= INT_MAX) {
39+
return (int)v;
40+
}
41+
/* Unparseable / non-positive / out-of-range → safe default. */
42+
}
43+
return fallback;
44+
}
45+
46+
int cbm_cypher_max_depth(void) {
47+
/* 10 — generous for a code call/def graph; an explicit `*1..N` above this is
48+
* WARN-capped, never an unbounded (cyclic-graph DoS) traversal. */
49+
return env_positive_int("CBM_CYPHER_MAX_DEPTH", 10);
50+
}
51+
52+
int cbm_mcp_max_depth(void) {
53+
/* 15 — ceiling for client-driven MCP graph traversals (trace_call_path,
54+
* detect_changes); the caller's `depth` is WARN-clamped to this. */
55+
return env_positive_int("CBM_MCP_MAX_DEPTH", 15);
56+
}

‎src/foundation/limits.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,17 @@ typedef enum {
3030
* leaking across runs. */
3131
long cbm_max_file_bytes(void);
3232

33+
/* Maximum variable-length path depth for the Cypher engine (the `*min..max`
34+
* hop ceiling). BOTH the explicit (`*1..N`) and unbounded (`*`, `*..m`) forms
35+
* are clamped to this, so `[:CALLS*1..1000000]` degrades to a WARN-and-cap
36+
* rather than an unbounded (cyclic-graph DoS) traversal. Override with
37+
* CBM_CYPHER_MAX_DEPTH (a positive integer). Default 10. */
38+
int cbm_cypher_max_depth(void);
39+
40+
/* Maximum traversal depth for client-driven MCP graph tools (trace_call_path,
41+
* detect_changes): the client `depth` argument is WARN-clamped to this so an
42+
* arbitrarily large value cannot drive an unbounded BFS over the shared store.
43+
* Override with CBM_MCP_MAX_DEPTH (a positive integer). Default 15. */
44+
int cbm_mcp_max_depth(void);
45+
3346
#endif /* CBM_LIMITS_H */

0 commit comments

Comments
 (0)