{"record":{"id":"be14ac0bce5f2c65","repo":"abhigyanpatwari/GitNexus","slug":"task-asset-snapshot-file-changed-while-materializi","errorCode":null,"errorMessage":"task asset snapshot file changed while materializing: {entry.path}","messagePattern":"task asset snapshot file changed while materializing: (.+?)","errorType":"exception","errorClass":"SandboxError","httpStatus":null,"severity":"critical","filePath":"eval/workflow_bench/task_assets.py","lineNumber":839,"sourceCode":"            raise SandboxError(f\"task asset snapshot file changed: {entry.path}\")\n        if _try_reflink(source_descriptor, destination_descriptor):\n            if os.fstat(destination_descriptor).st_size != entry.size:\n                raise SandboxError(f\"task asset reflink produced an invalid file: {entry.path}\")\n        else:\n            if entry.size > fallback_budget:\n                raise SandboxError(\n                    \"task asset filesystem cannot reflink the snapshot and the buffered fallback limit would be exceeded\"\n                )\n            os.ftruncate(destination_descriptor, 0)\n            os.lseek(source_descriptor, 0, os.SEEK_SET)\n            while True:\n                chunk = os.read(source_descriptor, COPY_CHUNK_BYTES)\n                if not chunk:\n                    break\n                _write_all(destination_descriptor, chunk)\n                fallback_bytes += len(chunk)\n            if fallback_bytes != entry.size:\n                raise SandboxError(f\"task asset snapshot file changed while materializing: {entry.path}\")\n        if _mutation_identity(opened) != _mutation_identity(os.fstat(source_descriptor)):\n            raise SandboxError(f\"task asset snapshot file changed while materializing: {entry.path}\")\n        os.fchmod(destination_descriptor, 0o600)\n    finally:\n        os.close(destination_descriptor)\n        os.close(source_descriptor)\n    try:\n        os.replace(temporary, destination)\n    except BaseException:\n        temporary.unlink(missing_ok=True)\n        raise\n    return fallback_bytes\n\n\ndef _try_reflink(source_descriptor: int, destination_descriptor: int) -> bool:\n    try:\n        fcntl.ioctl(destination_descriptor, FICLONE, source_descriptor)\n        return True","sourceCodeStart":821,"sourceCodeEnd":857,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/eval/workflow_bench/task_assets.py#L821-L857","documentation":"Two end-of-copy checks in _materialize_file: (a) after a buffered copy, the total bytes read (fallback_bytes) must equal entry.size; (b) for both reflink and buffered paths, a final _mutation_identity comparison on the source descriptor must equal the post-open identity. Either failing raises this error — the source moved during the copy.","triggerScenarios":"The source file was truncated, extended, or replaced mid-copy; a concurrent reader/writer caused the read loop to hit EOF early or read past the expected length.","commonSituations":"Concurrent truncation of the snapshot; AV scanner rewriting the file mid-copy; network filesystem (9p/NFS) reporting inconsistent sizes.","solutions":["Quiesce all writers to the snapshot during the entire materialize call","Move the snapshot to a local, stable filesystem","Re-prepare the snapshot from a clean capture"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from eval.workflow_bench.proposer_sandbox import SandboxError\n\ntry:\n    snapshot.materialize(clone)\nexcept SandboxError as exc:\n    if \"changed while materializing\" in str(exc):\n        raise SystemExit(f\"snapshot mutated mid-copy; isolate the cache dir: {exc}\") from exc\n    raise","preventionTips":["Quiesce all writers to the snapshot during the entire materialize call","Keep the snapshot on a local, stable filesystem rather than a network mount","Re-prepare the snapshot from a clean capture if the error recurs"],"tags":["sandbox","snapshot","integrity","toctou"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}