Repository navigation
feat: record output file logs - #145
Conversation
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]>
Reviewer's GuideData structuresDefine the annotation contract and limits used to persist output file logs on the outputs-filer job.
APISpecify the TESK marker-line format and document how the taskmaster turns it into the TES API output-file logs.
Uses of the APIConnect task completion to recording the outputs filer’s logs and add the generated annotation to its job.
ImplementationEnumerate uploaded files deterministically, derive their URLs and executor paths, and print a bounded marker line without exposing URLs in the pod log.
DocumentationExplain output-file log behavior, taskmaster persistence, upgrade compatibility, and the expanded end-to-end check.
TestsCover file discovery, URL derivation, marker emission, validation, Kubernetes persistence, failure handling, and task sequencing.
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 #145 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 1648 1747 +99
=========================================
+ Hits 1648 1747 +99 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit 8a91d59 #144 feat: record the uploaded output files · 3 of 4 met
|
There was a problem hiding this comment.
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
- 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]>
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.whatever the log level:
TESK_OUTPUT_FILE_LOGS [{"output":0,"relative":"s1/out.txt","size_bytes":"3"}].FILEoutput, everyfile below a
DIRECTORYoutput, and every file that the wildcards ofan output with
path_prefixmatched.user:password@), and the filer's log redacts URLs everywhere else.the last 1,000 lines of the succeeded pod's log, and checks it.
upload does (
filer.output_file_url).[{url, path, size_bytes}]as the annotationoutput-file-logsof the outputs filer's job, capped at 200,000 bytes.Kubernetes allows 256 KiB for all of a job's annotations.
annotation.
listpods,getpods/log,
patchjobs.Closes #144
Verification
coverage run -m pytest && coverage report: 822 passed, 7 skipped (thee2e 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.pyandtests/unit/test_taskmaster_output_logs.py. The e2e testtest_task_with_inputs_and_outputsnow also checks the annotation onthe outputs filer's job. It runs in CI's
End-to-end testjob.Review:
adversarial-reviewerandquality-reviewer, two rounds. Round1 found three high findings, all fixed:
none.
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,000lines. Round 2's low findings are fixed too.
CI: all checks passed, including
End-to-end test(kind), whichchecks the annotation, and both image scans.
Sourcery: 7 findings. Five are fixed in 8a91d59:
partial list;
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. Thisis 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 needsoutput_file_urlto derive URLs exactly as the upload does, and both images install the
same package.
Open questions
None.
🤖 Generated with Claude Code