Skip to content

Stop rebuilding the tool_calls primary key on every boot - #159

Closed
salluexez wants to merge 1 commit into
yc-software:mainfrom
salluexez:stop-rebuilding-tool-calls-pkey
Closed

Stop rebuilding the tool_calls primary key on every boot#159
salluexez wants to merge 1 commit into
yc-software:mainfrom
salluexez:stop-rebuilding-tool-calls-pkey

Conversation

@salluexez

@salluexez salluexez commented Aug 3, 2026

Copy link
Copy Markdown

Summary

Replace unconditional ALTER TABLE tool_calls DROP CONSTRAINT/ADD PRIMARY KEY on startup with a conditional DO $$ block in src/runs/postgres-run-store.ts that checks information_schema.constraint_column_usage first. This prevents taking an ACCESS EXCLUSIVE lock and rebuilding the primary key index on every application boot.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Copilot AI review requested due to automatic review settings August 3, 2026 15:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Postgres startup schema migration for tool_calls to avoid rebuilding the tool_calls primary key index on every boot by only applying the PK change when it appears to be needed.

Changes:

  • Replaces unconditional DROP CONSTRAINT/ADD PRIMARY KEY for tool_calls_pkey with a conditional DO $$ ... $$ block that inspects information_schema first.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +76 to +80
`DO $$
BEGIN
IF EXISTS (
SELECT 1 FROM information_schema.constraint_column_usage
WHERE table_name = 'tool_calls' AND constraint_name = 'tool_calls_pkey' AND column_name = 'run_id'
@16francej 16francej added code-pr Code submitted instead of an ADR bug Something isn't working labels Aug 4, 2026
@ReganBell

Copy link
Copy Markdown
Collaborator

Fixed on our side, going out shortly with you as co-author on the commit 🙏

@ReganBell ReganBell closed this Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working code-pr Code submitted instead of an ADR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants