Repository navigation
fix: serve the backend's logs in the view FULL - #419
Conversation
Get a finished task once more in the view `FULL` from its backend, and store its stdout, stderr and system logs, at most `post_task.max_log_size` per task, keeping the end of longer ones. A failure of this request keeps the final state and the rest of the logs. Closes #413 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Extract the share of logs into a function with its own tests, and state in the docs that a failure of the one request leaves a task without logs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Findings of the review of the view FULL: - Limit responses of the view FULL of configured backends as well, as logs of any size could exhaust the memory of a worker, again with each delivery of the poll. - Store a task with less if MongoDB refuses it, instead of retrying forever (many short logs aren't covered by the size limit). - Get the logs before storing the final state, for clients that read them once, right after it. - Keep no log texts at all with max_log_size 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Findings of the second review round: - Store the final state and the logs in one update, as clients may read them once, and only the state alone if that fails. - Skip the view FULL when a poll is delivered again, so that a response that cost a worker can't keep a task from finishing. - Limit the time of reading the view FULL as a whole. - Store with less also if values can't be encoded. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideCompleted tasks now make a bounded, best-effort FULL-view fetch for backend logs and atomically persist those logs with the final state, with response, memory, redelivery, and MongoDB-size safeguards plus documentation and test coverage. Sequence diagram for fetching and storing completed task logssequenceDiagram
participant Worker as CeleryWorker
participant TES as TESBackend
participant DB as MongoDB
Worker->>TES: get_task(remote_task_id, view=BASIC)
TES-->>Worker: Finished task state
opt first delivery and max_log_size > 0
Worker->>TES: get_task(remote_task_id, view=FULL)
TES-->>Worker: State, stdout, stderr, system_logs, outputs
end
Worker->>Worker: _limit_logs(logs, max_log_size)
Worker->>DB: _store_within_limit(state, logs, outputs)
DB-->>Worker: Final state and logs stored atomically
Flow diagram for resilient final task storageflowchart TD
A[Finished task received] --> B{Poll redelivered?}
B -->|No| C[Fetch FULL view]
B -->|Yes| D[Use last poll response]
C --> E{FULL fetch succeeds with same state?}
E -->|No| D
E -->|Yes| F[Limit log texts]
D --> F
F --> G{MongoDB accepts state and logs?}
G -->|Yes| H[Tracking ends]
G -->|No: document too large or invalid| I[Drop log texts]
I --> J{MongoDB accepts reduced task?}
J -->|Yes| H
J -->|No| K[Drop executor logs and outputs]
K --> L{MongoDB accepts state?}
L -->|Yes| H
L -->|No| M[Store state only and log error]
File-Level Changes
Possibly linked issues
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 #419 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 24 24
Lines 2542 2642 +100
==========================================
+ Hits 2542 2642 +100 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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="pro_tes/ga4gh/tes/backends.py" line_range="1062" />
<code_context>
+ content = bytearray()
+ deadline = time.monotonic() + timeout
+ with response:
+ for chunk in response.iter_content(chunk_size=RESPONSE_CHUNK_SIZE):
+ content += chunk
+ if len(content) > MAX_RESPONSE_SIZE:
</code_context>
<issue_to_address>
**Body reads exceed timeout**
When a backend slowly streams a response without triggering the per-read timeout, `read_limited` checks the deadline only after `iter_content` yields a chunk, so a blocking read can keep a worker occupied beyond `custom.tes.timeout` before the timeout is raised.
Limit each blocking body read to the time remaining before the whole-request deadline.
Also at `pro_tes/ga4gh/tes/backends.py:1069-1071`.
</issue_to_address>
### Comment 2
<location path="pro_tes/ga4gh/tes/backends.py" line_range="925" />
<code_context>
+ if limited:
+ return read_limited(
+ requests.request(
+ method, url, timeout=timeout, stream=True, **kwargs
+ ),
+ timeout=timeout[1],
</code_context>
<issue_to_address>
**Header reads exceed timeout**
When a backend slowly sends response headers while avoiding the per-read timeout, `requests.request` waits for the headers before `read_limited` starts its deadline, so the request can keep a worker blocked beyond `custom.tes.timeout` and delay task completion.
Apply the whole-request deadline while waiting for response headers as well as while reading the body.
Also at `pro_tes/ga4gh/tes/backends.py:1060`.
</issue_to_address>
### Comment 3
<location path="pro_tes/tasks/track_task_progress.py" line_range="328-330" />
<code_context>
+ mode="json", exclude_none=True, include={"state", "logs"}
+ ),
+ )
+ except (InvalidDocument, UnicodeEncodeError, OperationFailure) as exc:
+ if isinstance(exc, OperationFailure) and exc.code not in TOO_LARGE_CODES:
+ raise
+ logger.error(
+ "[%s] Logs of the finished task can't be stored: %s",
</code_context>
<issue_to_address>
**Oversized documents keep retrying**
When mongoDB's client-side BSON encoding rejects the final document as too large, `DocumentTooLarge` is not included in the caught exception types, so `_store_within_limit` propagates the client-side size refusal instead of dropping log data and retrying the write. `_poll` then retries the final task indefinitely rather than finishing tracking.
Catch `DocumentTooLarge` alongside the other document-size failures so the fallback reductions run.
</issue_to_address>
### Comment 4
<location path="pro_tes/tasks/track_task_progress.py" line_range="229" />
<code_context>
+ worker_id,
+ )
+ return basic
+ return full
+
+
</code_context>
<issue_to_address>
**BASIC outputs are lost**
When the BASIC poll contains outputs and the FULL response has missing, null, or empty logs, `_full_task` accepts the FULL response, so `_store_final` either fails or stores no outputs from it; the outputs from the BASIC poll are lost.
Treat a FULL response without logs as unavailable and use the BASIC response as the fallback.
Also at `pro_tes/tasks/track_task_progress.py:214`.
</issue_to_address>
### Comment 5
<location path="pro_tes/tasks/track_task_progress.py" line_range="523-530" />
<code_context>
+ return
+ # not if the message is delivered again: getting the logs may have cost its
+ # worker (e.g., out of memory), which must not keep the task from finishing
+ if not redelivered:
+ response = _full_task(
+ cli=cli,
+ worker_id=worker_id,
+ remote_task_id=kwargs["remote_task_id"],
+ basic=response,
+ )
+ try:
+ _store_final(db_client=db_client, worker_id=worker_id, response=response)
+ except Exception:
</code_context>
<issue_to_address>
**Redelivery erases stored logs**
When the worker commits the final state and FULL logs, then dies before Celery acknowledges its late-ack message, the redelivered poll skips `_full_task` but still passes the BASIC response to `_store_final`, which replaces the stored executor and system logs with the BASIC response’s omitted log text. Users permanently lose logs that were already committed.
On redelivery, avoid replacing already-stored final logs with BASIC-view logs; preserve the committed final data or make the final write conditional on the task not already being finalized.
</issue_to_address>
### Comment 6
<location path="tests/tasks/test_track_task_progress.py" line_range="348" />
<code_context>
+ error: Exception,
+) -> None:
+ """A failure to get the logs doesn't lose the final state and the outputs."""
+ client_class.full_error = error
+ run()
+ document = tasks.find_one({"worker_id": ARGS["worker_id"]})
</code_context>
<issue_to_address>
**Fetch failure path goes untested**
When the `FULL` fetch is removed or bypassed, `test_full_logs_unavailable` only checks the final state, outputs, and scheduling; it never asserts that the `FULL` request was attempted. If `_poll` stops fetching `FULL`, the configured error is unused and the test passes.
Assert that `client_class.views` includes `FULL` in this test.
</issue_to_address>
### Comment 7
<location path="tests/tasks/test_track_task_progress.py" line_range="375" />
<code_context>
+ assert document is not None
+ assert document["task"]["state"] == "QUEUED"
+ assert kwargs["state"] == "COMPLETE"
+ assert kwargs["logs"]
+ return upsert(self, **kwargs)
+
</code_context>
<issue_to_address>
**Atomic write can omit backend logs**
When the `FULL` response's log texts are omitted while existing task-log entries remain, `test_full_logs_with_final_state` accepts any truthy `kwargs["logs"]`; the existing task-log entry is truthy even when it contains no backend log text. The final state can therefore be written with stale logs and the test still passes.
Configure nonempty FULL log texts and assert that those texts are included in the same upsert as the final state.
</issue_to_address>Linked issues
#413 fix: serve the backend's logs in the view FULL · 7 of 7 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | When a task is final, get it once with view FULL | ✅ Met | The final-poll path makes one FULL request unless the poll was redelivered or log retrieval is disabled. |
| 2 | If that request fails, keep what the last poll got so the final state is not lost | ✅ Met | A failed fetch or a FULL response reporting another state falls back to the last poll's task before storing the final result. |
| 3 | Store stdout, stderr and system_logs | ✅ Met | Final-task storage copies executor logs and system logs into the stored task. |
| 4 | Limit the size of those logs per task | ✅ Met | The configurable per-task limit covers stdout, stderr and system logs; longer texts are truncated, and storage has further fallbacks if MongoDB refuses the document. |
| 5 | Add tests | ✅ Met | Tests cover FULL retrieval, fetch failures, log limits and storage fallbacks. |
| 6 | Add a smoke case | ✅ Met | The smoke test checks that FULL includes backend logs and BASIC omits them. |
| 7 | Update the docs | ✅ Met | API, configuration and upgrading docs describe the FULL-view logs and their limits. |
Sourcery assessment
Needs a human reviewer. 7 findings to address first, and with the default enabled, proTES fetches and persistently stores backend logs that task owners can read through the FULL view; logs may contain secrets, and the change makes that collection the default without a failure signal. Reverting stops future collection but does not remove logs already stored, and the per-task cap does not bound exposure across tasks.
Blocking findings: pro_tes/ga4gh/tes/backends.py:1062, pro_tes/ga4gh/tes/backends.py:925, pro_tes/tasks/track_task_progress.py:330, pro_tes/tasks/track_task_progress.py:229, pro_tes/tasks/track_task_progress.py:530, and 2 more
Findings of the automated review: - A poll delivered again after a task was stored no longer replaces its logs with those of the view BASIC. - A view FULL without logs no longer loses the outputs of the last poll. - Read limited responses with single reads, as whole chunks can take any time, which the time limit didn't cover. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in the review fixes #410, #412, #417, #419, #420, #421. The only conflict is in the module docstring of `pro_tes/ga4gh/tes/backends.py`: keeps this branch's removal of the FOCA 0.19 caveat about redirects, and the sentence of #419 about tasks in the view `FULL`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes #413
Summary
docs/api.mdpromised backend logs in the viewFULL, but proTES only polled in the viewBASIC, which has none. Now a finished task is got once more in the viewFULL.system_logs, at mostpost_task.max_log_sizeper task (default 1 MiB, at most 8 MiB,0turns it off): short logs are kept, the longer ones share the rest and keep their end.FULLare limited to 64 MiB andcustom.tes.timeoutas a whole, also for configured backends.docs/api.md,docs/configuration.md,docs/upgrading.md.FULL;check.shasserts them forFULLand their absence forBASIC.Verification
python -m pytestwith real Helm: all passed.pre-commit run --from-ref origin/dev --to-ref HEAD: passed.DocumentTooLargeand server-side code 10334 both end in a stored task.Test (MongoDB 7.0)in CI runstest_too_many_logs.Declined review findings
except Exceptionin_full_task, logging the type name only: messages of py-tes errors contain the whole task; no database call runs inside it.FULLfetch: best effort, documented indocs/api.md.requestsreads them whole: these backends are chosen by the admin; the module's docstring has the same gap for FOCA's client.FULLfetch may meet a refusal of the backend: answered by the re-read in Small findings of the 0.5.0 review #418.docs/configuration.md.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Retrieve and safely persist completed TES backend logs in the
FULLview while protecting task completion from oversized responses and storage failures.New Features:
FULLview, including executor stdout/stderr and system logs.Bug Fixes:
FULLlog fetches for redelivered polls so completed tasks can still finish.Enhancements:
FULLtask requests for all backend types.Documentation:
FULL-view backend logs, log size configuration, failure behavior, and upgrade considerations.Tests:
FULL.