Repository navigation
feat: report the CANCELING and PREEMPTED states - #151
Conversation
GET /tasks accepts the TES 1.1 filters state, tag_key and tag_value. Before, Spring ignored them and listed all tasks. - state takes every tesState of TES 1.1; TesState gets CANCELING and PREEMPTED so that they are accepted (TESK doesn't report them yet). Other values give 400 naming the parameter. - tag_key/tag_value are zipped into tags, matched as in the specification's table; more values than keys give 400. Commas stay part of a key or value (Spring would split a single value). - Name and tags filter the taskmaster jobs of a page before the other jobs are listed, the state once they are; pages can be shorter, as with name_prefix. - The parameters are in the API description, the arrays with collectionFormat multi. Closes #143 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Review fixes for the task filters: - A repeated tag_key is one more tag that must match, instead of its last value replacing the others (an empty one widened the filter). - Empty tag_key and empty extra tag_value parameters filter nothing, like an empty name_prefix or state. - The converter reads the tags of the stored task, with the parser it uses for the number of executors, instead of a second ObjectMapper in the service. - PREEMPTED counts as ended for cancelling; TaskFilter gets hasState. - Tests for null tag values and for invalid states not being echoed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Round-2 review fixes: converter tests for extractTags, a null filter value matches any value (as an empty one) instead of failing, and the docs say that values keep their positions after an empty tag_key. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
The patch coverage of Codecov needs both branches of the null checks in zipTags. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
As the issue asks, more tag_values than tag_keys give 400, also empty ones. The docs say that the state filter uses the state the response reports, read with several requests to Kubernetes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
TES 1.1 narrows CANCELED to cancelled tasks whose resources are gone, and adds CANCELING and PREEMPTED. - A cancelled task is CANCELING while any of its jobs (taskmaster, executors, outputs filer) has a pod that hasn't ended, or one that Kubernetes counts as active; then CANCELED. Getting a single task now also reads the outputs filer's pods. - Cancelling a CANCELING task answers 200 and patches nothing; a PREEMPTED task has ended and can't be cancelled. - A failed executor is PREEMPTED if its pods have DisruptionTarget=True with PreemptionByScheduler, TerminationByKubelet, DeletionByTaintManager or EvictionByEvictionAPI, and every failed pod has it; if any failed executor failed otherwise, EXECUTOR_ERROR. - The decision table of TaskStateResolverTest covers the new rules; docs/index.md describes them, and that Kubernetes deletes most disrupted pods soon, after which the task is EXECUTOR_ERROR. Closes #144 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
From the review of the CANCELING state: - Cancelling a CANCELING task labels a running taskmaster pod that lacks the label (labelling it failed before, or Kubernetes restarted the taskmaster), instead of answering 200 without effect. - A pod still listed after its deletion time (the end of its grace period, e.g. on a node that is gone) counts as ended, so it doesn't keep a cancelled task CANCELING until the node is removed. - Getting a task reads the outputs filer's pods only if the task is cancelled, the only rule that needs them. - Tests: a failed pod without disruption next to a disrupted running one is EXECUTOR_ERROR; the tested disruption reasons are all of them; cancel-test helpers set the job status explicitly. - docs/index.md: the deletion time, that the inputs filer isn't read, the re-labelling; the retries paragraph is its own paragraph again. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
From the second review: - Relabelling a running taskmaster pod of a CANCELING task skips a pod that can't be patched (e.g. gone in between), like pending pods, so the request still answers 200: the job's label decides. - A pod counts as ended one minute after its deletion time, not right at it, to allow for clocks of TESK API and the API server that differ. - TaskStateResolver.isLabelledCancelled holds the label check for jobs and pods. - docs/index.md: rules 1 and 2 are short again; what keeps a task CANCELING has its own paragraph; paragraphs are re-wrapped. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Reviewer's GuideImplementationResolve cancelled tasks as CANCELING until their jobs’ pods have ended, and classify disrupted executor failures as PREEMPTED.
Define the Kubernetes pod phases used by the resolver to distinguish ended pods.
DocumentationDocument the CANCELING and PREEMPTED state rules, cancellation behavior, and the state-filter reference.
TestsUpdate state-resolution tests to cover cancellation until pods end and the disruption criteria for PREEMPTED.
Adjust converter tests and expectations for tasks newly reported as CANCELING.
Verify cancellation behavior for CANCELING tasks, outputs-filer pods, and ended PREEMPTED tasks.
Update list-filter tests to expect CANCELING for tasks whose cancellation is still in progress.
Check integration filtering for CANCELING and confirm those tasks are not returned under CANCELED.
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 #151 +/- ##
==========================================
+ Coverage 72.98% 73.66% +0.68%
==========================================
Files 70 70
Lines 2946 3019 +73
Branches 330 345 +15
==========================================
+ Hits 2150 2224 +74
Misses 655 655
+ Partials 141 140 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit a400352 #144 feat: report the CANCELING and PREEMPTED states · 5 of 6 met
|
There was a problem hiding this comment.
Hey - I've found 5 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java" line_range="401" />
<code_context>
+ private void labelPodAsCancelledIfPossible(String podName, String why) {
try {
this.kubernetesClientWrapper.labelPodAsCancelled(podName);
} catch (KubernetesException e) {
logger.info(
- "Pending pod {} of a cancelled task not labelled (HTTP {}); its job ends anyway",
</code_context>
<issue_to_address>
**Cancellation succeeds after label failure**
When the pod-label PATCH fails for a reason other than the pod being gone, `labelPodAsCancelledIfPossible` catches the `KubernetesException`, so `cancelTask` returns successfully without delivering the pod label and the taskmaster keeps running its executors.
Propagate Kubernetes errors other than a missing-pod error from `labelPodAsCancelledIfPossible` so `cancelTask` does not report success.
Also at `src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java:402-406`.
</issue_to_address>
### Comment 2
<location path="src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java" line_range="388" />
<code_context>
+ boolean running =
+ pod.getStatus() != null
+ && PodPhase.RUNNING.getCode().equals(pod.getStatus().getPhase());
+ return running && !TaskStateResolver.isLabelledCancelled(pod.getMetadata());
}
</code_context>
<issue_to_address>
**Replacement taskmaster misses cancellation**
When a repeated cancel arrives while a replacement taskmaster pod is pending, `isRunningAndNotLabelledCancelled` excludes that pod from the `cancelTask` stream, so no pod label is applied and the taskmaster continues processing after the pod starts.
Include pending replacement pods that lack the cancellation label when selecting pods to label.
Also at `src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java:351`.
</issue_to_address>
### Comment 3
<location path="src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TaskStateResolver.java" line_range="96" />
<code_context>
+ * canceling. The slack allows for clocks of TESK API and the API server that differ.
+ */
+ private static boolean hasEnded(V1Pod pod) {
+ if (pod.getStatus() != null && ENDED_POD_PHASES.contains(pod.getStatus().getPhase())) {
+ return true;
+ }
</code_context>
<issue_to_address>
**Terminal pods skip deletion grace**
When a cancelled pod reaches `Succeeded` or `Failed` before its deletion timestamp plus 60 seconds, `hasEnded` returns true for `Succeeded` or `Failed` before checking the deletion timestamp, so the resolver reports `CANCELED` while that pod is still within its deletion grace period and terminating.
When a pod has a deletion timestamp, apply the deletion-time grace rule before treating its phase as ended.
</issue_to_address>
### Comment 4
<location path="src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TaskStateResolver.java" line_range="103" />
<code_context>
+ Optional.ofNullable(pod.getMetadata())
+ .map(V1ObjectMeta::getDeletionTimestamp)
+ .orElse(null);
+ return deletion != null && deletion.plusSeconds(DELETION_SLACK_SECONDS).isBeforeNow();
+ }
+
</code_context>
<issue_to_address>
**Filtered state differs from response**
When A task has a pod whose deletion timestamp is within the one-minute cutoff of the two state-resolution calls, `listTasks` resolves state once to apply the filter, then the task converter resolves it again to build the response. If the deletion-time cutoff passes between those calls, a task can match `CANCELING` but be returned as `CANCELED` (or vice versa), contrary to the documented filter behavior.
Resolve each task's state once and reuse that value for both filtering and response conversion.
</issue_to_address>
### Comment 5
<location path="src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java" line_range="346-358" />
<code_context>
+ if (state == TesState.CANCELING) {
</code_context>
<issue_to_address>
**Repeated cancel patches pod**
The issue requires a `CANCELING` cancellation to patch nothing, but this branch labels a running taskmaster pod when its cancellation label is missing. Already-labeled pods are left untouched, but the requirement is not met in every case.
</issue_to_address>Sourcery assessment
Approval pending. 5 findings to address first.
Blocking findings: src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java:401, src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java:388, src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TaskStateResolver.java:96, src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TaskStateResolver.java:103, src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java:358
From Sourcery: cancelling a CANCELING task also labels a pending taskmaster pod without the label (e.g. a restarted taskmaster), and only a pod that is gone (404) is skipped; other errors fail the request, as only the pod's label stops the taskmaster. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
… feat/144-canceling-preempted # Conflicts: # src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java
…empted # Conflicts: # docs/api.md # src/integration-test/java/uk/ac/ebi/tsc/tesk/NoAuthIT.java # src/test/java/uk/ac/ebi/tsc/tesk/tes/api/TasksApiControllerTest.java # src/test/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImplListTest.java
Was stacked on #149, which is merged;
devis merged into this branch.Summary
TES 1.1 narrows
CANCELEDto cancelled tasks whose resources are gone, and addsCANCELINGandPREEMPTED.CANCELINGwhile a job of the task (taskmaster, executors, outputs filer) has a pod that hasn't ended (pending, running, terminating,Unknown, no status yet) or that Kubernetes counts as active; thenCANCELED.CANCELINGuntil the node is removed. The minute allows for clock differences between TESK API and the API server.CANCELEDbefore the inputs filer's pod ended.CANCELINGtask answers200; it only labels a pending or running taskmaster pod that lacks the label (labelling failed before, or Kubernetes restarted the taskmaster), as only the pod's label stops the taskmaster. A pod that is gone (404) is skipped; other errors fail the request. (The issue says "patches nothing"; this deviation is decided: accepted by the maintainer, see the Sourcery thread.)CANCELEDandPREEMPTEDtasks have ended:400.DisruptionTarget=TruewithPreemptionByScheduler,TerminationByKubelet,DeletionByTaintManagerorEvictionByEvictionAPI, and every pod in phaseFailedhas it. The task isPREEMPTEDif every failed executor was disrupted, otherwiseEXECUTOR_ERROR. Pods without the condition (or already deleted) stayEXECUTOR_ERROR.PREEMPTEDis inCOMPLETED_STATES;TesStategot both states in feat: filter tasks by state and tags #149 already.docs/index.md(state rules, a CANCELING paragraph, the PREEMPTED paragraph incl. that Kubernetes deletes most disrupted pods soon, cancelling) anddocs/api.md(the state filter links to the rules).Closes #144
Verification
./mvnw -B spotless:apply clean verify checkstyle:check spotless:checkwith Temurin 8: all unit and integration tests pass,BUILD SUCCESS.TaskStateResolverTest: the decision table gets CANCELING rows per job and PREEMPTED executor rows; each disruption reason; retried executors; executor error winning over preempted; a failed pod without disruption next to a disrupted running one; pods without status or inUnknown; pods past/within/just after their deletion time; active count without pods.TesServiceImplCancelTest: canceling task not patched again; unlabelled running and pending taskmaster pods labelled; a pod that is gone skipped, other errors fail; pod without status skipped; canceled and preempted tasks give400; a running outputs filer keeps the task canceling; filer pods not read for tasks that aren't cancelled.TesServiceImplListTest,TesKubernetesConverterTest,NoAuthIT: expectations moved fromCANCELEDtoCANCELINGwhere pods still run;state=CANCELEDon a canceling task lists none.mkdocs build --strict: passes.Declined review findings
CANCELING: needs a new job lookup in the single and the list path; documented instead (see above).Unknownwithout a deletion timestamp still keeps a taskCANCELING(documented); timing those out would need a configurable limit.Succeeded/Failed(they hold no resources), and resolving the state once for filter and response (both use the same snapshot, milliseconds apart).TesServiceImplCancelTestand flattening theStream.concatinhasActiveJob: style; left as is.Open questions
None. Possible follow-up outside this repo: tesk-core could set a
podFailurePolicyon executor jobs, so that a disruption stays visible on the job after Kubernetes deletes the pod.🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Summary by Sourcery
Add TES 1.1 reporting for task cancellation progression and Kubernetes-preempted executor failures.
New Features:
CANCELINGfor cancelled tasks while task resources remain active, transitioning toCANCELEDonce they have ended.PREEMPTEDfor tasks whose failed executors were disrupted by recognized Kubernetes preemption or eviction events.CANCELINGtasks by completing any necessary taskmaster pod labeling and returning appropriate errors for ended tasks.Bug Fixes:
EXECUTOR_ERRORwhen any failed executor was not disrupted.Enhancements:
Documentation:
CANCELING,CANCELED, andPREEMPTEDstate rules, cancellation behavior, and Kubernetes disruption handling.Tests: