Skip to content

feat(snapshot s3)!: always report the bucket as the one artifact, and stop failing on an empty bucket - #1410

Merged
mbevc1 merged 12 commits into
mainfrom
snapshot-s3-bucket-is-the-artifact
Nov 26, 2026
Merged

mbevc1 merged 12 commits into
mainfrom
snapshot-s3-bucket-is-the-artifact

Conversation

@gsavage

@gsavage gsavage commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

kosli snapshot s3 now always reports exactly one artifact, named after the bucket, and a bucket
with nothing to fingerprint is no longer an error. This changes the default behaviour of the
command; it replaces the --allow-empty-bucket flag from #1405, which was reverted in #1407.

The approach was agreed by the team and is recorded in kosli-dev/cloud-capture#216.

Why

  • A bucket that was being snapshotted and was then emptied failed every later snapshot, so Kosli
    kept showing the last content the bucket held and the loss of the files was never recorded.
  • A bucket holding one object was reported as an artifact named after that object, while a bucket
    holding several was named after the bucket. Adding a second file renamed the artifact, and a
    one-object snapshot did not say which bucket it came from.

What changes for users (breaking)

Case Before Now
One object Artifact named after the object Artifact named after the bucket; same fingerprint
No objects, or only folder markers Fails: no matching file or dirs in bucket Reported as an empty bucket
--include / --include-regex / --exclude / --exclude-regex leave nothing Fails with the same error Reported as an empty bucket, with a warning
--skip-unusable-checksums skips every object Empty artifact list Reported as an empty bucket
Several objects Artifact named after the bucket Unchanged

"Reported as an empty bucket" means one artifact named after the bucket, with:

  • Fingerprint e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, which is what
    kosli fingerprint --artifact-type dir gives for an empty directory.
  • creationTimestamp 0, since no object supplies a modification time. A constant keeps
    repeated snapshots of an empty bucket identical.

The fingerprint calculation for buckets with content is unchanged: a single object is still
fingerprinted as that file, and several as a directory.

Not changed: with --fingerprint-source metadata and without --skip-unusable-checksums, an
object with no usable checksum still fails the snapshot.

Things for the reviewer to weigh

  • Log levels. An unfiltered empty bucket logs a plain line on stdout. Filters that leave
    nothing log a [warning], because a mistyped filter has the same effect and now no longer fails.
  • digest.VirtualDirSha256 accepts no files. It used to return an error; it now returns the
    empty-directory fingerprint, matching DirSha256 on an empty directory. The value is pinned in a
    test.
  • The ADR (docs/adr/20260911-s3-fingerprint-from-virtual-tree.md) gains a dated note rather
    than being rewritten, since the calculation it records still stands.

Testing

  • go test --short ./... passes against the local Kosli server, including the S3 command suite.
    That suite confirms the server accepts the empty-directory fingerprint and a timestamp of 0.
  • make lint reports 0 issues.
  • The real-AWS smoke test (TestGetS3Data) is skipped without AWS credentials and was not run.

Checklist

  • Docs are autogenerated from CLI help — make sure the help text reflects your changes
  • Helm chart (charts/k8s-reporter/) updated, if needed. Note: these changes live in a separate PR
  • Terraform provider and related changes (terraform-provider-kosli, terraform-aws-kosli-reporter) updated, if needed

The Helm chart does not snapshot S3. Whether terraform-aws-kosli-reporter relies on the old
behaviour has not been checked.

🤖 Generated with Claude Code

gsavage and others added 9 commits November 25, 2026 10:49
A bucket holding one object was reported as an artifact named after
that object, while a bucket holding several was reported as an artifact
named after the bucket. Adding a second file to a bucket therefore
renamed the artifact, and a one-object snapshot did not say which
bucket it was taken from.

The team decided that an S3 snapshot always reports the bucket as its
one artifact. The fingerprint is calculated as before: a single object
is still fingerprinted as that file, so it keeps matching an artifact
attested with --artifact-type file. Only the name changes.

BREAKING CHANGE: a snapshot of a bucket holding a single object now
names its artifact after the bucket instead of after the object.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…sult

The artifact is now always named after the bucket, which the caller
already holds, so the fingerprint pipeline no longer needs to decide a
name and hand it back.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ctory

VirtualDirSha256 refused an empty file list, although DirSha256 accepts
an empty directory and returns the sha256 of no input. An S3 bucket
with nothing to fingerprint is about to be reported as an artifact
rather than failing the snapshot, and its fingerprint should be the one
`kosli fingerprint --artifact-type dir` gives for an empty directory,
so the virtual calculation now agrees with the on-disk one for that
case too. The value is pinned in the test because snapshots will carry
it.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A bucket that listed no objects, or only folder markers, failed the
snapshot with "no matching file or dirs in bucket". When a bucket that
was being snapshotted was emptied, every later snapshot failed, so
Kosli kept showing the last content the bucket held and the loss of the
files was never recorded.

An empty bucket is a valid state, so it is now reported like any other:
one artifact named after the bucket. Its fingerprint is that of an
empty directory, the value `kosli fingerprint --artifact-type dir`
gives for one, so the calculation is the one already used for a bucket
with content. No object supplies a modification time, so the timestamp
is 0, which keeps repeated snapshots of an empty bucket identical. A
line on stdout says the bucket held no objects.

A filter that leaves nothing still fails; that changes next.

BREAKING CHANGE: snapshotting an S3 bucket that holds no objects now
succeeds and reports the bucket as an empty artifact, where it used to
exit with an error.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
When --include, --include-regex, --exclude or --exclude-regex left no
object to fingerprint, the snapshot failed with "no matching file or
dirs in bucket". The check dates from when the filters were added, on
the reasoning that nothing left to report most likely meant a mistyped
filter.

The team decided that the filters define what the snapshot sees of the
bucket, so a filtered view with nothing in it is reported the same way
as a bucket with nothing in it: one artifact named after the bucket,
with the empty-directory fingerprint. Failing instead would leave Kosli
showing the content from the last successful snapshot after the
matching objects had been removed.

A mistyped filter is still a real risk, so this case logs a warning
rather than the plain line an unfiltered empty bucket gets.

BREAKING CHANGE: snapshotting an S3 bucket with include or exclude
filters that match no object now succeeds, with a warning, and reports
the bucket as an empty artifact, where it used to exit with an error.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
With --fingerprint-source metadata and --skip-unusable-checksums, a
bucket in which no object had a usable SHA256 checksum was reported as
a snapshot with no artifacts. That was the only case in which an S3
snapshot carried an empty artifact list, and it left nothing in the
snapshot to say which bucket had been read.

An S3 snapshot now always carries exactly one artifact, the bucket, so
this case is reported like an empty bucket: named after the bucket,
with the empty-directory fingerprint. The warning naming the skipped
objects is unchanged.

BREAKING CHANGE: with --skip-unusable-checksums, a bucket whose objects
are all skipped is now reported as one artifact with the
empty-directory fingerprint instead of as an empty artifact list.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The help text said only that the content is reported as one artifact,
and that skipping every checksum gives an empty snapshot. Both are out
of date now that the artifact is always named after the bucket and a
bucket with nothing to report is an empty-directory artifact rather
than an error or an empty list.

The long description now states the name, which `kosli fingerprint`
artifact type the fingerprint corresponds to, and what is reported when
nothing is left, including the fingerprint value so it can be
recognised in Kosli. The --skip-unusable-checksums flag text follows.

The fingerprint ADR described the single-object artifact as named
after the object; it gains a dated note recording what has changed
rather than being rewritten, since the calculation it records stands.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…oke test

No case in TestGetS3Data ever set wantArtifactName, so it always fell
back to the bucket name. The artifact is now always named after the
bucket, so the field and its fallback say nothing and are removed.

The "includePaths is a file" case looked its fingerprint up under the
bucket name while the artifact was named README.md, so it could not
have passed against real AWS before the naming change. It is skipped
without AWS credentials and has not been run here.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The command suite still expected --include matching nothing to fail,
and the old wording for a bucket whose every checksum was skipped.
Both now expect the bucket to be reported as empty, and an
--exclude-regex that removes every object is covered alongside them.

A new case snapshots a bucket holding only a folder marker, from both
fingerprint sources. Because the suite reports to the local Kosli
server, it also shows that the server accepts what an empty bucket is
reported with: the empty-directory fingerprint and a timestamp of 0.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions github-actions Bot added documentation Improvements or additions to documentation go Pull requests that update go code feat breaking change labels Nov 25, 2026
@claude

claude Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @gsavage's task in 1m 34s —— View job


Follow-up review complete ✅

  • Fetch existing review comments / prior Claude findings
  • Diff BEFORE..AFTER (6552b00..03db746) and identify touched regions
  • Check status of each prior finding touched by new commits
  • Flag new bugs/regressions introduced by the new commits (none found)
  • Post summary comment

Summary posted: #1410 (comment)

The only Claude-raised finding (the aws.go:508 filter-warning wording) was already resolved before this diff range and wasn't touched by the two newest commits. The newest commits (9c859ef9, 03db7460) only touch test files and the ADR doc — dropping the now-redundant wantArtifactName test field and clarifying two ADR sentences that still described a single object as named by its basename — both addressing nits from mbevc1's earlier comment. No new bugs or regressions found in the touched lines, so no new inline comments were posted.

Not run: go vet/go build (tool permissions in this environment didn't allow it) — review was a manual read of the diff; risk is low since the changes are test-field removal and prose edits only.

Comment thread internal/aws/aws.go Resolved
…d the bucket

The warning fires whenever a filter is set and no object is left, but
that does not show the filters removed anything: the bucket may have
been empty, or held only folder markers, before any filter ran. Saying
"no object is left by the filters" then points someone debugging at
their filters when the bucket itself is the cause.

Reword the warning to say that no object matches the filters or the
bucket is empty. Counting the objects seen before filtering would let
the message be exact, but the reported snapshot is the same either way,
so the wording change is enough.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Comment thread internal/aws/aws.go Resolved
@gsavage

gsavage commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

I've tested this locally, using an S3 bucket into which I placed files, emptied it, uploaded with and without SHA256. In all cases the result was as expected -- a single artifact reported, with the name of the S3 bucket and the fingerprint for the files that matched, or the fingerprint for an empty bucket as the case may be.

Comment thread cmd/kosli/snapshotS3.go
const snapshotS3LongDesc = snapshotS3ShortDesc + awsAuthDesc + `
You can report the entire bucket content, or filter some of the content using ^--include^ / ^--exclude^ (literal prefix match) or ^--include-regex^ / ^--exclude-regex^ (Go regular expressions matched against the full object key).
In all cases, the content is reported as one artifact. If you wish to report separate files/dirs within the same bucket as separate artifacts, you need to run the command twice.
In all cases, the content is reported as one artifact, named after the bucket. If you wish to report separate files/dirs within the same bucket as separate artifacts, you need to run the command twice.

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.

Both runs now produce an artefact with the same name, and the sentence does not say they need separate environments.

@mbevc1

mbevc1 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

The change looks good and matches what was agreed.

Just few minor observations:

  1. A bucket holding one zero-byte object has the same fingerprint as an empty bucket.
    A probe test confirmed that a bucket containing only an empty .keep reports e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855. The server detects snapshot changes by fingerprint only (_started_or_changed and _exited in src/domain/environment_snapshots.py), so emptying that bucket records no new snapshot. The help text calls the value "the fingerprint of an empty directory"; it is also the fingerprint of an empty file. Low severity, but worth a sentence in the help or an explicit decision to accept.

  2. The Cloud Capture customer docs go stale.
    administration/cloud_capture/getting_started.md:234 in kosli-dev/docs says a bucket where no object has a checksum "is reported as holding no artifact". After this PR it is reported as one artifact with the empty fingerprint. client_reference/kosli_snapshot_s3.md still carries the old wording too; the PR checklist says that page is generated from the help text.

  3. kosli-dev/cloud-capture#227 is built on the removed flag.
    The draft passes --allow-empty-bucket, and its local/verify.py expects a snapshot with no artifact. Both are wrong against this PR.

  4. The empty artifact shows a 1970 timestamp in the UI.
    The issue left the rendering unchecked. src/app/templates/partials/artifact_details.html:16 passes creationTimestamp[-1] straight to dayjs.unix with no handling for 0. The server accepts the value: the schema only requires an integer, and the command suite passed in CI.

Nits

  • Tests: wantArtifactName in internal/aws/s3_fingerprint_test.go and internal/aws/s3_metadata_test.go is now always the bucket name, so the field is redundant.
  • ADR: the amendment note in docs/adr/20260911-s3-fingerprint-from-virtual-tree.md covers one phrase, but lines 42 and 56 still describe a single object as named by its basename.

gsavage and others added 2 commits November 26, 2026 08:59
… cases

Every S3 snapshot now names its one artifact after the bucket, so the
wantArtifactName field held the same value in every case of both
TestPinnedFingerprints tables and told the reader nothing. Assert the
bucket name directly instead, which leaves the fingerprint as the only
thing each case pins.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The amendment note under Guarantees says a single object is now named
after the bucket, but two other sentences in the record still described
the artifact name as the object's basename without pointing at it. A
reader landing on either one would take the old naming as current.

Annotate both in place rather than rewrite them, so the record still
shows what was decided at the time.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@claude

claude Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Follow-up review: commits 9c859ef..03db746 (since 6552b00)

Scope: git diff 6552b001..03db7460 touches only docs/adr/20260911-s3-fingerprint-from-virtual-tree.md, internal/aws/s3_fingerprint_test.go, and internal/aws/s3_metadata_test.go — test cleanup plus an ADR wording tweak.

Prior findings:

  1. internal/aws/aws.go:508 — filtersSet warning could mislead when the bucket was empty to begin with (raised by Claude in review 6058224036). Resolved earlier, in 6552b001 (the BEFORE commit for this diff) — the warning was reworded to "...matches the include and exclude filters (or the bucket is empty)". Not touched by the newest commits; no regression introduced. Thread already has a resolution reply from both gsavage and Claude — nothing further to close.
  2. cmd/kosli/snapshotS3.go:15 — long-desc wording about running the command twice for separate artifacts (raised by mbevc1, not a Claude finding, so out of scope for this follow-up per the task's "Claude findings only" instruction). File not touched by the newest commits — still open, unaddressed.

Nits from the PR-body comment thread (mbevc1), now addressed by these commits:

  • wantArtifactName redundancy in s3_fingerprint_test.go / s3_metadata_test.go — field removed, assertions now use fakeS3TestBucketName directly. Resolved (commit 9c859ef9).
  • ADR lines describing a single object as "named by its basename" — both call-out sentences (under "The switch is pinned" and "Snapshot equals attestation") now carry a parenthetical noting the name is the bucket name since the 2026-11-25 amendment. Resolved (commit 03db7460).

New inline comments: 0. The touched hunks are mechanical (dropping a now-constant test field, clarifying ADR prose) and don't introduce any new bug, security issue, or regression.

Note: go vet/go build could not be run in this environment (tool permissions didn't allow it), so this was a manual read of the diff rather than a compiled check. The changes are test-field removal and comment-only edits, so risk is low.

View job run

@gsavage

gsavage commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

We left client_reference/kosli_snapshot_s3.md alone, since that page is regenerated from the help text at release

@gsavage
gsavage requested a review from mbevc1 November 26, 2026 09:10
@gsavage

gsavage commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @mbevc1. In reply to #1410 (comment):

  1. Zero-byte object has the same fingerprint as an empty bucket. This is a design question for
    the team, so it is tracked in kosli-dev/server#8356 rather than changed in this PR.
  2. Cloud Capture docs. docs(cloud capture): describe a bucket as one artifact, empty or not docs#567 updates
    administration/cloud_capture/getting_started.md. It is a draft and will not be merged until
    this CLI change is released. client_reference/kosli_snapshot_s3.md is left for the release to
    regenerate from the help text.
  3. kosli-dev/cloud-capture#227. That PR is no longer needed and has been deleted.
  4. 1970 timestamp in the UI. This follows from the decision to report a timestamp of 0 for an
    empty bucket. No change in this PR; it will be discussed with the team.

Nits, both addressed:

  • Tests: 9c859ef removes the redundant wantArtifactName field from both
    TestPinnedFingerprints tables.
  • ADR: 03db746 annotates the two remaining "basename" sentences so they point at the amendment
    note.

@mbevc1
mbevc1 merged commit a1a4b77 into main Nov 26, 2026
21 checks passed
@mbevc1
mbevc1 deleted the snapshot-s3-bucket-is-the-artifact branch November 26, 2026 09:57
mbevc1 added a commit that referenced this pull request Nov 26, 2026
The long description told users to run the command twice to report
separate files or dirs as separate artifacts. Since #1410 every S3
artifact is named after the bucket, and a snapshot replaces the
environment's previous one, so two runs against one environment leave
only the second. The text now says to run once per subset with
--include, each against its own environment.

Also reword the flags-auth example comment from "what is running in" a
bucket to "the contents of" it, matching the other examples.
mbevc1 added a commit that referenced this pull request Nov 26, 2026
…1412)

* docs(snapshot s3): say separate artifacts need separate environments

The long description told users to run the command twice to report
separate files or dirs as separate artifacts. Since #1410 every S3
artifact is named after the bucket, and a snapshot replaces the
environment's previous one, so two runs against one environment leave
only the second. The text now says to run once per subset with
--include, each against its own environment.

Also reword the flags-auth example comment from "what is running in" a
bucket to "the contents of" it, matching the other examples.

* docs(snapshot s3): shorten the separate-artifacts sentence

The sentence named only --include, although --include-regex and the
exclude filters can also split a bucket into subsets, and it ended by
repeating that the artifact is named after the bucket. It now offers
--include as an example and keeps only the reason that matters: a
snapshot replaces the environment's previous one.
gsavage added a commit to kosli-dev/docs that referenced this pull request Nov 26, 2026
…567)

## When to merge

This describes behaviour from kosli-dev/cli#1410, which is not released.
However S3 snapshots are not enabled for any customers, so it is safe to
merge this now.

## What

Updates the "What to expect" list under *Capturing S3 buckets* in
`administration/cloud_capture/getting_started.md`:

- New: each bucket reports exactly one artifact, named after the bucket,
including a bucket that
  holds a single object (previously named after the object).
- New: an empty bucket is captured rather than failing, and reports the
fingerprint of an empty
  directory (`e3b0c442…b855`).
- Changed: a bucket where no object carries a SHA256 checksum is
reported as an empty bucket, where
  the page said it "is reported as holding no artifact".

## Why

Cloud Capture snapshots buckets with `kosli snapshot s3`, and
kosli-dev/cli#1410 changes that
command's default behaviour as agreed in kosli-dev/cloud-capture#216.

## Not included

`client_reference/kosli_snapshot_s3.md` still carries the old wording.
That page is generated from
the CLI help text at release, so it is left for the release to
regenerate.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change documentation Improvements or additions to documentation feat go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants