Assert the scan that must not happen, not the index that won

95d5a413f342 · AtlantisPleb · · parent 8ac99fe03785

Assert the scan that must not happen, not the index that won

The per-computer grant listing test named the index it expected in the
plan. Two indexes can answer that predicate, the table is empty in the
test database, and their estimated costs are near-identical — so the
planner was free to pick the other one, and did. The test was red on
main for a choice that was never wrong.

It now asserts the property worth holding: the listing does not
degrade to a sequential scan. That stays true whichever index the
planner picks, and still fails when the indexes are gone.

The sibling assertions were read the same way and kept, because in
those two cases only one index can serve the predicate at all — the
others lead on a column the filter does not name. Each now says so in
a comment, so the next reader knows which kind of assertion they are
looking at.

Mutation-checked before landing: dropping both usable indexes turns
the test red, restoring them returns it to green.

Built by a Devin child through the openagents coder's delegate tool;
the mutation proof was run in review, after installing the worktree's
dependencies the child could not.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GoYpb8FEmdxVErsv7ABCYi
Co-Authored-By
Claude Fable 5 <noreply@anthropic.com>

Deploy story

What this commit did to the running system — joined from the forge receipt chain, the part a commit page elsewhere cannot show.

pushed
by user · WAL seq 351 · 2026-08-25T06:57:11.759938Z

Changed files

  • modified test/openagents/machines/index_reach_test.exs

Diff

1 file changed, +11 -6

test/openagents/machines/index_reach_test.exs modified +11 -6

@@ -64,10 +64,13 @@ defmodule OpenAgents.Machines.IndexReachTest do

64 64
        Inference.revoke_active_for_machine(Ecto.UUID.generate())
65 65
      end)
66 66
67
    # The only index that can answer `machine_id = ?` on this table is the
68
    # `machine_id` index; the other indexes lead on `token_digest` or
69
    # `conversation_id`, which the predicate does not name.
67 70
    assert plan =~ "inference_grants_machine_id_index", plan
68 71
  end
69 72
70
  test "the per-computer grant listing is served by repository_machine_grants_machine_id_index" do
73
  test "the per-computer grant listing avoids a sequential scan on repository_machine_grants" do
71 74
    owner = owner()
72 75
    machine = computer(owner)
73 76

@@ -76,11 +79,11 @@ defmodule OpenAgents.Machines.IndexReachTest do

76 79
        Repositories.list_machine_grants(owner, machine.id)
77 80
      end)
78 81
79
    # The composite unique index leads on `repository_id`, which this filter
80
    # does not name, so it cannot serve here — which is why the single-column
81
    # index stopped being redundant the moment the listing landed.
82
    assert plan =~ "repository_machine_grants_machine_id_index", plan
83
    refute plan =~ "repository_machine_grants_repository_id_machine_id_index"
82
    # The planner may use the single-column `machine_id` index or the
83
    # composite unique index to satisfy the predicate, depending on the
84
    # table's shape and the join shape. The property that matters is that
85
    # the listing does not degrade to a sequential scan on the table.
86
    refute plan =~ ~r/Seq Scan\s+on\s+repository_machine_grants/, plan
84 87
  end
85 88
86 89
  test "the pairing sweep is served by machine_pairings_expires_at_index" do

@@ -89,6 +92,8 @@ defmodule OpenAgents.Machines.IndexReachTest do

89 92
        OpenAgents.Machines.expire_elapsed_pairings()
90 93
      end)
91 94
95
    # The sweep's predicate is `expires_at <= ?` plus a `status` filter; the
96
    # only index with `expires_at` is `machine_pairings_expires_at_index`.
92 97
    assert plan =~ "machine_pairings_expires_at_index", plan
93 98
  end
94 99

This page updates live while a promote is in flight · changelog