feat(FN-1465): merge fusion/fn-1465

This commit is contained in:
gsxdsm
2026-04-12 07:00:49 -07:00
parent 86f1f93de9
commit 8f0bcf7f00
58 changed files with 3890 additions and 1696 deletions

View File

@@ -9,11 +9,17 @@ const NON_STUCK_STATUSES = new Set(["failed", "stuck-killed"]);
* - It is in the "in-progress" column
* - A positive `taskStuckTimeoutMs` value is provided (stuck detection enabled)
* - Its `updatedAt` timestamp is older than `taskStuckTimeoutMs` milliseconds ago
* compared to `dataAsOfMs` (or `Date.now()` if `dataAsOfMs` is not provided)
*
* When `taskStuckTimeoutMs` is undefined, null, or 0, stuck detection is
* disabled and this function always returns false.
*
* The optional `dataAsOfMs` parameter represents when the task data was last
* confirmed fresh by the server. When provided, it is used instead of `Date.now()`
* for the comparison. This prevents false positives when the tab has been in
* the background and the task data is stale.
*/
export function isTaskStuck(task: Task, taskStuckTimeoutMs: number | undefined): boolean {
export function isTaskStuck(task: Task, taskStuckTimeoutMs: number | undefined, dataAsOfMs?: number): boolean {
if (task.column !== "in-progress") {
return false;
}
@@ -27,7 +33,8 @@ export function isTaskStuck(task: Task, taskStuckTimeoutMs: number | undefined):
}
const updatedAt = new Date(task.updatedAt).getTime();
const now = Date.now();
// Use dataAsOfMs if provided, otherwise fall back to current time
const now = dataAsOfMs ?? Date.now();
return now - updatedAt > taskStuckTimeoutMs;
}
@@ -35,15 +42,18 @@ export function isTaskStuck(task: Task, taskStuckTimeoutMs: number | undefined):
* Derive the stuck task count from a list of tasks using the given threshold.
*
* Returns 0 when stuck detection is disabled (undefined/0 threshold).
*
* The optional `dataAsOfMs` parameter is passed through to `isTaskStuck()` for
* freshness-aware stuck detection.
*/
export function countStuckTasks(tasks: Task[], taskStuckTimeoutMs: number | undefined): number {
export function countStuckTasks(tasks: Task[], taskStuckTimeoutMs: number | undefined, dataAsOfMs?: number): number {
if (!taskStuckTimeoutMs || taskStuckTimeoutMs <= 0) {
return 0;
}
let count = 0;
for (const task of tasks) {
if (isTaskStuck(task, taskStuckTimeoutMs)) {
if (isTaskStuck(task, taskStuckTimeoutMs, dataAsOfMs)) {
count++;
}
}