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:history download warns when it is cut off at 10,000 entries instead of passing as complete

aashubfc8ac808143
diff --git a/.claude/rules/audit-log-system.md b/.claude/rules/audit-log-system.md
index 15354ba4da..8663a3280e 100644
--- a/.claude/rules/audit-log-system.md
+++ b/.claude/rules/audit-log-system.md
@@ -175,7 +175,7 @@ than from config.
- `apps/erp/app/routes/x+/settings+/audit-logs.tsx` — settings (enable/disable, download), syncs subscriptions.
- `apps/erp/app/routes/x+/settings+/audit-logs.details.tsx` — full-screen filtered table (`getGlobalAuditLog`).
-- `apps/erp/app/routes/api+/audit-log.ts` — entity-scoped entries endpoint (50 newest; `all=true` pages through every live entry, capped at 10,000, for the drawer's opt-in CSV Download — `useAuditLog({ downloadable, downloadName })`, built client-side by `components/AuditLog/useAuditLogDownload.ts` with the pure row builder `buildAuditLogCsvRows` in `components/AuditLog/utils.ts`; a failed `all=true` read answers 500).
+- `apps/erp/app/routes/api+/audit-log.ts` — entity-scoped entries endpoint (50 newest; `all=true` pages through every live entry, capped at 10,000 with `truncated: true` when the history is longer (the download warns), for the drawer's opt-in CSV Download — `useAuditLog({ downloadable, downloadName })`, built client-side by `components/AuditLog/useAuditLogDownload.ts` with the pure row builder `buildAuditLogCsvRows` in `components/AuditLog/utils.ts`; a failed `all=true` read answers 500).
## Key migrations (newest = truth)
diff --git a/apps/erp/app/components/AuditLog/useAuditLogDownload.ts b/apps/erp/app/components/AuditLog/useAuditLogDownload.ts
index 9f63e66b48..6117b2ad16 100644
--- a/apps/erp/app/components/AuditLog/useAuditLogDownload.ts
+++ b/apps/erp/app/components/AuditLog/useAuditLogDownload.ts
@@ -51,8 +51,9 @@ export function useAuditLogDownload({
const response = await fetch(`/api/audit-log?${params.toString()}`);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
- const { entries } = (await response.json()) as {
+ const { entries, truncated } = (await response.json()) as {
entries: AuditLogEntry[];
+ truncated?: boolean;
};
const labels: AuditLogCsvLabels = {
@@ -85,6 +86,11 @@ export function useAuditLogDownload({
`${name}-history-${today(getLocalTimeZone()).toString()}.csv`,
{ fields: Object.values(labels.columns) }
);
+ if (truncated) {
+ toast.warning(
+ t`This history is too long to download in full. The file has the ${entries.length} most recent entries.`
+ );
+ }
} catch {
toast.error(t`Failed to download history`);
} finally {
diff --git a/apps/erp/app/routes/api+/audit-log.ts b/apps/erp/app/routes/api+/audit-log.ts
index 9059d45455..cc3700d8f8 100644
--- a/apps/erp/app/routes/api+/audit-log.ts
+++ b/apps/erp/app/routes/api+/audit-log.ts
@@ -68,8 +68,10 @@ export async function loader({ request }: LoaderFunctionArgs) {
return Response.json({ entries });
}
+ // Reads past the cap by up to one page, so a history longer than the cap
+ // is reported as truncated rather than passed off as complete.
const entries: Awaited<ReturnType<typeof getEntityAuditLog>> = [];
- while (entries.length < DOWNLOAD_MAX_ENTRIES) {
+ while (entries.length <= DOWNLOAD_MAX_ENTRIES) {
const page = await getEntityAuditLog(
client,
companyId,
@@ -84,7 +86,10 @@ export async function loader({ request }: LoaderFunctionArgs) {
entries.push(...page);
if (page.length < DOWNLOAD_PAGE_SIZE) break;
}
- return Response.json({ entries: entries.slice(0, DOWNLOAD_MAX_ENTRIES) });
+ return Response.json({
+ entries: entries.slice(0, DOWNLOAD_MAX_ENTRIES),
+ truncated: entries.length > DOWNLOAD_MAX_ENTRIES
+ });
} catch (err) {
logger.error("Failed to fetch audit log", {
companyId,