Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ project uses [semantic versioning][semver].

## [Unreleased]

### Added

- **A stall is reported instead of looking like a slow link.** A hung network
handle raises nothing — it just stops returning bytes — so nothing could be
retried and the job sat at a stale throughput figure. Source reads are now
taken in 1 MiB sub-reads and timed: a gap past `--stall-after` (15 s by
default) reports a `stalled` stage, the queue shows "no data for 34s" in
place of a rate that has stopped being true, and the file is named in the
job's warnings afterwards. Timing *bytes* rather than chunks is what makes it
trustworthy — an 8 MiB chunk over a degraded link legitimately takes half a
minute, and a chunk-granularity timer would call a working copy stalled.

The duration shown counts from the last byte, not from the warning. The first
report only fires once the threshold has already passed, so timing it from
there displayed "no data for 0s" on a source that had been silent for fifteen
seconds, and stayed that far short for as long as the outage lasted. That
figure is what someone reads to decide whether to go and look at the cable,
so the engine carries the silence it has already measured and the queue
backdates its clock by it.

### Changed

- **Full verification is the default.** The read-back is the only mode that
Expand Down Expand Up @@ -256,6 +276,10 @@ project uses [semantic versioning][semver].
of the relative path.
- **An uppercase hex digest in a previous ASC MHL generation was recorded as
`failed`.** The comparison is now case-insensitive for hex and exact for C4.
- The stalled stage now clears as soon as bytes resume on a slow link, instead
of staying up until the whole 8 MiB chunk has assembled.
- Time spent paused no longer counts toward the stall watchdog, so resuming a
healthy copy no longer reports a stall.
- **A source on a network share survives its session dropping.** The retry
machinery reopened a dead handle and resumed from the last delivered chunk
already; the classifier just did not recognise a dropped SMB session as
Expand All @@ -266,6 +290,13 @@ project uses [semantic versioning][semver].
offloading from a NAS over a VPN link: the path pings clean either side of
the drop, which is exactly why the retry is worth making. Recovery costs one
re-read of the chunk in flight.
- **A cancel is noticed while a read is hung.** The consumer blocked on the
chunk queue without a timeout and teardown then joined the reader thread
without a deadline, so cancelling a job whose source had stopped responding
waited for the operating system's timeout — the very thing the operator was
trying to escape. The queue is polled, the checkpoint is checked while
waiting, and a reader still blocked after a second is left behind: it is a
daemon holding one source handle, which it closes itself.
- **`offloader report` and `engine.rescan` now read the destination back.**
They used to mark every present file Verified without hashing it. They now
hash the destination bytes and mark a copy Verified only on a match, record a
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pip install -e ".[dev]"
`ffmpeg` and `ffprobe` on `PATH` are optional — the suite runs without them.

```sh
pytest # 1330 tests, about 20s
pytest # 1358 tests, about 20s
pytest --fuzz # property tests at 3000 examples each, about 3 min
ruff check src tests
pytest --cov=offloader --cov-report=term-missing
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ offloader verify D:\video\080426\A001
| `--paranoid` | read each source file twice and compare (offload only) |
| `--retries N` | attempts on a transient error, for a failing read, a whole-file retry after a failed write, and a verify reread (default 3, 1 disables) |
| `--retry-wait SECONDS` | pause before the first retry, backing off after (default 2) |
| `--stall-after SECONDS` | report a source that stops delivering bytes without failing, as a hung network mount does (default 15, 0 disables) |
| `--no-probe` | skip ffprobe metadata and thumbnails |
| `--quiet` | suppress progress |

Expand Down Expand Up @@ -518,7 +519,9 @@ bound, and running two at once against the same bus makes both slower and the
progress readout meaningless. Each row shows live throughput and ETA, and the
transport controls pause, resume, cancel, reprioritise, and open the reports
folder. Pause takes effect within one 8 MiB chunk; cancel deletes the partial
destination file rather than leaving something that looks complete.
destination file rather than leaving something that looks complete. A source
that stops delivering bytes reads as `Stalled on …` with the time since the
last one, rather than a throughput figure that has quietly stopped being true.

Two guards run before anything is queued:

Expand Down Expand Up @@ -635,13 +638,13 @@ Full verification only when every present destination was hashed.

```sh
pip install -e ".[dev]"
pytest # 1330 tests, ~20s
pytest # 1358 tests, ~20s
pytest --fuzz # same suite, 3000 examples per property (~3 min)
ruff check src tests
pytest --cov=offloader --cov-report=term-missing
```

1330 tests at 88% line coverage. They cover formatting against the reference's
1358 tests at 88% line coverage. They cover formatting against the reference's
exact strings, checksum vectors and streaming equivalence, copy/verify
behaviour including simulated destination corruption, pause/resume/cancel
concurrency, retry discrimination, BRAW container parsing, ffprobe parsing,
Expand Down
18 changes: 17 additions & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ agrees is fine, is reported as the structure-hash mismatch it is. See

A source on a network mount is handled like marginal media, because it fails
like it: the dropped-session error codes are retried, the handle reopened and
the read resumed from the last delivered chunk.
the read resumed from the last delivered chunk. A stall — bytes stopping with
no error raised at all — is timed at 1 MiB granularity so it is distinguishable
from a slow link, reported while it happens, and named in the job's warnings
afterwards.

`--paranoid` reads every source file a second time and compares, which is the
only thing that catches a read returning wrong bytes without reporting an error.
Expand Down Expand Up @@ -78,6 +81,19 @@ has `previousPath` for exactly this and it is not written.

*Where:* `ascmhl.py`, and `verify.py` to read it back.

### Aborting a hung read, not just reporting it

A stall is now detected and reported, and a cancel is honoured while one is in
progress. What is still not possible is ending the read itself: recovery waits
for the operating system to turn the hang into an error, up to `SessionTimeout`
— 60 seconds on Windows. On Windows `CancelIoEx` against the handle would do
it, reached through `ctypes` with `msvcrt.get_osfhandle`; POSIX has no portable
equivalent, which is why this is one platform's fix and not a general one.
Listed under "What is still not protected" in
[`docs/data-safety.md`](docs/data-safety.md).

*Where:* `engine.py`, around the `read_ahead` loop.

### Coordination between instances

One app instance serialises its queue. Two pointed at the same destination do
Expand Down
18 changes: 18 additions & 0 deletions docs/data-safety.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,24 @@ known.
freeze the source; offload from media nothing else is writing to. (In verified modes, a swap
that changes the size is caught by the size check; with `--verify none`
there is no such check.)
- **A read that stalls cannot be aborted, only reported.** Retrying needs an
error to react to, and a hung network handle raises nothing — it simply stops
returning bytes. The job now says so: reads are taken in 1 MiB sub-reads, and
a gap longer than `--stall-after` (15 s by default) is reported as a stall
rather than left looking like a slow link, with the file named in the job's
warnings afterwards. The duration the queue shows counts from the last byte,
not from the warning: the first report only fires once the threshold has
already passed, so timing it from there would show "no data for 0s" on a
source that had been silent for fifteen seconds, and stay that far short for
as long as the outage lasted. It is the number someone reads to decide
whether to go and look at the cable. A cancel is honoured during it too.
The stalled stage clears as soon as bytes resume, not when the whole chunk
has assembled, and time spent paused is not counted as silence from the
source.
What still cannot happen is aborting the read itself, so *recovery* waits on
the operating system to turn the hang into one of the codes above — on Windows, the SMB
client's `SessionTimeout`, 60 seconds by default. No data is at risk in the
meantime; the wait is real.

## Marginal media and dropped links

Expand Down
11 changes: 10 additions & 1 deletion src/offloader/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def __call__(self, event: engine.ProgressEvent) -> None:

pct = (event.job_bytes_done / event.job_bytes_total * 100
if event.job_bytes_total else 100.0)
line = (f" [{pct:5.1f}%] {event.stage:<6} "
# 7 wide: the longest stage name is "stalled", and a field that a stage
# overflows shifts every column after it.
line = (f" [{pct:5.1f}%] {event.stage:<7} "
f"{event.file_index + 1}/{event.file_total} {event.file_name}")
line = line[:110]
pad = max(0, self._width - len(line))
Expand Down Expand Up @@ -184,6 +186,12 @@ def _common_options(parser: argparse.ArgumentParser) -> None:
parser.add_argument("--retry-wait", type=float, default=2.0, metavar="SECONDS",
help="pause before the first retry, backing off after "
"(default: %(default)s)")
parser.add_argument("--stall-after", type=float, default=15.0,
metavar="SECONDS",
help="report a source that has gone this long without "
"delivering a byte, which a hung network mount "
"does without raising any error "
"(default: %(default)s, 0 disables)")
parser.add_argument("--profile", choices=[p.value for p in Profile],
default=Profile.MEDIA.value,
help="'media' (default) offloads camera cards with "
Expand Down Expand Up @@ -347,6 +355,7 @@ def _options_from(args: argparse.Namespace, destinations: list[Path]) -> engine.
delay=max(0.0, args.retry_wait)),
paranoid=getattr(args, "paranoid", False),
replace_existing=getattr(args, "replace_existing", False),
stall_after=max(0.0, getattr(args, "stall_after", 15.0)),
)


Expand Down
Loading
Loading