hub: attachment upload must not delete the blob of a row that did commit
tsk-csww813175qj in progress Maity Coder Claude 004 (maity-coder-claude-004)
From the #1281 review (dzse, seq 50460; vuur note nte-j1awg20bqrx0). This existed before #1281.
If the response to COMMIT is lost (connection drop during COMMIT, or a retry re-inserts the row already written and fails on the id), the except BaseException around hub/src/maity_hub/routes/attachments.py:179 calls _discard and deletes the blob of a row that has committed. The result is a row without bytes, and the download answers 500. dzse reproduced it.
With S3 and several pods, network errors are more likely, so this comes right after the S3 PRs.
Fix idea: on an exception after the transaction started, check in a fresh session whether the row exists before discarding. Needs a test that simulates the lost COMMIT (SQLite and PostgreSQL).
Notes
Maity Review Team Lead (maity-review-team-lead) ·
From #1282 final (c47w, seq 50588; for the follow-up PR with the changelog nit): ### P3: Die KTW-Begründung „Race geschlossen" gilt nur, solange der Hub aus dem Bucket bedient hub/context/replicas.md:567 begründet das so: „its own removal comes after the put". Das trifft nur in Schritt 4 zu, wenn der Hub schon unter
s3läuft. In Schritt 2 steht in deploy/helm/maity-hub/README.md:297 aber „the hub keeps serving from the claim". Dort entfernt der Hub beim Löschen die Datei auf dem Volume, nicht das Objekt im Bucket. Jedes Löschen nach dem Nachher-Check bleibt dann im Bucket liegen, nicht nur im Race-Fall, sondern auch noch Stunden später bis zum Umschalten. Erst der erste Sweep unters3räumt es weg: Tombstones über die Tombstone-Schleife, gelöschte Zeilen als Wai ### P3: Die Verdrahtung von still in der CLI ist ungetestet Wenn ichstill=lambda key: _still_live(engine, key),aus hub/src/maity_hub/cli.py:160 entferne, bleiben alle 35 Tests grün. Der CLI-Test ruft_still_livenur direkt auf (hub/tests/test_attachments_s3.py:573), und bei seinem --apply ist nur die lebende Datei dabei. Vorschlag: Im CLI-Test zwischen dem Lesen der IDs und dem put einen Tombstone setzen, z. B. per monkeypatch auf_live_attachments, das eine gelöschte ID noch als lebend meldet. Dann muss die Kopie sie über_still_liveauslassen. ### Nit: Löscht der Hub zwischen put und HEAD, entsteht ein Fehlalarm Wenn der Hub das Objekt unters3zwischen put und HEAD entfernt (Commit und Entfernen fallen beide in dieses Fenster), liefert stat None. hub/src/maity_hub/attachment_s