Skip to content

fix(edp): decode SeaweedFS S3 ETag so sync diff works correctly - #105

Open
0x5t4l1n wants to merge 2 commits into
intel:mainfrom
0x5t4l1n:fix/seaweedfs-etag-base64-decode
Open

0x5t4l1n wants to merge 2 commits into
intel:mainfrom
0x5t4l1n:fix/seaweedfs-etag-base64-decode

Conversation

@0x5t4l1n

Copy link
Copy Markdown

Summary

Fixes #99.

Every file uploaded through the SeaweedFS webhook was permanently flagged "update" and re-ingested (delete + re-embed) on every Synchronize, even when the file had not changed.

Root cause

process_seaweedfs_event() set the stored ETag to attributes.md5, which SeaweedFS populates with a base64 of the raw 16-byte MD5 digest (e.g. sRLjVZozmrH9kzZ5Ke8HGg==). The sync diff compares this against the ETag returned by the S3 API, which is a plain hex string (e.g. b112e3559a339bb1fd93367929ef071a). These two representations never match, so every file is treated as changed on every sync.

Fix

SeaweedFS stores the actual S3-compatible ETag string base64-encoded in new_entry.extended['Seaweed-X-Amz-ETag']. The fix prefers that field (decoded from base64) so the stored value is identical to what the S3 API reports. The old attributes.md5 path is kept as a fallback for older SeaweedFS versions that do not populate the extended block.

Before

etag = attributes.get('md5', '')   # base64 of raw 16-byte digest

After

extended = new_entry.get('extended', {})
seaweed_etag = extended.get('Seaweed-X-Amz-ETag', '')
if seaweed_etag:
    try:
        etag = base64.b64decode(seaweed_etag).decode('ascii').strip('"')
    except Exception:
        etag = attributes.get('md5', '')
else:
    etag = attributes.get('md5', '')

Validation

Tested on a live E-RAG 2.3.0 deployment (SeaweedFS 4.22, k3s) as described in the issue:

  • S3 PUT → create event → file registered with ETag bb12e3559a339bb1fd93367929ef071a, identical to the S3 HEAD value
  • GET /api/files/sync → "no action" with no manual Synchronize required
  • Multipart uploads are handled correctly because the stored ETag includes the -N suffix, exactly as the S3 API reports it
  • No schema or API change

@0x5t4l1n
0x5t4l1n requested a review from a team October 18, 2026 11:46
@sys-aibot

sys-aibot commented Oct 29, 2026 •

Copy link
Copy Markdown

Claude finished @intelpljanot's task in 29s —— View job


Verdict: needs changes

  1. No tests for the changed behavior — src/edp/app/main.py:792-799 (rule 5). src/edp/tests/test_main.py has no tests for process_seaweedfs_event. Please add cases for: a Seaweed-X-Amz-ETag value that decodes to hex, a multipart hex-N value, a value wrapped in quotes, invalid base64 (fallback path), and an entry with no extended block.
    Fix this →

  2. The fallback still causes the same bug — src/edp/app/main.py:797,799 (rule 5). attributes.md5 is a base64 of the raw digest, so if extended is missing (the older SeaweedFS case the comment mentions), the stored ETag still won't match the hex S3 ETag, and the file gets re-ingested on every sync, the same as before. Convert it to hex instead of using it raw: base64.b64decode(md5).hex(). That matches the S3 ETag for single-part uploads, which is all the old path ever handled.

  3. Silent broad except Exception — src/edp/app/main.py:796 (rule 5). A decode failure falls back without being logged, so a bad header can't be diagnosed. Catch (binascii.Error, UnicodeDecodeError) and log a warning.

  4. Duplicated fallback / unnecessary branching — src/edp/app/main.py:792-799 (rules 2, 3). attributes.get('md5', '') appears twice. Moving the logic into a small helper, e.g. _seaweedfs_etag(new_entry) -> str, would remove the duplicate, keep process_seaweedfs_event short and make finding 1 easy to test. Sketch:

    def _seaweedfs_etag(new_entry):
        raw = new_entry.get('extended', {}).get('Seaweed-X-Amz-ETag')
        try:
            if raw:
                return base64.b64decode(raw).decode('ascii').strip('"')
            return base64.b64decode(new_entry.get('attributes', {}).get('md5', '')).hex()
        except (binascii.Error, UnicodeDecodeError):
            logger.warning(...)
            return ''
  5. Comment too long — src/edp/app/main.py:787-791 (rule 4). The five-line comment repeats what the code already shows. Only the protocol quirk needs explaining, so one line is enough, e.g. # SeaweedFS stores the S3 ETag base64-encoded; attributes.md5 is base64 of the raw digest.

@cepera cepera 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.

thanks for the fix!

it looks like the commit is missing Signed-off-by. Since the change is based on the patch from #99, I think it'd fair to add it's author to Co-authored-by:.

I also agree with the @sys-aibot review. I verified points 1–5 on a live cluster.
nothing currently checks the stored etag. The e2e upload tests pass with or without this fix, because ingestion succeeds either way. Please add an e2e check in src/tests/e2e/validation/test_edp.py

Comment thread src/edp/app/main.py Outdated
# For simplicity, we use available md5 provided by seaweedfs as a tag
new_entry = event.message.new_entry
attributes = new_entry.get('attributes', {})
extended = new_entry.get('extended', {})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The {} default only covers a missing key. If the payload has "extended": null, then .get() returns None which will lead to an AttributeError. new_entry.get('extended') or {} covers both cases, as in the fix.patch attached to #99.

Comment thread src/edp/app/main.py Outdated
Comment on lines +796 to +797
except Exception:
etag = attributes.get('md5', '')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

please log a warning with the raw header value instead of as silent re-ingestions

Comment thread src/edp/app/main.py Outdated
Comment on lines +796 to +799
except Exception:
etag = attributes.get('md5', '')
else:
etag = attributes.get('md5', '')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

in general we have 2 fallbacks now. Maybe it'd be simpler to move etag logic into a helper func similr to

def _seaweedfs_etag(entry: dict) -> str:
    header = (entry.get('extended') or {}).get('Seaweed-X-Amz-ETag')

    if header:
        try:
            return base64.b64decode(header).decode('ascii').strip('"')
        except (binascii.Error, UnicodeDecodeError) as e:
            logger.warning(f"Cannot decode Seaweed-X-Amz-ETag {header!r}: {e}")

    md5 = (entry.get('attributes') or {}).get('md5')

    if md5:
        try:
            return base64.b64decode(md5).hex()
        except binascii.Error as e:
            logger.warning(f"Cannot decode md5 {md5!r}: {e}")

    return ''

@0x5t4l1n
0x5t4l1n force-pushed the fix/seaweedfs-etag-base64-decode branch from a7f0b95 to 98fbd00 Compare November 26, 2026 17:51
@0x5t4l1n

Copy link
Copy Markdown
Author

Thanks for verifying this on a live cluster, @cepera. I addressed the review in 98fbd00. The ETag helper handles null metadata, logs malformed header and MD5 values, and converts the fallback MD5 digest from base64 to hex. It preserves multipart ETag suffixes.

The upload e2e test now compares the stored ETag returned by the file API with the ETag returned by the S3 PUT. I replaced the unsigned commit with a signed-off commit and added a co-author trailer for @alexatosatos's patch in #99.

Six local ETag behavior checks, Python syntax checks, and git diff --check passed. I couldn't run the e2e test locally because there is no configured EDP cluster.

@0x5t4l1n

0x5t4l1n commented Dec 2, 2026

Copy link
Copy Markdown
Author

@cepera I've addressed the review feedback and added the requested tests. Could you take another look when you have a moment? Thanks.

0x5t4l1n and others added 2 commits December 4, 2026 15:45
Decode the S3-compatible ETag from SeaweedFS webhook metadata and
fall back to hex-encoding the raw MD5 digest. Handle null metadata
and log malformed values before falling back.

Check that the ETag stored by EDP matches the one returned by S3
after a presigned upload.

Fixes intel#99

Co-authored-by: alexatosatos <221882055+alexatosatos@users.noreply.github.com>
Signed-off-by: 0x5t4l1n <stalin78830@gmail.com>
Add unit tests for _seaweedfs_etag: base64 header decoded to the S3 ETag,
multipart "hex-N" suffix preserved, quoted value stripped, invalid base64
header falling back to the md5 digest as hex, missing and null extended
and attributes blocks, an undecodable md5, and an empty entry.

Assisted-by: Claude Code <https://claude.com/claude-code>
Signed-off-by: 0x5t4l1n <stalin78830@gmail.com>
@0x5t4l1n

0x5t4l1n commented Dec 4, 2026

Copy link
Copy Markdown
Author

@cepera thanks for the careful review (and for verifying on a live cluster). Everything you and the bot asked for is in the branch, now rebased on current main:

  • new_entry.get('extended') or {} handles "extended": null, and attributes are handled the same way.
  • Decode failures log a warning with the raw value (Cannot decode Seaweed-X-Amz-ETag ...) instead of falling back silently. The except clauses are narrowed to decode errors.
  • The two fallbacks are now one helper, _seaweedfs_etag(entry), close to your sketch. The attributes.md5 fallback hex-encodes the raw digest instead of using the base64 string.
  • Unit tests in src/edp/tests/test_main.py cover: base64 header to hex ETag, multipart hex-N, quoted value, invalid base64 falling back to md5, missing and null extended/attributes, undecodable md5, and an empty entry. The whole file passes locally (57 tests).
  • test_edp_upload_file in src/tests/e2e/validation/test_edp.py now compares the stored ETag with the ETag from the S3 PUT response, so the e2e test fails without the fix. I couldn't run the e2e suite here (it needs a live cluster), so please let CI or your cluster confirm it.
  • Commits carry Signed-off-by, and the first one has Co-authored-by for the author of [EDP][ERAG] Files uploaded through the SeaweedFS webhook are re-ingested on every sync #99. I re-signed them with the same identity I use on GitHub, so the commit hashes changed after the rebase.

Could you take another look?

@0x5t4l1n
0x5t4l1n force-pushed the fix/seaweedfs-etag-base64-decode branch from f02ae9c to 460a65f Compare December 4, 2026 10:20
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.

[EDP][ERAG] Files uploaded through the SeaweedFS webhook are re-ingested on every sync

3 participants