Extract and summarise bounds are each agent's own limits, set on its form

agents.limits holds extract_top, extract_min, summarise_top and
summarise_min; the scope query reads them per ranked row, and a row saved
before this behaves like a fresh agent. The four global config keys go.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-09-28 16:02:06 +02:00
1 parent e602eb3388
commit cebe62ddc9
20 files changed
+229 -147

No files matched your search

+29 -16
View File
@@ -11,7 +11,7 @@ import pytest
from pydantic import ValidationError
from desk.models import Item
from app.models import Application, company_key, place_key, title_key
from app.models import Application, Limits, company_key, place_key, title_key
from app.storage import LATEST, Store
@@ -62,6 +62,7 @@ def test_schema_creates_on_an_empty_file(tmp_path: Path) -> None:
"application_events", "agents", "scores", "state"} <= tables
assert "idx_roles_cluster" in indexes
assert store.migrations_applied == []
assert LATEST == 8
# A second open finds it current and applies nothing.
assert Store(path).migrations_applied == []
@@ -88,7 +89,7 @@ def test_a_v1_file_migrates_to_the_shape_a_new_file_has(tmp_path: Path) -> None:
for column in ("permit", "languages", "extract_tries", "summary", "summarised_at",
"article_text", "article_at", "read_at"):
conn.execute(f"ALTER TABLE roles DROP COLUMN {column}")
for column in ("intent_key", "intent_vec"):
for column in ("intent_key", "intent_vec", "limits"): # v3, v8
conn.execute(f"ALTER TABLE agents DROP COLUMN {column}")
# v1 had affinity on the company; the vote columns v4 added and v6
# drops again are not in a fresh file, so there is nothing to put back.
@@ -117,6 +118,7 @@ def _downgrade_to_v4(path: Path) -> None:
conn.execute("ALTER TABLE companies ADD COLUMN affinity INTEGER NOT NULL DEFAULT 0")
for column in ("ats", "country", "city"): # v7
conn.execute(f"ALTER TABLE companies DROP COLUMN {column}")
conn.execute("ALTER TABLE agents DROP COLUMN limits") # v8
conn.execute("DROP TABLE agent_companies")
conn.execute("DROP TABLE role_votes")
conn.execute("PRAGMA user_version = 4")
@@ -734,26 +736,37 @@ def test_a_summarys_tags_land_with_it_and_not_on_a_rejected_late_answer(
assert role is not None and role.tags == ["backend", "python"]
def test_summarise_waits_on_the_top_of_each_enabled_agent(store: Store) -> None:
"""Two agents each contribute their own top one; a closed role and a
gated score are not in anybody's top. A hidden company needs no case:
`score` writes no rows for it under the agent that hid it."""
def test_summarise_waits_on_the_top_of_each_enabled_agent_by_its_own_limits(
store: Store) -> None:
"""Each agent contributes its own top, as deep and as low as its own
`limits` say; a closed role and a gated score are in nobody's top. A
hidden company needs no case: `score` writes no rows for it under the
agent that hid it. An agent saved before v8 has `limits` of '{}', which
reads as the defaults."""
for sid in "abcd":
store.upsert_role(posting(sid))
a, b, c, d = (posting(s).uid for s in "abcd")
with store.transaction() as conn:
conn.execute("UPDATE roles SET closed_at = ? WHERE uid = ?", (store.now(), d))
one = store.save_agent("One")
two = store.save_agent("Two")
one = store.save_agent("One", limits=Limits(summarise_top=1, summarise_min=0))
two = store.save_agent("Two", limits=Limits(summarise_top=1, summarise_min=0))
store.replace_scores(one.id, [(d, 0.99, ""), (a, 0.9, ""), (b, 0.5, "")])
store.replace_scores(two.id, [(a, 0.95, "remote"), (c, 0.7, ""), (b, 0.8, "")])
waiting = {r.uid for r in store.summarise_waiting(10, per_agent=1)}
assert {r.uid for r in store.summarise_waiting(10)} == {a, b}
assert waiting == {a, b}
assert {r.uid for r in store.summarise_waiting(10, per_agent=2)} == {a, b, c}
assert store.summarise_pending(per_agent=2) == 3
assert [r.uid for r in store.summarise_waiting(10, 1, uids=[d])] == [d]
# The floor: b's best score is 0.8 under Two, c's 0.7, a's 0.9.
assert {r.uid for r in store.summarise_waiting(10, 2, min_score=0.75)} == {a, b}
assert store.summarise_pending(2, min_score=0.85) == 1
# Two goes deeper: its second, c, joins; One's second, b, was in already.
store.save_agent("Two", agent_id=two.id, limits=Limits(summarise_top=2, summarise_min=0))
assert {r.uid for r in store.summarise_waiting(10)} == {a, b, c}
assert store.summarise_pending() == 3
assert [r.uid for r in store.summarise_waiting(10, uids=[d])] == [d]
# The floor is Two's own: c at 0.7 drops, One's b at 0.5 stays.
store.save_agent("Two", agent_id=two.id,
limits=Limits(summarise_top=2, summarise_min=0.75))
store.save_agent("One", agent_id=one.id, limits=Limits(summarise_top=2, summarise_min=0))
assert {r.uid for r in store.summarise_waiting(10)} == {a, b}
# '{}' is the defaults, 30 at 0.5: One's b at 0.5 stays, Two's c at 0.7 is back.
with store.transaction() as conn:
conn.execute("UPDATE agents SET limits = '{}'")
assert {r.uid for r in store.summarise_waiting(10)} == {a, b, c}
assert store.agents()[0].limits == Limits()