Repository navigation
fix: resolve helper call sites and reject call-free collectors in expectations checker - #20
Conversation
…ectations checker Follow-ups from PR #16 delta verification: - read-after-wait no longer false-fails mixed wrapper collectors: helper names bound to exactly one tool (function-like binding or a declared function whose bounded body window references the tool) resolve as call sites for that tool; ambiguous helpers touching both tools vote for neither. frozen-lisbon-v4's genuine read->wait->read (wrapped reads, direct wait) now passes; frozen-lisbon-v3 and its param-swapped variant still fail read-first. - declaring collection expectations now requires at least one resolved call site (collection:call-sites); a comment-only stub that textually satisfies every marker fails with a distinct reason instead of sailing through the ordering carve-out. - helper classification guards: result assignments (const readResult = await readThread.call) are not helpers; function body windows cut at the next top-level declaration to prevent neighbour bleed. - three new mutation tests (mixed-wrapper pass, wait-first mixed fail, call-free stub fail); README semantics updated; CHANGELOG bullet.
📝 WalkthroughWalkthroughCollection expectation validation now resolves read and wait calls through bounded helper bindings and functions. It uses those call sites for ordering checks and rejects collections without resolved tool calls. Tests cover valid, invalid, and comment-only cases. ChangesCollection validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@skills/codex-graph/testcases/harness/expectations.js`:
- Around line 261-264: Update the ordering detail in expectations.js around the
firstRead/firstWait check to distinguish firstRead === -1 from a read that
occurs after the first wait; report the latter as the first wait preceding the
first read. In testcases.test.js lines 368-370, update the mixed wait-first
assertion to expect the corrected detail.
- Around line 64-67: Update the callable-binding detection regex in the
expectation harness around stemRe so direct references to the read or wait tool,
including namespaced references, are recognized alongside arrow, function,
resolveTool, and bind forms. Add a regression testcase covering a direct alias
such as readFor referencing the read tool and its subsequent .call invocation,
ensuring collection:call-sites resolves it.
- Around line 54-82: Update collectHelperNames in
skills/codex-graph/testcases/harness/expectations.js:54-82 to classify only
executable function bodies, excluding declaration headers, comments, and
strings. Update the ordering logic in
skills/codex-graph/testcases/harness/expectations.js:238-242 to derive direct
call order from executable invocation ranges, not tool references inside helper
definitions. In skills/codex-graph/testcases/harness/testcases.test.js:353-370,
declare readFor before run and verify wait-first invocation still fails
read_first; in skills/codex-graph/testcases/harness/testcases.test.js:373-391,
add comment-only and function-header fixtures with await/tool names and verify
only collection:call-sites fails.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: a0ad2658-40aa-4697-a511-d7a632fe759c
📒 Files selected for processing (4)
CHANGELOG.mdskills/codex-graph/testcases/README.mdskills/codex-graph/testcases/harness/expectations.jsskills/codex-graph/testcases/harness/testcases.test.js
| function collectHelperNames(scriptText, stemRe) { | ||
| const names = new Set(); | ||
| // Single-line bindings: judge only the declaration's own line so that a | ||
| // neighbouring declaration cannot bleed its tool name into this one, and | ||
| // require a function-like right-hand side (arrow, function keyword, tool | ||
| // binding, or bind) — `const readResult = await readThread.call(...)` | ||
| // stores a result and is not a callable helper. | ||
| for (const m of scriptText.matchAll( | ||
| /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=([^\n]*)/g, | ||
| )) { | ||
| if ( | ||
| stemRe.test(m[2]) && | ||
| /=>|\bfunction\b|resolveTool|\.bind\s*\(/.test(m[2]) | ||
| ) { | ||
| names.add(m[1]); | ||
| } | ||
| } | ||
| // Function helpers: judge a bounded body window, cut at the next | ||
| // top-level declaration so a small helper cannot inherit its | ||
| // neighbour's tool references. | ||
| for (const m of scriptText.matchAll( | ||
| /(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(/g, | ||
| )) { | ||
| let window = scriptText.slice(m.index, m.index + FN_HELPER_WINDOW); | ||
| const nextDecl = window | ||
| .slice(1) | ||
| .search(/\n(?:async\s+function\s|function\s|const\s|let\s|var\s)/); | ||
| if (nextDecl !== -1) window = window.slice(0, nextDecl + 1); | ||
| if (stemRe.test(window)) names.add(m[1]); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Resolve executable invocation sites instead of raw text matches.
The checker scans raw scriptText. A comment such as // await readThread.call(...) passes collection:call-sites. A readThread parameter can classify a function as a read helper. Also, a helper definition written before a caller contributes its internal await readThread before a later wait, even when the helper is first invoked only after that wait.
skills/codex-graph/testcases/harness/expectations.js#L54-L82: inspect only executable function bodies. Exclude declaration headers, comments, and strings from helper classification.skills/codex-graph/testcases/harness/expectations.js#L238-L242: derive ordering from executable invocation ranges. Do not use a wrapped tool call inside a helper definition as an earlier direct call site.skills/codex-graph/testcases/harness/testcases.test.js#L353-L370: declarereadForbeforerunand verify that a wait-first invocation sequence still failsread_first.skills/codex-graph/testcases/harness/testcases.test.js#L373-L391: add comment-only and function-header fixtures containingawaitand tool names. Verify that onlycollection:call-sitesfails.
📍 Affects 2 files
skills/codex-graph/testcases/harness/expectations.js#L54-L82(this comment)skills/codex-graph/testcases/harness/expectations.js#L238-L242skills/codex-graph/testcases/harness/testcases.test.js#L353-L370skills/codex-graph/testcases/harness/testcases.test.js#L373-L391
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@skills/codex-graph/testcases/harness/expectations.js` around lines 54 - 82,
Update collectHelperNames in
skills/codex-graph/testcases/harness/expectations.js:54-82 to classify only
executable function bodies, excluding declaration headers, comments, and
strings. Update the ordering logic in
skills/codex-graph/testcases/harness/expectations.js:238-242 to derive direct
call order from executable invocation ranges, not tool references inside helper
definitions. In skills/codex-graph/testcases/harness/testcases.test.js:353-370,
declare readFor before run and verify wait-first invocation still fails
read_first; in skills/codex-graph/testcases/harness/testcases.test.js:373-391,
add comment-only and function-header fixtures with await/tool names and verify
only collection:call-sites fails.
| if ( | ||
| stemRe.test(m[2]) && | ||
| /=>|\bfunction\b|resolveTool|\.bind\s*\(/.test(m[2]) | ||
| ) { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Resolve direct tool aliases.
const readFor = readThread; is a callable tool binding. Lines 65-67 reject it because its right-hand side has no arrow, function, resolveTool, or .bind(. An await readFor.call(...) invocation then has no resolved read call site and fails collection:call-sites.
Recognize a right-hand side that directly references the read or wait tool, including a namespaced reference. Add a regression for this binding form.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@skills/codex-graph/testcases/harness/expectations.js` around lines 64 - 67,
Update the callable-binding detection regex in the expectation harness around
stemRe so direct references to the read or wait tool, including namespaced
references, are recognized alongside arrow, function, resolveTool, and bind
forms. Add a regression testcase covering a direct alias such as readFor
referencing the read tool and its subsequent .call invocation, ensuring
collection:call-sites resolves it.
| ok = firstRead !== -1 && firstRead < firstWait; | ||
| detail = ok | ||
| ? "await-adjacent read call precedes the first wait call" | ||
| : "first await-adjacent wait call precedes any read call (wait-only collection, #13)"; | ||
| ? "read call site precedes the first wait call site" | ||
| : "first wait call site precedes any read call site (wait-only collection, #13)"; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Report the actual ordering failure.
When a read call site exists after the first wait, the current detail says “precedes any read call site” and labels the script “wait-only.” Both statements are false for the added mixed-wrapper test. Distinguish a missing read call site from a read call site that occurs after the first wait.
skills/codex-graph/testcases/harness/expectations.js#L261-L264: emit a separate detail forfirstRead === -1; otherwise state that the first wait precedes the first read.skills/codex-graph/testcases/harness/testcases.test.js#L368-L370: assert the corrected mixed wait-first detail.
📍 Affects 2 files
skills/codex-graph/testcases/harness/expectations.js#L261-L264(this comment)skills/codex-graph/testcases/harness/testcases.test.js#L368-L370
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@skills/codex-graph/testcases/harness/expectations.js` around lines 261 - 264,
Update the ordering detail in expectations.js around the firstRead/firstWait
check to distinguish firstRead === -1 from a read that occurs after the first
wait; report the latter as the first wait preceding the first read. In
testcases.test.js lines 368-370, update the mixed wait-first assertion to expect
the corrected detail.
| for (const m of scriptText.matchAll( | ||
| /(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(/g, | ||
| )) { | ||
| let window = scriptText.slice(m.index, m.index + FN_HELPER_WINDOW); | ||
| const nextDecl = window | ||
| .slice(1) | ||
| .search(/\n(?:async\s+function\s|function\s|const\s|let\s|var\s)/); | ||
| if (nextDecl !== -1) window = window.slice(0, nextDecl + 1); | ||
| if (stemRe.test(window)) names.add(m[1]); | ||
| } |
There was a problem hiding this comment.
🔴 A wait-only collection script can be marked correct because of a comment mentioning the read tool
Any function whose text merely mentions the read tool — including inside a comment or string — is treated as a read helper (collectHelperNames at skills/codex-graph/testcases/harness/expectations.js:74-83), so calling that function counts as reading and a script that never reads is judged to read first.
Impact: The harness green-lights the exact wait-only collection defect it exists to catch.
Comment text inside a function body is promoted to a read call site
The function-helper branch tests stemRe against a raw slice of the source, with no comment/string stripping. Any declared function whose 500-char window contains readThread (or read_task, etc.) is registered as a read helper name, and buildAwaitCallRe (skills/codex-graph/testcases/harness/expectations.js:87-93) then treats await thatFunction(...) as a read call site.
Reproduced against the current code:
async function logPlan(ids) {
// budget note: readThread maxOutputCharsPerItem stays at 20000
return ids.length;
}
const n = await logPlan(handles);
const snap = await waitThreads.call({ targets: handles });collection:read-first returns ok with detail "read call site precedes the first wait call site", even though the script performs no read at all. This contradicts the invariant restated in the new comment at skills/codex-graph/testcases/harness/expectations.js:220-229 and in skills/codex-graph/testcases/README.md that comments cannot flip ordering verdicts.
Prompt for agents
In collectHelperNames (skills/codex-graph/testcases/harness/expectations.js), the function-helper branch matches the read/wait tool stem against a raw source window, so a tool name appearing only in a comment or string literal inside (or after) a function body registers that function as a helper. buildAwaitCallRe then treats every `await thatFunction(...)` as a genuine tool call site, which lets a wait-only collector pass collection:read-first. The whole point of the await-adjacent matching (documented in the file header and testcases/README.md) is that comments and bindings cannot influence ordering verdicts. Consider stripping line/block comments and string literals from the script text before helper detection (a single pre-pass reused by both stem scans), and/or requiring the helper body to contain an actual call form (e.g. `toolName(` or `toolName.call(`) rather than a bare mention. Add a mutation test covering a comment-only mention inside an unrelated function in a wait-only script.
Was this helpful? React with 👍 or 👎 to provide feedback.
| let window = scriptText.slice(m.index, m.index + FN_HELPER_WINDOW); | ||
| const nextDecl = window | ||
| .slice(1) | ||
| .search(/\n(?:async\s+function\s|function\s|const\s|let\s|var\s)/); | ||
| if (nextDecl !== -1) window = window.slice(0, nextDecl + 1); | ||
| if (stemRe.test(window)) names.add(m[1]); |
There was a problem hiding this comment.
🟡 A correct read-then-wait-then-read collector is wrongly failed when a loop follows a one-line helper
The text window used to decide which tool a helper touches is cut only at the next declaration and not at the end of the helper itself (window.slice at skills/codex-graph/testcases/harness/expectations.js:77-82), so following top-level statements bleed in, the helper is judged to touch both tools, and a valid collector is reported as broken.
Impact: Correct generated workflows are reported as failing the collection-ordering rules.
Window bleed makes single-tool helpers look ambiguous
The cut regex only fires on \n followed by async function/function/const/let/var at column 0. A helper followed by a top-level loop, if, or expression statement keeps consuming up to FN_HELPER_WINDOW characters of unrelated code. If that trailing code touches the other tool, the helper lands in both readHelpers and waitHelpers and is filtered out of both by the ambiguity rule (skills/codex-graph/testcases/harness/expectations.js:232-237), so its call sites vanish.
Reproduced against the current code:
async function readFor(h) { return readThread.call({ threadId: h }); }
for (const h of handles) {
out[h] = await readFor(h);
await waitThreads.call({ targets: [h] });
out[h] = await readFor(h);
}Verdict: collection:read-first fails with "first wait call site precedes any read call site (wait-only collection, #13)" and collection:read-after-wait fails, although the script is a genuine read → wait → read collector — the mixed-wrapper class this PR is meant to fix.
Prompt for agents
collectHelperNames in skills/codex-graph/testcases/harness/expectations.js bounds a declared function's body by cutting at the next top-level declaration keyword only. Non-declaration top-level code (for/while loops, if blocks, bare expression statements) that follows a small helper is therefore included in the helper's window; if that code touches the other tool the helper becomes ambiguous and is discarded from both helper sets, which false-fails genuinely correct read -> wait -> read collectors (verified with a one-line readFor helper followed by a top-level for loop containing a direct waitThreads call). Consider bounding the body properly: scan braces from the function's opening `{` to its matching `}` (comment/string aware enough for this harness), or at minimum also cut the window at a line that starts at column 0 with any non-whitespace after the helper's closing brace.
Was this helpful? React with 👍 or 👎 to provide feedback.
| for (const m of scriptText.matchAll( | ||
| /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=([^\n]*)/g, | ||
| )) { | ||
| if ( | ||
| stemRe.test(m[2]) && | ||
| /=>|\bfunction\b|resolveTool|\.bind\s*\(/.test(m[2]) | ||
| ) { | ||
| names.add(m[1]); | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 Read helpers written as multi-line arrow functions are not recognised, failing correct collectors
Helper declarations whose body spans more than one line are judged only on their first line (matchAll over [^\n]* at skills/codex-graph/testcases/harness/expectations.js:61-70), so a common helper shape is never linked to the tool it calls and the script is reported as never reading after waiting.
Impact: Correct workflows using multi-line helper functions are reported as violating the read-after-wait rule.
Only single-line arrow bindings are resolved
skills/codex-graph/testcases/README.md:78-83 states that a function-like binding such as const readFor = … => counts as a call site for the tool it binds. In practice the binding branch inspects only the remainder of the declaration line, so const readFor = async (h) => { (body on following lines) matches the function-like test but not the tool stem, and the name is never registered. Declared-function helpers get a body window, arrow helpers do not.
Reproduced against the current code:
const readFor = async (h) => {
return await readThread.call({ threadId: h });
};
async function collect(h) {
let out = await readFor(h);
while (!out) { await waitThreads.call({ targets: [h] }); out = await readFor(h); }
return out;
}collection:read-after-wait fails with "no read call site after the first wait (#13)" even though every read after the wait goes through readFor.
Prompt for agents
In collectHelperNames (skills/codex-graph/testcases/harness/expectations.js), variable-bound helpers are judged only on their own declaration line, so a multi-line arrow helper (`const readFor = async (h) => {` with the tool call on the next line) is never resolved as a read/wait call site, false-failing collection:read-after-wait for correct collectors. README expectation semantics claim arrow bindings are resolved. Consider: when the declaration line's right-hand side is function-like but contains no tool stem, extend the inspection to a bounded body window for that binding (same bounded-window treatment declared functions get), while keeping the guard that a plain result assignment such as `const readResult = await readThread.call(...)` is not a helper. Add a mutation test for the multi-line arrow shape.
Was this helpful? React with 👍 or 👎 to provide feedback.
Follow-ups from the PR #16 delta verification (cg-lean, non-blocking pair), as a small separate PR off fresh main.
1. Mixed wrapper collectors no longer false-fail
read-after-waitfrozen-lisbon-v4's genuine
read → wait → readsequence failed because its reads go through a helper (readFor) while its wait is a direct call site — the wrapper carve-out only triggered when there were no direct call sites. The checker now resolves helper names bound to a read/wait tool as call sites for that tool:const readFor = … =>,resolveTool,.bind) judged on their own declaration line — result assignments (const readResult = await readThread.call(…)) are not helpers;Verified against the real artifacts: frozen-lisbon-v4 now passes call-sites/read-first/read-after-wait; frozen-lisbon-v3 and
/tmp/fpfn/v3-paramswap.jsstill fail read-first ("first wait call site precedes any read call site");/tmp/fpfn/correct.jspasses via genuine ordering judgment rather than the carve-out.2. Call-free scripts no longer sail through the carve-out
Declaring
collectionexpectations now requires at least one await-adjacent tool or resolved-helper call site (newcollection:call-sitescheck)./tmp/fpfn/stub2.js(8-line comment-only stub) now fails the 11-node L3 case with the distinct reason "collection declared but no tool call sites". The carve-out survives only for ordering judgments, exactly as prescribed.Tests & docs
Three new mutation tests (testcases suite 22/22): mixed-wrapper correct collector passes; genuinely wait-first mixed script still fails; call-free stub fails with only
collection:call-sitesfiring. README expectation semantics updated to match; one CHANGELOG Unreleased bullet. No AST checker, no formatters; diff is 4 files, +168/−40.Verification
sh scripts/run_regressions.shgreen end-to-end: validate_skill PASS, coherence selfcheck PASS, harness 17/17, testcases 22/22, 6/6 hint diagrams coherent, auto-release OK.Note
Low Risk
Changes are confined to the offline dynamic-workflow expectations harness and its documentation/tests; no runtime orchestration, auth, or data paths are modified.
Overview
Tightens the offline collection contract in
expectations.jsso golden workflow scripts are judged on real read/wait usage, not only directawait readThread/await waitThreadslines.Helper-aware call sites: The checker discovers function-like bindings and declared helpers that reference read or wait tools (single-line RHS, bounded function body window) and treats unambiguous helper names as await-adjacent call sites when building ordering regexes. Mixed collectors—e.g. direct
waitThreadswith reads viareadFor—no longer false-failread-after-wait; wait-first scripts still failread_first.Call-site gate: Declaring
collectionnow requires at least one resolved call site (collection:call-sites). Comment-only stubs can’t pass ordering checks via the old “no direct calls / wrapper carve-out.” When no sites resolve, ordering checks defer to that gate instead of inferring from tool bindings.Docs (
testcases/README.md), CHANGELOG, and three harness tests cover the mixed-wrapper pass/fail cases and the call-free stub failure.Reviewed by Cursor Bugbot for commit 2d8e5d5. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
Bug Fixes
Tests