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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
loop(1080): [t1.s1] Rewrote shared.server.ts getCustomFieldsSchemas to use explicit try/catch cache-miss fallthrough instead of the fragile return-in-finally (no catch); audited all other consumers — already null-safe; confirmed no raw ioredis imports.
Carbon Agent82663410cf1c
diff --git a/.ai/runs/1080/binding.loop.md b/.ai/runs/1080/binding.loop.mdnew file mode 100644index 0000000000..4789decd4c--- /dev/null+++ b/.ai/runs/1080/binding.loop.md@@ -0,0 +1,41 @@+---+id: "1080"+issue: 1080+kind: bug+risk: low+title: "Redis resilience: migrate remaining cache consumers (printing, ERP server files)"+acceptance:+ - "Grep confirms no raw import of ioredis outside packages/kv/ — all consumers go through @carbon/kv"+ - "packages/printing/src/cache.server.ts: cache reads treat null as a miss; writes don't throw"+ - "apps/erp/app/modules/shared/*.server.ts: Redis null returns handled as cache miss"+ - "apps/erp/app/modules/settings/*.server.ts: Redis null returns handled as cache miss"+ - "apps/erp/app/modules/users/*.server.ts: Redis null returns handled as cache miss"+ - "apps/erp/app/routes/api+/docs.ts: Redis null returns handled as cache miss"+ - "TypeScript clean: pnpm --filter @carbon/printing typecheck and relevant ERP packages"+ - "Biome lint clean"+---++## Context++PR #1083 (merged to main) wraps the `@carbon/kv` Redis client at the Proxy level via `withResilience()` in `packages/kv/src/resilient.ts`. All consumers that import `redis` from `@carbon/kv` automatically get fail-soft behavior — reads resolve `null` (collections `[]`), writes resolve `null`, no thrown errors. The resilience is handled at the wrapper level; per-call-site try/catch for connectivity is NOT needed.++## Task++Audit and harden the remaining cache consumers (non-auth, non-rate-limit):++1. Grep for `import.*ioredis` in all app/package code outside `packages/kv/` — any such import bypasses the resilience wrapper and must be changed to use `import { redis } from "@carbon/kv"` instead.++2. For each consumer file:+ - `packages/printing/src/cache.server.ts`+ - `apps/erp/app/modules/shared/*.server.ts`+ - `apps/erp/app/modules/settings/*.server.ts`+ - `apps/erp/app/modules/users/*.server.ts`+ - `apps/erp/app/routes/api+/docs.ts`++ Check: does the code assume `redis.get()` returns a non-null value? If it does (e.g. JSON.parse without null guard, destructuring without null check), fix it to treat `null` as a cache miss and fall through to the source of truth.++3. Do NOT add try/catch for Redis connectivity — that's already handled by the wrapper.++4. Run typecheck and lint; ensure clean.++5. Open a PR against main. Close issue #1080 from the PR body ("Closes #1080").diff --git a/apps/erp/app/modules/shared/shared.server.ts b/apps/erp/app/modules/shared/shared.server.tsindex 20f72805bd..5c828d8005 100644--- a/apps/erp/app/modules/shared/shared.server.ts+++ b/apps/erp/app/modules/shared/shared.server.ts@@ -59,42 +59,42 @@ export async function getCustomFieldsSchemas(}) {const key = await getCustomFieldsCacheKey(args);- let schema: CustomFieldsTableType[] | null = null;- try {- const cachedSchema = await redis.get(key);- if (cachedSchema) {- schema = JSON.parse(cachedSchema) as CustomFieldsTableType[];- }- } finally {- if (schema) {+ // redis.get returns null on a cache miss (or when Redis is unreachable — the+ // @carbon/kv resilience wrapper fails soft). Treat both, and a malformed+ // cached payload, as a miss and fall through to the database.+ const cachedSchema = await redis.get(key);+ if (cachedSchema) {+ try {return {- data: schema as CustomFieldsTableType[],+ data: JSON.parse(cachedSchema) as CustomFieldsTableType[],error: null};+ } catch {+ // Corrupt cache entry — fall through to the source of truth.}+ }- const query = client.from("customFieldTables").select("*");-- if (args?.companyId) {- query.eq("companyId", args.companyId);- }+ const query = client.from("customFieldTables").select("*");- if (args?.module) {- query.eq("module", args.module as any);- }+ if (args?.companyId) {+ query.eq("companyId", args.companyId);+ }- if (args?.table) {- query.eq("table", args.table);- }+ if (args?.module) {+ query.eq("module", args.module as any);+ }- const result = await query;- if (result.data) {- await redis.set(key, JSON.stringify(result.data));- }+ if (args?.table) {+ query.eq("table", args.table);+ }- return result;+ const result = await query;+ if (result.data) {+ await redis.set(key, JSON.stringify(result.data));}++ return result;}/**