Skip to content

feat(storage): per-object DEK envelopes and durable upload candidates for the object lake - #24883

Merged
Git-on-my-level merged 8 commits into
mainfrom
pgf/dek-per-object-keys
Nov 8, 2026
Merged

Git-on-my-level merged 8 commits into
mainfrom
pgf/dek-per-object-keys

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Requested by David

What changed and why

Give each new object-lake payload a random 256-bit DEK, wrapped locally with AES-KW under its versioned space key in the immutable 61-byte v2 header. Retain v1 reads, pointer schema, create-only retry semantics, shredding and rotation without re-wrap; add no per-object KMS calls.

Allow dev deployment admission with real bucket/KMS bindings. Move the binding check into shared admission so runtime manifest validation enforces it. Production deployment still refuses enabled writes or positive percentages until C4 wipe coverage is green. No deployment values or flag defaults change.

Persist content-free, create-only sweep candidates before each lake upload so a refused replay, superseded candidate, ambiguous response or worker loss cannot lose orphan discovery. Candidate-store failures refuse uploads. The serving path never deletes a replay candidate that another writer might reference.

Follows #24811 (merged). Closes the fix-before-enable item lead2 recorded on #24811: replay-refused uploads no longer lose orphan discovery.

Product invariants affected

none

How it was verified

  • Rebased on main after Offload large transcripts to the encrypted object lake (default off) #24811: six focused lake, pointer, lifecycle, config, runtime-env and offload files, 612 passed, zero failed.
  • Initial three focused files: 318 passed, zero failed; environment preflight: 18 passed, zero failed, eight optional warnings. Async scan: zero blocking findings.
  • Current C2-stack metadata validation: 4/4 passed; full C2-stack preflight: 36/36 passed. The broad selector is incomplete: 305/2,684 files have verified passing coverage; 2,379 remain uncovered. Own broad test processes were stopped under sustained shared-host overload. No full-suite green claim.
  • Required main-base make preflight: 15 passed, one failed, three cancelled, 26 not reached. The sole failure is the inherited synthetic-merge conflict in backend/database/review_changes.py and backend/docs/people-generation-writers.json. No rebase or unrelated conflict resolution is included. Main-base metadata: three passed, same one failure.

Hermetic tests used this worktree's Python 3.11 venv with GOOGLE_APPLICATION_CREDENTIALS and CLOUDSDK_* unset before launch. GCP tier: none. No real KMS/GCS or deployed runtime acceptance claimed.

Tests

Real AES-GCM/AES-KW and filesystem storage cover v2 format, v1 compatibility, independent DEKs under forced equal nonces, corrupted/swapped wraps, unknown/truncated envelopes, warm-cache shredding, rotation without rewriting and unchanged KMS decrypt counts. Config/runtime/lifecycle tests cover dev admission, real bindings and the C4 production gate. Codec tests cover offload round trips, absent/shredded states and upload-fence replay. Orphan regressions cover both inline-refusal checks, privacy/lock/tombstone and kill-switch changes, domain refusal/error, bounded upload/preload exhaustion, superseded sources, deferred CAS failure, preservation of already-referenced objects, write-ahead ordering, invalid/missing candidate storage and ambiguous upload completion.

UI evidence

UI-Evidence: none -- backend only

Failure class (fixes)

Failure-Class: none

Enable conditions

The #24811 replay-refusal orphan item is closed by durable write-ahead sweep candidates: every put records its content-addressed bucket/key in lake_upload_candidates before upload, and candidate-store failures prevent the upload. Refused or superseded replays retain discovery without deleting an object another writer may reference. C3 must consume candidates only after fencing writers and proving absence of all live/historical references. The janitor is not implemented here; production enablement still requires C4 wipe coverage and the existing authorized provisioning/ramp conditions.

Review fixes (round 1)

  • Bindings check parses OBJECT_LAKE_WRITE_PERCENT numerically: 0, 0.0 and 0 admit no writes and need no bindings; unparseable values still require them (test_enabled_write_binding_check_parses_percent_numerically, contract file 63 passed).
  • Upload-candidate change note now states the extra read on the AlreadyExists race path.

🤖 Generated with Claude Code

@Git-on-my-level Git-on-my-level self-assigned this Nov 7, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T01:37:15.166593Z 5579224 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 11 files

You’re at about 94% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Git-on-my-level and others added 2 commits November 8, 2026 07:32
A zero cohort written as 0.0 no longer demands bucket and KMS bindings;
unparseable values still do. Document the extra candidate read when
concurrent first puts race.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 4207f0d into main Nov 8, 2026
62 checks passed
@Git-on-my-level
Git-on-my-level deleted the pgf/dek-per-object-keys branch November 8, 2026 05:35
Git-on-my-level added a commit that referenced this pull request Nov 11, 2026
…conversation deletion (#24897)

<!-- claude-projects-attribution: {"github_login":"Git-on-my-level"} -->
_Requested by **David**_

Builds on the merged per-object DEK foundation (#24883).

## What changed and why

Account wipe requires a verified lake prefix purge after the
cell/directory step and before Firestore deletion. Its final key step
cancels every pending upload session and verifies terminal storage
status, repeats the current-bucket prefix purge, then repeats session
fencing and deletes each candidate's object in its recorded bucket with
verified absence before transactional compare-and-delete. It verifies
candidate absence and destroys wrapped space keys LAST. Failures retain
discovery and keys for retry, including when current bucket
configuration is unset.

Explicit conversation deletion durably fences the conversation and merge
donors and purges objects before document deletion. It synchronously
cancels pending sessions, queries terminal status, deletes each recorded
bucket binding, verifies absence, and compare-and-deletes unchanged
candidate rows. Storage/discovery failures return retryable 503; success
stays HTTP 204. Former buckets remain covered. Fenced writers retain
their post-upload authority checks and transactional settlement;
create-only retries preserve reused referenced objects for the deleting
orchestrator.

Each upload attempt uses a separate GCS resumable session initiated with
exact size, fixed metadata and generation-zero precondition before any
payload bytes. Its session URI is persisted with the candidate attempt
under the same transactional deletion fences. A refused candidate
transaction cancels the empty session best-effort. One PUT sends the
complete encrypted payload, capped at 8 MiB, without SDK retries. 412 at
initiation or finalization follows the create-only replay path. A
five-second pointer-success budget splits remaining time between
connect/read waits; deletion authority comes from storage session
fencing, never elapsed time.

Fencing sends DELETE to the recorded session URI, followed by the
documented status query: a zero-byte PUT with `Content-Range: bytes
*/<declared size>` (the attempt records its size). The terminal set is
an allowlist measured against GCS in a dev bucket on 2026-11-09:
- 200/201: finalized. Status and cancel both return 200 once the upload
has finalized.
- 412: a generation-0 finalize was refused. This is sticky: every later
status, cancel or upload returns 412, and the session cannot create the
object even after it is deleted.
- 499: cancelled. Every later status, cancel or upload returns 499,
including the final chunk of a partly uploaded session.
- 404/410: the service no longer knows the session.

Any other response fails closed and retains discovery: 308 (open), 400
(a malformed request, which poisons the session with 400 without proving
its state), auth errors, throttling, 5xx and transport errors. Every
retry cancels and queries again. [GCS resumable upload
protocol](https://cloud.google.com/storage/docs/performing-resumable-uploads)
supplies the storage fence. The session URI is a sensitive capability:
it is stored only in candidate state and excluded from pointers, logs,
metrics and raised exception messages. Local/offline uses persistent
filesystem sessions with the same transport path and cancel/finalize
locking.

Legacy timestamp-only attempts, including the `legacy` key and
candidates predating `in_flight`, fail closed at any age because they
have no recorded session to cancel. Lake writes have never been admitted
outside local/offline/dev (`_WRITE_STAGES`); no production legacy rows
exist. Production admission remains closed. No age-based erasure,
delayed re-purge, Cloud Tasks scheduling, internal re-purge handler or
wipe-drain setting remains. No new infrastructure or production
configuration changes.

## Product invariants affected

[INV-DATA-1](product/invariants/data-plane-continuity.md): deletion
markers, candidates and key authority use the customer data-plane
Firestore client.
[INV-CUTOVER-1](product/invariants/account-cohort-cutover.md) and
[INV-MEM-3](product/invariants/memory-canonical-fail-closed.md) cover
B2/C2 dependencies against main; C4 retains their admission and
continuity contracts.

## How it was verified

Round 12 passed 860 distinct targeted tests (0 failures/skips),
including 12 loopback Firestore tests. Runtime Pyright passed with 0
errors / 530 warnings; expanded changed test/support typing remains red
with 99 errors / 2999 warnings. The route-policy baseline, async-blocker
gate and formatting passed. Exact commands and exclusions are recorded
in `.agent-artifacts/pgf/c4-fix-r12-result.md`. Tests use local
encrypted storage, strict synthetic Firestore transactions, real HTTP
deletion serialization, scrubbed agent credentials and the prescribed
synthetic encryption secret. No GCP tier, production data or api.omi.me
access. Full selector/preflight and repository-wide typecheck are
excluded by this fix-round brief. No push, merge or deployment.

## Tests

Regressions cover lost-writer sessions cancelled by conversation
deletion/account wipe, rejected late finalization after key destruction,
finalization immediately before cancellation, terminal-status
classification, nonterminal/transport failure retention and key
preservation, legacy attempts at arbitrary ages, fenced candidate
transactions, capability redaction, initiation/finalization 412 replay,
independent same-key settlement, and existing owner/conversation
settlement races. Existing former-bucket deletion, absent current
configuration, delete/absence-check failures, wipe ceremony and HTTP
deletion contracts remain covered. Session persistence across local
client restart and generation-zero finalization are tested. Erasure APIs
accept no clock/expiry arguments. Candidate range drivers remain
single-field automatic-index maintenance queries (`serving=False`);
obsolete clock/expiry/scheduling driver arguments are removed. The
route-policy baseline is checked after route removal.

## UI evidence

UI-Evidence: none -- backend only

## Failure class (fixes)

Failure-Class: none

## Scoped cleanups (optional)

The artifact orchestrator reads raw donor inventory and performs
candidate cleanup even with the bucket unset. The developer delete
endpoint shares this orchestrator and retains its existing HTTP 500
failure behavior. Merge-internal donor deletion and pre-existing orphans
remain C3 scope. The accepted seven-day wrapped-key PITR tail remains.
Object/candidate purges remain pinned to release v1. Activation remains
separately authorized and requires the wipe-coverage gate and deployed
session-aware writers and deletion handling.

Line-Count-Exception: backend/routers/conversations.py | 2590 -> 2599 |
Preserve the existing delete route and its retryable storage/discovery
failure mapping; session mechanics live in the lake modules. Measured
against merge-base 697e744.

## Review fixes (round 15)

- 307c4f: with `BUCKET_CANONICAL_AUDIO` set, the conversation delete
route's donor-inventory read (`get_conversation_raw_snapshot`, now
narrowed to `sync_merged_from`) ran outside the 503 mapping. A failure
there now returns the retryable 503, before any audio or lake purge is
scheduled.
- fd278c: the single payload PUT now carries its full `Content-Range:
bytes 0-(n-1)/n`. Measured in GCS: it finalizes with 200 for 5 B and 300
KB payloads. The local session model accepts that exact range (or none,
as GCS also does) and rejects any other range.

## Review fixes (round 14)

- dffbc2: a finalize that returns 412 now fences its own session
(cancel, then a terminal status check through the session's client)
before settlement drops the URI. A status that is not terminal keeps the
attempt discoverable. Measured in GCS: 412 is sticky and terminal.
- babf78: the deletion protocol doc now records `size` and describes the
sized status query and the measured allowlist.

## Review fixes (round 13)

- c47184: the fence now uses an allowlist (200/201/404/410/499) instead
of a 4xx denylist, and the status query names the session's declared
size. Both were confirmed against GCS behavior measured in a dev bucket.
CI: local session records no longer use the lifecycle field name
`status`.

## Review fixes (round 12)

- Replaced elapsed-time upload assumptions with per-attempt GCS
resumable-session cancellation and terminal-status verification before
recorded-bucket deletion, absence checking and candidate erasure.
- Removed age-based cleanup, delayed scheduling/handler/policy entry,
the drain setting and registry entry, and their obsolete tests. Erasure
has no `now` parameter.
- Retained final key destruction, post-upload checks, create-only replay
and transactional settlement fences. Finalize responses populate the
blob generation so conditional fenced-writer deletion retains the SDK
behavior. Initiation-time 412 records settled discovery without a
session capable of committing.
- Legacy attempts fail closed indefinitely; malformed candidate state is
rejected. Session capabilities never appear in returned references or
raised messages.
- Updated persistent local session transport, query-driver signatures,
deletion protocol documentation and the required regression suites.

## Earlier review fixes retained

- Import `FieldFilter` from the public `google.cloud.firestore_v1` seam
for isolated test imports.
- Settlement re-reads conversation and account deletion fences in its
transaction and refuses a pointer after fenced object cleanup.
Conversation deletion always writes the durable tombstone, including
bucketless revisions.
- The R14 test guard retains quarantine behavior for legacy account
markers without `wipe_status`; no task claim or reconciliation re-drive
is admitted.
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