Skip to content

codegraph sync fails with "FOREIGN KEY constraint failed" after d0bb9be5 when a file lazy-loads a workspace package #2565

Closed

Description

@bompus

codegraph sync exits 1 with Failed to sync: FOREIGN KEY constraint failed whenever a changed .tsx file declares a PascalCase value that lazy-loads a workspace package, such as const EdgeFunctions = dynamic(() => import('icons').then((mod) => mod.EdgeFunctions)). A full index of the same project succeeds. Supabase's studio app has this pattern, and every sync after any edit to that app fails there.

Reproduction (a pnpm workspace with one package, one file): pnpm-workspace.yaml with packages/*; root package.json with workspaces: ["packages/*"] and a react dependency; packages/icons/package.json {"name":"icons","main":"./src/icons/index.ts"}; packages/icons/src/icons/index.ts exporting EdgeFunctions; and src/App.tsx:

import dynamic from 'next/dynamic';
const Chart = dynamic(() => import('icons').then((mod) => mod.EdgeFunctions));
export function App() { return <Chart />; }
git init . && codegraph init --yes .     # succeeds
echo "// touched" >> src/App.tsx
codegraph sync .                          # ✗ Failed to sync: FOREIGN KEY constraint failed, exit 1

It reproduces on upstream/main at eec9288a, and passes at 9b237093, the parent of d0bb9be5 (#2420). A git bisect over the 15 commits since 34dd3d2f, using a supabase checkout and a one-line edit to apps/studio/data/projects/clone-mutation.ts, ends at d0bb9be5.

Cause: lazyValueModules (added in #2420) records the module a lazy value loads as a synthesis input. For import('icons') the resolver returns the package directory, packages/icons, which is not an indexed file. The commit step copies the inputs into synthesis_inputs, whose file_path references files(path), so the insert fails and the whole sync rolls back. (Checked by listing the input rows missing from files when the commit fails: the only one is packages/icons.)

Possible fix: keep only paths that are in files when recording synthesis inputs.

Versions: upstream eec9288a and 3f714bcc, Node 24, Linux.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions