{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-of-a-best-selector-silently-return-a-stale-or-wrong-element-under-mutation",
  "title": "Why does an instance of a \"best\" selector silently return a stale or wrong element under mutation",
  "date_of_record": "2026 November 8",
  "scope": "Applies to any routine that selects a \"best\" element (max/min by key, top-k, argmax, best-fit) over a *live* collection that may be mutated concurrently or re-entered between comparison and return. Does not apply to selection over an immutable snapshot or to pure functions over value copies.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-of-a-best-selector-silently-return-a-stale-or-wrong-element-under-mutation.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-of-a-best-selector-silently-return-a-stale-or-wrong-element-under-mutation.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-of-a-best-selector-silently-return-a-stale-or-wrong-element-under-mutation.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1606,
    "python_slice_tokens": 382,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two different questions a \"best\" selector can answer, and they are not the same: 1. **\"Which element is best?\"** — a predicate over the current state of the collection. 2. **\"Give me the best element.\"** — a reference/handle to an object that is still best *at the moment the caller uses it*. A selector implemented as a scan-and-return answers (1). ...",
    "what_was_observed": "A task scheduler selected the next job by scanning a priority queue for the least-loaded worker and returning that worker handle. Under load testing with worker churn (workers joining/leaving, load counters updating), the scheduler occasionally dispatched two jobs to the same worker while another worker sat idle, and occasionally dispatched to a worker that had already been deregistered. Instrumentation showed the sc...",
    "condition_of_validity": "The scan-and-return selector is valid only when **all** of the following hold: - The collection is immutable for the entire interval from the first comparison to the caller's last use of the result, **or** - The caller re-validates the returned element under the same lock/epoch that guarded the scan, **or** - The result is treated as a *hint* and the consume...",
    "decision_boundary": "The operational fork is: - If the consumer can **reject and retry** cheaply (e.g., `try_claim(worker)` returns false and the scheduler re-scans), keep the scan-and-return selector and make the retry loop explicit and bounded. Document that the return is a hint. - If the consumer **cannot** retry (the decision is committed, e.g., a write is dispatched), the s...",
    "operational_effect": "Teams that miss this boundary see intermittent, load-dependent misdispatch that is invisible in unit tests (immutable fixtures) and rare in staging (low churn), then frequent in production under churn. The symptom is *not* an exception — it is duplicated work, idle capacity, or a dispatch to a dead handle, which surfaces as downstream timeouts far from the s..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "439fa2832a9737d3ea4d6f42a1f0a7b87f60be2c29e2e8a4f6e57656cf20aab9",
    "verified_classes": [
      "StaleSelectionError",
      "Selection",
      "VersionedBestSelector"
    ],
    "verified_functions": [
      "dispatch_next",
      "__init__",
      "add",
      "remove",
      "version",
      "select_best",
      "consume"
    ],
    "verified_functions_count": 7,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "StaleSelectionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
