Skip to content

fix: forward workflow attachments to the WES - #202

Merged
uniqueg merged 6 commits into
devfrom
fix/forward-attachments
Nov 23, 2026
Merged

uniqueg merged 6 commits into
devfrom
fix/forward-attachments

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Workflow attachments of POST /runs were 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 one workflow_attachment part per file, in order. This replaces the unused files dict, which could not carry repeated fields.
  • WorkflowRuns._forward passes the attachments on every try, including the failover to another WES instance.
  • File names are forwarded as sent, directories included, so relative paths such as workflow_url: main.cwl or tools/step.cwl resolve 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 as C:/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.txt becomes _con.txt). Any other name is forwarded under the safe file name that proWES already writes it under, for example ../x becomes x.
  • Smoke test: the fake WES returns the attachments it got (an ordered list) as outputs, and check.sh checks one run that has a nested name and a .. name.
  • Docs: docs/api.md (Runs), docs/configuration.md (Run requests) and docs/upgrading.md (0.20.0).

Decisions taken

  • Names with .. 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 with 400.
  • Names that clash only at the WES (data and data/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.
  • New tests failed before the fix: test_attachments_forwarded, test_failover_forwards_attachments, test_post_run_multipart.
  • Sourcery round (4 threads): regression tests first for drive-qualified names, Windows-reserved names and characters, best-fit lookalikes, the 1024/1025-byte boundary and reserved safe names (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 pytest 958 passed, 100% coverage (chart tests skipped locally, no built chart dependencies); pre-commit passed (actionlint skipped locally: no shellcheck); mkdocs build --strict passed. Reviewed by adversarial-reviewer and quality-reviewer (2 rounds).
  • CI after the Sourcery round: all checks passed on the first run (run 45131942900, head 6a098bc; gate CI passed, Sourcery check passed, no open threads).
  • CI (before the Sourcery round): all checks passed on the first run (run 45065987576: Lint, Test, Smoke test, Integration, Chart, Chart install, Docs, Scan image, codecov; gate 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 from docker compose logs prowes | grep -q under pipefail. grep -q exits at the first match, and the write error of docker compose logs then failed the pipeline. Reproduced locally on the first smoke run of this branch.

Declined review findings

  • Rejecting names that are not allowed with 400 instead of falling back to safe names: declined, because it changes accepted behaviour from fix: limit and sanitize run requests #119 (see Decisions taken).
  • File/directory prefix clashes at the WES: declined and documented (see Decisions taken).
  • Forwarding only printable-ASCII names as sent (to rule out all best-fit lookalikes): declined, because non-ASCII names such as données/a.csv are forwarded as sent by design; a blocklist of the lookalikes of \, /, : and " plus the NFKC check covers the known mappings.
  • Keeping a deprecated files= alias of WesClient.post_run(): declined, the client is internal and nothing passed files=; the rename is in docs/upgrading.md.
  • Names that differ only in case clash on case-insensitive WES file systems: not changed, they stay in the run directory; covered by the documented "clash only at the WES instance" rule.

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:

  • Forward workflow attachments from run submissions to every WES instance handling the run, including failover attempts.

Enhancements:

  • Preserve valid relative attachment paths for WES resolution while falling back to safe names for paths or filenames that could be unsafe on Linux or Windows.
  • Replace the WES client’s unused files mapping with ordered repeated workflow_attachment parts.
  • Expand smoke-test coverage to verify forwarded attachment names, contents, and ordering.

Documentation:

  • Document attachment forwarding behavior, filename safety rules, client API changes, and the upgrade impact.

Tests:

  • Add coverage for multipart attachment forwarding, failover propagation, filename normalization and safety, and end-to-end smoke behavior.

Chores:

  • Make smoke-log verification robust against pipefail-related Docker Compose output errors.

uniqueg and others added 4 commits November 22, 2026 21:06
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>
@uniqueg uniqueg self-assigned this Nov 22, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Replace the WES client's single-value files argument with ordered attachment tuples and encode each as its own workflow_attachment multipart part.

  • pro_wes/ga4gh/wes/client_wes.py L48-435 (4 small edits)

Uses of the API

Pass each run's forwarded attachments through to every WES submission attempt, including failover, and provide filename forwarding logic and safety rules.

  • pro_wes/ga4gh/wes/workflow_runs.py L73-98, L206-284, L299-306 (+5 small edits)

Implementation

Prefix safe filenames that Windows reserves for devices so the attachment can be written and forwarded safely.

  • pro_wes/ga4gh/wes/workflow_runs.py L1275-1278, L1289-1290

Documentation

Explain which attachment names are forwarded unchanged versus replaced with safe names, and document the changed client argument and upgrade implications.

  • docs/api.md L82-113
  • docs/configuration.md L349-358
  • docs/upgrading.md L219-234

Tests

Verify multipart ordering and repeated attachment fields, failover forwarding, filename sanitization, and end-to-end smoke behavior; also make smoke log searching robust under pipefail.

  • tests/ga4gh/wes/test_client_wes.py L524-554, L559-563 (+3 small edits)
  • tests/ga4gh/wes/test_retries.py L484-491, L497-515, L706-721 (+6 small edits)
  • tests/ga4gh/wes/test_run_request_limits.py L384-562, L625-636, L653-677 (+1 small edits)
  • tests/smoke/check.sh L134-160, L212-217
  • tests/smoke/fake_wes.py L8-11, L200-209, L226-240 (+3 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@read-the-docs-community

read-the-docs-community Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 proWES | 🛠️ Build #36093508 | 📁 Comparing 6a098bc against latest (00800a7)

  🔍 Preview build  

4 files changed
± api/index.html
± configuration/index.html
± reference/index.html
± upgrading/index.html

@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (00800a7) to head (6a098bc).
⚠️ Report is 1 commits behind head on dev.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 22, 2026 20:30
@sourcery-ai

sourcery-ai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit 6a098bc

#44 fix: workflow attachments not processed · 1 of 1 met

# Requirement Status Notes
1 Process workflow attachments from POST /runs, writing them outside the unique run-ID loop. ✅ Met The request attachments are read into uploads before run-environment creation, saved after a run directory is selected, and forwarded to the WES.

@sourcery-ai sourcery-ai 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.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread pro_wes/ga4gh/wes/workflow_runs.py Resolved
Comment thread pro_wes/ga4gh/wes/client_wes.py Resolved
Comment thread pro_wes/ga4gh/wes/workflow_runs.py Resolved
Comment thread pro_wes/ga4gh/wes/workflow_runs.py Resolved
uniqueg and others added 2 commits November 23, 2026 08:08
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
@uniqueg
uniqueg merged commit cf9620f into dev Nov 23, 2026
53 checks passed
@uniqueg
uniqueg deleted the fix/forward-attachments branch November 23, 2026 07:57
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.

fix: workflow attachments not processed

1 participant