Skip to content

fix: make Git Sync canonical gzip output deterministic - #587

Open
kocaemre wants to merge 1 commit into
OpenHands:mainfrom
kocaemre:fix/git-sync-canonical-gzip-mtime
Open

kocaemre wants to merge 1 commit into
OpenHands:mainfrom
kocaemre:fix/git-sync-canonical-gzip-mtime

Conversation

@kocaemre

@kocaemre kocaemre commented Oct 15, 2026 •

Copy link
Copy Markdown

Summary

  • Make Git Sync's canonical tarball gzip header deterministic (mtime=0, empty filename), so identical files and executable modes compare byte-for-byte across wall-clock seconds.
  • Add a clock-controlled regression that checks canonical idempotence and preserves extracted content/executable mode.

Fixes #586.

Verification

  • RED: uv run --frozen python -m pytest tests/test_git_sync_serializer.py::TestRebuildTarball::test_rebuild_is_identical_across_wall_clock_seconds -q -o addopts='' --tb=short → 1 expected failure (gzip header differs at byte 4).
  • GREEN: same command → 1 passed; uv run --frozen python -m pytest tests/test_git_sync.py tests/test_git_sync_serializer.py -q -o addopts='' --tb=short → 97 passed (2 pre-existing deprecation warnings).
  • uv run --frozen pre-commit run --files openhands/automation/git_sync/serializer.py tests/test_git_sync_serializer.py --show-diff-on-failure → Ruff format/lint, pycodestyle, Pyright passed; YAML hook skipped (no YAML changed).
  • git diff --check → passed. Full uv run --frozen python -m pytest tests/ -q -o addopts='' --tb=short --maxfail=1 attempted but timed out at the local tool's 420-second limit; not claimed green.

AI assistance was used for the patch and regression test; the author verified the behavior and checks above.

Jev-Fast-Audit

⚡ Jev fast audit · estimates · 0.30s · commit 0d093ca
Strongest signal: No primary concern selected.
Evidence: No primary concern to locate.
Coverage: complete supplied coverage; 4/4 hunks, 2/2 files.

All estimates and evidence
Estimate Likelihood / value Direct evidence
SQL injection 2.0% No direct hunk selected
Command injection 4.0% No direct hunk selected
Weakened authentication 3.0% No direct hunk selected
Weakened authorization 3.0% No direct hunk selected
Contract regression 14.0% F001H002 · openhands/automation/git_sync/serializer.py:225–246
Data loss 4.0% No direct hunk selected
Sensitive data disclosure 3.0% No direct hunk selected
Unexpected data transfer 3.0% No direct hunk selected
Credential misuse 3.0% No direct hunk selected
Untrusted instruction authority 2.0% No direct hunk selected
Package source redirection 3.0% No direct hunk selected
Unverified remote execution 2.0% No direct hunk selected
Privileged environment access 2.0% No direct hunk selected
Security assessment bypass 3.0% No direct hunk selected
Prohibited workload 2.0% No direct hunk selected
Primary concern None selected; confidence 88.0% No primary concern to locate

Signed-off-by: Emre K <110906681+kocaemre@users.noreply.github.com>
@github-actions github-actions Bot added the type: fix A bug fix label Oct 15, 2026
@neubig
neubig requested a review from all-hands-bot October 17, 2026 00:18

@all-hands-bot all-hands-bot 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.

This review was posted by an AI agent (OpenHands).

Review: PR #587 — fix: make Git Sync canonical gzip output deterministic

Scope: In-scope. openhands/automation/git_sync/serializer.py is this repository's single canonical tarball builder — canonical_tarball_bytes and deserialize_automation both call rebuild_tarball, and _stored_tarball_matches in loop.py compares those outputs byte-for-byte. The fix belongs exactly here; there is no cross-repository ownership question.

Change assessment: rebuild_tarball now wraps tarfile.open(mode="w") in gzip.GzipFile(mtime=0, filename="") instead of tarfile.open(mode="w:gz"), which took the gzip header MTIME from the wall clock. Tar member order, per-member mtime and modes are unchanged, so the change is confined to the gzip framing. Closing order (tar then gzip) is correct, and filename="" is not None, so no filename is derived from the fileobj.

Verified on head 0d093ca:

  • Pre-fix reproduction against the old w:gz implementation: two rebuild_tarball calls one second apart differ only in gzip MTIME (1000 vs 1001).
  • Post-fix: identical inputs at simulated time.time() 1000 and 1001 yield byte-identical output; the gzip MTIME field is 0 and the FLG byte is 0 (no embedded filename).
  • canonical_tarball_bytes(rebuild_tarball(...)) == rebuild_tarball(...) — canonicalization is idempotent.
  • tar xzf extracts the new stream with correct contents and the 0755 executable bit preserved, so the sandbox extraction path is unaffected.
  • uv run --frozen python -m pytest tests/test_git_sync.py tests/test_git_sync_serializer.py -q -o addopts='' → 97 passed, 2 pre-existing warnings, matching the author's claim; TestTarballUploadLifecycle passes.
  • Ruff check/format and pyright on both changed files pass.

Acceptance criteria in #586 (labels bug, ready-for-dev, priority:low): deterministic canonical bytes across wall-clock seconds, a sleep-free regression test, canonical idempotence, and preserved reuse-vs-replace behavior — all covered by the new test plus the existing tarball-upload lifecycle tests.

Non-blocking note: the fork PR's Run tests, ci, and Docker workflows are action_required (awaiting maintainer approval to run on the fork head), so no full-suite CI result exists for this SHA. Focused tests pass locally; approving those runs is a maintainer action, not a code defect.

No material correctness, security, or compatibility findings.

✅ APPROVED

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Git Sync tarball comparison depends on gzip timestamp

2 participants