Skip to content

fix(bb-file-bucket): reconcile current files after version deletion - #693

Merged
xyos merged 6 commits into
aws:mainfrom
ikenyal:fix/file-bucket-current-version-deletion
Nov 3, 2026
Merged

xyos merged 6 commits into
aws:mainfrom
ikenyal:fix/file-bucket-current-version-deletion

Conversation

@ikenyal

@ikenyal ikenyal commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Permanently deleting the newest stored data version of a local FileBucket removes its version-history entry but leaves its current body and metadata on disk. For histories containing only data versions, listVersions() then identifies the previous version as current while get(), scan(), and current presigned downloads still expose the deleted content. Deleting every stored data version leaves the same stale file accessible even though listVersions() is empty.

On S3, deleting the current data version exposes the next entry in the version history, which may be another data version or a delete marker: Restoring previous versions, Working with delete markers.

Issue #, if available: None for the original current-copy reconciliation fix.

Changes

  • Reconcile the mock's current body and metadata when deleting its newest stored data version. Copy the next stored data version without creating another version, preserving modification time and metadata, or remove the current copies when no data versions remain.
  • Do not remove an active __deleted__ flag during version deletion. get() and scan() continue to honor an active flag; deleting an older or unknown version does not rewrite the current file.
  • Share the existing newest-first version reader between deletion and listVersions() without yielding during reconciliation. Count only regular files, ignoring nested-key directories. This overlaps with the listing filter in fix(bb-file-bucket): ignore nested key directories in mock version history #1141; its explicit-version get() and restoreVersion() guards remain separate.
  • Complete current-body/metadata updates or removal before deleting the target version history. Preserve the version body until its sidecar is removed, tolerate missing copies, and propagate other I/O failures so the same version ID can be retried. This improves recoverability, not atomicity or rollback.
  • Keep regression tests at the mock API, dev file-server, and comprehensive frontend API layers, and the patch changeset covering FileBucket and the umbrella package.
  • Narrow the README/DESIGN/changelog wording: the mock does not retain historical delete markers across a subsequent put(), so this is not full S3 version-history parity.

Known limitation, not fixed here: put(old) -> delete() -> put(replacement) -> permanent deletion of the replacement exposes old with this PR, whereas S3 would make the earlier delete marker current. This already diverges on main (which returns the stale replacement); current-copy reconciliation alone cannot recover the discarded marker history. The exact sequence and its effect on get(), scan(), and listVersions() are documented under DESIGN's Mock vs AWS Behavior Differences. This is distinct from #1167, which makes local downloads honor a marker that is still present.

The remaining historical-marker behavior is tracked separately in #1209; this PR does not resolve it.

The AWS implementation, public API signatures, conditional exports, and mock storage format are unchanged. The delete() JSDoc now describes promotion and active-marker preservation. Historical marker support remains outside this PR.

Validation

  • The original regression tests reproduced stale reads/downloads before the fix and pass after current-copy reconciliation. Coverage includes body/metadata promotion, modification time, tied timestamps, last-version removal, repeated/concurrent deletion, active marker preservation, unknown IDs, older-version deletion, non-versioned buckets, and persisted-state reads.
  • Re-ran the reviewer's delete/re-upload/delete-version sequence against the current main FileBucket source and this PR, using real FileBucket/core/logger code and isolated temporary data. Main returns replacement; this PR returns old; both list k and mark v1 current. This confirms the documented remaining limitation, not a fix for it. S3's expected deleted state is based on its documented versioning semantics; no AWS deployment was performed for this local-mock fix.
  • npm run build
  • npm run lint and npm run lint:deps
  • npm test -w @aws-blocks/bb-file-bucket
  • npm test across all workspaces, with serial test-file execution and all generate-client fixture cases run in separate processes; none excluded
  • npm run test:e2e:local (comprehensive local E2E, vendorize, IAM-boundary synth, and background-suite regression tests)
  • API reports, export consistency, client user-agent consistency, packed assets, runtime guards, documentation synchronization, and changeset guards and their regression tests
  • git diff --check upstream/main

The latest review follow-up adds regression tests for nested-key directories, failed body/metadata promotion, failed last-version cleanup, failed version-sidecar removal, missing-file tolerance, and retrying after reopening the bucket. The new failure cases fail before this follow-up and pass after it, using real temporary filesystem obstructions rather than stubbing FileBucket behavior. The comprehensive frontend API suite also covers deletion against a prefix key without affecting its nested objects.

Checklist

  • PR description included
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ikenyal
ikenyal requested a review from a team as a code owner October 5, 2026 02:18
@changeset-bot

changeset-bot Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 46fdd5a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@aws-blocks/bb-file-bucket Patch
@aws-blocks/blocks Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

belaboe
belaboe previously approved these changes Nov 2, 2026

@belaboe belaboe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, verified red->green (8/34 new tests fail on main, all pass at head) and the S3 cases: deleting the newest version exposes the previous one in get/scan/listVersions/downloads, and deleting every version leaves nothing readable. Two non-blocking suggestions:

  1. The now-unguarded unlinkSync (index.mock.ts L227) throws EISDIR when readVersions returns a directory (docs while docs/readme.txt exists; main swallowed it), which surfaces as a 500. #1141 fixes that filter and conflicts with this PR in listVersions: whichever lands second, please move its withFileTypes + isFile() filter into readVersions rather than taking this side.
  2. Rewrite content/ + meta/ before unlinking the version file, so a failed write leaves state retryable (today it can leave v1's body with v2's content-type, and a retry is a no-op).

Nit: mention promote-on-delete in the delete() JSDoc. CI hasn't run on this PR yet (workflows await approval).

@ikenyal

ikenyal commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for checking the regression cases and catching the failure path. I've addressed all three suggestions:

  • Added the regular-file filter in the shared readVersions(), so both listing and deletion ignore nested-key directories. This matches the listing filter in fix(bb-file-bucket): ignore nested key directories in mock version history #1141; its get()/restoreVersion() guards remain separate.
  • Moved current body/metadata reconciliation before removing the target version. The version body is now removed last, after its sidecar; missing files are tolerated, while other I/O failures propagate. Regression tests reproduce failures with real filesystem obstructions and verify that retrying the same version ID, including after reopening the bucket, completes successfully.
  • Added promotion and active-marker behavior to the delete() JSDoc.

DESIGN also makes clear that this is retryable reconciliation, not atomicity or rollback. The historical delete-marker limitation tracked in #1209 is unchanged.

Build, lint, FileBucket tests, the full workspace unit suite, and local E2E all pass on the updated branch, including the nested-key deletion case through the frontend API.

@xyos
xyos merged commit 8fb67ec into aws:main Nov 3, 2026
42 checks passed
harsh62 added a commit that referenced this pull request Nov 3, 2026
Conflict resolution:

- packages/create-blocks-app/templates/auth/src/index.ts: #1239 edited
  templates/auth-cognito/src/index.ts, which this branch renamed to
  templates/auth and rewrote for the unified Auth block. Git applied the
  hunks to the renamed file; the one conflict was in refreshTodos()'s
  catch. Kept this branch's isBlocksError(error,
  'NotAuthenticatedException') check and showError(el, unknown) call, and
  added #1239's boolean returns. #1239's mutateTodo() helper and the
  caught "Show last code" lookup are ported as-is, except that they use
  isBlocksError for the signed-out check and pass the error straight to
  this branch's showError, which already takes unknown, so #1239's
  errorMessage() helper is not needed. No templates/auth-cognito/
  directory is re-created.
- .changeset/auth-cognito-todo-errors.md renamed to
  auth-template-todo-errors.md, and its text now names the `auth`
  template. Package unchanged (@aws-blocks/create-blocks-app, patch).
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.

3 participants