Skip to content

feat: record output file logs - #145

Merged
uniqueg merged 4 commits into
devfrom
feat/output-file-logs
Nov 14, 2026
Merged

uniqueg merged 4 commits into
devfrom
feat/output-file-logs

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Summary

The outputs filer and the taskmaster record the uploaded files (TES 1.1
logs[].outputs). The TESK API reads them in elixir-cloud-aai/tesk-api#160.

  • Once all outputs are uploaded, the outputs filer prints one last line,
    whatever the log level:
    TESK_OUTPUT_FILE_LOGS [{"output":0,"relative":"s1/out.txt","size_bytes":"3"}].
    • Each entry is one uploaded file: the file of a FILE output, every
      file below a DIRECTORY output, and every file that the wildcards of
      an output with path_prefix matched.
    • The line holds no URLs. They may carry credentials (presigned URLs,
      user:password@), and the filer's log redacts URLs everywhere else.
    • The list stops at 100,000 bytes.
    • An error while listing is logged and doesn't fail the filer.
  • After the outputs filer completes, the taskmaster reads that line from
    the last 1,000 lines of the succeeded pod's log, and checks it.
    • It derives each file's URL and path from the task's outputs, as the
      upload does (filer.output_file_url).
    • It stores [{url, path, size_bytes}] as the annotation
      output-file-logs of the outputs filer's job, capped at 200,000 bytes.
      Kubernetes allows 256 KiB for all of a job's annotations.
    • Any error is logged as a warning, and the task completes without the
      annotation.
    • The role's existing permissions are enough: list pods, get
      pods/log, patch jobs.
  • Docs: Filer (Output file logs), Taskmaster, Upgrading, Development.

Closes #144

Verification

  • coverage run -m pytest && coverage report: 822 passed, 7 skipped (the
    e2e tests are skipped locally); 100% coverage.

  • ruff check ., ruff format --check ., mypy: clean.

  • mkdocs build --strict: clean.

  • New unit tests are in tests/unit/test_filer_output_logs.py and
    tests/unit/test_taskmaster_output_logs.py. The e2e test
    test_task_with_inputs_and_outputs now also checks the annotation on
    the outputs filer's job. It runs in CI's End-to-end test job.

  • Review: adversarial-reviewer and quality-reviewer, two rounds. Round
    1 found three high findings, all fixed:

    • URLs with credentials went into the pod log. The filer now prints
      none.
    • The size cap loop was quadratic. It is now one pass on both sides.
    • A log that isn't valid UTF-8 could crash the taskmaster. Any error is
      now caught.
      It also found a medium one, fixed: the filer kept an unbounded list in
      memory. It now uses generators and a cap.
      Round 2 found a medium: CRI-O splits long lines into 8 KiB records,
      which count as lines for tail_lines. The taskmaster now reads 1,000
      lines. Round 2's low findings are fixed too.
  • CI: all checks passed, including End-to-end test (kind), which
    checks the annotation, and both image scans.

  • Sourcery: 7 findings. Five are fixed in 8a91d59:

    • a directory that can't be read now raises, rather than giving a
      partial list;
    • FTP directory URLs are now built as the upload builds them;
    • the size caps are now exact;
    • the tests now check the uploads and the order of the calls.
      Two are declined; see below. All threads are answered and resolved.

Declined review findings

  • Sourcery: wildcard matches are listed in full before the cap applies.
    The upload already lists them the same way (sorted(glob(...))).

  • Sourcery: the filer's line omits URLs and paths. This is deliberate,
    to keep credentials out of the pod's log. The annotation has the TES
    fields.

  • A directory output to S3 or FTP that holds names with #, ? or ;
    is uploaded to a truncated key, because the upload takes the URL's path
    through urlparse. The file logs then report the untruncated URL. This
    is an existing upload bug: wildcard matches are already refused for
    such names, directory entries aren't. It belongs in its own issue
    (fix: directory uploads truncate names with # ? ; #146).

  • The quality review suggested sharing the byte-cap loop between the
    filer and the taskmaster. The entries and the warnings differ, and the
    loops are short.

  • The taskmaster imports tesk_core.filer. It needs output_file_url
    to derive URLs exactly as the upload does, and both images install the
    same package.

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 3 commits November 14, 2026 00:20
The outputs filer prints the uploaded files (TES 1.1 tesOutputFileLog:
url, path, size_bytes) as its last stdout line, after the marker
TESK_OUTPUT_FILE_LOGS. Once the outputs filer has completed, the
taskmaster reads that line from the pod's log, checks it, and stores it
as the annotation `output-file-logs` of the outputs filer's job, capped
at 200,000 bytes, for the TESK API to report as logs[].outputs. Errors
are logged; the task completes either way. No new permissions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
From the review: the filer now lists each uploaded file by the index
of its output and its path below it, without URLs, which may carry
credentials; the taskmaster derives URLs and paths from the task as
the upload does. Both sides cap the list in one pass, and errors while
listing or storing the files never fail the filer or the taskmaster.
The taskmaster reads only the log's last 10 lines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Container runtimes split long log lines into records (CRI-O: at most
8 KiB), which count as lines for tail_lines, so the last 10 could miss
the start of a long marker line. Also from the review: the filer logs
a failed listing as an error, so that it shows without --debug.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg self-assigned this Nov 13, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Define the annotation contract and limits used to persist output file logs on the outputs-filer job.

  • src/tesk_core/taskmaster.py L95-107

API

Specify the TESK marker-line format and document how the taskmaster turns it into the TES API output-file logs.

  • src/tesk_core/filer.py L52-58 (+3 small edits)
  • src/tesk_core/taskmaster.py L25

Uses of the API

Connect task completion to recording the outputs filer’s logs and add the generated annotation to its job.

  • src/tesk_core/taskmaster.py L500, L948-1063

Implementation

Enumerate uploaded files deterministically, derive their URLs and executor paths, and print a bounded marker line without exposing URLs in the pod log.

  • src/tesk_core/filer.py L1318-1449, L1494-1516

Documentation

Explain output-file log behavior, taskmaster persistence, upgrade compatibility, and the expanded end-to-end check.

  • docs/development.md L91-94
  • docs/filer.md L92-120
  • docs/taskmaster.md L73-92
  • docs/upgrading.md L28-37

Tests

Cover file discovery, URL derivation, marker emission, validation, Kubernetes persistence, failure handling, and task sequencing.

  • tests/e2e/test_taskmaster_e2e.py L9, L44-48
  • tests/unit/test_filer_output_logs.py L1-372
  • tests/unit/test_taskmaster_output_logs.py L1-308

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

@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ba4f8d9) to head (8a91d59).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #145   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         1648      1747   +99     
=========================================
+ Hits          1648      1747   +99     

☔ 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 14, 2026 00:07
@sourcery-ai

sourcery-ai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit 8a91d59

#144 feat: record the uploaded output files · 3 of 4 met

# Requirement Status Notes
1 The outputs filer prints the uploaded files after the last upload, including each file’s URL, executor path, and size. 🟡 Partly met The filer lists the requested files and sizes, but its log line contains only the output index and relative path; the taskmaster derives the URL and executor path later.
2 The taskmaster reads and checks the filer’s log line, then stores the list as the outputs-filer job’s annotation, capped with a warning if needed. ✅ Met
3 Add unit and end-to-end tests. ✅ Met The change adds unit tests and extends the end-to-end test to check the annotation.
4 Update the Filer, Taskmaster, and Upgrading docs. ✅ Met

@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 7 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/tesk_core/filer.py" line_range="1399" />
<code_context>
+    if os.path.isfile(local):
+        yield "", os.path.getsize(local)
+        return
+    for root, dirs, files in os.walk(local):
+        # Files by name, then the subdirectories by name, depth first
+        dirs.sort()
</code_context>
<issue_to_address>
**Incomplete output logs appear valid**

When directory traversal encounters an `OSError` after upload succeeds, `os.walk` silently ignores scanning errors by default, so `files_below` returns a partial or empty list and `print_output_logs` presents it as valid; the taskmaster stores incomplete output logs without warning.

Make directory-scan errors propagate from `files_below` and report the listing failure instead of printing a partial list as valid.
</issue_to_address>

### Comment 2
<location path="src/tesk_core/filer.py" line_range="1376" />
<code_context>
+    """
+    if filedata.get("path_prefix") and hasWildcards(filedata["path"]):
+        prefix = filerPath(taskPath(filedata["path_prefix"]))
+        for match in sorted(glob(filerPath(filedata["path"]))):
+            relative = os.path.relpath(match, prefix).replace(os.sep, "/")
+            for below, size in files_below(match):
</code_context>
<issue_to_address>
**Wildcard listing exceeds memory cap**

When a wildcard output matches enough files to exhaust the filer pod's available memory during the post-upload listing, `sorted(glob(...))` materializes every wildcard match before `output_file_logs` can apply its byte cap. With a very large match set, this second full scan after upload can exhaust the filer pod's memory, so Kubernetes marks the filer job failed and the task fails despite the files already being uploaded.

Bound or stream wildcard match enumeration so the byte cap can stop listing without first materializing every match.
</issue_to_address>

### Comment 3
<location path="src/tesk_core/filer.py" line_range="1428" />
<code_context>
+        base = taskPath(output["path"])
+    if not relative:
+        return output["url"], base
+    return url_join(output["url"], relative), base.rstrip("/") + "/" + relative
+
+
</code_context>
<issue_to_address>
**FTP annotation URL differs**

When a directory output uses FTP and its URL ends in `/`, `output_file_url` uses `url_join` to strip the trailing slash, while `FTPTransput.upload_dir` appends `"/"` to the original URL; the annotation therefore records a different URL from the one used for the uploaded file.

Build FTP annotation URLs with the same joining behavior as `FTPTransput.upload_dir`.
</issue_to_address>

### Comment 4
<location path="src/tesk_core/filer.py" line_range="1350" />
<code_context>
+                "relative": relative,
+                "size_bytes": str(file_size),
+            }
+            size += len(json.dumps(entry, separators=(",", ":"))) + 1
+            if size > OUTPUT_LOGS_MAX_BYTES:
+                logging.warning(
</code_context>
<issue_to_address>
**Output logs truncate too early**

When the serialized output-file list is near either configured byte cap, both size counters start at `len("[]")` but add a separator byte for every entry, including the first; the filer and taskmaster therefore stop early and omit files that would fit in the serialized output logs.

Count separator bytes only between entries in both size counters.

Also at `src/tesk_core/taskmaster.py:1029-1030`.
</issue_to_address>

### Comment 5
<location path="src/tesk_core/filer.py" line_range="1345-1348" />
<code_context>
+    size = len("[]")
+    for index, output in enumerate(outputs):
+        for relative, file_size in output_files(output):
+            entry = {
+                "output": index,
+                "relative": relative,
+                "size_bytes": str(file_size),
+            }
+            size += len(json.dumps(entry, separators=(",", ":"))) + 1
</code_context>
<issue_to_address>
**Filer line omits URL and path**

The issue asks the filer line to include each file's URL and executor path, but these entries contain only the output index, relative path, and size; the taskmaster reconstructs the URL and path for the annotation instead. The stored TES records have the requested fields, but the specified filer-log fields are absent.
</issue_to_address>

### Comment 6
<location path="tests/unit/test_filer_output_logs.py" line_range="265-272" />
<code_context>
+        monkeypatch: The fixture that sets the command line.
+        capsys: The fixture that captures the standard output.
+    """
+    write(prefix, "a.txt", "a")
+    write(prefix, "b.txt", "bb")
+    outputs = [
+        {"path": "/a.txt", "url": "s3://b/a?secret=x", "type": "FILE"},
+        {"path": "/b.txt", "url": "s3://b/b", "type": "FILE"},
+    ]
+
+    assert run_main(monkeypatch, "outputs", {"inputs": [], "outputs": outputs}) == 0
+
+    out = capsys.readouterr().out
</code_context>
<issue_to_address>
**Skipped uploads still pass**

When `main()` stops calling `process_file` before printing output logs, `test_main_prints_output_logs` pre-creates the files at lines 265–266 and never asserts `mock_process` was called, so it passes even if `main()` skips the uploads. `test_main_output_logs_error` likewise never checks its mocked upload call at line 332, so it can pass without an upload too.

Assert that `process_file` is called with each expected output in both tests, and make the success-path mock create the files it claims to upload.

Also at `tests/unit/test_filer_output_logs.py:332`.
</issue_to_address>

### Comment 7
<location path="tests/unit/test_taskmaster_output_logs.py" line_range="299-301" />
<code_context>
+        data = json.load(fh)
+    data["outputs"] = [{"path": "/out", "url": "s3://b/out", "type": "DIRECTORY"}]
+
+    run_task(data, "filer_name", "filer_version")
+
+    mock_record.assert_called_once_with("task-1000-outputs-filer", data["outputs"])
</code_context>
<issue_to_address>
**Completion order goes unchecked**

When `run_task` calls `record_output_logs` before `filerjob.run_to_completion` returns, `test_run_task_records_output_logs` only asserts at line 301 that `record_output_logs` was called. It never checks `mock_run` or call order, so the test still passes if `run_task` records the logs before the outputs filer completes.

Assert that the mocked completion call precedes the recording call, or make the completion mock fail if recording has already occurred.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 6 findings to address first, and a bad listing or URL mapping can leave incorrect file metadata, including credential-bearing URLs, in the outputs filer job’s annotation and expose it through the API. That annotation survives a revert, but it is bounded and can be cleared or rebuilt; the change does not alter the upload itself.

Blocking findings: src/tesk_core/filer.py:1399, src/tesk_core/filer.py:1376, src/tesk_core/filer.py:1428, src/tesk_core/filer.py:1350, tests/unit/test_filer_output_logs.py:272, and 1 more


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

Comment thread src/tesk_core/filer.py Resolved
Comment thread src/tesk_core/filer.py Resolved
Comment thread src/tesk_core/filer.py Resolved
Comment thread src/tesk_core/filer.py Resolved
Comment thread src/tesk_core/filer.py Resolved
Comment thread tests/unit/test_filer_output_logs.py Resolved
- A directory that can't be read while listing raises, so that the
  filer prints no line rather than an incomplete one.
- The FTP upload of a directory appends the path as it is; its URLs
  are now derived the same way.
- Both size caps count the JSON exactly (no comma before the first
  entry).
- Tests check the uploads and that the logs are recorded after the
  outputs filer completed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 1e5cf0f into dev Nov 14, 2026
46 checks passed
@uniqueg
uniqueg deleted the feat/output-file-logs branch November 14, 2026 00:51
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.

feat: record the uploaded output files

1 participant