Repository navigation
fix: check output paths in linear time - #410
Merged
Merged
Conversation
Replace the regular expression that finds wildcards in output paths, which took quadratic time on some paths, with a linear scan that finds the same wildcards. Limit the size of the paths of a task to 4096 bytes in `validate_task`, so also after plugins changed the task. Closes #408 Co-Authored-By: Claude Opus 5.5 <[email protected]>
State which fields the limit covers, test the response of the API and lone surrogates, and test the scan directly on brackets only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR makes output wildcard compatibility checks linear-time and bounds every task path to 4096 UTF-8 bytes through centralized post-plugin validation, rejecting oversized tasks before persistence or relay and documenting the behavior. Sequence diagram for bounded task submission validationsequenceDiagram
actor Client
participant API as Task API
participant Plugins
participant Validator as validate_task
participant Store as Task persistence
participant Backend
Client->>API: POST /tasks
API->>Plugins: Run task pipeline
Plugins-->>API: Return possibly modified task
API->>Validator: validate_task(payload)
Validator->>Validator: _task_paths(task)
alt Any path exceeds MAX_PATH_SIZE
Validator-->>API: ValueError
API-->>Client: 400 Bad Request
API-->>Store: Do not persist task
API-->>Backend: Do not relay task
else All paths are within 4096 UTF-8 bytes
Validator-->>API: Valid task
API->>Store: Persist task
API->>Backend: Relay task
API-->>Client: Accepted
end
Flow diagram for linear-time output wildcard detectionflowchart LR
Path[Output path] --> Check{Contains * or ?}
Check -->|Yes| Wildcard[Wildcards detected]
Check -->|No| Opening[Find first opening bracket]
Opening --> Bracket{Closing bracket at least two positions later}
Bracket -->|Yes| Wildcard
Bracket -->|No| Clear[No wildcards]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #410 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 24 24
Lines 2479 2500 +21
=========================================
+ Hits 2479 2500 +21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
uniqueg
marked this pull request as ready for review
November 4, 2026 04:47
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="pro_tes/gateway.py" line_range="262" />
<code_context>
- TesTask(**payload)
+ task = TesTask(**payload)
tes_task(payload)
+ for path in _task_paths(task):
+ # JSON can carry lone surrogates
+ if len(path.encode("utf-8", errors="surrogatepass")) > MAX_PATH_SIZE:
</code_context>
<issue_to_address>
**Oversized plugin paths reach backend**
When a forward-phase plugin adds or changes an outbound path to more than 4096 bytes, `check_outbound` sanitizes a copy and calls `tes_task` without checking the path limit, so the backend runs a task that exceeds the limit while the stored task retains the earlier path.
Validate the outbound task's paths against `MAX_PATH_SIZE` in `check_outbound` before sending it to the backend.
</issue_to_address>
### Comment 2
<location path="docs/api.md" line_range="45" />
<code_context>
- proTES is configured to remove them, and tasks with inline contents of
- inputs over `max_inline_content`, with `413 Content Too Large`: see
+ proTES is configured to remove them, and tasks with a path over 4096
+ bytes (the value of `PATH_MAX` on Linux; `path` of inputs and outputs, `path_prefix`,
+ `volumes`, and `workdir`, `stdin`, `stdout` and `stderr` of executors);
+ tasks with inline contents of inputs over `max_inline_content` are
</code_context>
<issue_to_address>
**Generated clients miss path limit**
When a client relies on the published OpenAPI schema to construct or validate a task with a path over 4096 UTF-8 bytes, the published OpenAPI schema still defines task path fields as unconstrained strings, so clients generated from it accept paths that the server rejects with `400 Bad Request`.
Describe the 4096-byte limit in the published schema for each affected field, noting that it is a byte limit rather than a character-count limit.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: pro_tes/gateway.py:262, docs/api.md:45
uniqueg
added a commit
that referenced
this pull request
Nov 4, 2026
Brings in the review fixes #410, #412, #417, #419, #420, #421. The only conflict is in the module docstring of `pro_tes/ga4gh/tes/backends.py`: keeps this branch's removal of the FOCA 0.19 caveat about redirects, and the sentence of #419 about tasks in the view `FULL`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #408.
has_wildcardsreplaces the regular expression for wildcards in output paths: a linear scan with the same matches (*,?, or a[with a]at least two characters later).validate_tasklimits each path of a task to 4096 bytes of UTF-8 (pathof inputs and outputs,path_prefix,volumes, andworkdir,stdin,stdoutandstderrof executors), so also after plugins changed the task. Longer ones get400 Bad Request.docs/api.mddocuments the limit.Verification
pytest: full suite, with Helm 3.22.1 and the built chart dependencies. New tests: exhaustive comparison with the old pattern on all strings of[,]andaup to length 8; 1 MB paths checked in under a second; each path field; the limit in bytes; a lone surrogate;POST /tasksanswers400and keeps nothing.pre-commit runon the changed files (ruff, semgrep, gitleaks, ast-grep, mypy): passed.Declined review findings
PATH_MAXincludes the terminating NUL, so 4095 would be the exact Linux limit (low): kept 4096, the common value, and the docstring and docs say it is the value ofPATH_MAX, and that backends may allow less.🤖 Generated with Claude Code
Summary by Sourcery
Enforce efficient output wildcard validation and a 4096-byte limit across task paths.
Bug Fixes:
Documentation:
Tests: