Skip to content

Commit 951b9ab

Browse files
authored
Merge branch 'main' into fix/1839-1864-stage-orphans
2 parents 91e3121 + 9b85dd3 commit 951b9ab

59 files changed

Lines changed: 4421 additions & 318 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/_lint.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ jobs:
6868
- name: Install build deps
6969
run: sudo apt-get update && sudo apt-get install -y zlib1g-dev
7070

71-
- name: Install LLVM 22 (pinned analyzer toolchain)
71+
- name: Install LLVM 21 (pinned analyzer toolchain)
7272
run: |
7373
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
74-
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-22 main" | sudo tee /etc/apt/sources.list.d/llvm-22.list
74+
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-21 main" | sudo tee /etc/apt/sources.list.d/llvm-21.list
7575
sudo apt-get update
76-
sudo apt-get install -y clang-tidy-22
76+
sudo apt-get install -y clang-tidy-21
7777
7878
- name: Memory-analyzer gate
79-
run: scripts/ci/lint-mem.sh clang-tidy-22
79+
run: scripts/ci/lint-mem.sh clang-tidy-21

‎.github/workflows/_test.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ jobs:
227227
- name: Install deps
228228
run: sudo apt-get update && sudo apt-get install -y zlib1g-dev ccache
229229

230-
- name: Install LLVM 22 (pinned diagnostic toolchain)
230+
- name: Install LLVM 21 (pinned diagnostic toolchain)
231231
run: |
232232
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
233-
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-22 main" | sudo tee /etc/apt/sources.list.d/llvm-22.list
233+
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-21 main" | sudo tee /etc/apt/sources.list.d/llvm-21.list
234234
sudo apt-get update
235-
sudo apt-get install -y clang-22
235+
sudo apt-get install -y clang-21
236236
237237
- name: Compiler cache (content-verified, restore)
238238
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
@@ -247,11 +247,11 @@ jobs:
247247
# lane: stack-use-after-return, stack-use-after-scope, and strict string
248248
# checks. Mirrors `make -f Makefile.cbm diag`, including its reasoning
249249
# for leaving detect_invalid_pointer_pairs out.
250-
- name: Test (clang-22, ASan+UBSan + off-by-default ASan checks)
250+
- name: Test (clang-21, ASan+UBSan + off-by-default ASan checks)
251251
env:
252252
ASAN_OPTIONS: "detect_stack_use_after_return=1:strict_string_checks=1:detect_stack_use_after_scope=1"
253253
run: |
254-
scripts/test.sh CC=clang-22 CXX=clang++-22 \
254+
scripts/test.sh CC=clang-21 CXX=clang++-21 \
255255
SANITIZE="-fsanitize=address,undefined -fno-omit-frame-pointer -fno-optimize-sibling-calls"
256256
257257
- name: Compiler cache (save)

‎Makefile.cbm‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ TEST_REPRO_SRCS = \
707707
tests/repro/repro_issue787.c \
708708
tests/repro/repro_issue842.c \
709709
tests/repro/repro_issue964.c \
710+
tests/repro/repro_issue1692.c \
710711
tests/repro/repro_invariant_calls.c \
711712
tests/repro/repro_invariant_graph.c \
712713
tests/repro/repro_invariant_breadth.c \

‎README.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ overwrite user-modified agents.
491491
| Agent | Activation | MCP config | Durable context / augmentation |
492492
|-------|------------|------------|--------------------------------|
493493
| Claude Code | Detected | `~/.claude.json` | Skill + three exact-tool graph agents; `SessionStart`, `SubagentStart`, non-blocking `PreToolUse` for `Grep`/`Glob`/`Bash`, and post-`Read` coverage |
494-
| Codex CLI | Detected | `$CODEX_HOME/config.toml` | `AGENTS.md`, skill, three read-only agents; `SessionStart` + `SubagentStart` |
494+
| Codex CLI | Detected | `$CODEX_HOME/config.toml` | Managed `AGENTS.md` activation pointer, skill, three read-only agents; `SessionStart` + `SubagentStart` |
495495
| Gemini CLI | Detected | `.gemini/settings.json` | `GEMINI.md`, three explicit read/graph-tool subagents; `BeforeTool`, `AfterTool` `read_file` coverage, and `SessionStart` |
496496
| Zed | Detected | platform `settings.json` (JSONC) | `AGENTS.md` + shared skill |
497497
| OpenCode | Detected | `$OPENCODE_CONFIG` or resolved global config | `AGENTS.md`, skill, three deny-by-default read-only agents; plugin adds grep/glob graph lookup, post-`read` coverage, first-tool-result session context, and post-compaction reinjection |
@@ -536,6 +536,11 @@ overwrite user-modified agents.
536536
| Oh My Pi (omp) | Detected | Effective agent directory (`OMP_PROFILE` / `PI_CODING_AGENT_DIR`; default `~/.omp/agent/mcp.json`) | Skill and three direct-MCP graph-tool subagents (Scout/Verify/Auditor); preserves user `AGENTS.md` |
537537
| Sourcegraph Cody | Explicit opt-in | Existing `$CBM_CODY_CONFIG_PATH` | MCP only |
538538

539+
For Codex, install keeps only a tiny managed activation pointer in global
540+
`$CODEX_HOME/AGENTS.md`; all detailed behavior lives in the installed `codebase-memory` skill.
541+
Fresh installs create the pointer, upgrades replace the legacy full managed block while preserving
542+
all user-owned bytes, and uninstall removes only the managed pointer.
543+
539544
### Sessions, compaction, and subagents
540545

541546
Hooks installed by this project are fail-open and context-only. Claude Code's

‎internal/cbm/cbm.c‎

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,42 @@ static const char *cbm_string_read(void *payload, uint32_t byte, TSPoint point,
213213

214214
// --- Parse timeout callback ---
215215

216+
/* Budget for the tree-sitter progress callback. The PRIMARY gate is per-thread
217+
* CPU time: a worker descheduled under CI contention burns WALL time but not
218+
* CPU, so a starved-but-parseable file must NOT be abandoned merely because the
219+
* 5 s budget elapsed in wall-clock against near-zero CPU. That false "parse
220+
* timeout" silently dropped a file's defs and, with them, every cross-file edge
221+
* those defs anchored (e.g. a Celery.send_task definition backing an ASYNC_CALLS
222+
* edge). A generous WALL ceiling stays as a backstop so a genuinely
223+
* stuck/spinning parse still terminates in bounded time. */
224+
#define CBM_PARSE_WALL_CEILING_FACTOR 12ULL /* ~60 s ceiling for the 5 s CPU budget */
225+
226+
typedef struct {
227+
uint64_t cpu_deadline_ns; // trip once this thread's CPU time passes it
228+
uint64_t wall_ceiling_ns; // hard wall backstop for a spinning/stuck parse
229+
} CBMParseBudget;
230+
231+
#ifdef CBM_ENABLE_TEST_SEAMS
232+
/* Deterministic RED-repro seam (armed by CBM_TEST_WALL_STALL_ON in
233+
* cbm_extract_file_ex): when set, the timeout callback reads the WALL clock this
234+
* many ns ahead of reality while CPU time is untouched — emulating a worker
235+
* descheduled long enough for the old wall-only budget to elapse against
236+
* near-zero CPU. With the CPU-time budget the parse still completes; a wall-only
237+
* / tight-ceiling budget drops the file. Thread-local so it cannot leak across
238+
* worker threads. Compiled only into seam-enabled test artifacts. */
239+
static CBM_TLS uint64_t tl_parse_wall_seam_offset_ns = 0;
240+
#endif
241+
242+
/* tree-sitter's TSProgressCallback mandates a non-const TSParseState*; a const
243+
* parameter here would not match the opts.progress_callback assignment below. */
244+
// cppcheck-suppress constParameterCallback
216245
static bool cbm_timeout_cb(TSParseState *state) {
217-
uint64_t deadline = *(uint64_t *)state->payload;
218-
return now_ns() > deadline;
246+
const CBMParseBudget *budget = (const CBMParseBudget *)state->payload;
247+
uint64_t wall = now_ns();
248+
#ifdef CBM_ENABLE_TEST_SEAMS
249+
wall += tl_parse_wall_seam_offset_ns;
250+
#endif
251+
return cbm_thread_cpu_time_ns() > budget->cpu_deadline_ns || wall > budget->wall_ceiling_ns;
219252
}
220253

221254
// --- Thread-local parser pool ---
@@ -1620,11 +1653,26 @@ static CBMFileResult *extract_file_ex_body(const char *source, int source_len, C
16201653
};
16211654

16221655
TSParseOptions opts = {0};
1623-
uint64_t deadline_ns = 0; // cppcheck-suppress unreadVariable
1656+
CBMParseBudget budget = {0}; // cppcheck-suppress unreadVariable
16241657
if (timeout_micros > 0) {
1625-
deadline_ns = t0 + ((uint64_t)timeout_micros * USEC_TO_NSEC);
1626-
opts.payload = &deadline_ns;
1658+
uint64_t budget_ns = (uint64_t)timeout_micros * USEC_TO_NSEC;
1659+
// Descheduling burns wall time but not CPU: gate on this thread's CPU
1660+
// time so a starved-but-parseable file is not abandoned, with a generous
1661+
// wall ceiling as a backstop against a genuinely spinning/stuck parse.
1662+
budget.cpu_deadline_ns = cbm_thread_cpu_time_ns() + budget_ns;
1663+
budget.wall_ceiling_ns = t0 + budget_ns * CBM_PARSE_WALL_CEILING_FACTOR;
1664+
opts.payload = &budget;
16271665
opts.progress_callback = cbm_timeout_cb;
1666+
#ifdef CBM_ENABLE_TEST_SEAMS
1667+
tl_parse_wall_seam_offset_ns = 0;
1668+
const char *stall_on = getenv("CBM_TEST_WALL_STALL_ON");
1669+
if (stall_on && stall_on[0] && rel_path && strstr(rel_path, stall_on)) {
1670+
// Push the wall reading past the 1x budget (the old wall-only budget
1671+
// trips) but well under the generous ceiling (the CPU-time budget
1672+
// survives): budget + 1 s, deterministic, no real timing involved.
1673+
tl_parse_wall_seam_offset_ns = budget_ns + NSEC_PER_SEC;
1674+
}
1675+
#endif
16281676
}
16291677

16301678
TSTree *tree = ts_parser_parse_with_options(parser, NULL, ts_input, opts);

‎internal/cbm/extract_defs.c‎

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#define MAX_PARAMS_MINUS_1 31
2424
#define MAX_RETURN_TYPES 16
2525
#define MAX_RETURN_TYPES_MINUS_1 15
26+
#define MAX_ATTR_WRAPPERS 16 // stacked C#/PHP attribute_list siblings per declaration (#1692)
27+
#define MAX_ATTR_WRAPPERS_MINUS_1 15
2628

2729
// Tree traversal limits.
2830
enum {
@@ -1323,7 +1325,7 @@ static const char *extract_docstring(CBMArena *a, TSNode node, const char *sourc
13231325
return NULL;
13241326
}
13251327

1326-
static TSNode find_jvm_modifiers(TSNode node, CBMLanguage lang);
1328+
static int find_jvm_modifiers(TSNode node, CBMLanguage lang, TSNode *out, int max);
13271329

13281330
/* HTTP method names recognized in decorator calls (e.g., @router.post → "POST") */
13291331
static const char *decorator_method_name(const char *attr_text) {
@@ -1713,12 +1715,9 @@ static void scan_route_annotations(CBMArena *a, TSNode owner, const char *source
17131715
*out_method = NULL;
17141716
*out_jax_path = NULL;
17151717

1716-
TSNode wrappers[2];
1717-
int wn = 0;
1718-
TSNode modifiers = find_jvm_modifiers(owner, spec->language);
1719-
if (!ts_node_is_null(modifiers)) {
1720-
wrappers[wn++] = modifiers;
1721-
}
1718+
/* MINUS_1: the owner node itself is appended below, after the wrappers. */
1719+
TSNode wrappers[MAX_ATTR_WRAPPERS];
1720+
int wn = find_jvm_modifiers(owner, spec->language, wrappers, MAX_ATTR_WRAPPERS_MINUS_1);
17221721
/* Direct-child annotations (some grammars attach the annotation as a child
17231722
* of the method node rather than under `modifiers`). */
17241723
wrappers[wn++] = owner;
@@ -1872,13 +1871,23 @@ static int count_modifier_annotations(TSNode modifiers, const CBMLangSpec *spec)
18721871
return count;
18731872
}
18741873

1875-
// Find the wrapper child that holds annotations/attributes for languages where
1876-
// they are nested under an intermediate node rather than being a prev-sibling:
1877-
// Java/Kotlin/C#/Swift → `modifiers` (contains annotation/attribute)
1878-
// PHP 8 → `attribute_list` (contains attribute_group)
1879-
// Returns a null node when the language has no such wrapper.
1880-
static TSNode find_jvm_modifiers(TSNode node, CBMLanguage lang) {
1881-
TSNode null_node = {0};
1874+
// Find every wrapper child that holds annotations/attributes for languages
1875+
// where they are nested under an intermediate node rather than being a
1876+
// prev-sibling:
1877+
// Java/Kotlin/Swift → `modifiers` (one node, contains every annotation)
1878+
// C#/PHP 8 → `attribute_list` (contains attribute/attribute_group)
1879+
//
1880+
// C#/PHP attribute stacks are NOT a single wrapper: each bracketed group
1881+
// (`[Foo]`, `[Bar]`, ...) compiles to its own `attribute_list` node, so
1882+
// `[A] [B] [C]` above a declaration produces three separate `attribute_list`
1883+
// siblings among that declaration's children — not one `attribute_list`
1884+
// holding three entries. A field-name lookup (`ts_node_child_by_field_name`)
1885+
// only ever returns the first child registered under a given field, so using
1886+
// it here silently dropped every attribute after the first bracket group
1887+
// (#1692). Scanning all children by kind fixes that for C#/PHP and is a
1888+
// no-op change for Java/Kotlin/Swift, where `modifiers` never repeats.
1889+
// Writes up to `max` wrapper nodes into `out`; returns how many were found.
1890+
static int find_jvm_modifiers(TSNode node, CBMLanguage lang, TSNode *out, int max) {
18821891
const char *wrapper = NULL;
18831892
switch (lang) {
18841893
case CBM_LANG_JAVA:
@@ -1888,19 +1897,12 @@ static TSNode find_jvm_modifiers(TSNode node, CBMLanguage lang) {
18881897
break;
18891898
case CBM_LANG_CSHARP:
18901899
case CBM_LANG_PHP:
1891-
/* C# attributes live in an `attribute_list` child (modifiers like
1892-
* `public` are separate `modifier` nodes); PHP 8 likewise nests
1893-
* `attribute_group` under `attribute_list`. */
18941900
wrapper = "attribute_list";
18951901
break;
18961902
default:
1897-
return null_node;
1898-
}
1899-
TSNode w = ts_node_child_by_field_name(node, wrapper, (uint32_t)strlen(wrapper));
1900-
if (ts_node_is_null(w)) {
1901-
w = cbm_find_child_by_kind(node, wrapper);
1903+
return 0;
19021904
}
1903-
return w;
1905+
return cbm_find_children_by_kind(node, wrapper, out, max);
19041906
}
19051907

19061908
// Count direct children of `node` that are decorator/annotation nodes (used by
@@ -1978,13 +1980,14 @@ static const char **extract_decorators(CBMArena *a, TSNode node, const char *sou
19781980
prev = ts_node_prev_sibling(prev);
19791981
}
19801982

1981-
TSNode modifiers = {0};
1983+
TSNode wrappers[MAX_ATTR_WRAPPERS];
1984+
int wn = 0;
19821985
int mod_count = 0;
19831986
int child_count = 0;
19841987
if (count == 0) {
1985-
modifiers = find_jvm_modifiers(node, lang);
1986-
if (!ts_node_is_null(modifiers)) {
1987-
mod_count = count_modifier_annotations(modifiers, spec);
1988+
wn = find_jvm_modifiers(node, lang, wrappers, MAX_ATTR_WRAPPERS);
1989+
for (int w = 0; w < wn; w++) {
1990+
mod_count += count_modifier_annotations(wrappers[w], spec);
19881991
}
19891992
/* Languages like Scala attach the annotation directly as a child of the
19901993
* definition node (no wrapper, no prev-sibling). */
@@ -2014,8 +2017,8 @@ static const char **extract_decorators(CBMArena *a, TSNode node, const char *sou
20142017
}
20152018
prev = ts_node_prev_sibling(prev);
20162019
}
2017-
if (!ts_node_is_null(modifiers)) {
2018-
idx = collect_modifier_decorators(a, modifiers, source, spec, result, idx, total);
2020+
for (int w = 0; w < wn && mod_count > 0; w++) {
2021+
idx = collect_modifier_decorators(a, wrappers[w], source, spec, result, idx, total);
20192022
}
20202023
if (child_count > 0) {
20212024
idx = collect_child_decorators(a, node, source, spec, result, idx, total);

‎internal/cbm/helpers.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,18 @@ TSNode cbm_find_child_by_kind(TSNode parent, const char *kind) {
466466
return null_node;
467467
}
468468

469+
int cbm_find_children_by_kind(TSNode parent, const char *kind, TSNode *out, int max) {
470+
int n = 0;
471+
uint32_t count = ts_node_child_count(parent);
472+
for (uint32_t i = 0; i < count && n < max; i++) {
473+
TSNode child = ts_node_child(parent, i);
474+
if (strcmp(ts_node_type(child), kind) == 0) {
475+
out[n++] = child;
476+
}
477+
}
478+
return n;
479+
}
480+
469481
/* ── Node-type classification: TSSymbol bitset acceleration ───────────────
470482
* cbm_kind_in_set is called for nearly every AST node (function/class/call/
471483
* import/branching sets), so a linear strcmp over the type-name array is a hot

‎internal/cbm/helpers.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ char *cbm_cpp_out_of_line_parent_class(CBMArena *a, TSNode node, const char *sou
122122
// Find a child node by kind string.
123123
TSNode cbm_find_child_by_kind(TSNode parent, const char *kind);
124124

125+
// Find every child node matching `kind` (unlike cbm_find_child_by_kind,
126+
// which stops at the first match). Writes up to `max` nodes into `out`;
127+
// returns how many were found. Repeated sibling nodes of the same kind are
128+
// common in some grammars (e.g. C#/PHP stack each `[Attr]` as its own
129+
// attribute_list child) — see #1692.
130+
int cbm_find_children_by_kind(TSNode parent, const char *kind, TSNode *out, int max);
131+
125132
/* --- Lisp-family shared gates ---------------------------------------------
126133
* The defs, calls and unified extractors each walk the same generic `list`
127134
* node and must agree on what it means. The predicates below therefore live

0 commit comments

Comments
 (0)