Skip to content

fix: save api runs with no key instead of crashing; race-safe migrations - #159

Merged
vsn411 merged 1 commit into
mainfrom
fix/run-status-not-configured
Nov 20, 2026
Merged

vsn411 merged 1 commit into
mainfrom
fix/run-status-not-configured

Conversation

@vsn411

@vsn411 vsn411 commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Found during end-to-end testing before go-live.

Bugs

  1. secfoo run --agent api with no API key crashed with a traceback. The api adapter returns status not_configured (added in 7216d34), but the runs.status CHECK constraint was never widened, so saving the run raised IntegrityError: CHECK constraint failed. This is the first thing a user without an agent CLI sees.
  2. The first multi-skill run after an upgrade could fail with duplicate column name. Skills run in parallel threads, each with its own connection, and every connection runs the ADD COLUMN migrations. On an old database two connections could both see a column missing. Found by the new concurrency test.
  3. An id wider than SQLite's INTEGER returned 500 (/assessments/99999999999999999999, OverflowError).

Fix

  • schema.sql allows not_configured.
  • _migrate_runs_status_check widens the CHECK on existing databases with SQLite's documented table rebuild:
    • builds the new table from the existing table's own DDL, so the columns earlier migrations appended keep their order
    • turns foreign keys off for the swap
    • re-checks under BEGIN IMMEDIATE, so concurrent opens migrate once
    • leaves databases with no status CHECK alone
  • Column migrations treat a lost ADD COLUMN race as success.
  • The app maps OverflowError to 404.

Tests

tests/test_storage/test_run_status_migration.py:

  • every value of agents.base.Status saves on a fresh schema
  • the real ApiAdapter with no key goes through execute_runs
  • an old-schema DB with an appended column and a child row: rows, references, indexes, CHECK and foreign-key enforcement all survive the rebuild
  • four concurrent opens; idempotence
  • a DB with no status CHECK is left alone

tests/test_web/test_assessment_routes.py: oversized ids return 404.

Four of the five new storage tests and two of the three new route tests fail on main. Full suite: 1842 passed.

🤖 Generated with Claude Code

'secfoo run --agent api' with no API key ended in an IntegrityError
traceback: the adapter returns status 'not_configured' (added in 7216d34)
but runs.status's CHECK constraint never allowed it. The schema now does,
and existing databases get the CHECK widened by a table rebuild that keeps
column order, rows and references.

Testing that migration under concurrent opens also exposed an existing
upgrade bug: skills run in parallel threads with their own connections,
so the first multi-skill run on an old database could race on ADD COLUMN
and fail with 'duplicate column name'. A lost race is now treated as done.

Also: an id wider than SQLite's INTEGER in a dashboard URL returned 500
(OverflowError); it is now a 404.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vsn411
vsn411 merged commit 650b64b into main Nov 20, 2026
7 checks passed
vsn411 added a commit that referenced this pull request Nov 20, 2026
…ink check tolerates GitHub 503s (#163)

* fix: retry the WAL switch instead of failing parallel first opens

Switching a database to WAL takes an exclusive lock, and SQLite returns
'database is locked' for it at once instead of honouring busy_timeout.
Several skills opening a new or pre-WAL database at the same moment
failed about 1 open in 20; the #159 concurrency test hit it
intermittently. The switch now retries briefly. WAL persists in the
file, so only the first open ever switches it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci: do not fail the link check on github.com 503s

github.com throttles blob pages crawled from Actions runners with 503,
which turned main red twice on 2026-11-20 with 1 and 18 'errors' on
pages that exist. A broken link is a 404, which still fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix: retry store setup on 'database schema has changed' too

CI (Python 3.10, Linux) showed parallel first opens of a new database
can also fail with 'database schema has changed' while another
connection creates the tables, not only with the WAL switch's
'database is locked'. Every setup step is idempotent, so the whole
setup is now retried on a fresh connection for either error, until a
10-second deadline; any other error raises at once. Deterministic tests
inject each error; the parallel stress test now prints the failing
tracebacks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Satyanarayana Vuppala <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant