fix(FN-4823): tighten lease recovery audit semantics

Fusion-Task-Id: FN-4823
Fusion-Task-Lineage: 0034c04f-df82-4a1b-9f25-b93643a2c157
This commit is contained in:
Fusion (runfusion.ai)
2026-05-16 21:20:44 -07:00
committed by gsxdsm
parent a9dfb17b3d
commit 405d24f9ab
2 changed files with 4 additions and 2 deletions

View File

@@ -270,6 +270,7 @@ describe("MeshLeaseManager", () => {
expect(ok).toBe(true);
expect(taskStore.updateTask).toHaveBeenCalled();
expect(recordRunAuditEvent.mock.calls.some((call) => call[0].mutationType === "task:auto-recover-lease-already-healed")).toBe(true);
expect(recordRunAuditEvent.mock.calls.some((call) => call[0].mutationType === "task:auto-recover-lease-released")).toBe(false);
});
it("returns false when central claim release remains unavailable after retry", async () => {

View File

@@ -402,8 +402,9 @@ export class MeshLeaseManager {
// FN-4823/FN-4819 §2.5: without central claim store, retain local-only recovery behavior.
const nextEpoch = (task.checkoutLeaseEpoch ?? 0) + 1;
let centralResult: "released" | "already-healed" | "foreign-owner" | "unavailable" = "released";
if (this.options.centralClaimStore && this.options.projectId) {
const centralResult = await this.releaseCentralClaim(task, `${reason} (${stale.reason ?? "stale"})`, nextEpoch);
centralResult = await this.releaseCentralClaim(task, `${reason} (${stale.reason ?? "stale"})`, nextEpoch);
if (centralResult === "foreign-owner" || centralResult === "unavailable") {
return false;
}
@@ -427,7 +428,7 @@ export class MeshLeaseManager {
}
}
if (this.options.centralClaimStore && this.options.projectId) {
if (this.options.centralClaimStore && this.options.projectId && centralResult === "released") {
await this.emitLeaseAudit(task, "task:auto-recover-lease-released", {
priorOwnerNodeId: task.checkoutNodeId ?? null,
priorOwnerAgentId: task.checkedOutBy ?? null,