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: migration timeout

Brad Barbinfa053609e9cf
diff --git a/.ai/plans/2026-07-10-geometry-rs-implementation.md b/.ai/plans/2026-07-10-geometry-rs-implementation.md
index 887bdfcd02..0f66f71c6d 100644
--- a/.ai/plans/2026-07-10-geometry-rs-implementation.md
+++ b/.ai/plans/2026-07-10-geometry-rs-implementation.md
@@ -15,7 +15,7 @@
## Rust conventions (apply to every task)
-From `.agents/skills/rust-best-practices` (read `references/chapter_01.md`, `chapter_04.md`, `chapter_05.md` before writing code):
+From `.ai/skills/rust-best-practices` (read `references/chapter_01.md`, `chapter_04.md`, `chapter_05.md` before writing code):
- Errors: `thiserror` enums in library crates (`planner`, `converter`, `glb`, `geometry-types`, `occt-bridge`); `anyhow` only in the `server` binary.
- **Never `unwrap()`/`expect()` outside `#[cfg(test)]`.** OCCT and mesh data are hostile inputs.
diff --git a/.github/workflows/functions.yml b/.github/workflows/functions.yml
index c7d2020719..ada7cb8ee6 100644
--- a/.github/workflows/functions.yml
+++ b/.github/workflows/functions.yml
@@ -1,22 +1,18 @@
name: Deploy Self-Hosted Functions
on:
- # Run after the Deploy Apps workflow completes so functions sync only once the
- # app deploy has finished (avoids racing ECS/infra changes).
- workflow_run:
- workflows: ["Deploy Apps"]
- types:
- - completed
- branches:
- - main
+ # Deploying edge functions to the self-hosted Supabase instance is independent
+ # of the ECS app deploy, so trigger directly on pushes that touch the functions.
+ # (Sync Inngest Functions is the workflow that must wait for Deploy Apps.)
+ push:
+ branches: [main]
+ paths: ["packages/database/supabase/functions/**"]
workflow_dispatch:
jobs:
functions:
name: Deploy Self-Hosted Functions
runs-on: ubuntu-latest
- # Only run if the triggering Deploy Apps workflow succeeded (or if manually triggered)
- if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
strategy:
matrix:
environment:
@@ -29,39 +25,9 @@ jobs:
INSTANCE_SSH_KEY: ${{ secrets[matrix.environment.instance_ssh_key] }}
steps:
- - name: Checkout code
- uses: actions/checkout@v4
- with:
- # Check out the commit that triggered the deploy so the path filter
- # inspects the right changes (workflow_run does not set the ref for us).
- ref: ${{ github.event.workflow_run.head_sha || github.ref }}
- fetch-depth: 0
-
- # workflow_run does not support path filters natively, so check whether the
- # triggering commit actually touched the edge functions. Skipped for manual runs.
- # We diff locally (checkout above uses fetch-depth: 0, so full history is
- # present) rather than dorny/paths-filter, which tried to `git fetch` the
- # base as a refspec — `<sha>~1` is a valid revision but not a valid refspec,
- # so that fetch failed with "invalid refspec".
- - name: Check for function changes
- id: filter
- if: ${{ github.event_name == 'workflow_run' }}
- run: |
- head='${{ github.event.workflow_run.head_sha }}'
- changed=$(git diff --name-only "${head}~1" "${head}" -- packages/database/supabase/functions)
- if [ -n "$changed" ]; then
- echo "functions=true" >> "$GITHUB_OUTPUT"
- else
- echo "functions=false" >> "$GITHUB_OUTPUT"
- fi
-
- # Give ECS / infra a moment to stabilize after the deploy. Skipped for manual runs.
- - name: Wait for infrastructure to stabilize
- if: ${{ github.event_name == 'workflow_run' && steps.filter.outputs.functions == 'true' }}
- run: sleep 60
+ - uses: actions/checkout@v4
- name: Setup SSH key
- if: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.functions == 'true' }}
run: |
mkdir -p ~/.ssh
echo "$INSTANCE_SSH_KEY" > ~/.ssh/id_rsa
@@ -69,11 +35,10 @@ jobs:
ssh-keyscan -H $INSTANCE_HOST >> ~/.ssh/known_hosts
- name: Deploy functions
- if: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.functions == 'true' }}
run: |
ssh ubuntu@$INSTANCE_HOST 'sudo bash /home/ubuntu/supabase/sync-carbon-functions.sh'
- name: Cleanup SSH key
- if: ${{ always() && (github.event_name == 'workflow_dispatch' || steps.filter.outputs.functions == 'true') }}
+ if: always()
run: |
rm -f ~/.ssh/id_rsa
diff --git a/.gitignore b/.gitignore
index f5b9e4db17..12ba6b601f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,8 +15,6 @@ server/dist
public/dist
vite.config.ts.timestamp*
.claude-flow
-.claude/settings.local.json
-.claude/scheduled_tasks.lock
.mcp.json
opencode.json
.windsurf
@@ -63,18 +61,19 @@ packages/database/supabase/seed.sql
.superpowers
# Agent scratch — local-only, never commit
-.claude/scratch/
apps/*/portless.json
packages/database/supabase/snippets/**
.pr-review
-# .claude/ and .codex/ rules+skills are symlinks created by .ai/scripts/install-skills.sh
-# Source of truth is .ai/rules/ and .ai/skills/ — never edit under .claude/ or .codex/ directly
-.claude/rules/
-.claude/skills/
-.claude/notes/
+# Agent harness dirs — generated/symlinked by .ai/scripts/install-skills.sh, or local-only.
+# Source of truth is .ai/rules/ and .ai/skills/ — never edit under these directly.
+.agents/
+.claude/
.codex/
+# External skills manifest — locally resolved from skill sources, not committed
+skills-lock.json
+
# Editor/IDE settings — local, not source
.vscode/
diff --git a/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json b/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json
index 9447a7d6e7..077f333d38 100644
--- a/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json
+++ b/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json
@@ -1,5 +1,5 @@
{
- "generated": "2026-07-13T13:11:38.566Z",
+ "generated": "2026-07-13T15:52:44.850Z",
"totalTools": 1327,
"modules": 15,
"tools": [
diff --git a/conductor.json b/conductor.json
new file mode 100644
index 0000000000..b5c5acf42a
--- /dev/null
+++ b/conductor.json
@@ -0,0 +1,7 @@
+{
+ "scripts": {
+ "setup": "echo \"$CONDUCTOR_WORKSPACE_NAME\" > .carbon-worktree && pnpm install && ./packages/dev/bin/crbn env sync && bash .ai/scripts/install-skills.sh",
+ "run": "./packages/dev/bin/crbn up --all",
+ "archive": "./packages/dev/bin/crbn down --volumes"
+ }
+}
diff --git a/packages/database/supabase/migrations/20260713214441_remove-inventory-shipped-not-invoiced-account.sql b/packages/database/supabase/migrations/20260713214441_remove-inventory-shipped-not-invoiced-account.sql
index 6124381fa5..7f0ce44e5d 100644
--- a/packages/database/supabase/migrations/20260713214441_remove-inventory-shipped-not-invoiced-account.sql
+++ b/packages/database/supabase/migrations/20260713214441_remove-inventory-shipped-not-invoiced-account.sql
@@ -23,9 +23,29 @@ ALTER TABLE "accountDefault"
-- ============================================================
-- Step 2: Delete the seeded account where it is unused
-- ============================================================
--- Guarded per row: skip accounts with journal history, and swallow FK
--- violations from any other reference (e.g. an admin wired it into other
--- custom config) — those rows simply stay in the chart.
+-- Deleting a chart-of-accounts row makes Postgres enforce every FK that
+-- references "account" (~40 of them, several via ("number","companyId") into
+-- salesOrderLine / salesInvoiceLine / purchaseInvoiceLines / journalLine). During
+-- a live deploy that delete can block on a lock held by the running app, and the
+-- ambient statement_timeout then cancels the whole DO block (SQLSTATE 57014) —
+-- which is what happened here (prod data is small, so scan cost is not the cause).
+--
+-- Fix: lift statement_timeout so the cleanup isn't cancelled, but cap lock waits
+-- (lock_timeout) so a held lock bails fast instead of hanging the deploy; a row we
+-- can't take cleanly is simply left in the chart. (statement_timeout must be set as
+-- a separate top-level statement BEFORE the DO block — the timer is armed when a
+-- statement starts, so SET *inside* the block is too late to disarm it.)
+--
+-- Guarded per row: skip accounts with journal history, and swallow ANY error
+-- (a RESTRICT FK, the posted-journal immutability trigger on a stray SET NULL
+-- cascade into "journalLine", or a lock_timeout) so one stuck account never aborts
+-- the batch — those rows simply stay in the chart for an admin to remove.
+--
+-- Re-runnable: Step 1 above uses IF EXISTS and this block re-selects live rows,
+-- so re-executing the whole file after a mid-file failure is a no-op.
+
+SET statement_timeout = 0;
+SET lock_timeout = '15s';
DO $$
DECLARE
@@ -42,9 +62,12 @@ BEGIN
LOOP
BEGIN
DELETE FROM "account" WHERE "id" = v_account."id";
- EXCEPTION WHEN foreign_key_violation THEN
- -- still referenced somewhere (custom config) — leave it in the chart
+ EXCEPTION WHEN OTHERS THEN
+ -- still referenced (RESTRICT FK) or blocked by a trigger — leave it in the chart
NULL;
END;
END LOOP;
END $$;
+
+SET lock_timeout = DEFAULT;
+SET statement_timeout = DEFAULT;