Skip to content

fix(core): cap ZIP import and search query input sizes - #1939

Merged
phernandez merged 2 commits into
fix/1902-api-key-promptfrom
fix/1899-import-search-input-limits
Oct 29, 2026
Merged

phernandez merged 2 commits into
fix/1902-api-key-promptfrom
fix/1899-import-search-input-limits

Conversation

@phernandez

Copy link
Copy Markdown
Member

Why

Two CodeRabbit deep-scan findings where uploaded or caller-supplied input on hosted Cloud drives unbounded work:

What changed

  • MAX_PROJECT_ZIP_FILES = 20_000 and MAX_PROJECT_ZIP_IGNORE_PATTERNS = 500 (archive-authored patterns only; Basic Memory defaults don't count). Both fail fast with ProjectZipImportError, the same way the existing size cap does.
  • MAX_SEARCH_TEXT_CHARS = 4_000 on SearchQuery.text. The MCP search tool assigns fields after construction, so the cap is enforced when the API router validates the request body, locally and on Cloud. The similar-notes probe is capped at 900 chars, well inside the limit.

I picked hard limits over the "aggregate work budget" the scan suggested. They are simpler and fail with a clear message.

Measured ZIP planning time (one core):

files archive patterns time
20,000 500 17.4s
20,000 50 3.9s
2,000 500 1.7s

Verification

  • New tests for the file cap, the pattern cap (defaults excluded), the schema cap, and a 422 from QUERY /v2/.../search/. Each fails without the fix.
  • Related suites in full (importers, tests/api/v2, search schema and MCP search tools, project management): 665 passed, 1 skipped.
  • just fast-check: clean

Cloud picks up both caps through build_project_zip_import_plan and the core search router after the next re-pin. No Cloud code change is needed.

Stacked on #1938.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CMYVL1x91B8kJxy7nn2GU8

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 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-29T02:20:59.674353Z bf57919 PR opened
ℹ️ 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: bf5791959d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +104 to +105
text: Optional[str] = Field( # Full-text search (supports boolean operators)
default=None, max_length=MAX_SEARCH_TEXT_CHARS

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 Validate oversized prompt inputs at the request boundary

When a caller sends more than 4,000 characters to either POST /prompt/search or POST /prompt/continue-conversation, SearchPromptRequest.query and ContinueConversationRequest.topic accept the payload, but the handlers then construct SearchQuery internally and trigger this new max_length validation. Because that ValidationError occurs inside the route rather than during request parsing, the catch-all handler converts it to a 500 instead of the intended 422. Apply the same limit to both prompt request fields or explicitly translate this validation failure.

AGENTS.md reference: AGENTS.md:L129-L130

Useful? React with 👍 / 👎.

@phernandez
phernandez added this pull request to stack #1940 October 29, 2026 02:31
@phernandez
phernandez force-pushed the fix/1899-import-search-input-limits branch from bf57919 to 3ae4b05 Compare October 29, 2026 02:33
phernandez and others added 2 commits October 28, 2026 21:42
Project ZIP planning matched every archive file against every
archive-authored ignore pattern with no bound on either count. Cap ZIP
imports at 20,000 files and 500 archive ignore patterns, failing fast
with a clear error. The worst case at the caps measures about 17s on
one core, against an unbounded cost before.

Search text had no length limit, and Postgres boolean phrase parsing
does a whole-query replacement per phrase. Cap SearchQuery.text at
4,000 characters, enforced when the API validates the request.

Fixes #1899
Fixes #1893

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CMYVL1x91B8kJxy7nn2GU8
Signed-off-by: phernandez <[email protected]>
The prompt search and continue-conversation routes build SearchQuery
internally, so an oversized query or topic tripped the new length cap
inside the handler and surfaced as a 500. Apply the same cap to both
request fields so oversize is a 422.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CMYVL1x91B8kJxy7nn2GU8
Signed-off-by: phernandez <[email protected]>
@phernandez
phernandez force-pushed the fix/1899-import-search-input-limits branch from 2ffca9a to 6ffd079 Compare October 29, 2026 02:42
@phernandez
phernandez merged commit 7b19263 into main Oct 29, 2026
14 checks passed
@phernandez
phernandez deleted the fix/1899-import-search-input-limits branch October 29, 2026 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant