← Back to Pull requests

feat(drive): sweep chunks left by aborted uploads #198

Open
unknown opened this pull request with 515 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 05, 2026 04:16 UTC
Author

What and why

P41 (#172), item "A sweep deletes drive chunk prefixes that have no manifest and are older than a documented age longer than the longest allowed upload, so it never deletes an upload in progress. VaultStore gains a listing that returns last_modified." Supersedes #191, with that review addressed, as one commit.

A drive upload writes its chunks first and its manifest last, so an upload that stops partway leaves chunks nothing points to.

  • platform-storage:

  • - VaultStore::list_entries returns each object's path, size and last-modified time (VaultEntry).
    - TenantPaths::drive_chunk_parts and drive_manifest_parts parse drive paths back to (TenantId, ObjectId).
    - list_drive_entries_all_tenants is the only cross-tenant listing. The tenants prefix it lists is private to the crate, and it returns only parsed drive entries, each with its own tenant's path, so no path spanning tenants leaves platform-storage. The THREAT_MODEL.md cross-tenant row says so.
  • platform-api:

  • - PUT /api/v1/drive/objects/{id}/manifest returns 409, audited as data.access "denied", unless every chunk 0..chunk_count is stored. An upload that paused long enough to be swept now fails visibly instead of committing a file whose chunks 404.
    - sweep::sweep_orphaned_chunks deletes the chunks of objects with no manifest and no chunk written for ORPHAN_MIN_AGE (24 hours). Just before deleting, it re-reads the manifest and re-lists the object's chunks, so a manifest or chunk written since the first listing saves the object.
    - Only chunks this run deleted are counted, and an object it deleted nothing from (another replica got there first) emits no "ok" audit event.
    - A storage error on one object no longer stops the run; the other objects are swept and the first error is returned.
    - spawn_sweeper runs it hourly from main.
  • docs/ARCHITECTURE.md, docs/THREAT_MODEL.md, CHANGELOG.md.
  • Limits, documented in the module and ARCHITECTURE.md:

  • Ages are the store's last-modified times, so the API host's clock must be within hours of the store's.

  • A chunk re-sent between the sweep's re-list and its deletes can still be deleted. That upload's manifest is then refused, so no broken file is listed.
  • How it was tested

    backend/crates/platform-api/tests/drive_sweep.rs, with a vault that reports chosen last-modified times:

  • aborted_upload_is_swept, recent_upload_is_left_alone, the_newest_chunk_decides_an_objects_age, complete_objects_are_never_swept.

  • delete_that_failed_partway_is_finished_by_the_sweep_only_without_a_manifest, a_manifest_is_matched_only_within_its_own_tenant, other_tenant_data_is_ignored.

  • a_manifest_written_after_the_listing_saves_the_object, a_chunk_rewritten_after_the_listing_saves_the_object.

  • chunks_already_deleted_are_not_counted, one_failing_object_does_not_stop_the_others, a_listing_outage_fails_the_sweep_and_deletes_nothing.

  • a_swept_upload_cannot_commit_its_manifest: through the API, the swept upload's manifest gets 409 and nothing is listed.
  • drive_api.rs: a_manifest_needs_every_chunk_it_names (no chunks, a gap, then accepted) and an_empty_file_needs_no_chunks. Existing drive tests now upload chunks before the manifest, as the client does.

    audit_coverage.rs: orphan_sweep_deletions_are_audited, a_manifest_missing_chunks_is_audited_as_denied.

    platform-storage: drive_paths_parse_back_to_tenant_and_object, list_entries_reports_size_and_last_modified, and list_entries in the outage-classification test.

    Checklist

  • scripts/check.sh passes locally

  • Every new refusal has a negative test

  • Every new security decision emits a SECURITY_AUDIT_EVENT covered by audit_coverage.rs

  • Fails closed on missing configuration, key material, or attestation

  • No new cryptographic primitives; suites stay behind their type aliases

  • Synthetic or public data only (docs/DATA_POLICY.md)

  • Docs and CHANGELOG.md updated for user-visible changes

  • Architectural decision recorded in docs/adr/ if one was made (not required, per P41)
  • Diff: 515 lines (+386 / -129) across 6 files Reviewer: abendrothj Review duration: 5038m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.53) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.53 · 515 lines diff across 6 files
    0.53
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.374
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #198"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52.7% (MEDIUM) · Higher = larger blast radius
    52.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 30.1% · Safe to merge
    30.1%