Skip to content

fix: prevent UNIQUE constraint error when same tool is passed twice#1419

Open
octo-patch wants to merge 1 commit into
simonw:mainfrom
octo-patch:fix/issue-1252-duplicate-tool-sqlite-error
Open

fix: prevent UNIQUE constraint error when same tool is passed twice#1419
octo-patch wants to merge 1 commit into
simonw:mainfrom
octo-patch:fix/issue-1252-duplicate-tool-sqlite-error

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #1252

Problem

When the same tool file is passed multiple times via -T (e.g. llm prompt -T llm_time -T llm_time ...), the database logging fails with:

sqlite3.IntegrityError: UNIQUE constraint failed: tool_responses.tool_id, tool_responses.response_id

This happens because ensure_tool() returns the same tool_id for duplicate tools (tools are deduplicated by hash), but the loop in log_to_db() calls db["tool_responses"].insert() for each occurrence, producing two rows with the same (tool_id, response_id) primary key.

Solution

Add ignore=True to the tool_responses.insert() call so that duplicate (tool_id, response_id) pairs are silently skipped instead of raising an integrity error.

Testing

Added a test that passes the same tool twice and confirms exit_code == 0 (previously this would raise an unhandled exception).

…l passed twice (fixes simonw#1252)

When the same tool file is passed multiple times via -T (e.g. -T llm_time -T llm_time),
the tool_responses table insert fails with a UNIQUE constraint error because the same
(tool_id, response_id) pair is inserted twice. Use ignore=True so that duplicate
tool_responses rows are silently skipped.

Co-Authored-By: Octopus <liyuan851277048@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tools with the same name will manifest as sqlite errors

1 participant