syft-job: declared code_hash never matches on a CRLF checkout, and submission_hash order differs on Windows
Since #9536, a job counts as received only when code_hash(as_sent=False) on the data owner's files equals the code_hash(as_sent=True) the submitter declared. I hit two cases where the two sides compute different digests over the same job.
1. CRLF bytes on the owner's disk. _as_sent reads each file in text mode, which turns \r\n into \n. The owner side then hashes the raw disk bytes. If the owner's copy keeps CRLF, the hashes never match and the job never counts as received. I first saw this in a two-role run sharing one folder on a Windows git checkout with core.autocrlf=true. Minimal repro with submission.py from main:
run.sh = b"#!/bin/sh\r\npython code/main.py\r\n"
code/main.py = b"print('hi')\r\n"
code_hash(d, as_sent=True) -> 9e3488aafc502eb4...
code_hash(d) -> c414493b5e759660... (never matches)
same files with LF -> 9e3488aafc502eb4...
The two-machine sync path may never produce CRLF on the owner side. I have not run it on a Windows owner, so I can't say whether this case reaches users through sync or only through local and shared-folder setups.
2. File order on Windows. _digest sorts Path objects. WindowsPath compares case-insensitively and PosixPath does not. For code/B.py and code/a.py, Windows hashes a.py first and Linux hashes B.py first. A submitter on Windows and an owner on Linux then disagree whenever a job has mixed-case names. Sorting on relative.as_posix() would make the order the same everywhere.
3. A smaller related point. _as_sent opens files with the locale encoding. That is cp1252 on many Windows machines, so non-ASCII source text may encode differently from the owner's UTF-8 copy. Passing encoding="utf-8" (with the existing fallback to raw bytes) would pin it. I found this by reading the code, not in a run.
Possible fix for all three: hash relative.as_posix() in sorted string order, and normalize newlines and encoding identically on both sides, or on neither.
Context: I built an independent result receipt on top of the approved hash from #9536. It lets anyone check that a published score came from the exact approved job, with no access to the model or the data. The receipt restates your hash format with the standard library, which is how these edges surfaced. The code and docs are at https://github.com/HarperZ9/flywheel/blob/main/docs/features/pysyft-result-receipt.md. I'm happy to open a PR for the sort fix if that helps.
More context on the work behind this issue, in case it's useful to the team.
Result receipt on the approved hash. It binds a published score to the exact job a data owner approved under #9536, to the approval record syft-job writes, and to the per-item rows the job releases, then signs the whole thing. Anyone with the job folder and the released rows can check it with the Python standard library. I ran it end to end on a real syft-job flow built from the #9536 merge commit: the job scored 40 of 50, and revealing the hidden answers reproduced that score. 16 tamper cases each flip MATCH to DRIFT. The enclave attestation link is reported as unverifiable rather than claimed. Docs: https://github.com/HarperZ9/flywheel/blob/main/docs/features/pysyft-result-receipt.md
Placebo test for Shapley attribution over sources. It mixes each real source with empty, irrelevant and shuffled controls and reports how often the controls get credit, with Wilson intervals. The bar was pre-registered before the run. qwen2.5:7b gave controls credit 0 of 80 times (95% CI 0.000 to 0.046). An exploratory qwen2.5:0.5b run gave them credit 7 of 80 times, so the test can fail. Docs: https://github.com/HarperZ9/flywheel/blob/main/docs/features/shapley-placebo.md
The offer to send a PR for the sort fix stands.
I independently verified the reporter's claims on current dev (submission.py @ 0b1d6ccc) and can narrow the bug to an exact call site:
-
CRLF asymmetry confirmed, byte-for-byte. The reporter's repro inputs reproduce the exact two hash prefixes from the issue on Linux (
as_sent=True→9e3488aafc502eb4…,as_sent=False→c414493b5e759660…), while LF-only files hash identically both ways. So_as_sent's text-mode read (universal-newline normalization + locale decode, re-encoded as UTF-8) vs the owner'sread_bytes()is a real divergence, not a misreading of the code. -
Sort-order asymmetry confirmed at the pathlib level.
_digestdoessorted()over nativePathobjects:PureWindowsPathsortscode/a.pybeforecode/B.py,PurePosixPathreverses it. The digest feedsrelative.as_posix()bytes in feed order, so identical file sets hash differently depending on which OS sorted them — even with byte-identical content. -
The mismatch is pinned to one comparison. The submitter declares
code_hash(job_dir, as_sent=True)(client.py:212,:503— normalized), but the owner's receipt check_has_all_filescompares it againstcode_hash(submission_dir)(client.py:600—as_sentdefaults toFalse, i.e. rawread_bytes()). Normalized-vs-raw is the exact boundary this issue describes. -
The rest of the chain is self-consistent, so the fix surface is small.
SubmissionRecord.received_hash(client.py:582,:654) and the approval re-check (job.py:420) both usesubmission_hash, which is raw on both sides — no mismatch there.
Suggested minimal fix: pass as_sent=True in _has_all_files's comparison so both sides normalize identically (this also makes the syncer-vs-local-folder distinction moot — _as_sent converges to the same bytes on both sides either way), and sort on relative.as_posix() in _digest so feed order is platform-independent. One caveat: I found no test referencing code_hash/as_sent, so the current behavior looks unpinned, but worth a maintainer's confirmation before changing _digest's ordering.
@HarperZ9 Are you still working on the sorting fix? I reproduced the CRLF mismatch in JobClient's job and API-request paths and have regression tests ready.
A receipt-only normalization experiment also accepted newline changes made after the hash was declared, although the later raw approval checks still rejected mutations. Would a tests-only PR be useful while we settle the local-delivery byte contract?