← Back to Pull requests

test(worker): force the restart's reservation on its own lock turn #6037

Open
unknown opened this pull request with 324 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 12, 2026 15:48 UTC
Author

Description

Problem


The KV event monitor's replacement-race test passed on the ordering it was written against. That ordering unlocked the slot and removed by URL on a later turn, which could take a stream another add started in between. One poll crossed both turns, so the old ordering reserved the slot too under the test's single poll.

Solution


The test holds the lock when the restart is first polled and queues a read of the slot behind the restart's turn. The lock is fair, so the read runs the moment that turn ends and finds the reservation. Under the old ordering it finds the stream still active. The race then runs to its end under timeout guards: a third object takes the stream while the restart waits, and the restart leaves it. Two doc lines read right again.

Changes


  • model_gateway/src/worker/kv_event_monitor.rs: the forcing test and a test-only slot reader usable under a held lock, moved below stop.

  • model_gateway/src/app_context.rs: the monitor's doc names start_kv_stream as the chooser of a worker's stream kind for both workflows.
  • Test Plan


  • cargo test -p smg --lib worker::kv_event_monitor: 108 passed, three runs.

  • cargo test -p smg --lib: 4571 passed. Clippy and rustdoc clean with warnings denied.

  • Before: the old test stayed green under the old ordering. After: the new test finds the slot still active and fails under it.

  • Two mutants three times each: the old ordering restored, and the registry read by URL rather than by object. Each turns the new test red.

  • A second gate ran alone on the merge onto main: the forcing test and its module three times each, the library, every binary's compile. Clippy and rustdoc clean, the two mutants red. 23 of 24 rows green, the one red a binary row that fails on the base alone, a hub fetch with no network.

  • An independent review read the forcing test against the restart's lock turns and the docs against their chooser, with both mutants red. Its chain was green on the merge onto main.

  • Reuse: the forcing test uses the module's lock and its slot helpers. The docs name the chooser that exists. No new mechanism.
  • Numbers


    | mutant of the restart arm | before | after |
    |---|---|---|
    | unlock, then remove by URL on a later turn | none red | one test red |
    | the registry read by URL, not by object | none red | one test red |

    The module's tests under each mutant, on the old test and on the new one. No production code changes.

    Release note


    The KV event monitor's replacement-race regression test now fails on the ordering it guards against, and two doc lines read right.

    Diff: 324 lines (+243 / -81) across 4 files Reviewer: claude[bot] Review duration: 10m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.42) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 324 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.346
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #6037"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 42.0% (MEDIUM) · Higher = larger blast radius
    42.0%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 22.4% · Safe to merge
    22.4%