Repository navigation
fix: forward workflow attachments to the WES - #202
Conversation
grep -q in a pipe stops reading at the first match; with pipefail, the write error of docker compose logs then failed the version check now and then. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Attachments of POST /runs were written to the run's storage but never sent to the WES instance. Send them with the run, in order, to every WES instance it goes to: under their names as sent where the WES API allows them (relative paths without ., .. or empty parts, NFKC-stable, printable, no backslash, quote or percent sign, bounded length), else under their safe file names. The fake WES of the smoke test returns the attachments it got, and the smoke test checks them. Closes #44 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Parts that start or end with a space or end with a dot fall back to the safe name, as Windows drops trailing dots and spaces: a part '.. ' would become '..' there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reviewer's GuideAPIReplace the WES client's single-value
Uses of the APIPass each run's forwarded attachments through to every WES submission attempt, including failover, and provide filename forwarding logic and safety rules.
ImplementationPrefix safe filenames that Windows reserves for devices so the attachment can be written and forwarded safely.
DocumentationExplain which attachment names are forwarded unchanged versus replaced with safe names, and document the changed client argument and upgrade implications.
TestsVerify multipart ordering and repeated attachment fields, failover forwarding, filename sanitization, and end-to-end smoke behavior; also make smoke log searching robust under
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Documentation build overview
4 files changed± api/index.html± configuration/index.html± reference/index.html± upgrading/index.html |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #202 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 1444 1461 +17
=========================================
+ Hits 1444 1461 +17 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit 6a098bc #44 fix: workflow attachments not processed · 1 of 1 met
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="pro_wes/ga4gh/wes/workflow_runs.py" line_range="236" />
<code_context>
+ part not in ("", ".", "..")
+ and part == part.strip(" ")
+ and not part.endswith(".")
+ and not set(part) & set('\\"%')
+ and part.isprintable()
+ and len(part.encode()) <= MAX_FILENAME_BYTES
</code_context>
<issue_to_address>
**Attachments escape the run directory**
When an attachment name uses a Windows drive prefix and the destination WES interprets names as Windows paths, `_forward_parts_allowed` accepts the colon in names such as `C:/outside.txt`, so `_forward_name` forwards the drive-absolute path unchanged. The Windows WES can write the attachment outside its run directory, allowing a caller to overwrite files on the WES host.
Reject Windows drive-qualified paths in `_forward_parts_allowed` before forwarding the name.
</issue_to_address>
### Comment 2
<location path="pro_wes/ga4gh/wes/client_wes.py" line_range="389" />
<code_context>
self,
form_data: dict[str, str],
- files: dict[str, tuple[str, bytes]] | None = None,
+ attachments: Sequence[tuple[str, bytes]] | None = None,
timeout: float | None = None,
deadline: float | None = None,
</code_context>
<issue_to_address>
**Existing client calls stop working**
When an existing caller invokes `WesClient.post_run(..., files=...)`, python callers that pass the previously supported `files=` keyword now get `TypeError` before a request is sent, so existing integrations using `WesClient.post_run` break despite this being a fix release.
Keep a backward-compatible `files` argument or provide a documented migration path with an appropriate versioned API change.
</issue_to_address>
### Comment 3
<location path="pro_wes/ga4gh/wes/workflow_runs.py" line_range="206" />
<code_context>
+ The file name to forward.
+ """
+ if (
+ len(filename.encode()) <= MAX_PATH_BYTES
+ # unchanged by NFKC, so that lookalikes (e.g., fullwidth dots and
+ # slashes, U+FF0E and U+FF0F) never become `../` at WES instances
</code_context>
<issue_to_address>
**Long attachments cannot be opened**
When a long attachment name is forwarded to a WES using Linux pathname limits, including a name exactly 4096 bytes long, `_forward_name` accepts a name of exactly 4096 bytes, but Linux pathname limits include the terminating NUL, and the WES may add its run-directory prefix before opening it. The resulting path exceeds the limit, so the WES cannot access the attachment and the run fails.
Limit the forwarded name length to leave room for the terminating NUL and any run-directory prefix.
Also at `pro_wes/ga4gh/wes/workflow_runs.py:73-75`.
</issue_to_address>
### Comment 4
<location path="pro_wes/ga4gh/wes/workflow_runs.py" line_range="205-211" />
<code_context>
+ Returns:
+ The file name to forward.
+ """
+ if (
+ len(filename.encode()) <= MAX_PATH_BYTES
+ # unchanged by NFKC, so that lookalikes (e.g., fullwidth dots and
+ # slashes, U+FF0E and U+FF0F) never become `../` at WES instances
+ # that normalize names
+ and unicodedata.normalize("NFKC", filename) == filename
+ and _forward_parts_allowed(filename)
+ ):
+ return filename
</code_context>
<issue_to_address>
**Reserved names block Windows attachments**
When an attachment has a Windows-reserved name or character and the WES stores attachments on a Windows filesystem, `_forward_parts_allowed` accepts names such as `CON` and characters such as `:`, so `_forward_name` forwards names the Windows WES cannot create as ordinary files. The attachment is unavailable at the expected path and the run fails.
Reject Windows-reserved names and characters in `_forward_parts_allowed`.
Also at `pro_wes/ga4gh/wes/workflow_runs.py:236-239`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 4 findings to address first, and if the forwarding or filename checks are wrong, attachment contents or names could be exposed to the configured WES under unintended paths. Reverting stops future forwarding, but cannot undo data already sent.
Blocking findings: pro_wes/ga4gh/wes/workflow_runs.py:236, pro_wes/ga4gh/wes/client_wes.py:389, pro_wes/ga4gh/wes/workflow_runs.py:206, pro_wes/ga4gh/wes/workflow_runs.py:211
Attachment names with a colon (drive-qualified names such as C:/x), other characters that Windows forbids, or parts that Windows reserves for devices (CON, NUL, COM1, ...) are forwarded under their safe file names; reserved safe names get a leading underscore. Names are forwarded as sent only up to 1024 bytes, so that the run directory of a WES instance fits in front within PATH_MAX. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Names with characters that Windows code pages turn into separators,
colons or double quotes ("best fit", e.g., yen sign to backslash) are
forwarded under their safe file names. Tests cover reserved names with
spaces, the safe names of reserved names and their clashes and lengths.
The docs list the forwarding rules as bullets and match the code.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Summary
Workflow attachments of
POST /runswere checked and written to the run's storage, but never sent to the WES instance, so workflows that rely on attached files could not run. This PR sends them with the run:WesClient.post_run(attachments=...)sends oneworkflow_attachmentpart per file, in order. This replaces the unusedfilesdict, which could not carry repeated fields.WorkflowRuns._forwardpasses the attachments on every try, including the failover to another WES instance.workflow_url: main.cwlortools/step.cwlresolve at the WES. This holds only where the WES API allows the name: a relative path with no empty,.or..parts, unchanged by NFKC, printable, with no backslash, percent sign, character that Windows forbids in file names (:<>|?*", so no drive-qualified names such asC:/x) or "best fit" lookalike of\,/,:or"(e.g.¥,∕), no part that Windows reserves for devices (CON,NUL,COM1, also with extensions), no part that starts or ends with a space or ends with a dot, at most 1024 bytes long and at most 255 bytes per part. Safe names that Windows reserves get a leading_(con.txtbecomes_con.txt). Any other name is forwarded under the safe file name that proWES already writes it under, for example../xbecomesx.check.shchecks one run that has a nested name and a..name.docs/api.md(Runs),docs/configuration.md(Run requests) anddocs/upgrading.md(0.20.0).Decisions taken
..and other names that are not allowed keep being accepted, as the fix: limit and sanitize run requests #119 tests require, and are neutralised to safe names instead of being refused with400.dataanddata/x) are forwarded as they are, and the docs say so. Rejecting them would need prefix checks across all attachments, with little benefit.Verification
coverage run -m pytest+coverage report: all passed, 100% coverage. The chart tests were skipped locally because there is no working Helm; CI runs them.pre-commit run --all-files: passed.mkdocs build --strict: passed.tests/smoke/check.sh(Docker Compose, own project name): passed, including the new attachment check.test_attachments_forwarded,test_failover_forwards_attachments,test_post_run_multipart.test_forward_name,test_secure_filename_reserved,test_attachment_names_refused,test_attachments_forwarded); they failed before the fix, except the two refused-name cases, which pin behaviour that already held. Afterwards:coverage run -m pytest958 passed, 100% coverage (chart tests skipped locally, no built chart dependencies); pre-commit passed (actionlint skipped locally: no shellcheck);mkdocs build --strictpassed. Reviewed by adversarial-reviewer and quality-reviewer (2 rounds).CI passed, Sourcery check passed, no open threads).CI passed).Unrelated fixes
test: read smoke logs in full before searching: the "proWES didn't read the WES version of the fake WES" smoke failure (seen on feat: forward the workflow engine (version) #199) came fromdocker compose logs prowes | grep -qunderpipefail.grep -qexits at the first match, and the write error ofdocker compose logsthen failed the pipeline. Reproduced locally on the first smoke run of this branch.Declined review findings
400instead of falling back to safe names: declined, because it changes accepted behaviour from fix: limit and sanitize run requests #119 (see Decisions taken).données/a.csvare forwarded as sent by design; a blocklist of the lookalikes of\,/,:and"plus the NFKC check covers the known mappings.files=alias ofWesClient.post_run(): declined, the client is internal and nothing passedfiles=; the rename is indocs/upgrading.md.Closes #44
🤖 Generated with Claude Code
Summary by Sourcery
Forward workflow attachments with submitted runs so WES workflows can resolve their files, including during failover.
Bug Fixes:
Enhancements:
Documentation:
Tests:
Chores: