← Back to Pull requests

Skip a superseded scheduled store instead of failing it #46

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 29, 2026 05:03 UTC
Author

What it does

When two fetchers save the same data in the same minute, the store of the older payload fails with superseded and sends a Sentry Issue, although the newer payload's store writes the data. This happened on 2026-11-26 and 2026-11-28, when an S forecast gate and its collector fetched together. PR #44 moved the weather gate off the collector's minute. The same collision is still possible for:

  • the Previous Runs gates and weather-fetch-ecmwf-prev-day1, at 09:40 and 13:40;

  • jao_capacity_d1 and jao-fetch, at 12:40;

  • fingrid_morning and a drifted fingrid-fetch retry.
  • This PR fixes the cause for all of them (user decision 2026-11-29, "Fix this"):

  • StagedImport --skip-superseded. It is a store option and no data option. With it, a payload that a newer one supersedes ends as {"status":"skipped","step":"store","reason":"superseded","payload":{…}}: exit 0, no write, no failure report or log error.

  • Every scheduled Temporal store passes it: job steps (jobs.run_step) and S forecast gate stores (s_forecast.staged_fetch), through staged.store_args(..., skip_superseded=...).

  • ImportReplay does not. A replay of an older file still fails superseded, so the operator sees that newer data exists.
  • The newest-payload check is unchanged: it runs under the store lock, and an older payload still never writes over newer data.

    No workflow patch is needed. Only the store activity's arguments change, not the command sequence, and the replay tests pass.

    Data effects

    None.

    Verification

  • Laravel:

  • - FetchWeatherStagedCommandTest (23 tests) has a new case: a superseded payload stored with --skip-superseded is skipped with exit 0, writes nothing and logs no error, and the newest payload still stores with the option.
    - Full suite: 3439 tests, 2 failing. Both are SyncProductionDatabaseCommandTest, which needs the local database.sqlite that a worktree does not have.
  • Orchestration: 144 passed, with the known flaky test_a_readiness_check_failing_across_the_cut_misses_the_gate left out.

  • - A new test: a scheduled job whose store answers skipped succeeds with no Issue.
    - The pinned store argument lists now distinguish scheduled stores (with the flag) from replay stores (without it).
  • vendor/bin/pint --test and git diff --check are clean.
  • Docs

  • laravel/app/Services/ImportPayload/AGENTS.md: the trait options and the reason for the skip.

  • orchestration/AGENTS.md: the gate paragraph and a new "superseded scheduled store" rule under Staged imports.
  • Needs separate approval after the merge

    A deploy of both roles. The PHP option and the Python argument ship in the same image.

    🤖 Generated with Claude Code

    <!-- greptile_comment -->

    <!-- greptile_summary -->

    <h2><ruby><rp>Confidence Score: 3/5 · Fix the weekly refit's wait for stored Fingrid data and the mixed-worker deployment path before merging.</rp></ruby><a href="https://app.greptile.com/api/retrigger?id=122975751&amp;sig=1f316d4d411233ff5fab713c7580a4f65aa4f50c674bab06a86e3d26125ec43d"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img alt="Retrigger" src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2" align="right"></picture></a><a href="https://app.greptile.com/-/switch-tenant?tenant=breezily&amp;next=%2Fsepsi77%2Fvoltikka%2Fpull%2F46&amp;utm_source=greptile_review&amp;utm_medium=github&amp;utm_campaign=view_in_greptile"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptileDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2"><img alt="View in Greptile" src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewInGreptile.svg?v=2" align="right"></picture></a>Confidence Score: 3/5 <sup><img alt="Tier: plus" title="Review tier: plus" src="https://greptile-static-assets.s3.amazonaws.com/badges/effort-plus.svg?v=3" height="12"></sup></h2>

    <!-- greptile-risk -->

    Fix the weekly refit's wait for stored Fingrid data and the mixed-worker deployment path before merging.

    <h2>Findings</h2>

    1. <img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top">&nbsp;Refit can train too early <a href="https://github.com/sepsi77/voltikka/pull/46#discussion_r4730128790">▶</a>
    2. <img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top">&nbsp;Old workers reject new stores <a href="https://github.com/sepsi77/voltikka/pull/46#discussion_r4730128792">▶</a>

    <details><summary>Fix with agent prompt</summary>

    `

    ### Issue 1
    orchestration/src/voltikka_orchestration/s_forecast.py:228-229
    `staged_fetch()` also serves `SWeeklyRefit`, which starts training immediately after this call succeeds. On Monday, its `fingrid:fetch` can overlap the `fingrid_morning` gate or a collector retry. If the newer payload exists but its store is delayed or fails, the refit's store now skips and training reads the old database. Training leaves out missing Fingrid targets and can still activate the model.
    
    The refit requires Sunday's Fingrid hours as training targets. Wait for stored Fingrid data before training, or keep the refit's store strict.
    
    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
    
    ### Issue 2
    orchestration/src/voltikka_orchestration/staged.py:49
    Workflow code adds the new flag, but another worker can execute the activity. During a rolling deploy, the new worker starts polling before the old worker stops. Both use the same queue without worker versioning. A store scheduled by new code can therefore reach old PHP, which does not define `--skip-superseded`. The store fails on the unknown option, and `CommandFailed` is not retried.
    
    Ship PHP support before enabling the argument, or add the flag inside the activity version that supports it.
    
    ---
    
    For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
    

    </details>

    <h3>Summary</h3>

    Adds --skip-superseded so scheduled stores can skip older payloads quietly while ImportReplay` keeps the existing refusal.

  • Scheduled stores skip older payloads without failing.
  • <details open><summary><h3>Diagram</h3></summary>

    %%{init: {'theme': 'neutral'}}%%
    flowchart TD
        A[Scheduled fetch saves payload] --> B[Store takes command lock]
        B --> C{Newer matching payload exists?}
        C -->|No| D[Store data]
        C -->|Yes, scheduled| E[Skip without writing]
        C -->|Yes, replay| F[Fail as superseded]
        E --> G[Job succeeds]
        E --> H[Weekly refit starts training]
        H --> I[Newer store may still be pending]
    

    </details>

    <!-- greptile_confidence_score:3 -->

    <sub>Reviews (1) · Last reviewed commit: "Skip a superseded scheduled store instea..." · Reviewed by Greptile</sub>

    <!-- /greptile_comment -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: greptile-apps[bot] Review duration: 14m
    All Vouch review confidence checks passed
    Residual risk 0.31 = Change Risk (0.52) × (1 − Review Confidence (0.40)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 88% · Reviewer familiarity: 35%
    40%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #46"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 40.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 40.2% · Lower = rushed or shallow review
    40.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 31.1% · Safe to merge
    31.1%