feat(ao): W4-E3 manual organize guard, series completion, engine retry, v0.1.0
- POST /organization-records: sourcePaths must resolve (realpath) under a
registered library_root or downloader path-mapping host path; `..` and
symlink escapes rejected (400), dryRun included. Move requires an admin
session, or an API key with an automation_grant covering the entity or a
matching one-time approval (consumed on use), else 403. Manual Move from a
managed download_task with unsatisfied H&R returns 409 and opens a
decision; never silently downgraded to Copy.
- Series slot completion: total episode count is unknown while units are
provisional, so the slot is not satisfied and the subscription keeps
tracking; coverage is registered per actual file (creating provisional
episode units), and already_in_library files count as verified presence.
- POST /engine/runs/{id}/retry (admin): re-enqueue by original task name and
raw input with idempotency key retry:<id>:<n>, audited; retry button on
the run detail page.
- E7 regular series e2e, E8 AT24 tag removal / task disappearance e2e.
- All workspace members and root set to version 0.1.0; CHANGELOG.md.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
591cc78c7d
commit
ceff9cf51f
25 files changed
+1566
-57
No files matched your search
@@ -56,8 +56,20 @@ const D = {
|
||||
response: EngineCancelResult,
|
||||
tags,
|
||||
},
|
||||
retry: {
|
||||
method: "post",
|
||||
path: "/engine/runs/{id}/retry",
|
||||
scope: "admin",
|
||||
summary: "按原任务名与输入重新入队(新幂等键 retry:<id>:<序号>)",
|
||||
params: RunIdParam,
|
||||
response: z.object({ runId: z.string(), retryOf: z.string(), attempt: z.number().int().positive() }),
|
||||
tags,
|
||||
},
|
||||
} as const satisfies Record<string, Def>;
|
||||
|
||||
/** 可重跑的终态(运行中/待执行的 run 先取消再重跑) */
|
||||
const RETRYABLE = new Set(["completed", "succeeded", "failed", "canceled"]);
|
||||
|
||||
const NAMESPACE = "default";
|
||||
const iso = (d: Date | null) => (d ? d.toISOString() : null);
|
||||
|
||||
@@ -257,4 +269,39 @@ export function registerEngineRoutes(app: ModuleApp, ctx: ServerContext, opts: {
|
||||
);
|
||||
return { canceled };
|
||||
});
|
||||
// 重跑:读原 run 的任务名与信封里的原始输入(不经脱敏),以新幂等键重新入队;业务侧幂等仍由各任务的 op 账本保证
|
||||
endpoint(app, D.retry, async ({ params, actor }) => {
|
||||
const t = sql.raw(`"${opts.schema ?? "openworkflow"}".workflow_runs`);
|
||||
const r = await sql<{ workflow_name: string; status: string; input: unknown }>`
|
||||
select workflow_name, status, input from ${t} where namespace_id = ${NAMESPACE} and id = ${params.id}`.execute(
|
||||
ctx.db,
|
||||
);
|
||||
const run = r.rows[0];
|
||||
if (!run) throw new ApiException("not_found", `run ${params.id} 不存在`);
|
||||
if (!RETRYABLE.has(run.status))
|
||||
throw new ApiException("conflict", `run 状态为 ${run.status},只能重跑已结束的 run(可先取消)`);
|
||||
const env = (run.input ?? {}) as { input?: unknown; traceId?: string; priority?: number };
|
||||
const prefix = `retry:${params.id}:`;
|
||||
const prev = await sql<{ n: number }>`
|
||||
select count(*)::int as n from tasks_run_meta where idempotency_key like ${`${prefix}%`}`.execute(ctx.db);
|
||||
const attempt = (prev.rows[0]?.n ?? 0) + 1;
|
||||
let runId: string;
|
||||
try {
|
||||
({ runId } = await ctx.engine.enqueue(run.workflow_name, "input" in env ? env.input : {}, {
|
||||
idempotencyKey: `${prefix}${attempt}`,
|
||||
traceId: env.traceId ?? `retry:${params.id}`,
|
||||
...(typeof env.priority === "number" ? { priority: env.priority } : {}),
|
||||
}));
|
||||
} catch (err) {
|
||||
throw new ApiException("precondition_failed", `无法重新入队:${(err as Error).message}`);
|
||||
}
|
||||
await audit(
|
||||
ctx,
|
||||
actor,
|
||||
"engine.run_retry",
|
||||
{ type: "engine_run", id: params.id },
|
||||
{ workflowName: run.workflow_name, newRunId: runId, attempt },
|
||||
);
|
||||
return { runId, retryOf: params.id, attempt };
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user