Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit bada352

Browse files
authored
Include a reason when a task has never started (#3148)
* Include a reason to mark a task as failed * mark dependent task cancelled when the task is cancelled * cleanup * build fix
1 parent 5d8f245 commit bada352

File tree

9 files changed

+26
-19
lines changed

9 files changed

+26
-19
lines changed

docs/webhook_events.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,8 @@ If webhook is set to have Event Grid message format then the payload will look a
11831183
481,
11841184
482,
11851185
483,
1186-
484
1186+
484,
1187+
485
11871188
],
11881189
"title": "ErrorCode"
11891190
},
@@ -1829,7 +1830,8 @@ If webhook is set to have Event Grid message format then the payload will look a
18291830
481,
18301831
482,
18311832
483,
1832-
484
1833+
484,
1834+
485
18331835
],
18341836
"title": "ErrorCode"
18351837
}
@@ -2774,7 +2776,8 @@ If webhook is set to have Event Grid message format then the payload will look a
27742776
481,
27752777
482,
27762778
483,
2777-
484
2779+
484,
2780+
485
27782781
],
27792782
"title": "ErrorCode"
27802783
}
@@ -3501,7 +3504,8 @@ If webhook is set to have Event Grid message format then the payload will look a
35013504
481,
35023505
482,
35033506
483,
3504-
484
3507+
484,
3508+
485
35053509
],
35063510
"title": "ErrorCode"
35073511
},
@@ -5579,7 +5583,8 @@ If webhook is set to have Event Grid message format then the payload will look a
55795583
481,
55805584
482,
55815585
483,
5582-
484
5586+
484,
5587+
485
55835588
],
55845589
"title": "ErrorCode"
55855590
},

src/ApiService/ApiService/Functions/AgentEvents.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
250250

251251
if (done.ExitStatus.Success) {
252252
_log.Info($"task done. {task.JobId:Tag:JobId}:{task.TaskId:Tag:TaskId} {done.ExitStatus:Tag:Status}");
253-
await _context.TaskOperations.MarkStopping(task);
253+
await _context.TaskOperations.MarkStopping(task, "task is done");
254254

255255
// keep node if keep-on-completion is set
256256
if (task.Config.Debug?.Contains(TaskDebugFlag.KeepNodeOnCompletion) == true) {

src/ApiService/ApiService/Functions/Tasks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private async Async.Task<HttpResponseData> Delete(HttpRequestData req) {
170170

171171
}
172172

173-
await _context.TaskOperations.MarkStopping(task);
173+
await _context.TaskOperations.MarkStopping(task, "task is deleted");
174174

175175
var response = req.CreateResponse(HttpStatusCode.OK);
176176
await response.WriteAsJsonAsync(task);

src/ApiService/ApiService/Functions/TimerTasks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public async Async.Task Run([TimerTrigger("00:00:15")] TimerInfo myTimer) {
2626
var expriredTasks = _taskOperations.SearchExpired();
2727
await foreach (var task in expriredTasks) {
2828
_logger.Info($"stopping expired task. job_id:{task.JobId:Tag:JobId} task_id:{task.TaskId:Tag:TaskId}");
29-
await _taskOperations.MarkStopping(task);
29+
await _taskOperations.MarkStopping(task, "task is expired");
3030
}
3131

3232

src/ApiService/ApiService/OneFuzzTypes/Enums.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public enum ErrorCode {
3939
UNEXPECTED_DATA_SHAPE = 482,
4040
UNABLE_TO_SEND = 483,
4141
NODE_DELETED = 484,
42+
TASK_CANCELLED = 485,
4243
// NB: if you update this enum, also update enums.py
4344
}
4445

src/ApiService/ApiService/onefuzzlib/JobOperations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public async Async.Task<Job> Stopping(Job job) {
111111

112112
if (notStopped.Any()) {
113113
foreach (var task in notStopped) {
114-
await _context.TaskOperations.MarkStopping(task);
114+
await _context.TaskOperations.MarkStopping(task, "job is stopping");
115115
}
116116
} else {
117117
job = job with { State = JobState.Stopped };

src/ApiService/ApiService/onefuzzlib/TaskOperations.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface ITaskOperations : IStatefulOrm<Task, TaskState> {
1919
Result<IEnumerable<Container>?, TaskConfigError> GetInputContainerQueues(TaskConfig config);
2020

2121
IAsyncEnumerable<Task> SearchExpired();
22-
Async.Task MarkStopping(Task task);
22+
Async.Task MarkStopping(Task task, string reason);
2323
Async.Task MarkFailed(Task task, Error error, List<Task>? taskInJob = null);
2424

2525
Async.Task<TaskVm?> GetReproVmConfig(Task task);
@@ -99,14 +99,14 @@ public IAsyncEnumerable<Task> SearchExpired() {
9999
return QueryAsync(filter: filter);
100100
}
101101

102-
public async Async.Task MarkStopping(Task task) {
102+
public async Async.Task MarkStopping(Task task, string reason) {
103103
if (task.State.ShuttingDown()) {
104104
_logTracer.Verbose($"ignoring post - task stop calls to stop {task.JobId:Tag:JobId}:{task.TaskId:Tag:TaskId}");
105105
return;
106106
}
107107

108108
if (!task.State.HasStarted()) {
109-
await MarkFailed(task, Error.Create(ErrorCode.TASK_FAILED, "task never started"));
109+
await MarkFailed(task, Error.Create(ErrorCode.TASK_CANCELLED, reason, "task never started"));
110110
} else {
111111
_ = await SetState(task, TaskState.Stopping);
112112
}
@@ -124,16 +124,16 @@ public async Async.Task MarkFailed(Task task, Error error, List<Task>? taskInJob
124124
_logTracer.Info($"task failed {task.JobId:Tag:JobId}:{task.TaskId:Tag:TaskId} - {error:Tag:Error}");
125125

126126
task = await SetState(task with { Error = error }, TaskState.Stopping);
127-
await MarkDependantsFailed(task, taskInJob);
128-
}
129-
130-
private async Async.Task MarkDependantsFailed(Task task, List<Task>? taskInJob = null) {
131127
taskInJob ??= await SearchByPartitionKeys(new[] { $"{task.JobId}" }).ToListAsync();
132128

129+
var dependentError =
130+
error.Code == ErrorCode.TASK_CANCELLED
131+
? Error.Create(ErrorCode.TASK_CANCELLED, $"prerequisite task is cancelled.")
132+
: Error.Create(ErrorCode.TASK_FAILED, $"prerequisite task is failed.");
133133
foreach (var t in taskInJob) {
134134
if (t.Config.PrereqTasks != null) {
135135
if (t.Config.PrereqTasks.Contains(task.TaskId)) {
136-
await MarkFailed(t, Error.Create(ErrorCode.TASK_FAILED, $"prerequisite task failed. task_id:{t.TaskId}"), taskInJob);
136+
await MarkFailed(t, dependentError, taskInJob);
137137
}
138138
}
139139
}

src/ApiService/IntegrationTests/AgentEventsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ await Context.InsertAll(
123123
}
124124

125125
[Fact]
126-
public async Async.Task WorkerDone_ForNonStartedTask_MarksTaskAsFailed() {
126+
public async Async.Task WorkerDone_ForNonStartedTask_MarksTaskAsCancelled() {
127127
await Context.InsertAll(
128128
new Node(_poolName, _machineId, _poolId, _poolVersion),
129129
// task state is scheduled, not running
@@ -148,7 +148,7 @@ await Context.InsertAll(
148148

149149
// should be failed - it never started running
150150
Assert.Equal(TaskState.Stopping, task.State);
151-
Assert.Equal(ErrorCode.TASK_FAILED, task.Error?.Code);
151+
Assert.Equal(ErrorCode.TASK_CANCELLED, task.Error?.Code);
152152
}
153153

154154
[Fact]

src/pytypes/onefuzztypes/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ class ErrorCode(Enum):
291291
UNEXPECTED_DATA_SHAPE = 482
292292
UNABLE_TO_SEND = 483
293293
NODE_DELETED = 484
294+
TASK_CANCELLED = 485
294295
# NB: if you update this enum, also update Enums.cs
295296

296297

0 commit comments

Comments
 (0)