Repository navigation
Conversation
Python's sqlite3 driver only opens a transaction before INSERT/UPDATE/DELETE, so DDL that ran first committed on its own. When migration 030 failed to decrypt legacy KV state (wrong or missing AUTOMATION_KV_SECRET), the revision rolled back but the schema did not: from 028 the 029 column survived, from 029 the 030 rename and new tables survived, and every retry then failed on them (OpenHands/OpenHands#18299, #575). - migrations/env.py: on SQLite, disable the driver's implicit BEGIN and issue BEGIN IMMEDIATE when the migration transaction begins (SQLAlchemy's documented pysqlite recipe). The whole upgrade is now one transaction, and a second migrator waits for the write lock. - 029: skip the column if an earlier failed run already added it. - 030: if automation_kv_legacy is present next to empty new tables (what a failed run left behind), drop the empty tables and rename the legacy table back before running. Non-empty tables are refused and left untouched. - 030: name AUTOMATION_KV_SECRET in the decryption error. - app.py: stop claiming the database may be inconsistent after a failure. Tests cover failed upgrades from 028 and 029 with missing and wrong secrets (schema, revision and every KV row unchanged, then retry succeeds), repair of both partial states, and refusal of an ambiguous one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MetmkfA8Cb49iE8tJb8GNp
|
Warning Your comment is too long (maximum is 65536 characters), so the coverage report was not added. See the job log for how to reduce it. |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Assessment
Scope is correct for this repository: OpenHands/automation owns the Alembic migrations and the SQLite auto-migration startup path (migrations/env.py, openhands/automation/app.py). Linked issue #575 is open with ready-for-dev and priority:low, and the change addresses the migration atomicity plus the two partial states it describes. The Canvas secret decoupling is correctly left to OpenHands/OpenHands#18307.
Verified on head e96fd9a:
migrations/env.pyapplies SQLAlchemy's documented pysqlite recipe (isolation_level=Noneplus abeginlistener issuingBEGIN IMMEDIATE) to the SQLite migration engine only. The production startup path reaches it:settings.db_urlcomes fromAUTOMATION_DB_URL, whichis_sqlite()reads, soBEGIN IMMEDIATEwraps the wholeengine.begin()upgrade and rolls schema, data andalembic_versionback together.- 029 is idempotent (skips an existing column) and 030 repairs a leftover
automation_kv_legacybeside the empty new tables. The non-empty-new-table case raises before any drop, and the check-before-drop ordering is correct. The combined 028-start state (029 column present and 030 rename/tables present) is also handled: 029 skips and 030 repairs. - The
app.pymessage change is accurate under the single-transaction upgrade, and startup still aborts on failure.
Checks: I ran tests/test_kv_migration.py and tests/test_migration_history.py (10 passed) and tests/test_db.py::TestSqliteMigrations (3 passed) against this head; ruff check/format are clean on the changed files. GitHub Actions for the head are green (unit-tests, backend, image build).
Two non-blocking notes, not merge blockers:
- Issue #575 asks for the recovery procedure and its backup/validation steps to be documented. The code's error messages and the PR description cover it, but nothing lands in-repo (e.g.
docs/kv-store-design.md); a short recovery note would help operators of already-broken installs. - The explicit two-concurrent-migrator test the issue lists is not added. The PR's reasoning is sound: a naive held-lock test also passes on the old code, and the rollback tests prove the transaction begins before the first DDL. I do not consider this blocking.
✅ APPROVED
Issue #575 asks for the recovery procedure, with its backup and validation steps, to be documented. Add it to the migration section of the KV design doc: what a failed 030 leaves behind now that SQLite upgrades are one transaction, how to recover with the original secret, how the half-migrated states from earlier releases are repaired, and what a lost secret costs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MetmkfA8Cb49iE8tJb8GNp
|
Thanks for the review. On the two notes:
Generated by Claude Code |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Assessment
Scope is correct for this repository: OpenHands/automation owns the Alembic migrations and the SQLite auto-migration startup path (migrations/env.py, migrations/versions/029_*, 030_*, openhands/automation/app.py). Linked issue #575 is open with ready-for-dev and priority:low. CI for this head is green (unit-tests, backend, image build, PR title/description all success; no failing checks).
Since the previous APPROVED on e96fd9a, the only code change on this head is the added docs/kv-store-design.md recovery section; I confirmed the diff e96fd9a..8721933 touches only that file. I re-ran the focused suite on this exact head:
tests/test_kv_migration.py tests/test_migration_history.py-> 10 passedtests/test_db.py tests/test_kv_per_key.py-> 42 passedruff checkandruff format --checkclean on the changed files;pyrightclean on the migration files.
Findings
The change is correct and well-tested:
_use_explicit_sqlite_transactionsapplies SQLAlchemy's documented pysqlite recipe (disable the driver's implicit BEGIN, emitBEGIN IMMEDIATEon SQLAlchemy'sbegin). I exercised the listener directly across repeatedengine.begin(), a second pooled connection, and a rollback of a nested savepoint inside an open transaction; isolation is preserved. This makes the whole upgrade one real transaction, so schema, data andalembic_versionroll back together, and it takes the write lock up front so a second migrator serializes.- 029 skips
consecutive_auth_failureswhen present, and 030's_undo_partial_upgradeonly reverts the exact empty-table shape a failed run leaves, refusing with a message when a new table holds rows. Both are gated on this being the only writer of those objects, matching the reproduction in #575. - The 030 decryption error now names
AUTOMATION_KV_SECRETand states the stored state was not modified;app.py's message now matches the new transactional guarantee. - The
docs/kv-store-design.mdrecovery steps (back up, set the original secret, restart; repair of half-migrated databases; lost-secret cost including Git Sync tokens wrapped withAUTOMATION_KV_SECRET) are consistent with the code and with thesecret_storefallback described inAGENTS.md.
No blocking or non-blocking defects found. PostgreSQL behavior is unaffected (the listener is only registered for SQLite; the 029/030 recovery paths are no-ops there).
✅ APPROVED
Co-authored-by: openhands <openhands@all-hands.dev>
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Assessment
Scope is correct for this repository: OpenHands/automation owns the KV store and its Alembic migrations. All three changed files (migrations/versions/030_kv_per_key_rows.py, docs/kv-store-design.md, tests/test_kv_migration.py) are in scope; no product or architecture decision is needed.
The head 71a54f0 merges current main into the branch; the PR's own diff against main remains +216/−13 across the three files above, and the only change to the PR's own files since the last approved head (8721933) is the one-line docs update aligning the recovery log string with the code (app.py now logs "Database migrations applied successfully", which this PR's docs now match — verified against the current app.py:92).
Verification
uv run python -m pytest tests/test_kv_migration.py tests/test_migration_history.pyat this exact head: 13 passed (parametrized failure/repair matrix expands the 10 focused cases described in the PR).- Migration chain is linear with a single head (
034);029→030→031→032→033→034is a complete upgrade path from the released schema. _undo_partial_upgradeonly fires whenautomation_kv_legacyexists, refuses to touch a partial 030 state whoseautomation_kv/automation_kv_metarows are non-empty (RuntimeError mid-transaction rolls back — nothing changed), and otherwise drops the empty tables and renames the legacy table back, all inside the singleBEGIN IMMEDIATEtransaction thatmigrations/env.pyopens for SQLite. On PostgreSQL the repair is a no-op, and PG already gets full rollback from itsengine.begin()migration transaction, so parity is preserved.- The docs' recovery procedure matches the implementation: a retry with the original secret re-runs 030 inside one transaction; a lost secret is documented as unrecoverable except by deliberately deleting KV rows.
CI on this head: backend and both image builds green; unit-tests was still running at review time. No failing checks on 71a54f0.
No material correctness, security, or design findings. The failure-path snapshot tests prove the atomicity claim, and the repair tests use the exact DDL released 029/030 produce, so the recovery path is exercised against real broken states rather than idealized ones.
✅ APPROVED
Co-authored-by: openhands <openhands@all-hands.dev>
|
📁 PR Artifacts Notice This PR adds or changes temporary PR-specific documents under |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands). (re-review requested via all-hands-bot event 36083982300; this head f2bef0b is new since the previous approvals on 71a54f0, so a fresh review was performed)
Assessment
Scope is correct for this repository: OpenHands/automation owns the Alembic migrations and their SQLite/PostgreSQL parity (AGENTS.md "Database" section and the repo review guide's "Database and migration parity" checkpoint). The PR is a focused follow-up to the already-merged #592 transaction control: it repairs the remaining partial-030 state that releases before the single-transaction migration runner left on SQLite.
What was verified
Repair preconditions hold. The docstring premise that the new tables are empty in the partial state is confirmed by the pre-#592 migrations/env.py (209f74b): under the old SQLite connection settings, the rename and CREATE TABLE DDL persisted while the row inserts and the alembic_version bump rolled back together. The original ciphertext therefore remains intact in automation_kv_legacy, which is what _undo_partial_upgrade relies on when it drops the empty new tables and renames the legacy table back before the normal flow re-runs.
The guard is sound. Rows committed without the version bump cannot result from the released code (the DML and version bump committed in the same deferred transaction), so the non-empty-table refusal in migrations/versions/030_kv_per_key_rows.py is a conservative tripwire for unexpected shapes, and it changes nothing when it fires. All shapes the released code could leave are handled: legacy with empty new tables, and legacy with no new tables at all (the partial list is empty and the rename-back alone restores the 029 state).
Composition with transactional rollback is correct. On a retry that fails again (still wrong or missing secret), BEGIN IMMEDIATE + rollback restores the partial state exactly, so the repair is re-runnable; the next attempt with the right secret completes. The refusal and rollback paths do not mutate data.
PostgreSQL is unaffected. automation_kv_legacy cannot survive a failed 030 on PostgreSQL (transactional DDL), so _undo_partial_upgrade returns immediately there; the PR's PG verification and the early-return guard agree.
Tests exercise real paths. The new tests drive real alembic subprocess runs against real SQLite files and snapshot schema, revision, and every KV row across failures — no mocks. I ran tests/test_kv_migration.py and tests/test_migration_history.py on this head: 13 passed, matching the PR's claim. All GitHub Actions checks on f2bef0b are green, including the required unit-tests job.
Docs match the code. The recovery steps added to docs/kv-store-design.md reference the actual startup log line (Database migrations applied successfully, openhands/automation/app.py:93), and the .pr/ evidence images follow the repository's PR-artifacts convention with SHA-pinned links in the description.
No material correctness, security, compatibility, or acceptance-criterion findings on this head.
✅ APPROVED
AGENT:
Summary
Retries can recover the released partial states using the original KV secret.
Why
Main now fixes transaction atomicity and partial-029 retries via #592. This PR adds recovery for the partial-030 tables left by older releases.
Issue Number
Fixes #575. Part of OpenHands/OpenHands#18299. Companion KV pinning: OpenHands/OpenHands#18307.
How to Test
Recorded: 10 focused migration/history tests passed; the old migration code failed seven of nine KV tests. Released-code broken databases recovered with the original key; PostgreSQL 16 and the real Canvas launcher were also checked.
Previously recorded verification
New tests in
tests/test_kv_migration.pybuild disposable SQLite databases:$version. The pre-existing 028/missing-secret test is folded into this one.Run against this branch:
The same test file against
main's migrations fails 7 of the 9 KV tests. The 028/missing-secret case fails on the schema snapshot because 029's column survived. The repair tests fail with the two errors above.Real-database checks beyond the unit tests:
main(028 and 029 starts, wrong key), then started this branch on them:$versionintact.scripts/dev-with-automation.mjswithOH_AUTOMATION_LOCAL_PATHpointing at this branch. A database at 028 holding KV data written under the session key started cleanly (028 → 032, "SQLite database migrations applied successfully") and kept its values.Full suite:
uv run python -m pytest tests/ -n 4gave 1376 passed, 0 failed, 520 errors. All 520 errors aredocker.errors.DockerExceptionfrom the PostgreSQL/MinIO container fixtures, because my environment had no Docker daemon. Those fixtures build their schema withcreate_all, not migrations, and CI will run them.ruff format,ruff check,pycodestyleandpyrightare clean on the changed files.Video/Screenshots
Not applicable: verification tooling or migration behavior; recorded proof is above.
Type
Notes
Every SQLite startup briefly takes a write lock, with the driver’s default 5 s wait. Recovery requires the original AUTOMATION_KV_SECRET and a backup first; a lost secret cannot be reconstructed. The full local suite had 1,376 passes and 520 Docker-fixture setup errors because no daemon was available—not a green full suite. No dedicated concurrency test was claimed.
Visual explanation by Codex using HumanLayer show-me.
Before/after evidence (re-verified 13 November on main 949c001)
Same script both times: build a SQLite DB to
029, seed one legacy KV document encrypted with the original secret, apply exactly the DDL released 030 leaves behind after a failed decrypt, then retryalembic upgrade headwith the originalAUTOMATION_KV_SECRET.I merged current
maininto this branch (migrations now end at 037).tests/test_kv_migration.py+tests/test_migration_history.py: 13 passed on the branch. The sametest_kv_migration.pyrun againstmain's migrations: 5 failed, 7 passed. The screenshots live in.pr/, which the release PR removes.This update was made by an AI agent (OpenHands) on behalf of Graham Neubig.
Jev-Fast-Audit
⚡ Jev fast audit · estimates · 0.31s · commit f2bef0b⚠️ reduced context — partial coverage; 11/11 hunks, 5/5 files (missing patch: 2).
Strongest signal: No primary concern selected.
Evidence: No primary concern to locate.
Coverage:
All estimates and evidence
Current verification (25 October)
Updated with current main and preserved the already-merged #592 transaction control, SQLite-only 029 repair, and newer PostgreSQL startup/engine handling. The remaining diff covers partial-030 recovery, clearer decryption errors, recovery documentation, and broader regression tests. Expected head revisions now come from Alembic rather than a literal.
Focused migration/history/SQLite/KV tests: 29 passed. Ruff, formatting, pycodestyle, and pyright pass on changed Python files. A broader startup suite had 34 passes and 11 Docker-fixture setup errors because no Docker daemon is available; that is not a passing PostgreSQL suite. Updated the documented startup log message to match current main. Fresh CI and review are requested.