Skip to content

feat: GSM Secrets - Backfill API to move plain-text secrets into the store - #477

Open
yuechao-qin wants to merge 6 commits into
gsm-t2-read-at-launchfrom
gsm-t3-backfill
Open

yuechao-qin wants to merge 6 commits into
gsm-t2-read-at-launchfrom
gsm-t3-backfill

Conversation

@yuechao-qin

@yuechao-qin yuechao-qin commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

What

An admin route moves the rows still in the database (secret table) into the secret store, a batch at a time, until the table is empty. Responses below are the ones the tests assert:

POST /api/admin/secrets/backfill_storage?limit=2          # rows alice/A, alice/B, bob/C
→ {"moved": 2, "skipped": [], "left_in_table": 1, "stopped_on": null}

POST /api/admin/secrets/backfill_storage?limit=2          # alice/A, alice/BIG (the store refuses it), alice/C
→ {"moved": 2, "skipped": [{"user_id": "alice", "secret_name": "BIG"}], "left_in_table": 1, "stopped_on": null}

POST /api/admin/secrets/backfill_storage                  # the store is down
→ {"moved": 0, "skipped": [], "left_in_table": 2,
   "stopped_on": {"user_id": "alice", "secret_name": "A", "error": "RuntimeError: store unavailable"}}
Result Meaning
moved rows moved in this run, at most limit
skipped rows the store refused as invalid (ApiValidationError, e.g. a value too large); they stay in the table and do not count toward limit
left_in_table rows still in the table after the run; 0 means done
stopped_on the row and error that ended the run early, or null; run it again once fixed

user_id and secret_name narrow the run to matching rows. Admins only; with no secret_store given, the route is a 422.

Each row moves in one commit: lock the row, create it in the store with every column, delete the row. If the store already has it, an earlier run stopped after copying; the row is still the truth, so update replaces the copy. A PUT or DELETE of the same row waits on the lock, then finds no row and goes to the store.

Why

#474 sends new secrets to the store but never moves existing rows, so that a request does only what it says. This is the one place rows move. It is safe to repeat and to run while the secret routes are in use, because each move locks its row.

Verification

  • tests/test_secret_store.py, through the route: no store → 422; non-admin → 403; limit caps the moves and a second run finishes; user_id and secret_name filters; an invalid row is skipped, listed and not counted; an error stops the run with its row and text, and a rerun finishes; every column is carried; a copy left by a stopped run is replaced by the row; the row is locked while it moves.
  • Mutation-checked: dropping the lock, keeping a stale copy, dropping description or extra_data, not deleting the row, not committing each row, ignoring limit, counting skipped rows, stopping on an invalid row, not catching other errors, carrying on after one, and ignoring the filters each turn tests red. The rollback after a skipped row only releases a row lock, which SQLite does not take, so no test here can see it.
  • Full suite: 672 passed, 22 failed — the same 22 in tests/instrumentation/test_execution_tracing.py fail on master. Also passes on Python 3.14.

@yuechao-qin
yuechao-qin requested a review from Ark-kun as a code owner November 18, 2026 05:37
@yuechao-qin
yuechao-qin added this pull request to stack #476 November 18, 2026 05:37
# Conflicts:
#	tests/test_secret_value_store.py
…nvalid rows, stops on errors

Returns moved, skipped, left_in_table and stopped_on; skipped rows do not count toward limit.
@yuechao-qin
yuechao-qin requested a review from a team November 19, 2026 04:46
Comment on lines +638 to +640
return secrets_service.backfill_secret_storage(
session=session, limit=limit, user_id=user_id, secret_name=secret_name
)
# Conflicts:
#	tests/test_secret_store.py
… store, delete

The routes no longer move rows, so the backfill owns the move. A copy left by a stopped run is replaced by the row.
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.

2 participants