Skip to content

fix(responses): parse code-mode declarations in bounded linear time - #7025

Merged
lidge-jun merged 3 commits into
lidge-jun:devfrom
luvs01:codex/upstream-collab-linear-parser-20261013
Oct 13, 2026
Merged

lidge-jun merged 3 commits into
lidge-jun:devfrom
luvs01:codex/upstream-collab-linear-parser-20261013

Conversation

@luvs01

@luvs01 luvs01 commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Parse code-mode tool declarations with bounded forward progress instead of repeated delimiter rescans. Long malformed input no longer produces quadratic work or false collaboration evidence.
  • Treat quoted text and line/block comments as opaque while balancing the declaration. Apostrophes and unmatched brackets inside comments retain valid tool evidence; unterminated comments and quotes remain invalid.
  • Preserve existing deferred collaboration behavior and document the bounded parser contract.

Verification

  • Candidate f9b02c5ef9f08a49f0377354b6089fa0ab6b36d7 is based on current dev 6da2774369aa32552e318e333902499683d053bc. Its three changed files match reviewed source revision ce1fa40b2201e04364cc816ed71282c22520f78a byte for byte.
  • Windows, pinned Bun 1.4.3: bun test --isolate --parallel=1 --timeout 60000 tests/codex-integration/code-mode-collab-surface.test.ts tests/codex-integration/deferred-collab-surface.test.ts — 93 pass, 0 fail, including comment regressions and existing parser/deferred-state cases.
  • bun run typecheck, bun run structure:check, bun run privacy:scan, and git diff --check passed. Privacy scanning covered the materialized sparse checkout, including all changed files.
  • Independent old/new comparison reproduced the two comment failures before the fix and verified both corrected outputs plus an unchanged control. Source-revision hosted CI succeeded; skipped platform matrices are not treated as executed tests.
  • A local full-suite run was not repeated while preparing independent changes on the shared Windows machine; focused regressions and exact source CI are the preparation evidence. This new commit still requires its own CI and maintainer review, so this PR opens in Draft.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

Summary by CodeRabbit

  • Bug Fixes
    • Nested tool listings now recognize valid declarations with nested types, comments, and quoted delimiters, while rejecting malformed or incomplete declarations.
    • Extremely long descriptions and declarations are handled within defined limits, helping prevent unreliable nested tool listings.

Scan declarations and pending headings with bounded forward progress, preserving quoted types and line or block comments as opaque text. Reject malformed delimiter closure and retain valid comment-heavy declarations below the bound.

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 31 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 37ca656f-9689-4baf-894e-79c0eda0be6c
📥 Commits

Reviewing files that changed from the base of the PR and between cad577c and fd89652.

📒 Files selected for processing (2)
  • src/server/responses/code-mode-collab-surface.ts
  • tests/codex-integration/code-mode-collab-surface.test.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 958fa8f9-7ac3-4556-85e7-a1883ddd6ae6
📥 Commits

Reviewing files that changed from the base of the PR and between e6d7e56 and cad577c.

📒 Files selected for processing (3)
  • src/server/responses/code-mode-collab-surface.ts
  • structure/subagents.md
  • tests/codex-integration/code-mode-collab-surface.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

📝 Walkthrough

Nested tool declaration recognition now uses structural parsing with size limits and delimiter checks. The rendered-tool scan indexes pending headings by name and applies a description-size bound. Tests cover malformed declarations, valid nested syntax, and adversarial input sizes.

Changes: Nested tool parsing

Layer / File(s) Summary
Declaration validation
src/server/responses/code-mode-collab-surface.ts, tests/codex-integration/code-mode-collab-surface.test.ts, structure/subagents.md
At code-mode-collab-surface.ts:80-173, declaration recognition validates the identifier, typed parameter, balanced delimiters, and complete Promise return type. It rejects declarations over 64 KiB and unterminated quoted or commented regions. Tests at code-mode-collab-surface.test.ts:223-247 cover malformed syntax and valid nested types, comments, and quoted delimiters. The documentation at subagents.md:451 describes the parsing limits and rules.
Bounded scan and heading ownership
src/server/responses/code-mode-collab-surface.ts, tests/codex-integration/code-mode-collab-surface.test.ts
At code-mode-collab-surface.ts:204-247, descriptions over 1 MiB produce no rendered tools, and pending headings are indexed by normalized name. Declaration ownership uses the earliest matching heading and removes it and later pending headings. Tests at code-mode-collab-surface.test.ts:369-404 cover oversized descriptions, repeated headings, and declaration-size cases.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to cad57

The change makes code-mode declaration parsing linear-time and rejects malformed declarations. No actionable merge-blocking risk is evident from the supplied context.

Pre-merge checks · Passed 5
Passed Passed checks (5 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: replacing code-mode declaration parsing with bounded linear-time parsing. It matches the source changes and stated objectives.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 13, 2026
@lidge-jun
lidge-jun marked this pull request as ready for review October 13, 2026 07:10
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T07:21:49.488959Z cad577c Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cad577cd90

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

return /^(?:args|input): \S[\s\S]*\): Promise<[^>\s][\s\S]*>; \};$/.test(text.slice(prefix.length));
const rest = signature.slice(openParen + 1);
const typed = rest.startsWith("args: ") ? 6 : rest.startsWith("input: ") ? 7 : -1;
if (typed < 0 || isSpace(rest[typed])) return undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject an empty declaration parameter type

When a caller-controlled listing has a matching heading and declare const tools: { multi_agent_v1__spawn_agent(args: ): Promise<unknown>; };, typed points at the ), so this whitespace-only guard passes and the balance loop immediately treats that same character as the function's closer. completeDeclarationName therefore returns the V1 name even though the declaration has no parameter type, newly classifying the request as rendered V1 (and enabling downstream V1 guidance when its other gates pass); reject a closing delimiter at the type start or require actual type content before accepting the balancing ).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@-

A parameter written as `args: )` or `args: /* note */)` let the balancing
scan treat its own closer as the separator and accept the declaration. The
previous regex refused that shape; require type content before the closer.
@lidge-jun
lidge-jun merged commit 68e7d0f into lidge-jun:dev Oct 13, 2026
35 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants