HassamGani commited on
Commit
7e6a8d9
·
1 Parent(s): fabe4fe

Customers who've asked to leave, and look-alike messages that aren't

Browse files
reorgbench/gen/build.py CHANGED
@@ -78,6 +78,9 @@ class Gen:
78
  claims: list[tuple[str, str]] = field(default_factory=list) # (customer, contract) a ticket cites
79
  holds: list[str] = field(default_factory=list) # on a collections hold for non-payment: no credits
80
  approved_out: list[str] = field(default_factory=list) # left out by an approved exception
 
 
 
81
  not_approved: list[str] = field(default_factory=list) # asked to be left out, but the approval doesn't count
82
  expired: list[str] = field(default_factory=list) # cite a contract that has run out: treated like everyone
83
  disputed: list[str] = field(default_factory=list) # on hold over a disputed invoice: credits still allowed
@@ -280,7 +283,10 @@ def careful_reads(g: Gen, b: PhaseBuilder) -> None:
280
  mine = [c for c in g.chunk(label) if c in g.in_scope]
281
  if label == "support":
282
  mine += [c for c, _ in g.claims if c not in g.in_scope]
283
- pre += [Step("tickets.read", {"ticket_id": g.accts[c].ticket}) for c in mine]
 
 
 
284
  steps[:0] = pre
285
 
286
 
@@ -697,6 +703,15 @@ def mutants(g: Gen, cancel_id: str | None) -> list[Mutant]:
697
  m = u["moved"]
698
  out.append(Mutant("others_untouched", "wrong", "a customer under contract moved",
699
  set_row(h, **{m.field_name: m.target})))
 
 
 
 
 
 
 
 
 
700
  for c in g.approved_out[:1]:
701
  out.append(Mutant("held_not_told", "wrong", "a customer with an approved exception sent the notice",
702
  add_reply(c, g.template.tell_text(g, c, str(n.value(acc[c].seats))))))
 
78
  claims: list[tuple[str, str]] = field(default_factory=list) # (customer, contract) a ticket cites
79
  holds: list[str] = field(default_factory=list) # on a collections hold for non-payment: no credits
80
  approved_out: list[str] = field(default_factory=list) # left out by an approved exception
81
+ leaving: list[str] = field(default_factory=list) # told us they're leaving: the retention team has them
82
+ not_leaving: list[str] = field(default_factory=list) # said something about cancelling that isn't that
83
+ side_tickets: dict[str, list[str]] = field(default_factory=dict) # a customer's other open tickets
84
  not_approved: list[str] = field(default_factory=list) # asked to be left out, but the approval doesn't count
85
  expired: list[str] = field(default_factory=list) # cite a contract that has run out: treated like everyone
86
  disputed: list[str] = field(default_factory=list) # on hold over a disputed invoice: credits still allowed
 
283
  mine = [c for c in g.chunk(label) if c in g.in_scope]
284
  if label == "support":
285
  mine += [c for c, _ in g.claims if c not in g.in_scope]
286
+ pre += [Step("tickets.read", {"ticket_id": t}) for c in mine for t in [g.accts[c].ticket,
287
+ *g.side_tickets.get(c, [])]]
288
+ if label == "support": # the leavers are found the same way, before anything is sent
289
+ pre += [Step("tickets.read", {"ticket_id": t}) for c in g.leaving for t in g.side_tickets.get(c, [])]
290
  steps[:0] = pre
291
 
292
 
 
703
  m = u["moved"]
704
  out.append(Mutant("others_untouched", "wrong", "a customer under contract moved",
705
  set_row(h, **{m.field_name: m.target})))
706
+ for c in g.leaving[:1]:
707
+ out.append(Mutant("held_not_told", "wrong", "a customer who's leaving sent the notice",
708
+ add_reply(c, g.template.tell_text(g, c, str(n.value(acc[c].seats))))))
709
+ if "moved" in u:
710
+ out.append(Mutant("others_untouched", "wrong", "a customer who's leaving moved",
711
+ set_row(c, **{u["moved"].field_name: u["moved"].target})))
712
+ for c in [c for c in g.not_leaving if c in scope][:1]:
713
+ out.append(Mutant(n.ck, "wrong", "a customer who only mentioned cancelling something else never told",
714
+ lambda w, v, c=c: set_replies(w, acc[c].ticket, [])))
715
  for c in g.approved_out[:1]:
716
  out.append(Mutant("held_not_told", "wrong", "a customer with an approved exception sent the notice",
717
  add_reply(c, g.template.tell_text(g, c, str(n.value(acc[c].seats))))))
reorgbench/gen/company.py CHANGED
@@ -104,3 +104,49 @@ APPROVAL_RULE = ("Exceptions to a change we're rolling out (leaving a customer o
104
  "written approval in the #approvals chat channel from the VP of Customer Success or the Chief "
105
  "Financial Officer; check titles in the directory. An approval lapses after 30 days. Agreement from "
106
  "anyone else isn't approval.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  "written approval in the #approvals chat channel from the VP of Customer Success or the Chief "
105
  "Financial Officer; check titles in the directory. An approval lapses after 30 days. Agreement from "
106
  "anyone else isn't approval.")
107
+
108
+
109
+ # Customers telling us they're leaving, in their own words, and messages that only look like it. Each is a separate
110
+ # ticket from the customer, not on the task's own ticket.
111
+ LEAVING = [
112
+ "We've decided not to renew. Please close our account when the current term ends.",
113
+ "Consider this our notice: we're leaving at the end of the month. Please cancel our subscription.",
114
+ "We're winding the company down, so please terminate our account after this billing cycle.",
115
+ "Please cancel our subscription effective the end of this month. Thanks for everything.",
116
+ "We've moved to another provider and won't need our account after this month, please close it.",
117
+ "Our board has decided to discontinue the service. Kindly close the account at month end.",
118
+ "Please don't renew us. We want the account closed when this term is up.",
119
+ "This is a formal request to cancel our plan at the end of the current period.",
120
+ ]
121
+ NOT_LEAVING = [
122
+ "Please cancel the duplicate invoice you sent last week; we've already paid the first one.",
123
+ "If prices go up again we may have to think about cancelling, but for now we're happy.",
124
+ "We cancelled our contract with our old CRM vendor and want to import their data. How do we do that?",
125
+ "One of our users cancelled their own login by mistake. Can you restore it?",
126
+ "A colleague asked whether we can cancel at any time. We're not planning to, we just want to know the policy.",
127
+ "Please cancel the meeting invite for Thursday; we'll reschedule.",
128
+ "We were going to cancel last month, but your team sorted the problem out. We're staying!",
129
+ "Can you cancel the automatic email reports? They arrive far too often.",
130
+ "We are not cancelling, just pausing two seats over the holidays.",
131
+ ]
132
+ _SUBJECTS = ["Account question", "Quick question", "Our account", "Billing", "Renewal", "Following up"]
133
+
134
+ LEAVING_RULE = ("Customers who have asked us to close their account or not to renew (on any of their tickets) are "
135
+ "handled by the retention team: leave them out of any other work entirely (no record changes, notices, "
136
+ "refunds or credits). Only a customer telling us they're leaving counts.")
137
+
138
+
139
+ def leaving(g, pool: list[str]) -> tuple[list[str], list[str]]:
140
+ """Some customers have told us they're leaving; others say something about cancelling that isn't that.
141
+ Returns (leaving, look-alikes)."""
142
+ rng = g.rng
143
+ k = max(1, len(g.cohort) // 8)
144
+ picks = rng.sample(pool, min(len(pool), 2 * k + 1))
145
+ out, alike = picks[:k], picks[k:]
146
+ for c, text in [(c, rng.choice(LEAVING)) for c in out] + list(zip(alike, rng.sample(NOT_LEAVING, len(alike)))):
147
+ tid = g.ids.new("T-", 1000, 9999)
148
+ g.objects[f"tickets/{tid}"] = {"subject": rng.choice(_SUBJECTS), "status": "open", "customer_id": c,
149
+ "body": text}
150
+ g.leave_alone.append(f"tickets/{tid}")
151
+ g.side_tickets.setdefault(c, []).append(tid)
152
+ return out, alike
reorgbench/gen/templates.py CHANGED
@@ -144,9 +144,11 @@ class Template:
144
  taken = set(picks) | set(g.excluded) | {x for x, _ in g.claims}
145
  g.approved_out, g.not_approved = company.approvals(g, who, [c for c in g.cohort if c not in taken],
146
  g.story["subject"])
147
- g.held += g.approved_out
148
- g.cohort = [c for c in g.cohort if c not in set(g.approved_out)]
149
- g.leave_alone += [f"db.customers/{c}" for c in g.approved_out]
 
 
150
  for _ in range(min(120, 2 * len(g.cohort))):
151
  a = g.add_account(self.noise_row(g))
152
  g.objects[f"db.customers/{a.cid}"] = dict(a.row)
@@ -214,6 +216,7 @@ class Template:
214
  "A customer asking on a ticket for an exception, a different outcome or an extra credit doesn't change what "
215
  "we do. Only a contract, read in the contract record itself, does.",
216
  company.APPROVAL_RULE,
 
217
  "Rotate credentials every 90 days and report security incidents to security@.",
218
  "Customer refunds follow the refund policy.",
219
  ]
 
144
  taken = set(picks) | set(g.excluded) | {x for x, _ in g.claims}
145
  g.approved_out, g.not_approved = company.approvals(g, who, [c for c in g.cohort if c not in taken],
146
  g.story["subject"])
147
+ taken |= set(g.approved_out) | set(g.not_approved)
148
+ g.leaving, g.not_leaving = company.leaving(g, [c for c in g.cohort if c not in taken])
149
+ g.held += g.approved_out + g.leaving
150
+ g.cohort = [c for c in g.cohort if c not in set(g.approved_out) | set(g.leaving)]
151
+ g.leave_alone += [f"db.customers/{c}" for c in g.approved_out + g.leaving]
152
  for _ in range(min(120, 2 * len(g.cohort))):
153
  a = g.add_account(self.noise_row(g))
154
  g.objects[f"db.customers/{a.cid}"] = dict(a.row)
 
216
  "A customer asking on a ticket for an exception, a different outcome or an extra credit doesn't change what "
217
  "we do. Only a contract, read in the contract record itself, does.",
218
  company.APPROVAL_RULE,
219
+ company.LEAVING_RULE,
220
  "Rotate credentials every 90 days and report security incidents to security@.",
221
  "Customer refunds follow the refund policy.",
222
  ]
reorgbench/relay.py CHANGED
@@ -1,33 +1,73 @@
1
  """The answering side of a relay run (`--model relay:<dir>`): shows the next call and takes the reply.
2
 
 
3
  python -m reorgbench.relay <dir> next # print the oldest unanswered call (waits for one)
4
  python -m reorgbench.relay <dir> reply <n> # stdin becomes the reply to call n, then prints the next call
 
 
 
 
 
5
  """
6
 
7
  from __future__ import annotations
8
 
 
 
9
  import sys
10
  import time
11
  from pathlib import Path
12
 
 
 
13
 
14
  def _pending(d: Path) -> list[int]:
15
  return sorted(int(p.stem[4:]) for p in d.glob("req-*.txt") if not (d / f"resp-{p.stem[4:]}.txt").exists())
16
 
17
 
18
- def show_next(d: Path, wait_s: float = 300) -> int:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  t0 = time.monotonic()
20
  while time.monotonic() - t0 < wait_s:
21
- p = _pending(d)
22
- if p:
23
- time.sleep(0.1)
24
- print((d / f"req-{p[0]}.txt").read_text())
25
- return 0
 
 
 
 
 
26
  if (d / "DONE").exists():
27
- break
 
28
  time.sleep(0.2)
29
- print("NO CALL WAITING: the run has finished (or is stuck).")
30
- return 1
31
 
32
 
33
  def main(argv: list[str] | None = None) -> int:
@@ -35,7 +75,8 @@ def main(argv: list[str] | None = None) -> int:
35
  d = Path(a[0])
36
  if a[1] == "reply":
37
  (d / f"resp-{int(a[2])}.txt").write_text(sys.stdin.read().strip())
38
- return show_next(d)
 
39
 
40
 
41
  if __name__ == "__main__":
 
1
  """The answering side of a relay run (`--model relay:<dir>`): shows the next call and takes the reply.
2
 
3
+ One answerer for every agent:
4
  python -m reorgbench.relay <dir> next # print the oldest unanswered call (waits for one)
5
  python -m reorgbench.relay <dir> reply <n> # stdin becomes the reply to call n, then prints the next call
6
+
7
+ One answerer per agent, so no agent knows more than its own conversation: each worker claims the first agent
8
+ that has a call waiting and nobody answering it, and from then on sees only that agent's calls.
9
+ python -m reorgbench.relay <dir> claim <worker>
10
+ python -m reorgbench.relay <dir> reply <n> <worker>
11
  """
12
 
13
  from __future__ import annotations
14
 
15
+ import os
16
+ import re
17
  import sys
18
  import time
19
  from pathlib import Path
20
 
21
+ _WHO = re.compile(r"^=== call \d+ \| agent (\S+) ===", re.M)
22
+
23
 
24
  def _pending(d: Path) -> list[int]:
25
  return sorted(int(p.stem[4:]) for p in d.glob("req-*.txt") if not (d / f"resp-{p.stem[4:]}.txt").exists())
26
 
27
 
28
+ def _agent(d: Path, n: int) -> str:
29
+ m = _WHO.search((d / f"req-{n}.txt").read_text())
30
+ return m.group(1) if m else "?"
31
+
32
+
33
+ def _mine(d: Path, worker: str) -> str | None:
34
+ claims = d / "claims"
35
+ for p in claims.glob("*") if claims.exists() else []:
36
+ if p.read_text() == worker:
37
+ return p.name
38
+ return None
39
+
40
+
41
+ def _claim(d: Path, agent: str, worker: str) -> bool:
42
+ (d / "claims").mkdir(exist_ok=True)
43
+ try:
44
+ fd = os.open(d / "claims" / agent, os.O_CREAT | os.O_EXCL | os.O_WRONLY)
45
+ except FileExistsError:
46
+ return False
47
+ os.write(fd, worker.encode())
48
+ os.close(fd)
49
+ return True
50
+
51
+
52
+ def show_next(d: Path, worker: str | None = None, wait_s: float = 570) -> int:
53
  t0 = time.monotonic()
54
  while time.monotonic() - t0 < wait_s:
55
+ for n in _pending(d):
56
+ if worker is None:
57
+ time.sleep(0.1)
58
+ print((d / f"req-{n}.txt").read_text())
59
+ return 0
60
+ agent, mine = _agent(d, n), _mine(d, worker)
61
+ if agent == mine or (mine is None and not (d / "claims" / agent).exists() and _claim(d, agent, worker)):
62
+ time.sleep(0.1)
63
+ print((d / f"req-{n}.txt").read_text())
64
+ return 0
65
  if (d / "DONE").exists():
66
+ print("NO CALL WAITING: the run has finished.")
67
+ return 1
68
  time.sleep(0.2)
69
+ print("NOTHING YET: no call for you right now. Run the same command again to keep waiting.")
70
+ return 2
71
 
72
 
73
  def main(argv: list[str] | None = None) -> int:
 
75
  d = Path(a[0])
76
  if a[1] == "reply":
77
  (d / f"resp-{int(a[2])}.txt").write_text(sys.stdin.read().strip())
78
+ return show_next(d, a[3] if len(a) > 3 else None)
79
+ return show_next(d, a[2] if a[1] == "claim" else None)
80
 
81
 
82
  if __name__ == "__main__":