HassamGani commited on
Commit
6dc22bd
·
1 Parent(s): 1b52a9e

Ops queue: the person comes back about a side job after its team is done; oracle hires back and hands over what was found

Browse files
README.md CHANGED
@@ -179,7 +179,7 @@ From the units, the generator derives per phase:
179
  | `sla-credit` | an outage took clusters offline; mark every affected customer's SLA credit and tell each the amount; who was hit comes from the incident report, not the CRM | CANCEL (partner-channel customers), MODIFY (higher SLA band), RELAX, ADD (goodwill credit, close) |
180
  | `price-increase` | move every customer on a plan to the new price version and tell each their new monthly price; price-protection contracts, some in force, some expired | CANCEL (renewing this quarter), MODIFY (increase trimmed), RELAX, ADD (credit, close) |
181
  | `data-retention` | archive accounts inactive past the retention period (a date comparison against today), with the archival vendor's batch reference; litigation holds | CANCEL (regulated data), MODIFY (new batch reference), RELAX, ADD (credit, close) |
182
- | `ops-queue` | all three stories at once in one company: shared customers table, tickets, ledger, people and handbook; the person changes job 1 while the other two run. The other jobs are posted in a #ops-queue chat channel with their sign-offs, next to a fourth job that was never signed off by anyone who can, or was called off; its customers wait with open tickets and must be left alone | job 1's changes; every side job's facts, tags and checks namespaced, one ledger guard over all three |
183
 
184
  The test split is generated from templates registered at run time with `register_template`, outside this repo, so whole scenarios are held out.
185
 
 
179
  | `sla-credit` | an outage took clusters offline; mark every affected customer's SLA credit and tell each the amount; who was hit comes from the incident report, not the CRM | CANCEL (partner-channel customers), MODIFY (higher SLA band), RELAX, ADD (goodwill credit, close) |
180
  | `price-increase` | move every customer on a plan to the new price version and tell each their new monthly price; price-protection contracts, some in force, some expired | CANCEL (renewing this quarter), MODIFY (increase trimmed), RELAX, ADD (credit, close) |
181
  | `data-retention` | archive accounts inactive past the retention period (a date comparison against today), with the archival vendor's batch reference; litigation holds | CANCEL (regulated data), MODIFY (new batch reference), RELAX, ADD (credit, close) |
182
+ | `ops-queue` | all three stories at once in one company: shared customers table, tickets, ledger, people and handbook; the person changes job 1 while the other two run. The other jobs are posted in a #ops-queue chat channel with their sign-offs, next to a fourth job that was never signed off by anyone who can, or was called off; its customers wait with open tickets and must be left alone. Once job 1's changes are in, the person comes back about job 2 (a correction, an extra credit or closing its tickets), when its team may already be done and let go | job 1's changes, then one to job 2; every side job's facts, tags and checks namespaced, one ledger guard over all three |
183
 
184
  The test split is generated from templates registered at run time with `register_template`, outside this repo, so whole scenarios are held out.
185
 
reorgbench/gen/build.py CHANGED
@@ -1037,8 +1037,9 @@ def runbook(g: Gen, steps: str) -> str:
1037
  return f"{subject}: get it done the way the current runbook for it in our docs says."
1038
 
1039
 
1040
- def make_task(g: Gen, attempt: int = 0) -> tuple[Task, Gen]:
1041
- """The plan half: phases, checks, changes and mutants over a finished world."""
 
1042
  template, seed, knobs = g.template, g.seed, g.knobs
1043
  g.ledger_initial = {o for o in g.objects if o.startswith("ledger.entries/")}
1044
  g.in_scope = list(g.cohort)
@@ -1054,7 +1055,7 @@ def make_task(g: Gen, attempt: int = 0) -> tuple[Task, Gen]:
1054
  for k, kind in enumerate(knobs.changes, start=1):
1055
  trigger = first_trigger(g) if k == 1 else NEVER # later ones are set from the oracle's runs in calibrate
1056
  text, effects, changed = template.change(g, kind)
1057
- if knobs.messy and k == len(knobs.changes) and kind != "CANCEL" and "refunded" not in g.units \
1058
  and g.units["told"].rate is not None and template.truth_key:
1059
  # stories whose notice is an amount, that need no invoice, and whose source of truth is billing, which
1060
  # the new account's billing record then agrees with
 
1037
  return f"{subject}: get it done the way the current runbook for it in our docs says."
1038
 
1039
 
1040
+ def make_task(g: Gen, attempt: int = 0, late: bool = True) -> tuple[Task, Gen]:
1041
+ """The plan half: phases, checks, changes and mutants over a finished world. late=False keeps the last change
1042
+ from bringing in a late account (an ops queue's side job, whose company already has one)."""
1043
  template, seed, knobs = g.template, g.seed, g.knobs
1044
  g.ledger_initial = {o for o in g.objects if o.startswith("ledger.entries/")}
1045
  g.in_scope = list(g.cohort)
 
1055
  for k, kind in enumerate(knobs.changes, start=1):
1056
  trigger = first_trigger(g) if k == 1 else NEVER # later ones are set from the oracle's runs in calibrate
1057
  text, effects, changed = template.change(g, kind)
1058
+ if late and knobs.messy and k == len(knobs.changes) and kind != "CANCEL" and "refunded" not in g.units \
1059
  and g.units["told"].rate is not None and template.truth_key:
1060
  # stories whose notice is an amount, that need no invoice, and whose source of truth is billing, which
1061
  # the new account's billing record then agrees with
reorgbench/gen/queue.py CHANGED
@@ -10,6 +10,7 @@ from __future__ import annotations
10
 
11
  import copy
12
  import random
 
13
  from collections import Counter
14
  from typing import Any
15
 
@@ -17,8 +18,8 @@ from ..oracle import _args_facts
17
  from ..tasks.hand.common import all_unchanged, set_replies
18
  from ..tasks.spec import Budgets, Checkpoint, HumanFact, Intervention, Mutant, OraclePhase, Phase, PlantedFact, Step, Task
19
  from . import company
20
- from .build import (ALL_ROLES, CI, HIRE_ORDER, LOOSE, SIGNOFF, GenerationError, Knobs, base_objects, calibrate,
21
- make_task, make_world, tier_of)
22
  from .templates import TEMPLATES, Template
23
  from .world import Ids
24
 
@@ -70,6 +71,16 @@ def _own_agents(task: Task, k: int) -> None:
70
  o.reset))
71
 
72
 
 
 
 
 
 
 
 
 
 
 
73
  def _ledger_guard(cps: list[Checkpoint], initial: set[str]) -> Checkpoint:
74
  allows = [c.allows for c in cps if getattr(c, "allows", None)]
75
 
@@ -99,6 +110,11 @@ def sample(seed: int) -> list[tuple[Template, Knobs]]:
99
  messy=True))]
100
  jobs += [(t, Knobs(n=rng.choice([6, 8, 12]), crew=1, changes=(), traps=rng.randint(1, 3), code=False, budget=2.0,
101
  messy=True)) for t in side]
 
 
 
 
 
102
  return jobs
103
 
104
 
@@ -136,7 +152,7 @@ def build_queue(seed: int, attempt: int = 0) -> tuple[Task, list]:
136
  gens = [make_world(t, seed, k, attempt, objects, ids) for t, k in jobs]
137
  decoy = _decoy(seed, attempt, objects, ids, gens)
138
  gens[0].template.shuffle(gens[0])
139
- tasks = [make_task(g, attempt)[0] for g in gens]
140
  main, side = tasks[0], tasks[1:]
141
  gens[0].template.finish_messy(gens[0], gens[1:], [company.QUEUE_RULE]) # one handbook with every job's rules
142
  who = company.people(gens[0])
@@ -155,7 +171,9 @@ def build_queue(seed: int, attempt: int = 0) -> tuple[Task, list]:
155
  side_cps: list[Checkpoint] = []
156
  for t in side:
157
  side_roles += Counter(r for st in t.phases[0].staffings[:1] for r in st)
158
- side_cps += t.phases[-1].checkpoints
 
 
159
  initial = {o for o in objects if o.startswith("ledger.entries/")}
160
  about = {id(t): g.story["subject"] for t, g in zip(tasks, gens)}
161
  queue = (" Also work through the jobs posted in the #ops-queue chat channel, doing the ones that are signed off as "
@@ -203,6 +221,33 @@ def build_queue(seed: int, attempt: int = 0) -> tuple[Task, list]:
203
  phases.append(Phase(goal, cps, staffings, o))
204
  ivs = [Intervention(iv.id, iv.change, f"About the {about[id(main)]}: {iv.text}", iv.trigger,
205
  iv.fallback_round, iv.min_gap, iv.world_effects) for iv in main.interventions]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  human = [SIGNOFF] + ([CI] if any("code" in g.units for g in gens) else []) + [HumanFact(
207
  "queue", "which jobs in the ops queue to do, sign-off, other requests in #ops-queue",
208
  "Do the jobs in #ops-queue that the VP of Customer Success or the CFO signed off, unless one of them called "
 
10
 
11
  import copy
12
  import random
13
+ import re
14
  from collections import Counter
15
  from typing import Any
16
 
 
18
  from ..tasks.hand.common import all_unchanged, set_replies
19
  from ..tasks.spec import Budgets, Checkpoint, HumanFact, Intervention, Mutant, OraclePhase, Phase, PlantedFact, Step, Task
20
  from . import company
21
+ from .build import (ALL_ROLES, CI, HIRE_ORDER, LOOSE, NEVER, SIGNOFF, GenerationError, Knobs, base_objects,
22
+ calibrate, make_task, make_world, tier_of)
23
  from .templates import TEMPLATES, Template
24
  from .world import Ids
25
 
 
71
  o.reset))
72
 
73
 
74
+ _READS = ("query", "list", "read", "search", "lookup", "accounts", "credit_history", "list_charges", "tables")
75
+
76
+
77
+ def _does_work(s: Step, known: set[str]) -> bool:
78
+ """A step worth hiring someone back for: not a ghost, and it changes something or finds something new."""
79
+ if (s.if_done or "").split(":")[-1] in ("ghost", "owed"):
80
+ return False
81
+ return not s.tool.split(".")[-1].startswith(_READS) or any(n not in known for n in s.provides)
82
+
83
+
84
  def _ledger_guard(cps: list[Checkpoint], initial: set[str]) -> Checkpoint:
85
  allows = [c.allows for c in cps if getattr(c, "allows", None)]
86
 
 
110
  messy=True))]
111
  jobs += [(t, Knobs(n=rng.choice([6, 8, 12]), crew=1, changes=(), traps=rng.randint(1, 3), code=False, budget=2.0,
112
  messy=True)) for t in side]
113
+ # the person comes back about the first side job once the main job's changes are in: by then its team may be
114
+ # done and gone, so the change has to find its way to whoever can still act on it, or to someone hired back
115
+ late = [c for c in ("MODIFY", "ADD:credit", "ADD:close") if c in side[0].pool and c not in jobs[0][1].changes]
116
+ t, k = jobs[1]
117
+ jobs[1] = (t, Knobs(n=k.n, crew=1, changes=(rng.choice(late),), traps=k.traps, code=False, budget=2.0, messy=True))
118
  return jobs
119
 
120
 
 
152
  gens = [make_world(t, seed, k, attempt, objects, ids) for t, k in jobs]
153
  decoy = _decoy(seed, attempt, objects, ids, gens)
154
  gens[0].template.shuffle(gens[0])
155
+ tasks = [make_task(g, attempt, late=j == 0)[0] for j, g in enumerate(gens)]
156
  main, side = tasks[0], tasks[1:]
157
  gens[0].template.finish_messy(gens[0], gens[1:], [company.QUEUE_RULE]) # one handbook with every job's rules
158
  who = company.people(gens[0])
 
171
  side_cps: list[Checkpoint] = []
172
  for t in side:
173
  side_roles += Counter(r for st in t.phases[0].staffings[:1] for r in st)
174
+ side_cps += t.phases[0].checkpoints
175
+ changed = [t for t in side if t.interventions]
176
+ final_cps = [c for t in side for c in t.phases[-1].checkpoints]
177
  initial = {o for o in objects if o.startswith("ledger.entries/")}
178
  about = {id(t): g.story["subject"] for t, g in zip(tasks, gens)}
179
  queue = (" Also work through the jobs posted in the #ops-queue chat channel, doing the ones that are signed off as "
 
221
  phases.append(Phase(goal, cps, staffings, o))
222
  ivs = [Intervention(iv.id, iv.change, f"About the {about[id(main)]}: {iv.text}", iv.trigger,
223
  iv.fallback_round, iv.min_gap, iv.world_effects) for iv in main.interventions]
224
+ for t in changed:
225
+ p = t.phases[1]
226
+ cps = [c for c in main.phases[-1].checkpoints if c.id != "no_stray_ledger_entries"]
227
+ cps += [c for c in final_cps if c.id != "no_stray_ledger_entries"]
228
+ cps += [_ledger_guard([*main.phases[-1].checkpoints, *final_cps], initial), held_back]
229
+ o = copy.copy(p.oracle)
230
+ o.steps = {k: list(v) for k, v in p.oracle.steps.items()}
231
+ # its team was let go once its part was done: whoever the change needs is hired back, briefed with what
232
+ # the first team found, which the orchestrator kept from their reports
233
+ known = {n for q in phases for st in q.oracle.steps.values() for x in st for n in x.provides}
234
+ real = [l for l, st in o.steps.items() if any(_does_work(x, known) for x in st)]
235
+ o.hires = [l for l in dict.fromkeys([*o.hires, *real]) if l not in alive]
236
+ need = sorted({n for st in o.steps.values() for s in st for n in _args_facts(s.args)})
237
+ if need:
238
+ o.orchestrator_steps = [*o.orchestrator_steps, Step("docs.read", {"doc_id": ["{" + n + "}" for n in need]},
239
+ if_done="never:ghost")]
240
+ o.retire = [l for l in o.retire if l in alive or l in o.hires]
241
+ o.retire_now = [l for l in o.retire_now if l in alive]
242
+ o.reset = [l for l in o.reset if l in alive]
243
+ alive = (alive | set(o.hires)) - set(o.retire) - set(o.retire_now)
244
+ iv = t.interventions[0]
245
+ text = f"About the {about[id(t)]}: {iv.text}"
246
+ # the reference team: the main job's, plus the side agents still on once the change is done
247
+ side_end = Counter(l.split("#")[0] for l in alive if re.search(r"#j\d+$", l))
248
+ team = [sorted((Counter(a) + side_end).elements()) for a in main.phases[-1].staffings]
249
+ phases.append(Phase(phases[-1].goal + " " + text, cps, team, o))
250
+ ivs.append(Intervention(iv.id, iv.change, text, NEVER, None, iv.min_gap, iv.world_effects))
251
  human = [SIGNOFF] + ([CI] if any("code" in g.units for g in gens) else []) + [HumanFact(
252
  "queue", "which jobs in the ops queue to do, sign-off, other requests in #ops-queue",
253
  "Do the jobs in #ops-queue that the VP of Customer Success or the CFO signed off, unless one of them called "
reorgbench/gen/templates.py CHANGED
@@ -294,9 +294,10 @@ class Template:
294
  def finish_messy(self, g: Gen, also: list[Gen] = (), rules_too: list[str] = ()) -> None:
295
  """The operations handbook, written once the changes (and so the credit cap) are known. In a shared
296
  company, also lists the other workstreams, whose own rules go in too."""
297
- cr = g.units.get("credited")
 
298
  new = cr.cap if cr is not None and cr.cap is not None else g.rng.choice([40, 60, 80])
299
- cap = g.story.get("cap_old", new + 20)
300
  rules = [
301
  "Expenses over $500 need a purchase order.",
302
  "Answer customer tickets within two business days, in plain language.",
@@ -328,7 +329,7 @@ class Template:
328
  "(policy-updates); where the two differ, the update wins.")
329
  g.objects["docs/operations-handbook"] = {"title": "Operations handbook", "text": " ".join(
330
  f"{i}. {r}" for i, r in enumerate(rules, 1))}
331
- fut = g.story.get("cap_future", new + 30)
332
  updates = [
333
  ("2026-04-20", "Purchasing", "Expenses over $750 now need a purchase order (was $500)."),
334
  ("2026-05-11", "Security", "Rotate credentials every 60 days (was 90)."),
 
294
  def finish_messy(self, g: Gen, also: list[Gen] = (), rules_too: list[str] = ()) -> None:
295
  """The operations handbook, written once the changes (and so the credit cap) are known. In a shared
296
  company, also lists the other workstreams, whose own rules go in too."""
297
+ src = next((x for x in [g, *also] if x.units.get("credited")), g) # the job whose credits the caps govern
298
+ cr = src.units.get("credited")
299
  new = cr.cap if cr is not None and cr.cap is not None else g.rng.choice([40, 60, 80])
300
+ cap = src.story.get("cap_old", new + 20)
301
  rules = [
302
  "Expenses over $500 need a purchase order.",
303
  "Answer customer tickets within two business days, in plain language.",
 
329
  "(policy-updates); where the two differ, the update wins.")
330
  g.objects["docs/operations-handbook"] = {"title": "Operations handbook", "text": " ".join(
331
  f"{i}. {r}" for i, r in enumerate(rules, 1))}
332
+ fut = src.story.get("cap_future", new + 30)
333
  updates = [
334
  ("2026-04-20", "Purchasing", "Expenses over $750 now need a purchase order (was $500)."),
335
  ("2026-05-11", "Security", "Rotate credentials every 60 days (was 90)."),
reorgbench/oracle.py CHANGED
@@ -25,6 +25,7 @@ _DONE = re.compile(r"^DONE PHASE (\d+)$", re.M)
25
  _RESET = re.compile(r"^RESET$", re.M)
26
  _ROLE = re.compile(r"^ROLE ([\w#]+)$", re.M)
27
  _TEAM = re.compile(r"^TEAM ([\w#]+)=(\w+)$", re.M)
 
28
 
29
 
30
  def role_of_label(label: str) -> str:
@@ -197,6 +198,8 @@ class OracleWorker:
197
  m = _ROLE.search(text)
198
  if m and not self.started:
199
  self.label = m.group(1)
 
 
200
  for name, raw in _FACT.findall(text):
201
  self.run.facts.setdefault(name, json.loads(raw))
202
  if sender is not None:
@@ -226,7 +229,7 @@ class OracleWorker:
226
  for role in sorted(self.ctl.consumers(name, self.phase)):
227
  if role == self.label:
228
  continue
229
- for aid in self.team.get(role, []):
230
  if (name, aid) not in self.sent:
231
  out.setdefault(aid, []).append(name)
232
  return out
@@ -254,7 +257,9 @@ class OracleWorker:
254
  return act
255
  if self.run.idle and self.reported < self.phase:
256
  self.reported = self.phase
257
- return {"type": "msg", "to": [self.info.parent], "content": f"DONE PHASE {self.phase}"}
 
 
258
  return {"type": "noop"}
259
 
260
 
@@ -271,8 +276,11 @@ class OracleOrchestrator:
271
  self.spawns: list[str] = []
272
  self.pending_spawns = 0
273
  self.pending_labels: list[str] = []
 
 
274
  self.instruct: list[str] = []
275
  self.resets: list[str] = []
 
276
  self._enter_phase(0)
277
 
278
  def _enter_phase(self, k: int) -> None:
@@ -305,12 +313,16 @@ class OracleOrchestrator:
305
  k, c = it["kind"], it["content"]
306
  if k == "spawned":
307
  self.role_of[c["agent_id"]] = self.pending_labels.pop(0)
 
308
  self.alive.append(c["agent_id"])
309
  self.assigned[c["agent_id"]] = self.phase
310
  self.pending_spawns -= 1
311
  elif k == "message":
312
  for d in _DONE.findall(c["text"]):
313
  self.done.add((c["from"], int(d)))
 
 
 
314
  for name, raw in _FACT.findall(c["text"]):
315
  self.run.facts.setdefault(name, json.loads(raw))
316
  elif k == "result":
@@ -336,14 +348,25 @@ class OracleOrchestrator:
336
  self.pending_spawns += 1
337
  self.pending_labels.append(role)
338
  needed = self.ctl.needs(role, self.phase)
 
339
  leaving = {a for a, _ in self.kills}
340
  team = [a for a in self.alive if a not in leaving]
 
 
 
341
  brief = "\n".join(filter(None, [f"PHASE {self.phase}", f"ROLE {role}", self._team_lines(team),
342
- fact_lines(self.run.facts, needed)]))
343
  return {"type": "spawn", "role": role_of_label(role), "brief": brief, "intro": team}
344
  if self.pending_spawns:
345
  return {"type": "noop"}
346
 
 
 
 
 
 
 
 
347
  while self.instruct: # an agent already let go needs no phase notice
348
  msg = self._instruct(self.instruct.pop(0), reset=False)
349
  if msg["to"]:
 
25
  _RESET = re.compile(r"^RESET$", re.M)
26
  _ROLE = re.compile(r"^ROLE ([\w#]+)$", re.M)
27
  _TEAM = re.compile(r"^TEAM ([\w#]+)=(\w+)$", re.M)
28
+ _TAGS = re.compile(r"^TAGS (\S+)$", re.M) # what an earlier agent with this label already did
29
 
30
 
31
  def role_of_label(label: str) -> str:
 
198
  m = _ROLE.search(text)
199
  if m and not self.started:
200
  self.label = m.group(1)
201
+ for tags in _TAGS.findall(text):
202
+ self.run.done_tags |= set(tags.split(","))
203
  for name, raw in _FACT.findall(text):
204
  self.run.facts.setdefault(name, json.loads(raw))
205
  if sender is not None:
 
229
  for role in sorted(self.ctl.consumers(name, self.phase)):
230
  if role == self.label:
231
  continue
232
+ for aid in ([self.info.parent] if role == "orchestrator" else self.team.get(role, [])):
233
  if (name, aid) not in self.sent:
234
  out.setdefault(aid, []).append(name)
235
  return out
 
257
  return act
258
  if self.run.idle and self.reported < self.phase:
259
  self.reported = self.phase
260
+ tags = ",".join(sorted(self.run.done_tags))
261
+ return {"type": "msg", "to": [self.info.parent],
262
+ "content": f"DONE PHASE {self.phase}" + (f"\nTAGS {tags}" if tags else "")}
263
  return {"type": "noop"}
264
 
265
 
 
276
  self.spawns: list[str] = []
277
  self.pending_spawns = 0
278
  self.pending_labels: list[str] = []
279
+ self.pending_facts: list[list[str]] = []
280
+ self.tags: dict[str, set[str]] = {} # label -> what its agents reported done, for anyone hired back to it
281
  self.instruct: list[str] = []
282
  self.resets: list[str] = []
283
+ self.passed: set[tuple[str, str]] = set() # (fact, agent) the orchestrator has handed on
284
  self._enter_phase(0)
285
 
286
  def _enter_phase(self, k: int) -> None:
 
313
  k, c = it["kind"], it["content"]
314
  if k == "spawned":
315
  self.role_of[c["agent_id"]] = self.pending_labels.pop(0)
316
+ self.passed |= {(n, c["agent_id"]) for n in self.pending_facts.pop(0)}
317
  self.alive.append(c["agent_id"])
318
  self.assigned[c["agent_id"]] = self.phase
319
  self.pending_spawns -= 1
320
  elif k == "message":
321
  for d in _DONE.findall(c["text"]):
322
  self.done.add((c["from"], int(d)))
323
+ for tags in _TAGS.findall(c["text"]):
324
+ if c["from"] in self.role_of:
325
+ self.tags.setdefault(self.role_of[c["from"]], set()).update(tags.split(","))
326
  for name, raw in _FACT.findall(c["text"]):
327
  self.run.facts.setdefault(name, json.loads(raw))
328
  elif k == "result":
 
348
  self.pending_spawns += 1
349
  self.pending_labels.append(role)
350
  needed = self.ctl.needs(role, self.phase)
351
+ self.pending_facts.append([n for n in needed if n in self.run.facts])
352
  leaving = {a for a, _ in self.kills}
353
  team = [a for a in self.alive if a not in leaving]
354
+ # only what its own steps branch on: what it already did, not a list of everyone it touched
355
+ used = {t for st in self.ctl.steps(self.phase, role) for t in (st.if_done, st.unless_done) if t}
356
+ done = ",".join(sorted(self.tags.get(role, set()) & used))
357
  brief = "\n".join(filter(None, [f"PHASE {self.phase}", f"ROLE {role}", self._team_lines(team),
358
+ fact_lines(self.run.facts, needed), done and f"TAGS {done}"]))
359
  return {"type": "spawn", "role": role_of_label(role), "brief": brief, "intro": team}
360
  if self.pending_spawns:
361
  return {"type": "noop"}
362
 
363
+ for a in self.alive: # a fact a teammate reported that an agent hired alongside it still needs
364
+ owed = [n for n in self.ctl.needs(self.role_of[a], self.phase) if n in self.run.facts
365
+ and (n, a) not in self.passed]
366
+ if owed:
367
+ self.passed |= {(n, a) for n in owed}
368
+ return {"type": "msg", "to": [a], "content": fact_lines(self.run.facts, owed)}
369
+
370
  while self.instruct: # an agent already let go needs no phase notice
371
  msg = self._instruct(self.instruct.pop(0), reset=False)
372
  if msg["to"]:
tests/test_generator.py CHANGED
@@ -183,6 +183,21 @@ def test_ops_queue_runs_every_story_at_once():
183
  assert "decoy_untouched" in ids # a posted job that isn't signed off
184
  posts = [d for o, d in t.initial_objects.items() if o.startswith("chat/") and d["channel"] == "ops-queue"]
185
  assert len(posts) == 3 and "#ops-queue" in t.phases[0].goal
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
 
187
 
188
  def test_messy_overcharge_refunds_are_summed_from_invoice_lines():
 
183
  assert "decoy_untouched" in ids # a posted job that isn't signed off
184
  posts = [d for o, d in t.initial_objects.items() if o.startswith("chat/") and d["channel"] == "ops-queue"]
185
  assert len(posts) == 3 and "#ops-queue" in t.phases[0].goal
186
+ # the person comes back about a side job last, after its team may have finished
187
+ side = t.title.split(": ", 1)[1].split(", ")[1]
188
+ assert t.interventions[-1].text.startswith(f"About the {side}: ") and len(t.phases) == len(t.interventions) + 1
189
+ before = {c.id for c in t.phases[-2].checkpoints if c.id.startswith("j1_")}
190
+ assert {c.id for c in t.phases[-1].checkpoints if c.id.startswith("j1_")} - before
191
+
192
+
193
+ @pytest.mark.parametrize("seed", range(6))
194
+ def test_queue_handbook_caps_are_the_credited_jobs(seed):
195
+ from reorgbench.gen.queue import build_queue
196
+ t, gens = build_queue(seed)
197
+ cr = [g.units["credited"] for g in gens if "credited" in g.units]
198
+ assert len(cr) <= 1
199
+ if cr and cr[0].cap is not None:
200
+ assert f"cap is now ${cr[0].cap} per account" in t.initial_objects["docs/policy-updates"]["text"]
201
 
202
 
203
  def test_messy_overcharge_refunds_are_summed_from_invoice_lines():