Skip to content

fix(automation): prevent duplicate local Reddit runs - #112

Merged
Sam-24-dev merged 3 commits into
mainfrom
fix/reddit-local-runner-safety
Sep 15, 2026
Merged

Sam-24-dev merged 3 commits into
mainfrom
fix/reddit-local-runner-safety

Conversation

@Sam-24-dev

@Sam-24-dev Sam-24-dev commented Sep 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Version the real guarded entry point used by both local launch authorities.
  • Prevent concurrent Sunday/logon invocations with one native Windows named mutex before state checks or filesystem mutation.
  • Fail closed on pre-existing tracked or ignored local outputs and restore only files captured by the current run.
  • Rebuild public metadata from final canonical bridges and enforce the unchanged 192-hour freshness limit before publication.

Root cause

Task Scheduler and the Startup catch-up launcher are independent authorities. Task Scheduler's IgnoreNew policy does not protect the Startup path, and both converge on an unversioned guard without cross-process exclusion. The main runner also performed Git reset/checkout operations before its transaction snapshot, which could discard pre-existing local data.

After sync_assets, the runner restores final canonical non-Reddit bridges. Without regenerating run_manifest.json and checking canonical freshness after that restore, publication could retain pre-restore provenance and recreate the false-green freshness class fixed remotely by PR #111.

Changes

File Change
automation/run_reddit_baseline_guarded.ps1 Version the real guard and add the earliest shared named-mutex exclusion with a clear canonical-log skip.
automation/run_reddit_baseline.ps1 Replace destructive synchronization/reset behavior with a clean-main, tracked-and-ignored fail-closed preflight; snapshot before mutation; regenerate the final frontend manifest and enforce 192-hour canonical freshness after final bridge restoration.
automation/reddit_output_transaction.psm1 Reuse exact-file snapshots for selective restoration of assets changed by this run.
tests/test_local_reddit_runner.py Cover lock collision, tracked/ignored dirty preflight, canonical manifest provenance, stale-source rejection, and prepublication rollback with no publication path.

Final pre-push validation

  • python -m pytest tests/test_local_reddit_runner.py -q — 11 passed.
  • python -m pytest — 247 passed; one existing Pandera FutureWarning.
  • PowerShell parser for the guard, runner, and transaction module — passed.
  • ruff check tests/test_local_reddit_runner.py — passed.
  • bandit -r backend scripts -x **/__pycache__/** -ll — passed; 8,932 lines scanned, zero issues.
  • detect-secrets-hook --baseline .secrets.baseline -- <candidate files> — passed.
  • git diff --check — passed.
  • No real scheduler, runner, ETL, deployment, workflow dispatch, or manual data update was executed; runtime behavior is covered with temporary deterministic fixtures.

Final metadata order

  1. Restore final non-Reddit canonical bridges.
  2. Rebuild home_highlights.json from final bridges.
  3. Generate frontend/assets/data/run_manifest.json with the existing final-bridge generator.
  4. Run the existing canonical freshness guard with the unchanged 192-hour threshold.
  5. Run remaining prepublication validation and bridge integrity.
  6. Only then enter branch, commit, push, and PR publication logic.

The local runner publishes only frontend/assets/data; the remote aggregate root is not generated here. run_manifest.json was already part of the existing exact-file transaction snapshot.

Review-size exception

This is one atomic safety unit with 715 changed lines. The 261-line guarded runner must be versioned so the fix is reproducible, and the tests cover the required lock, data-preservation, provenance, freshness, and rollback boundaries. Separating the shared entry point from its caller, transaction boundary, or regression proof would leave an independently unsafe slice. No unrelated formatting or refactor is included.

Controlled post-merge operation

After merge, install the exact merged bytes of the three versioned automation files into the local automation clone without git pull, reset, checkout, clean, or broad cleanup. Verify Task Scheduler still targets automation/run_reddit_baseline_weekly.cmd; only then remove %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\TechnologyTrend-RedditBaselineCatchupOnLogon.cmd. The ignored on-logon wrapper may remain inert.

Out of scope

  • No scheduler configuration, cron, ETL, deployment, production data, remote workflow, or dependency changes.
  • No change to the local automation clone or Startup shortcut in this PR.

@Sam-24-dev Sam-24-dev added the bug Something isn't working label Sep 15, 2026
Copilot AI lite review requested due to automatic review settings September 15, 2026 20:13
@Sam-24-dev Sam-24-dev added the bug Something isn't working label Sep 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Sam-24-dev
Sam-24-dev merged commit cc81365 into main Sep 15, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants