Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix(tables): a lost or cancelled table job frees its company lock and slot after 15 minutes, not an hour

aashuf9b553d39516
diff --git a/.claude/rules/table-csv-export.md b/.claude/rules/table-csv-export.md
index b66800a65f..fb8ee1bffd 100644
--- a/.claude/rules/table-csv-export.md
+++ b/.claude/rules/table-csv-export.md
@@ -188,7 +188,8 @@ list and re-read every loaded page. The steps:
| One part | `{companyId}/exports/{userId}/{exportId}.parts/{n}.csv` (`tableExportPartKey`) |
**The lock.** One Redis key per company and job kind, value = the job id,
-TTL one hour (`TABLE_JOB_LOCK_TTL_SECONDS`). Take, release and extend are each
+TTL 15 minutes (`TABLE_JOB_LOCK_TTL_SECONDS`), so a run Inngest lost or
+cancelled (no `onFailure`) frees its lock and slot within 15 minutes. Take, release and extend are each
one Lua script: `SET NX EX` that returns the TTL on refusal,
compare-and-delete, compare-and-expire. A job deletes or extends only a lock
that still holds its own id. `onFailure` also releases it and deletes the
diff --git a/packages/jobs/src/table-jobs/handlers.ts b/packages/jobs/src/table-jobs/handlers.ts
index 60facb94c6..442714e67d 100644
--- a/packages/jobs/src/table-jobs/handlers.ts
+++ b/packages/jobs/src/table-jobs/handlers.ts
@@ -131,9 +131,13 @@ export function tableJobLockKey(kind: TableJobKind, companyId: string): string {
return `table-job:${kind}:${companyId}`;
}
-/** Seconds a lock lives if its job never deletes it (a crashed process). Each
- * step of a running job sets it back to this (`extendTableJobLock`). */
-export const TABLE_JOB_LOCK_TTL_SECONDS = 60 * 60;
+/**
+ * Seconds a lock (and its slot) lives if its job never deletes it: a crashed
+ * process, or a run Inngest lost or cancelled (`onFailure` does not run then,
+ * and the cancel event does not name the job). Each step sets it back to this
+ * (`extendTableJobLock`), and a step ends within the load balancer's 600 s.
+ */
+export const TABLE_JOB_LOCK_TTL_SECONDS = 15 * 60;
/**
* The running table jobs of every company: a sorted set of job ids, scored by
diff --git a/packages/jobs/src/table-jobs/lock.ts b/packages/jobs/src/table-jobs/lock.ts
index 30a539b8f1..c77706aaac 100644
--- a/packages/jobs/src/table-jobs/lock.ts
+++ b/packages/jobs/src/table-jobs/lock.ts
@@ -130,7 +130,7 @@ export async function releaseTableJobLock(
);
}
-/** Sets the lock's TTL back to the full hour while it still holds `jobId`:
+/** Sets the lock's TTL back to `TABLE_JOB_LOCK_TTL_SECONDS` while it still holds `jobId`:
* a long run must not lose its lock to the next request. */
export async function extendTableJobLock(
kind: TableJobKind,