Repository navigation
feat(tes/data/crypt4gh): add a teardown executor - #73
Conversation
Add the option --remove to the decryption script, for the teardown executor: it removes each decrypted file and the temporary files left next to it by a stopped decryption. Missing files are fine, so that a restarted executor runs again; files that can't be removed are logged and give exit status 1. --remove doesn't go with --key or --file. The image's smoke test runs the teardown twice and checks that it removes the decrypted and temporary files and keeps other files. Refs #67 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Add the teardown executor after the task's own executors, which removes the decrypted files (setting teardown, on by default). Copies of it among the task's own executors are dropped, so that it runs once, at the end, also when a task passes the plugin twice. The opt-in setting teardown_on_error sets ignore_error on the task's own executors, so that the teardown runs after they fail. It is off by default: it lets later executors run after a failure, Funnel then reports such tasks as COMPLETE, and TESK refuses ignore_error true. The README documents these limits and when backends remove the decrypted files otherwise. Closes #67 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
The teardown executor now runs the script with --clear VOLUME instead of --remove for each decrypted file: it removes everything in the volume, but keeps the volume itself. The volume is reserved for the plugin, so this also removes files that the task's executors derived from the decrypted files there (e.g. an index next to its input) and temporary files of a stopped decryption, without matching names. Symbolic links are removed, not followed; --clear refuses relative paths and /. From the review: README on moved teardown copies and backend sources, a test for near-copies of the teardown executor, the full argparse error, split changelog entries and smoke-test messages. Refs #67 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
--clear now refuses a directory that is itself a symbolic link, so that its target is never emptied; links inside it were already removed, not followed. Wording of the summaries, docstrings and help now says that the teardown empties the volume, not only the decrypted files. Refs #67 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Reviewer's GuideData structuresAdd the teardown settings to the plugin configuration, with teardown enabled by default and teardown-on-error disabled.
APIAdd the script’s
ImplementationValidate that teardown-on-error is used only with teardown, and pass both settings into task rewriting.
Implement safe, repeatable removal of the reserved volume’s contents and dispatch
Construct the teardown executor and update rewriting to deduplicate it at the end while optionally setting
DocumentationExplain teardown behavior, backend error semantics, configuration, and the decrypted-data lifecycle, and update the changelog and plugin descriptions.
TestsExtend plugin rewriting, configuration, script, and executor tests to cover teardown ordering, cleanup safety, error behavior, and idempotence.
Update the image smoke test to verify repeatable teardown, removal of derived and temporary files, and preservation of the mount and external files.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Documentation build overview
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #73 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 826 886 +60
Branches 111 125 +14
=========================================
+ Hits 826 886 +60
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit 37d8bc2 #67 feat(tes/data/crypt4gh): add a teardown executor · 3 of 3 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="plugins/tes/data/crypt4gh/src/foca_plugins/tes/data/crypt4gh/task.py" line_range="342" />
<code_context>
- task["volumes"] = [*items(task, "volumes"), volume]
+ if ignore_errors:
+ executor["ignore_error"] = True
+ task["executors"] = [decryption, *own, *([removal] if teardown else [])]
+ if not again:
+ task["volumes"] = [*items(task, "volumes"), volume]
</code_context>
<issue_to_address>
**Failed decryption skips teardown**
When decryption fails and removal of a written target or temporary file also fails, `remove` only logs an `OSError` and continues, so a failed decryption can leave plaintext or temporary files behind; the decryption executor then fails before the final teardown runs, including with `teardown_on_error`, and the files remain until backend cleanup.
Ensure failed-decryption cleanup retries or clears the volume before returning failure, and report cleanup failures explicitly.
</issue_to_address>
### Comment 2
<location path="plugins/tes/data/crypt4gh/src/foca_plugins/tes/data/crypt4gh/decrypt.py" line_range="192" />
<code_context>
+after them that empties that volume again. The successor of the Crypt4GH
+middleware of proTES.
<!-- --8<-- [end:summary] -->
| | |
</code_context>
<issue_to_address>
**Files remain after teardown succeeds**
When a task executor leaves a process running that writes into the volume during teardown, `clear` uses one initial directory snapshot and returns `done` without checking again, so files created after the snapshot remain in the volume while teardown reports success, leaving decrypted or derived data on disk.
Have `clear` recheck the directory before reporting success and continue clearing until it is empty.
Also at `plugins/tes/data/crypt4gh/src/foca_plugins/tes/data/crypt4gh/decrypt.py:170`.
</issue_to_address>
### Comment 3
<location path="plugins/tes/data/crypt4gh/src/foca_plugins/tes/data/crypt4gh/decrypt.py" line_range="182" />
<code_context>
+ # Links are removed, never followed
+ if entry.is_dir() and not entry.is_symlink():
+ shutil.rmtree(entry)
+ else:
+ entry.unlink()
+ except FileNotFoundError:
</code_context>
<issue_to_address>
**Files remain in partly cleared directories**
When a nested entry in a directory being cleared cannot be removed, `shutil.rmtree(entry)` stops at the first nested removal error, and `clear` catches the error only after that traversal has stopped, leaving removable siblings in the subtree and plaintext in the volume while teardown exits nonzero.
Change the directory-removal logic to continue attempting to remove the remaining descendants after an individual removal error.
</issue_to_address>
### Comment 4
<location path="plugins/tes/data/crypt4gh/tests/test_crypt4gh.py" line_range="278" />
<code_context>
+ request = make_inbound(make_task())
+ plugin.on_request(request, make_context())
+ executors = request.payload["executors"]
+ assert len(executors) == 2
+ assert executors[0] == decryption_executor(
+ ("/in/reads.fq.c4gh", "/vol/crypt4gh/reads.fq")
</code_context>
<issue_to_address>
**Disabled teardown can drop task work**
When the `teardown=False` path emits the decryption executor and teardown executor instead of preserving the task's executor, `test_on_request_can_leave_out_teardown` at lines 278 and 282 checks only the executor count and that the second executor lacks `ignore_error`; an output containing the decryption executor followed by the teardown executor therefore passes even though it drops the task's executor and adds teardown when disabled.
Assert that the second executor equals the original task executor, or compare the complete expected executor list.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 4 findings to address first, and after the task’s executors finish, the teardown script removes every entry in the configured volume, including files those executors derived from decrypted inputs. If that volume contains data the task needs to retain, a successful teardown leaves no failure signal and reverting the change will not restore the deleted files.
Blocking findings: plugins/tes/data/crypt4gh/src/foca_plugins/tes/data/crypt4gh/task.py:342, plugins/tes/data/crypt4gh/src/foca_plugins/tes/data/crypt4gh/decrypt.py:192, plugins/tes/data/crypt4gh/src/foca_plugins/tes/data/crypt4gh/decrypt.py:182, plugins/tes/data/crypt4gh/tests/test_crypt4gh.py:278
The teardown removed directories in the volume with shutil.rmtree, which stops at the first entry it can't remove and leaves the rest of that directory. It now removes directories entry by entry and goes on after errors, so only the entries that can't be removed stay; links are still removed, not followed. The test of the setting teardown off now compares the whole list of executors. Refs #67 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Brings in the teardown executor (#73). The changelog keeps the entries of both: the teardown entries and the published image. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Summary
Adds a teardown executor to
tes.data.crypt4ghthat removes the decrypted data after the task's own executors.teardown, on by default). It is added after the task's own executors and runs the decryption image's script with--clear <volume>. This removes everything in the plugin's volume but keeps the volume itself, which may be a mount point. That covers the decrypted files, temporary files of a stopped decryption, and files that the task's executors derived from the decrypted files there (e.g. an index written next to its input). The volume is reserved for the plugin: no input, output or volume of the task may be in it, so nothing there is a result. Symbolic links in it are removed, not followed, and--clearrefuses relative paths,/and a directory that is itself a link. Missing or already empty volumes are fine, so a restarted executor runs again. If an entry can't be removed, the executor exits with status 1.teardown_on_error(opt-in, off by default). Setsignore_error: trueon the task's own executors, but not on the decryption or teardown executor, so that the teardown also runs after one of them fails.decrypt.pygets--clear DIRECTORY, which can't be combined with--key/--file.image/smoke.shnow also runs the teardown twice and checks three things: the volume is empty (including a derived file in a subdirectory and a temporary file), a link out of the volume was not followed, and the volume and a file outside it remain.TES semantics and backends (why
teardown_on_erroris opt-in)tesExecutor.ignore_error: by default, execution stops at the first executor that fails. Withignore_error: true, the runner records the exit code and continues with the next executor. So by default the teardown runs only if all of the task's own executors succeed.tesk-api): accepts onlyignore_error: falseand refusestruewith400 Bad Request. Withteardown_on_erroron, every Crypt4GH task sent to TESK would be refused.calypr/funnel,internal/worker/worker.go): an executor error is cleared when that executor hasignore_error, so a task whose own executor failed endsCOMPLETEif the teardown succeeds. Later executors also run after a failure.LeaveWorkDiris set.KEEP_FAILED_PVCkeeps the PVCs of tasks that don't complete.Because turning it on changes how tasks run and how they are reported, and breaks TESK,
teardown_on_errorstays off by default. The README documents the limits.Verification
uv run ruff check,ruff format --check,ast-grep scan,python -m scripts.packages mypy plugins/tes/data/crypt4gh: passed.coverage run --source plugins/tes/data/crypt4gh/src -m pytest plugins/tes/data/crypt4gh+coverage report: 129 passed, 100% (Python 3.13, FOCA 0.22.0).coverage run --source scripts,docs -m pytest tests: passed, 100%.mkdocs build --strict(docs group): passed.uv build --all-packages --no-create-gitignore+python -m scripts.checks dist dist: passed.pre-commit run --all-files: passed.docker build -f image/Dockerfile …+image/smoke.sh: passed, including the new teardown checks.--clearnow refuses a directory that is a link, and some wording was fixed.teardown: falsecompares the whole list of executors.Declined review findings
ignore_errorfor a teardown executor left from a pass with other settings (teardown off,teardown_on_erroron) is declined. The README already says to chain gateways with this plugin only with the same settings.--clearvs--key/--filerule with an argparse mutually exclusive group is declined. argparse can't express "either--clear, or both--keyand--file", so the checks stay explicit and tested.Open questions
None.
Closes #67
🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV