diff --git a/docs/WINDOWS_SCHEDULING.md b/docs/WINDOWS_SCHEDULING.md index b08c171..68440a9 100644 --- a/docs/WINDOWS_SCHEDULING.md +++ b/docs/WINDOWS_SCHEDULING.md @@ -249,7 +249,33 @@ to get wrong, because the obvious signal is the broken one: `newest_data` is the right signal and the documented one: it *"advances ONLY when genuinely new data arrives"* (see [status.json](../README.md#statusjson--new-data-signal-for-downstream-tools)). -Snapshot it before the fetch and after, and skip the syncs only when the two agree. + +**Key the guard on what was delivered, not on what arrived.** The obvious shape is to +snapshot `newest_data` before the fetch and after and sync only on the difference. Do not: +that fires on the single repeat which happens to watch the map move, so one failed delivery +is final for the whole window. + +> [!WARNING] +> **Measured on the reference box on 2026-10-23, and it cost a release.** CFTC published at +> 15:28, the 15:29 repeat captured the new week and called the syncs, the SMB mirror +> delivered nothing, and the wrapper exited. Every repeat after it read `BEFORE == AFTER` +> and skipped the syncs as "nothing new landed". Both replicas sat on the previous week +> until a human noticed, and the public dash only got the data because someone fetched CFTC +> on it by hand. The fetch half of the pipeline had worked perfectly, inside 90 seconds of +> publication. +> +> The mirror failure itself was transient. The destination took a new DHCP lease at +> 15:30:19, seconds before the copy, and the identical copy ran clean 90 minutes later: +> 156 files, nothing failed. `robocopy /R:2 /W:5` gives up in about ten seconds, so a +> wireless re-association on the far end is enough to lose a pass. **That is the point.** +> A ten-second blip cost a whole release only because the guard then refused to retry. + +Record the fingerprint of the last run in which **every** replica took the data, in a file +beside the wrapper, and compare the store against *that*. A failed delivery is then retried +on the next repeat, a delivered week is still skipped for the rest of the window, and a quiet +Friday costs exactly what it did before. It also removes the ordering trap entirely: it no +longer matters which repeat sees the data arrive. Keep that file out of the store itself, or +the mirror will carry one box's scheduling state to every replica. **Do not guard the daily catch-up as well.** This is the trap on the other side, and it costs you bars rather than time. Both sync scripts mirror **both** stores since ADR-0007, so the @@ -269,8 +295,18 @@ Set-ScheduledTask -TaskName 'cotdata COT (Fri release)' -Action $a string as the executable path, so the argument ends up part of the filename.) **Make the guard fail toward syncing.** If `status.json` is missing or unparseable, sync -anyway rather than skipping. A redundant mirror is merely slow; a skipped one is invisible, -which is the failure mode this whole page exists to prevent. +anyway rather than skipping. A missing or empty delivery record reads the same way: nothing +was ever confirmed delivered, so deliver. A redundant mirror is merely slow; a skipped one is +invisible, which is the failure mode this whole page exists to prevent. + +**Do not gate one replica's delivery on another's.** If your wrapper chains an SMB mirror and +a remote push, the tempting `if errorlevel 1 exit /b` between them makes the second replica +hostage to the first. On 2026-10-23 that is what kept the week from the internet-facing +replica, the one with actual readers, because a laptop on the LAN was unreachable over SMB. +[`sync-store.cmd`](examples/windows/sync-store.cmd) already refuses to make this mistake +between its own two store passes, for the reason stated there: one broken thing should not +present as two. Run every delivery, capture each exit code on its own following line, and +exit the worst of them. ## Testing your tasks diff --git a/docs/examples/windows/run-equities.cmd b/docs/examples/windows/run-equities.cmd index f1ac559..212011c 100644 --- a/docs/examples/windows/run-equities.cmd +++ b/docs/examples/windows/run-equities.cmd @@ -113,7 +113,21 @@ REM The guard above means these are reached only when every symbol wrote. A REM partial equities fetch is not mirrored: the retry loop re-runs the whole REM full-history fetch, and the sync goes with the run that finally succeeds. call "REPLACE_WITH_SCHEDULER_DIR\sync-store.cmd" -if errorlevel 1 exit /b %ERRORLEVEL% +set "SYNC_RC=%ERRORLEVEL%" call "REPLACE_WITH_SCHEDULER_DIR\push-to-server.cmd" -exit /b %ERRORLEVEL% +set "PUSH_RC=%ERRORLEVEL%" + +REM The push is NOT gated on the sync. An `if errorlevel 1 exit /b` used to sit +REM between these two calls, so a failed SMB mirror to the Mac also starved the +REM remote replica, the one with actual readers. That is the mistake sync-store.cmd +REM already refuses to make between its own two store passes: one broken thing +REM presenting as two. Run both deliveries, then report. +REM +REM The two empty-guards are not paranoia: cmd aborts the whole file on a numeric +REM IF with an empty operand, which would skip the exit below and report success. +if "%SYNC_RC%"=="" set "SYNC_RC=1" +if "%PUSH_RC%"=="" set "PUSH_RC=1" +set "WORST=%SYNC_RC%" +if %PUSH_RC% GTR %WORST% set "WORST=%PUSH_RC%" +exit /b %WORST% diff --git a/docs/examples/windows/run-series.cmd b/docs/examples/windows/run-series.cmd index 77a40d7..198ac84 100644 --- a/docs/examples/windows/run-series.cmd +++ b/docs/examples/windows/run-series.cmd @@ -99,12 +99,29 @@ REM The raw JSON under _raw\tradingview never rides along: both scripts exclude REM _raw by name at any depth, for databento's paid raw store. Keep the directory REM name exactly _raw or both exclusions silently stop applying. call "REPLACE_WITH_SCHEDULER_DIR\sync-store.cmd" -if errorlevel 1 exit /b %ERRORLEVEL% +set "SYNC_RC=%ERRORLEVEL%" call "REPLACE_WITH_SCHEDULER_DIR\push-to-server.cmd" -if errorlevel 1 exit /b %ERRORLEVEL% +set "PUSH_RC=%ERRORLEVEL%" + +REM The push is NOT gated on the sync. An `if errorlevel 1 exit /b` used to sit +REM between these two calls, so a failed SMB mirror to the Mac also starved the +REM remote replica, the one with actual readers. That is the mistake sync-store.cmd +REM already refuses to make between its own two store passes: one broken thing +REM presenting as two. Run both deliveries, then report. +REM +REM The two empty-guards are not paranoia: cmd aborts the whole file on a numeric +REM IF with an empty operand, which would skip the exit below and report success. +if "%SYNC_RC%"=="" set "SYNC_RC=1" +if "%PUSH_RC%"=="" set "PUSH_RC=1" +set "WORST=%SYNC_RC%" +if %PUSH_RC% GTR %WORST% set "WORST=%PUSH_RC%" +if not "%WORST%"=="0" echo series: delivery incomplete ^(sync %SYNC_RC%, push %PUSH_RC%^). REM The build's code, not the push's: a partial build that synced cleanly is still REM a run with a refusal in it, and the operator and the verifier both want to see -REM that rather than a 0. -exit /b %RC% +REM that rather than a 0. A clean build with a broken delivery is still a failure, +REM though, so when the build has nothing to say the delivery's code is what exits. +REM The echo above is why a partial build cannot hide a failed mirror. +if not "%RC%"=="0" exit /b %RC% +exit /b %WORST% diff --git a/docs/examples/windows/sync-store.cmd b/docs/examples/windows/sync-store.cmd index 975181f..2d97574 100644 --- a/docs/examples/windows/sync-store.cmd +++ b/docs/examples/windows/sync-store.cmd @@ -27,6 +27,35 @@ set "COT_DEST=REPLACE_WITH_COTDATA_DEST_PATH" set "BAR_SRC=REPLACE_WITH_MARKETDATA_STORE_PATH" set "BAR_DEST=REPLACE_WITH_MARKETDATA_DEST_PATH" +REM --------------------------------------------------------------------------- +REM THE RETRY BUDGET: /R:6 /W:10, six attempts over sixty seconds per failure. +REM +REM It was /R:2 /W:5, which gives up in about ten seconds, and on 2026-10-23 that +REM lost a COT release. The SMB destination took a new DHCP lease at 15:30:19 and +REM the capture pass called this script seconds later; the copy failed, and the +REM Friday poller's guard then read the store as already current and skipped every +REM remaining repeat. The identical copy ran clean ninety minutes later: 156 files, +REM nothing failed. Ten seconds is simply less than a wireless re-association on +REM the far end, and that destination roams between mesh access points. +REM +REM Sixty seconds rides out a re-association without pretending to ride out an +REM outage. Know the ceiling before raising it further: /R and /W are PER FAILURE, +REM so on a destination that is reachable but flaky enough to fail file after file, +REM the budget multiplies by the file count. It is bounded here because an +REM unreachable share fails at the directory level once, not per file, so a +REM powered-off replica costs about a minute per pass rather than hours. +REM +REM Two consequences worth knowing before you tune this: +REM - The exit codes below are unchanged, so a failure after six attempts still +REM reports exactly as it did before. The budget buys attempts, not silence. +REM - run-cot.cmd --poll repeats every 2 min, and Task Scheduler will not start a +REM second instance while one runs. During a real outage both passes burn their +REM budget, so the effective poll cadence stretches by a minute or two. That is +REM only true while something is broken, and the guard retries either way. +REM +REM If a failure ever shows ERROR 67 (network name not found) that these retries do +REM not catch, /TBD is the flag for it: it waits for share names to be defined. +REM Not added here because nothing has produced that error to test it against. REM --------------------------------------------------------------------------- REM Pass 1 — the COT store. REM @@ -50,7 +79,7 @@ REM matches by NAME AT ANY DEPTH, so had it been called manifest.json this sync REM have silently delivered raw bytes with no index. REM /XF also drops partial-write temps (*.tmp from parquet/JSON writes, *.part from REM in-flight raw downloads) so a sync mid-capture never lands a truncated file. -robocopy "%COT_SRC%" "%COT_DEST%" /MIR /R:2 /W:5 /NFL /NDL /NP ^ +robocopy "%COT_SRC%" "%COT_DEST%" /MIR /R:6 /W:10 /NFL /NDL /NP ^ /XD _cache _raw citpy ^ /XF manifest.json *.tmp *.part set "COT_RC=%ERRORLEVEL%" @@ -77,7 +106,7 @@ REM replica has no use for it and re-fetching it costs money. REM REM Both stores commit parquet with an atomic replace, so *.tmp / *.part are the REM same partial-write guard as above. -robocopy "%BAR_SRC%" "%BAR_DEST%" /MIR /R:2 /W:5 /NFL /NDL /NP ^ +robocopy "%BAR_SRC%" "%BAR_DEST%" /MIR /R:6 /W:10 /NFL /NDL /NP ^ /XD _raw ^ /XF *.tmp *.part set "BAR_RC=%ERRORLEVEL%"