Release v2.17.1: Add technical post-mortem on Dec 01 quant data absence, regressions, and lossless VPS reconciliation to docs/archive/
This commit is contained in:
1 parent
a27c8f445b
commit
c3f17a2bea
4 files changed
+105
-2
No files matched your search
@@ -0,0 +1,102 @@
|
||||
# Technical Post-Mortem: Dec 01 Quant Data Absence, Cascading Feature Regressions & Lossless VPS Reconciliation (`v2.17.1`)
|
||||
|
||||
- **Artifact Scope:** `/workspace/encyclopedia-knowledge-graph/docs/archive/postmortem-dec01-quant-data-and-vps-reconciliation.{md,pdf}` (Cold-rotated engineering post-mortem in `completed-plans-archive.tar.gz` & `archive-manifest.json`)
|
||||
- **Commits Analyzed:** `d95446f` (Baseline `v2.17.1`) -> `7a016a6..5eca430` (Regressive intermediate commits) -> `52153e7..91cf671` (Remediated `v2.17.1`)
|
||||
- **Initial Incident Goal:** Diagnose the absence of `2026-12-01` data on the live `/quant/` surface (`https://hyperstitionstud.io/quant/`).
|
||||
|
||||
---
|
||||
|
||||
## 1. Why a Single-Line Diagnostic Escalated into Multi-Surface Regressions
|
||||
|
||||
The initial symptom (`window.HyperstitionStudio.QuantTimeSeries.dates_utc` ending at `2026-11-30` despite `generated_at_utc = 2026-12-02T13:03:10Z`) had a single root cause in `src/hyperstitionstud_io/quant/timeseries.py` line 450:
|
||||
|
||||
```python
|
||||
dates_utc = [f"2026-11-{d:02d}" for d in range(1, 31)]
|
||||
```
|
||||
|
||||
Instead of isolating that root cause and tracing its downstream invariants, the intermediate session triggered a five-stage failure cascade:
|
||||
|
||||
1. **Ad-Hoc Uncommitted VPS Execution:** Running `collector.py --live --append-history` and `timeseries.py` directly in the VPS shell (rather than via `deploy/run-vps-data-production.sh`) modified `site/quant/{real-market-history.json,financial-aq-harvest-latest.json,quant-timeseries.json,quant-timeseries-data.js}` in the VPS working tree without committing or pushing them.
|
||||
2. **Last-Bar-Only & Intraday Pollution in `collector.py`:** `_fetch_yahoo_chart()` fetched `?range=1mo&interval=1d` (~22 daily bars) but discarded all bars except `valid_pairs[-1]`. When invoked on `2026-12-02` at `13:03 UTC` (prior to the `21:00 UTC` US closing bell), `valid_pairs[-1]` for the 18 US equities was `2026-12-01` (skipping `2026-11-30`), whereas `valid_pairs[-1]` for the 5 24-hour/overnight instruments (`BTC-USD`, `ETH-USD`, `SOL-USD`, `HG=F`, `^VIX`) was an unclosed `2026-12-02` intraday candle (skipping `2026-12-01` and appending a premature `2026-12-02` column where 19/24 tickers reported `"No data available"`).
|
||||
3. **Inverted `--theirs` Semantics During `git pull --rebase --autostash`:** In `git rebase`, `--ours` is upstream (`origin/main`) and `--theirs` is the rebased local commit. However, during the final `git stash apply` step of `--autostash`, `HEAD` is already at `origin/main`, so `--ours` is `origin/main` and `--theirs` is the dirty local stash. The conflict handler in `deploy/sync-vps-repos.sh` (`git checkout --theirs -- "${uf}" && git reset HEAD -- "${uf}"`) overwrote newly pulled `origin/main` files with the old dirty VPS stash and left them unstaged (`M`) in the working tree on every subsequent run.
|
||||
4. **Volatile Telemetry Hash Coupling in `closeups_sync.py`:** `introspect_live_ui_elements()` hashed `total_bars` and `db_entries_count` into `ui_elements_fingerprint_sha256`. When `checkout --theirs` reverted `quant-timeseries.json` on the VPS to the 30-day stash (`472` bars) while `ui-elements-manifest.json` from `origin/main` reflected 32 days (`518` bars), `hs-closeups-sync --check` failed. Changing `sync-vps-repos.sh` from `hs-closeups-sync --check` to `hs-closeups-sync` (mutating) forced the VPS (`Pillow 13.0.0`) to re-render tracked PNGs on disk, triggering a FreeType box-width breach on `quadrant-3-tab-3-math-ts-rust.png` (`346px > 334px`) and dirtying tracked PNGs on the VPS.
|
||||
5. **Destructive `git reset --hard` Without Snapshot & Unbound `prev_head` (`5eca430`):** Attempting to stop the autostash loop by deleting `prev_head=` and inserting raw `git reset --hard` + `git clean -fd` introduced an unbound variable crash under `set -euo pipefail` (`${prev_head}`) and created an unconditional data-loss path for any uncommitted VPS telemetry.
|
||||
|
||||
---
|
||||
|
||||
## 2. Engineering Changes: Rationale, Pros & Cons
|
||||
|
||||
### Change 1: Dynamic Calendar Span (`timeseries.py`) & 3-Month Lookback with Completed Closing-Bell Cutoff (`collector.py` — Strategy C)
|
||||
|
||||
- **Technical Specification:**
|
||||
- `latest_completed_closing_bell_date_utc()` sets the upper date cutoff `max_date_utc` to `T - 1 day` when `now_utc.hour < 21` and `T` when `now_utc.hour >= 21` (`16:00 EST / 21:00 UTC` US closing bell).
|
||||
- `_fetch_yahoo_chart_series()` queries `?range=3mo&interval=1d` (and `_fetch_stooq_csv_series()` uses a 75-row window) to compute each bar's `prev_close` (`valid_pairs[idx - 1]`) and 20-session trailing `volume_ratio_20d` (`valid_pairs[idx - 20 : idx]`), while filtering emitted bars to `MIN_SCOPE_DATE_UTC ("2026-11-01") <= obs_date <= max_date_utc`.
|
||||
- `timeseries.py` derives `dates_utc` as the contiguous UTC calendar sequence `min(all_dates) .. max(all_dates)` (`0` hardcoded year/month strings).
|
||||
- **Rationale:**
|
||||
Eliminates both the hardcoded November boundary and the single-bar (`valid_pairs[-1]`) gap when harvests miss a day or run mid-day, while preventing 24-hour crypto/futures feeds from advancing `dates_utc` into an unclosed equity trading day prior to `21:00 UTC`.
|
||||
- **Consequences (Pros):**
|
||||
- **Pro 1:** Backfills all 23 public instruments across every trading session in `2026-11-01 .. 2026-12-01` (`514` bars; `23/23` public instruments on `2026-11-30` and `2026-12-01`), with full 20-day trailing volume ratios on early-November dates via the October lookback bars.
|
||||
- **Pro 2:** Prevents `/quant/` Panel 3 (which defaults to `dates_utc[-1]`) from displaying `"No data available"` across all 18 US equities during daytime hours before `21:00 UTC`.
|
||||
- **Consequences (Cons / Trade-offs):**
|
||||
- **Con 1 (Intraday Crypto Lag Until `21:00 UTC`):** 24-hour crypto (`BTC-USD`, `ETH-USD`, `SOL-USD`) and overnight futures (`HG=F`) bars for calendar day `T` are withheld from `quant-timeseries.json` until the `21:00 UTC` US closing bell on day `T` so cross-asset synchronous alignment across all 23 public tickers is preserved.
|
||||
- **Con 2 (Linear Growth of `quant-timeseries.json`):** Because `MIN_SCOPE_DATE_UTC = "2026-11-01"` is fixed and `end_d` advances by 1 day every 24 hours, `dates_utc` grows by 24 bars/day (~48 KB/day raw JSON, ~4 KB/day Brotli-11). Over a 1-year horizon (~8,760 bars), a rolling window or quarterly partition will eventually be needed if bundle size exceeds ~15 MB uncompressed.
|
||||
|
||||
---
|
||||
|
||||
### Change 2: Pre-Reset Telemetry Snapshot, Git/Stash/Reflog Excavator & Post-Reset Union Reconciliation (`collector.py`, `sync-vps-repos.sh`, `run-vps-data-production.sh` — Strategy A)
|
||||
|
||||
- **Technical Specification:**
|
||||
- Added `--snapshot-telemetry <DIR>` (`snapshot_local_telemetry()` + `_excavate_git_json_versions()`) and `--reconcile-telemetry <DIR>` (`reconcile_telemetry_snapshot()`).
|
||||
- Before `git reset --hard ${remote_name}/${branch}` and `git stash clear`, `sync-vps-repos.sh` snapshots on-disk `site/quant/{real-market-history.json,real-macro-indicators.json,daily-brief-state.json,financial-aq-harvest-latest.json}` and union-merges any valid bars (`2026-11-01 <= dt_s <= max_date_utc`) present in `git stash list` (`stash@{0..N}` and `stash@{i}^3`) or `git log --all -n 35`.
|
||||
- After `git reset --hard ${remote_name}/${branch}` (and across `HYPERSTITION_SYNC_REEXEC=1`), `--reconcile-telemetry` inspects whether the snapshot contains any completed `(symbol, date_utc)` bar or FRED observation missing from `origin/main`. If `merged_bars_count == 0` and `merged_macro_obs_count == 0`, it performs `0` disk writes. If net-new completed observations exist, it merges them, recompiles `quant.timeseries` and `quant.daily_brief`, commits, and pushes on top of `origin/main`.
|
||||
- **Rationale:**
|
||||
Separates Git tree alignment (`git reset --hard origin/main`, which must be conflict-free and deterministic) from domain data merge (set-union by `(symbol, date_utc)` and `(series_id, date_utc)`, which is commutative and associative).
|
||||
- **Consequences (Pros):**
|
||||
- **Pro 1:** Completely eliminates `git pull --rebase --autostash` text-merge conflicts on multi-megabyte JSON files and `README.md`, leaving `0` dirty files (`git status` 100% clean) after every deployment.
|
||||
- **Pro 2:** Guarantees zero loss of valid completed bars harvested on the VPS even if they were trapped in an uncommitted working tree or `git stash` entry prior to deployment.
|
||||
- **Consequences (Cons / Trade-offs):**
|
||||
- **Con 1 (Upstream Precedence on Same-Date Corrections):** In `reconcile_telemetry_snapshot()`, when a `(symbol, date_utc)` key already exists with a non-null `close_usd` in `origin/main`, `origin/main`'s value takes precedence over the local snapshot (the snapshot only fills missing dates or missing `market_cap_str` / `volume_ratio_20d` fields). This is necessary so intentional upstream corrections (or removal of bad values) are not reverted by a stale local VPS copy, but it means an ad-hoc manual edit to an *existing* date's `close_usd` on the VPS will be overwritten by `origin/main` unless committed and pushed first.
|
||||
- **Con 2 (Non-Telemetry Uncommitted Edits on VPS Are Discarded):** Because `sync-vps-repos.sh` executes `git reset --hard ${remote_name}/${branch}` after snapshotting `site/quant/*.json`, any ad-hoc uncommitted edits made directly on the VPS to *code or HTML/JS files* outside `site/quant/*.json` are discarded in favor of `origin/main` (enforcing `localhost -> git.libre.audio -> VPS` code discipline).
|
||||
|
||||
---
|
||||
|
||||
### Change 3: IPv4-Forced Parallel FRED CSV Harvester & 13-Month YoY Retention (`macro.py` — Strategy B)
|
||||
|
||||
- **Technical Specification:**
|
||||
- Updated `fetch_fred_series_csv()` to invoke `curl -4 -sS -L --max-time <timeout>` without custom bot `User-Agent` strings, parallelized across all 14 FRED series via `ThreadPoolExecutor(max_workers=7)`.
|
||||
- Union-merges live FRED CSV rows with `cached_bundle["raw_fred_observations"]`, retains all `>= 2026-11-01` daily observations for `1d` series (`EFFR`, `SOFR`, `DGS10`, `DFEDTARU`), and retains 13 monthly / 5 quarterly rows for `1mo` / `1q` series to compute 12-month / 4-quarter `yoy_change_pct` and `yoy_change_bps`.
|
||||
- **Rationale:**
|
||||
Python `urllib.request` resolved `fred.stlouisfed.org` to an IPv6 route first (which hung for `8.0s` per series), and Akamai Bot Manager tarpitted requests carrying the custom `HyperstitionStudio-MacroHarvester/2.0` User-Agent header. Both caused `macro.py` to stall for `112s` and silently degrade to the 2-row `_VERIFIED_FRED_SEED_OBSERVATIONS` fallback.
|
||||
- **Consequences (Pros):**
|
||||
- **Pro 1:** Reduces live 14-series FRED harvest latency from `112s` (timeout failure) to `~1.2s` (100% live success).
|
||||
- **Pro 2:** Populates real `2026-11-01 .. 2026-12-01` daily observations (`22` rows for `EFFR`/`SOFR`, `21` for `DGS10`, `31` for `DFEDTARU`) and restores non-null YoY metrics across all 10 monthly/quarterly macro series.
|
||||
- **Consequences (Cons / Trade-offs):**
|
||||
- **Con 1 (Subprocess Dependency on `curl` for IPv4 Fast-Path):** Relies on `/usr/bin/curl -4` for the IPv4 fast-path (falling back to Python `safe_urlopen` if `curl` is absent). If running in a minimal container image without `curl` and with broken host IPv6 routing, `safe_urlopen` would still experience IPv6 connection delay.
|
||||
|
||||
---
|
||||
|
||||
### Change 4: Structural-Only UI Fingerprint, Dynamic Font Fitting & Pre-Commit Gate `DEPLOY-GATE-D04` (`closeups_sync.py`, `deploy_scripts_sync.py`, `test_core_suite.py`)
|
||||
|
||||
- **Technical Specification:**
|
||||
- Removed volatile daily data counts (`total_bars`, `db_entries_count`) from `combined_hash` (`ui_elements_fingerprint_sha256`) in `closeups_sync.py`.
|
||||
- Applied `_fit_font_for_width(..., max_width=286)` to all code lines in `quadrant-3-tab-3-math-ts-rust.png`.
|
||||
- Added hard checks in `DEPLOY-GATE-D04` (`deploy_scripts_sync.py`, run by `.git/hooks/pre-commit`) requiring `--snapshot-telemetry`, `--reconcile-telemetry`, `prev_head=`, `closeups_sync --check`, and `readme_sync --hooks-only` (and forbidding `readme_sync --install-hooks`) inside `deploy/sync-vps-repos.sh`.
|
||||
- **Rationale:**
|
||||
The VPS runs `Pillow 13.0.0` while the development container runs `Pillow 12.3.0`. Any command in `sync-vps-repos.sh` that re-renders tracked PNGs or rewrites tracked `README.md` files on the VPS dirties the VPS Git checkout.
|
||||
- **Consequences (Pros):**
|
||||
- **Pro 1:** Daily market harvests on the VPS never invalidate `hs-closeups-sync --check`, and `sync-vps-repos.sh` is guaranteed read-only on tracked repository files when in sync with `origin/main`.
|
||||
- **Pro 2:** Pre-commit Gate `DEPLOY-GATE-D04` mechanically blocks any model from committing a regression that removes telemetry snapshotting or enables mutating `closeups_sync` / `readme_sync` flags in `sync-vps-repos.sh`.
|
||||
- **Consequences (Cons / Trade-offs):**
|
||||
- **Con 1 (Static Bar Count in Homepage Quadrant 2 Closeup Until UI Change or `--force`):** Because `total_bars` is no longer part of `ui_elements_fingerprint_sha256`, the decorative bar count text rendered inside `quadrant-2-esoteric-finance-quant.png` only updates when a DOM/JS UI structure change triggers a closeup re-render or when `hs-closeups-sync --force` is run during release preparation on `localhost`.
|
||||
|
||||
---
|
||||
|
||||
## 3. Summary Matrix of Changes, Pros & Cons
|
||||
|
||||
| Component & Change | Problem Solved | Pro (Technical Benefit) | Con / Engineering Trade-off |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| **`collector.py` & `timeseries.py`**<br/>`?range=3mo`, `MIN_SCOPE_DATE_UTC = "2026-11-01"`, `latest_completed_closing_bell_date_utc()` (`21:00 UTC` cutoff) | Hardcoded Nov 1..30 range; `valid_pairs[-1]` skipping Nov 30 / Dec 01 and polluting incomplete Dec 02 intraday crypto bars | `100%` (23/23) public ticker coverage across all trading days `2026-11-01 .. 2026-12-01` (`514` bars) + full 20d volume ratios | 24h crypto/futures bars for day `T` wait until `21:00 UTC` US closing bell on day `T`; bundle grows by ~24 bars/day |
|
||||
| **`collector.py` & `deploy/*.sh`**<br/>`--snapshot-telemetry` (working tree + `git stash` + `git log --all`) + `git reset --hard` + `--reconcile-telemetry` | `--autostash` `--theirs` inversion clobbering `origin/main` and leaving files perpetually `M`/`U` on VPS; raw `reset --hard` losing VPS data | Zero Git merge conflicts, `0` dirty files after deploy, and lossless union recovery of any completed VPS bars | `origin/main` takes precedence on existing `(symbol, date_utc)` keys; non-telemetry uncommitted code edits on VPS are discarded |
|
||||
| **`macro.py`**<br/>`curl -4` parallel FRED CSV fetcher + 13-month / 5-quarter retention | Blackholed IPv6 + Akamai custom `User-Agent` tarpit causing `112s` timeouts and 2-row seed fallback (`yoy = null`) | `1.2s` live fetch across all 14 FRED series; full `2026-11-01 .. 2026-12-01` daily series + real YoY inflation/M2 metrics | Depends on `/usr/bin/curl -4` for the IPv4 fast-path (falls back to `safe_urlopen` if `curl` is absent) |
|
||||
| **`daily_brief.py`**<br/>Same-day identical-posterior `run_history` deduplication | Repeated test/deploy runs on the same day bloating `daily-brief-state.json` with identical runs (`18 -> 22`) | Collapses redundant same-day identical-posterior re-runs into sequential `Q-RUN-0001 .. Q-RUN-0010` lineage | Intra-day re-runs whose regime posteriors do not change overwrite that day's run timestamp in-place rather than logging each invocation |
|
||||
| **`closeups_sync.py` & `deploy_scripts_sync.py`**<br/>Structural-only fingerprint, `_fit_font_for_width`, and `DEPLOY-GATE-D04` pre-commit enforcement | VPS `Pillow 13.0.0` vs container `Pillow 12.3.0` PNG diffing, box-border breach, and `README.md` dirtying on VPS | `sync-vps-repos.sh` never mutates tracked PNGs or `README.md` on VPS; pre-commit hook blocks regressive script edits | Decorative bar count inside homepage closeup PNG only refreshes on UI structure change or `hs-closeups-sync --force` |
|
||||
Reference in new issue
Block a user