Repository navigation
Replace SQLite UPSERT with INSERT OR REPLACE (Lambda python3.9) - #12
Merged
Merged
Conversation
AWS Lambda's python3.9 runtime (the MAWS default) ships SQLite 3.7.17, which predates UPSERT (3.24). In shared history mode the first rotation wrote closed_at with ON CONFLICT ... DO UPDATE and failed with 'near "ON": syntax error' on every later message, so the bot stopped answering. The same syntax was in clear_message_history and clear_global_history. history_metadata is a two-column table keyed by key, so INSERT OR REPLACE is equivalent. Tests emulate the old SQLite parser and add a static guard against UPSERT/RETURNING in mas/ and maws/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
AWS Lambda's python3.9 runtime (the MAWS default) ships SQLite 3.7.17, which predates UPSERT (added in 3.24). In
history_mode="shared", the first rotation of a shared history file writesclosed_atwithINSERT ... ON CONFLICT(key) DO UPDATE, which fails withnear "ON": syntax error. Because the file never gets marked closed, every later message retries the rotation and fails, so the bot stops answering. Seen in production on a bot with shared history + FIFO.The same syntax was also in
clear_message_history(shared mode, reached by/clear) andclear_global_history.Fix
Replace the three UPSERTs with
INSERT OR REPLACE.history_metadatais a two-column table withkeyas primary key and no triggers, so the result is identical.Tests
tests/test_sqlite_compat.pyemulates the old SQLite parser (rejects UPSERT/RETURNING with the same error). Rotation, metadata replacement,/clearand global clear fail on main with the exact production traceback and pass with this change.mas/ormaws/; on main it flags exactly the three lines fixed here.🤖 Generated with Claude Code