chap-analytics 0.2.5__tar.gz → 0.2.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/CHANGELOG.md +45 -0
  2. {chap_analytics-0.2.5/chap_analytics.egg-info → chap_analytics-0.2.6}/PKG-INFO +12 -7
  3. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/README.md +9 -4
  4. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/__init__.py +1 -1
  5. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/briefs.py +59 -9
  6. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/export.py +11 -8
  7. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/frames.py +62 -2
  8. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/schema.py +5 -0
  9. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/stats.py +73 -10
  10. {chap_analytics-0.2.5 → chap_analytics-0.2.6/chap_analytics.egg-info}/PKG-INFO +12 -7
  11. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics.egg-info/SOURCES.txt +3 -0
  12. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics.egg-info/requires.txt +2 -2
  13. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/pyproject.toml +3 -3
  14. chap_analytics-0.2.6/tests/test_acknowledgements.py +128 -0
  15. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_charts_and_briefs.py +17 -0
  16. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_handoff_and_routing.py +12 -7
  17. chap_analytics-0.2.6/tests/test_held_passes.py +90 -0
  18. chap_analytics-0.2.6/tests/test_recorded_decisions.py +98 -0
  19. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_review_passes.py +69 -0
  20. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_watch_export_models.py +15 -0
  21. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/LICENSE +0 -0
  22. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/MANIFEST.in +0 -0
  23. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/_patch.py +0 -0
  24. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/_report/report.css +0 -0
  25. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/_report/report.html +0 -0
  26. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/_report/report.js +0 -0
  27. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/_report/stats.js +0 -0
  28. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/_vendor/LICENSE.vega +0 -0
  29. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/_vendor/LICENSE.vega-embed +0 -0
  30. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/_vendor/LICENSE.vega-lite +0 -0
  31. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/_vendor/README.md +0 -0
  32. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/_vendor/render.js +0 -0
  33. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/_vendor/vega-embed.min.js +0 -0
  34. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/_vendor/vega-lite.min.js +0 -0
  35. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/_vendor/vega.min.js +0 -0
  36. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/charts.py +0 -0
  37. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/graph.py +0 -0
  38. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/load.py +0 -0
  39. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/models.py +0 -0
  40. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/py.typed +0 -0
  41. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/report.py +0 -0
  42. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/sample.py +0 -0
  43. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics/watch.py +0 -0
  44. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics.egg-info/dependency_links.txt +0 -0
  45. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/chap_analytics.egg-info/top_level.txt +0 -0
  46. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/examples/build_notebook.py +0 -0
  47. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/examples/chap_analytics_walkthrough.ipynb +0 -0
  48. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/examples/support_desk.py +0 -0
  49. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/setup.cfg +0 -0
  50. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/conftest.py +0 -0
  51. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/js_stats_runner.js +0 -0
  52. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_differential.py +0 -0
  53. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_example.py +0 -0
  54. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_from_url_scheme.py +0 -0
  55. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_graph.py +0 -0
  56. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_identity.py +0 -0
  57. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_notebook.py +0 -0
  58. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_patch_limits.py +0 -0
  59. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_projection.py +0 -0
  60. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_redaction_and_malformed.py +0 -0
  61. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_refusals.py +0 -0
  62. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_report.py +0 -0
  63. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_sample_and_export.py +0 -0
  64. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_stats.py +0 -0
  65. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_successors.py +0 -0
  66. {chap_analytics-0.2.5 → chap_analytics-0.2.6}/tests/test_typescript_store.py +0 -0
@@ -4,6 +4,51 @@
4
4
  so a protocol release moves the coordinator packages together and leaves this
5
5
  one where it is until the tables or the analyses change.
6
6
 
7
+ ## 0.2.6
8
+
9
+ Reads the logs of `chap-coordinator` 0.3.5.
10
+
11
+ ### Added
12
+
13
+ - **Time to open and time to decide.** Coordinators from 0.3.5 record
14
+ `review.acknowledge` when a reviewer opens a review. The decisions table
15
+ gains `acknowledged_at`, `time_to_open_s` and `time_to_decide_s`, and
16
+ `stats.latency` splits each pass's wait the same way, open passes
17
+ included; `open_queue` says which waiting reviews were opened. The
18
+ latency brief reports both medians, counts the waiting reviews nobody
19
+ has opened, and says to tell reviewers when a review arrives where most
20
+ of the wait comes before anyone opens the work. A log without
21
+ acknowledgements reads as before.
22
+ - **Decisions a bridge recorded.** A framework bridge records a decision a
23
+ person made outside CHAP, and from 0.3.5 the call carries
24
+ `via: "bridge-record"`. The decisions table and each pass in
25
+ `stats.latency` carry `via`; `latency_by`, `survival` and the latency
26
+ brief leave out passes a recorded decision settled, and the brief counts
27
+ them. It also points out decisions made within a second of their request,
28
+ which a bridge from before 0.3.5 records unmarked.
29
+ - **The artefact each decision was made on.** The decisions table gains
30
+ `artefact`.
31
+
32
+ ### Fixed
33
+
34
+ - **A completion after a review.** From 0.3.5 a task that has held a review
35
+ completes only through a decision, and completing it again opens a new
36
+ pass. The replay read such a completion as the end of the task, so the
37
+ decision that followed landed in the earlier pass. It now holds the
38
+ completion and opens a pass when a decision or an acknowledgement on the
39
+ task follows, or when the state shows the task under review; a log from
40
+ before 0.3.5 reads as before.
41
+ - **The successor of an escalated task.** From 0.3.5 `escalate.raise`
42
+ hands a review on with the work: the successor requires review when the
43
+ original held one. The replay now reads it so.
44
+ - **Approved evaluation cases.** `export.evaluation_cases(include_approved=True)`
45
+ gave approved tasks an empty `agent_output` and `corrected_output`. Both
46
+ now hold the artefact the settling decision approved.
47
+ - **One reviewer.** The concentration brief said reviewing was spread across
48
+ people when one reviewer decided everything on a small sample, and wrote
49
+ "1 reviewers". One reviewer is now named as the only one, and a high
50
+ share on too few decisions says the sample is too small to tell.
51
+
7
52
  ## 0.2.5
8
53
 
9
54
  Reads the review rounds of `chap-coordinator` 0.3.4.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chap-analytics
3
- Version: 0.2.5
3
+ Version: 0.2.6
4
4
  Summary: The record of a collaboration between people and agents, measured and drawn: a CHAP audit chain as documented tables, statistics with their intervals, graphs, charts, briefs and a self-contained interactive report
5
5
  Author-email: Brightbeam AI <oss@brightbeam.com>
6
6
  License-Expression: Apache-2.0
@@ -29,7 +29,7 @@ License-File: LICENSE
29
29
  Requires-Dist: pandas>=2.0
30
30
  Requires-Dist: numpy>=1.23
31
31
  Provides-Extra: coordinator
32
- Requires-Dist: chap-coordinator>=0.3.0; extra == "coordinator"
32
+ Requires-Dist: chap-coordinator>=0.3.5; extra == "coordinator"
33
33
  Provides-Extra: viz
34
34
  Requires-Dist: altair>=5; extra == "viz"
35
35
  Requires-Dist: vl-convert-python>=1.0; extra == "viz"
@@ -41,7 +41,7 @@ Requires-Dist: nbclient>=0.9; extra == "notebook"
41
41
  Requires-Dist: ipykernel>=6; extra == "notebook"
42
42
  Provides-Extra: dev
43
43
  Requires-Dist: pytest>=8; extra == "dev"
44
- Requires-Dist: chap-coordinator>=0.3.4; extra == "dev"
44
+ Requires-Dist: chap-coordinator>=0.3.5; extra == "dev"
45
45
  Requires-Dist: nbformat>=5; extra == "dev"
46
46
  Requires-Dist: altair>=5; extra == "dev"
47
47
  Requires-Dist: networkx>=3; extra == "dev"
@@ -145,7 +145,7 @@ reversed the agent's decision, or a rejection.
145
145
  | Which part of the prompt to fix | Where do the corrections land in the artefact? | Patch path frequency by task kind | Heatmap of `top_path` (the first segment of the corrected path) against kind, with the rationales behind each cell one click away |
146
146
  | Retune the routing thresholds | Does the agent's reported confidence track its outcomes? | Reliability curve, expected calibration error, Brier score | Reliability diagram with per-bin counts |
147
147
  | Promote an agent from trial to production | Is the substantive correction rate below the bar, given how many tasks have been seen? | Beta posterior probability that the true rate is under the threshold; Wald's sequential test | Posterior density against the threshold; the sequential test between its bounds |
148
- | Add reviewers, or reroute | Where do decisions wait, and for whom? | Time to decision as a Kaplan-Meier curve with open reviews censored; latency by reviewer; the open queue | Survival curve; median and 90th percentile per reviewer |
148
+ | Add reviewers, or reroute | Where do decisions wait, and for whom? | Time to decision as a Kaplan-Meier curve with open reviews censored; latency by reviewer; the open queue; where reviewers acknowledge opening a review, time to open and time to decide; decisions a framework bridge recorded from outside CHAP counted apart, and decisions too quick to have been read pointed out | Survival curve; median and 90th percentile per reviewer |
149
149
  | Rewrite an ambiguous policy | Do reviewers agree with each other on the same artefact? | Fleiss' kappa across multi-reviewer passes; pairwise Cohen's kappa; abstentions by category | Agreement matrix |
150
150
  | Clarify the task inputs | How often do agents have to ask, and does anyone answer in time? | Whispers (an agent's deadline-bound question to a person) per task, the share that lapsed unanswered, response time | Lapse rate by asker |
151
151
  | Cover the shift | Are handoffs accepted, and how fast? | Acceptance rate, response time, declines by recipient | Acceptance by recipient |
@@ -360,9 +360,14 @@ which rows are censored. It knows when a decision settled a review under
360
360
  each review rule (`any_one_approves`, `all_approve`, `quorum:N`). It keeps
361
361
  review passes apart, so a task sent back for revision is measured from each
362
362
  pass's own opening and `outcome` reads from the decision that settled the
363
- last pass. It reconstructs the corrected artefact from the patch with the
364
- coordinator's own RFC 6902 semantics. It counts the tasks the server mints
365
- on escalation and supersession, with what they inherit from the original.
363
+ last pass. It tells a decision a person sent from their own client, such as
364
+ a desk, from one a framework bridge recorded in their name, made in an
365
+ interface outside CHAP: `decisions.via` is `bridge-record` for those, and
366
+ the time-to-decision measures leave them out, since their time on the log
367
+ measures no review. It reconstructs the corrected artefact from the patch
368
+ with the coordinator's own RFC 6902 semantics. It counts the tasks the
369
+ server mints on escalation and supersession, with what they inherit from
370
+ the original.
366
371
  And it says how sure it is: `id_certain` and `assignee_certain` mark the
367
372
  rows where the chain admits more than one reading, so the population to
368
373
  draw conclusions from is a filter away.
@@ -96,7 +96,7 @@ reversed the agent's decision, or a rejection.
96
96
  | Which part of the prompt to fix | Where do the corrections land in the artefact? | Patch path frequency by task kind | Heatmap of `top_path` (the first segment of the corrected path) against kind, with the rationales behind each cell one click away |
97
97
  | Retune the routing thresholds | Does the agent's reported confidence track its outcomes? | Reliability curve, expected calibration error, Brier score | Reliability diagram with per-bin counts |
98
98
  | Promote an agent from trial to production | Is the substantive correction rate below the bar, given how many tasks have been seen? | Beta posterior probability that the true rate is under the threshold; Wald's sequential test | Posterior density against the threshold; the sequential test between its bounds |
99
- | Add reviewers, or reroute | Where do decisions wait, and for whom? | Time to decision as a Kaplan-Meier curve with open reviews censored; latency by reviewer; the open queue | Survival curve; median and 90th percentile per reviewer |
99
+ | Add reviewers, or reroute | Where do decisions wait, and for whom? | Time to decision as a Kaplan-Meier curve with open reviews censored; latency by reviewer; the open queue; where reviewers acknowledge opening a review, time to open and time to decide; decisions a framework bridge recorded from outside CHAP counted apart, and decisions too quick to have been read pointed out | Survival curve; median and 90th percentile per reviewer |
100
100
  | Rewrite an ambiguous policy | Do reviewers agree with each other on the same artefact? | Fleiss' kappa across multi-reviewer passes; pairwise Cohen's kappa; abstentions by category | Agreement matrix |
101
101
  | Clarify the task inputs | How often do agents have to ask, and does anyone answer in time? | Whispers (an agent's deadline-bound question to a person) per task, the share that lapsed unanswered, response time | Lapse rate by asker |
102
102
  | Cover the shift | Are handoffs accepted, and how fast? | Acceptance rate, response time, declines by recipient | Acceptance by recipient |
@@ -311,9 +311,14 @@ which rows are censored. It knows when a decision settled a review under
311
311
  each review rule (`any_one_approves`, `all_approve`, `quorum:N`). It keeps
312
312
  review passes apart, so a task sent back for revision is measured from each
313
313
  pass's own opening and `outcome` reads from the decision that settled the
314
- last pass. It reconstructs the corrected artefact from the patch with the
315
- coordinator's own RFC 6902 semantics. It counts the tasks the server mints
316
- on escalation and supersession, with what they inherit from the original.
314
+ last pass. It tells a decision a person sent from their own client, such as
315
+ a desk, from one a framework bridge recorded in their name, made in an
316
+ interface outside CHAP: `decisions.via` is `bridge-record` for those, and
317
+ the time-to-decision measures leave them out, since their time on the log
318
+ measures no review. It reconstructs the corrected artefact from the patch
319
+ with the coordinator's own RFC 6902 semantics. It counts the tasks the
320
+ server mints on escalation and supersession, with what they inherit from
321
+ the original.
317
322
  And it says how sure it is: `id_certain` and `assignee_certain` mark the
318
323
  rows where the chain admits more than one reading, so the population to
319
324
  draw conclusions from is a filter away.
@@ -41,7 +41,7 @@ The layers, bottom up:
41
41
  """
42
42
  from __future__ import annotations
43
43
 
44
- __version__ = "0.2.5"
44
+ __version__ = "0.2.6"
45
45
 
46
46
  from . import briefs, charts, export, graph, models, sample, stats, watch # noqa: E402
47
47
  from .frames import Frames, frames # noqa: E402
@@ -165,21 +165,58 @@ def calibration(f: Frames) -> Brief:
165
165
  # ============================================================================
166
166
 
167
167
  def latency(f: Frames) -> Brief:
168
- """How long reviews wait for a first decision, and how many are still waiting."""
169
- lt = _stats.latency(f)
168
+ """How long reviews wait for a first decision, and how many are still
169
+ waiting. Where reviewers acknowledge opening a review, the wait splits
170
+ into the time before a reviewer opened it and the time they took then.
171
+
172
+ A pass a framework bridge recorded, from a decision made outside CHAP,
173
+ is counted and left out of the times, which it does not measure; a
174
+ decision within a second of its request is pointed out, being too soon
175
+ for anyone to have read the work."""
176
+ passes = _stats.latency(f)
170
177
  q = _stats.open_queue(f)
171
178
  by = _stats.latency_by(f, by="reviewer")
172
- if lt.empty:
179
+ if passes.empty:
173
180
  return Brief("latency", "How long decisions take", "No reviews opened yet.",
174
- "No review pass is on this chain.", "Nothing waiting.", False, lt)
181
+ "No review pass is on this chain.", "Nothing waiting.", False, passes)
182
+ recorded = passes[passes["via"] == _stats.RECORDED]
183
+ lt = passes[passes["via"] != _stats.RECORDED]
175
184
  decided = lt[lt["event"]]
185
+ if len(recorded) == 1:
186
+ elsewhere = ("1 review pass was settled by a decision made outside CHAP and recorded by a framework "
187
+ "bridge; its time on the log measures no review, and is left out.")
188
+ else:
189
+ elsewhere = (f"{len(recorded)} review passes were settled by decisions made outside CHAP and recorded "
190
+ "by a framework bridge; their times on the log measure no review, and are left out.")
191
+ if decided.empty and q.empty:
192
+ return Brief("latency", "How long decisions take",
193
+ "Every decision here was made outside CHAP, so none times a review.",
194
+ elsewhere, "Nothing waiting.", False, by)
176
195
  med = decided["duration_s"].median() if not decided.empty else float("nan")
177
196
  p90 = decided["duration_s"].quantile(0.9) if not decided.empty else float("nan")
178
197
  head = (f"Half of the reviews were decided within {_hours(med)}, nine in ten within {_hours(p90)}; "
179
198
  f"{len(q)} still waiting.")
180
199
  parts = [f"{len(decided)} review passes reached a decision."]
200
+ if not recorded.empty:
201
+ parts.append(elsewhere)
202
+ instant = int((decided["duration_s"] < 1).sum())
203
+ if instant:
204
+ parts.append(f"{_n(instant, 'decision')} came within a second of {'its' if instant == 1 else 'their'} "
205
+ "request, too soon for anyone to have read the work: check how "
206
+ f"{'it was' if instant == 1 else 'they were'} made.")
207
+ seen = decided.dropna(subset=["time_to_open_s"])
208
+ med_open = seen["time_to_open_s"].median() if not seen.empty else float("nan")
209
+ med_decide = seen["time_to_decide_s"].median() if not seen.empty else float("nan")
210
+ if not seen.empty:
211
+ parts.append(f"In the {len(seen)} a reviewer acknowledged opening, half were opened within "
212
+ f"{_hours(med_open)} of the request, and half decided within {_hours(med_decide)} "
213
+ f"of being opened.")
181
214
  if not q.empty:
182
215
  parts.append(f"The oldest open review has waited {_hours(q.iloc[0]['age_s'])}.")
216
+ if (f.events["method"] == "review.acknowledge").any():
217
+ unopened = int(q["acknowledged_at"].isna().sum())
218
+ parts.append(f"Of the {len(q)} still waiting, {unopened} "
219
+ f"{'has' if unopened == 1 else 'have'} not been opened.")
183
220
  named = by.dropna(subset=["reviewer"]).sort_values("median_s", ascending=False)
184
221
  if len(named) >= 2:
185
222
  slow, fast = named.iloc[0], named.iloc[-1]
@@ -187,13 +224,18 @@ def latency(f: Frames) -> Brief:
187
224
  f"{fast['reviewer']} is quickest at {_hours(fast['median_s'])}.")
188
225
  if not q.empty and len(q) > max(3, 0.1 * len(lt)):
189
226
  decision = "More than a tenth of reviews are waiting: add a reviewer to that kind of work or reroute it."
190
- elif pd.notna(p90) and pd.notna(med) and p90 > 4 * med:
191
- decision = "The long tail is a few stuck items rather than general load: chase the oldest open reviews."
227
+ elif len(seen) >= 5 and med_open > 4 * med_decide:
228
+ decision = ("Most of the wait comes before a reviewer opens the work: tell reviewers when a "
229
+ "review arrives.")
230
+ elif not q.empty and pd.notna(p90) and pd.notna(med) and p90 > 4 * med:
231
+ decision = "A few stuck items make the long tail, and the general load keeps up: chase the oldest open reviews."
192
232
  else:
193
233
  decision = "Decisions are keeping up with the work."
194
234
  return Brief("latency", "How long decisions take", head, " ".join(parts), decision,
195
235
  len(decided) >= 10, by, {"median_s": float(med) if pd.notna(med) else None,
196
- "p90_s": float(p90) if pd.notna(p90) else None, "open": len(q)})
236
+ "p90_s": float(p90) if pd.notna(p90) else None, "open": len(q),
237
+ "median_open_s": float(med_open) if pd.notna(med_open) else None,
238
+ "median_decide_s": float(med_decide) if pd.notna(med_decide) else None})
197
239
 
198
240
 
199
241
  # ============================================================================
@@ -396,15 +438,23 @@ def concentration(f: Frames) -> Brief:
396
438
  return Brief("concentration", "Who carries the reviewing", "No decisions yet.",
397
439
  "No reviewer has decided on any agent's work.", "Nothing to balance.", False, c)
398
440
  top = c.iloc[0]
441
+ n_reviewers = int(top["n_reviewers"])
399
442
  head = (f"{top['top_reviewer']} takes {_pct(top['top_share'])} of the decisions on {top['assignee']}'s work "
400
- f"({int(top['n_decisions'])} decisions across {int(top['n_reviewers'])} reviewers).")
443
+ f"({int(top['n_decisions'])} decisions across {n_reviewers} "
444
+ f"reviewer{'' if n_reviewers == 1 else 's'}).")
401
445
  text = ""
402
446
  if not cen.empty:
403
447
  hub = cen.iloc[0]
404
448
  text = (f"{hub['participant']} sits between the most work on the collaboration graph "
405
449
  f"(betweenness {hub['betweenness']:.2f}, {int(hub['in_weight'])} items in, {int(hub['out_weight'])} out).")
406
- if top["top_share"] > 0.6 and top["sufficient"]:
450
+ if n_reviewers == 1:
451
+ decision = (f"{top['top_reviewer']} is the only reviewer of {top['assignee']}'s work, so one person's "
452
+ "judgement is the standard: add a second reviewer to check it, or accept that knowingly.")
453
+ elif top["top_share"] > 0.6 and top["sufficient"]:
407
454
  decision = f"One reviewer decides most of {top['assignee']}'s work: spread it, or accept that their standard is the standard."
455
+ elif top["top_share"] > 0.6:
456
+ decision = (f"{int(top['n_decisions'])} decisions are too few to say whether one reviewer carries "
457
+ f"{top['assignee']}'s work.")
408
458
  else:
409
459
  decision = "Reviewing is spread across people."
410
460
  return Brief("concentration", "Who carries the reviewing", head, text, decision, bool(top["sufficient"]), c)
@@ -45,9 +45,10 @@ def evaluation_cases(f: Frames, *, include_approved: bool = False) -> pd.DataFra
45
45
  One row per corrected task: ``input`` (where the chain carries state),
46
46
  ``agent_output`` (the artefact under review), ``corrected_output`` (the
47
47
  patch applied), ``rationale``, ``tags``, ``intent_preserved``, and who
48
- decided. With ``include_approved`` the approved tasks are added with the
49
- corrected output equal to the agent's, so a harness can score acceptance
50
- as well as correction.
48
+ decided. With ``include_approved`` the approved tasks are added, each
49
+ with the artefact the reviewer approved as both the agent's output and
50
+ the corrected output, so a harness can score acceptance as well as
51
+ correction.
51
52
  """
52
53
  inputs = _inputs(f)
53
54
  o = f.overrides
@@ -64,13 +65,15 @@ def evaluation_cases(f: Frames, *, include_approved: bool = False) -> pd.DataFra
64
65
  if include_approved and not f.decisions.empty:
65
66
  approved = f.tasks[f.tasks["outcome"] == "approved"]
66
67
  settle = _stats._settling_decisions(f).set_index("task_id")
67
- # An approval carries no artefact of its own: the agent's output was
68
- # accepted as drafted, so both output columns stay empty on these rows.
68
+ # The agent's output was accepted as drafted, so the artefact the
69
+ # approval was made on is both the output and the corrected output.
69
70
  for t in approved.itertuples(index=False):
70
- reviewer = settle["reviewer"].get(t.task_id) if t.task_id in settle.index else None
71
+ decided = t.task_id in settle.index
72
+ reviewer = settle["reviewer"].get(t.task_id) if decided else None
73
+ artefact = settle["artefact"].get(t.task_id) if decided else None
71
74
  rows.append({"task_id": t.task_id, "kind": t.kind, "assignee": t.assignee, "reviewer": reviewer,
72
- "ts": t.settled_at, "input": inputs.get(t.task_id), "agent_output": None,
73
- "corrected_output": None, "rationale": None, "tags": [], "policy_refs": [],
75
+ "ts": t.settled_at, "input": inputs.get(t.task_id), "agent_output": artefact,
76
+ "corrected_output": artefact, "rationale": None, "tags": [], "policy_refs": [],
74
77
  "intent_preserved": None, "outcome": "approved"})
75
78
  out = pd.DataFrame(rows, columns=cols)
76
79
  return out.sort_values("ts").reset_index(drop=True) if not out.empty else out
@@ -256,6 +256,9 @@ class _Review:
256
256
  artefact: Any = None
257
257
  decisions: list[dict] = field(default_factory=list)
258
258
  settled_at: pd.Timestamp | None = None
259
+ #: When each reviewer opened the review in front of them, from their first
260
+ #: review.acknowledge in this pass.
261
+ acknowledged: dict[str, pd.Timestamp] = field(default_factory=dict)
259
262
 
260
263
 
261
264
  #: What a task is given when it is made, rather than what happens to it
@@ -319,6 +322,10 @@ class _Task:
319
322
  assignee_moved: bool = False
320
323
  confidence_reported: bool = False
321
324
  reviews: list[_Review] = field(default_factory=list)
325
+ #: A completion on a task that has held a review, before any decision or
326
+ #: request after it: (when, reviewers, rule, artefact) of the pass it
327
+ #: opened, if a coordinator from 0.3.5 wrote the log.
328
+ held_round: tuple | None = None
322
329
 
323
330
  def attribute(self, made: _Creation | None) -> None:
324
331
  """Take this creation's attributes as this task's own."""
@@ -663,12 +670,23 @@ def _replay(chain: Chain) -> _Index: # noqa: C901 - one pass, one branch per me
663
670
  r = t.open_review(ts, [x for x in r.requested_to if x != actor], r.rule, None)
664
671
  r.artefact = p.get("output")
665
672
  t.state, t.settled_at = "review_requested", None
673
+ t.held_round = None
666
674
  else:
667
675
  t.state = "completed"
668
676
  t.settled_at = ts
677
+ # From chap-coordinator 0.3.5 a task that has held a review
678
+ # completes only through a decision: this completion opened a
679
+ # new pass of that review, as on a task that requires review.
680
+ # Before 0.3.5 it completed the task. The log reads the same
681
+ # either way, so the pass is held here and opened when a
682
+ # decision on it shows that a coordinator from 0.3.5 wrote it.
683
+ r = t.review
684
+ t.held_round = None if r is None else (
685
+ ts, [x for x in r.requested_to if x != actor], r.rule, p.get("output"))
669
686
 
670
687
  elif method == "review.request" and tid:
671
688
  t = task(tid)
689
+ t.held_round = None
672
690
  addressed = _as_list(p.get("to"))
673
691
  r = t.review
674
692
  if t.state == "review_requested" and r is not None:
@@ -688,9 +706,33 @@ def _replay(chain: Chain) -> _Index: # noqa: C901 - one pass, one branch per me
688
706
  p.get("artefact"))
689
707
  t.state, t.settled_at = "review_requested", None
690
708
 
709
+ elif method == "review.acknowledge" and tid:
710
+ # review/1.0: a reviewer has opened the review in front of them.
711
+ # A coordinator takes one only while a review is open, so one
712
+ # after a completion that would have completed the task before
713
+ # 0.3.5 shows that the completion opened a new pass, as a
714
+ # decision does. One the replay finds no open pass for belongs to
715
+ # none, and is left out. A coordinator takes one per reviewer per
716
+ # pass; the first is kept wherever a log holds more.
717
+ t = task(tid)
718
+ if t.held_round is not None:
719
+ opened, to, rule, artefact = t.held_round
720
+ t.open_review(opened, to, rule, artefact)
721
+ t.held_round = None
722
+ t.state, t.settled_at = "review_requested", None
723
+ r = t.review
724
+ if r is not None and t.state == "review_requested" and isinstance(actor, str) and ts is not None:
725
+ r.acknowledged.setdefault(actor, ts)
726
+
691
727
  elif method in ("decide.approve", "decide.reject", "decide.override",
692
728
  "abstain.declare") and tid:
693
729
  t = task(tid)
730
+ if t.held_round is not None:
731
+ # A decision after a completion that would have completed the
732
+ # task before 0.3.5: the completion opened a new pass.
733
+ opened, to, rule, artefact = t.held_round
734
+ t.open_review(opened, to, rule, artefact)
735
+ t.held_round = None
694
736
  r = t.review
695
737
  if r is None:
696
738
  # The coordinator accepts a decision on a task under review, so
@@ -706,6 +748,7 @@ def _replay(chain: Chain) -> _Index: # noqa: C901 - one pass, one branch per me
706
748
  "request_revision": bool(p.get("request_revision")) if kind == "reject" else None,
707
749
  "abstain_category": p.get("category") if kind == "abstain" else None,
708
750
  "digest_bound": p.get("approved_artefact_digest") is not None,
751
+ "via": p.get("via") if isinstance(p.get("via"), str) else None,
709
752
  "is_final": False,
710
753
  }
711
754
  r.decisions.append(d)
@@ -748,11 +791,12 @@ def _replay(chain: Chain) -> _Index: # noqa: C901 - one pass, one branch per me
748
791
  spec = p.get("new_task") if isinstance(p.get("new_task"), dict) else {}
749
792
  # The successor inherits the original's kind where the spec names
750
793
  # none, and its mode where the spec names none. It requires review
751
- # when the original did, and otherwise under the rule task.create
794
+ # when the original did, or, from chap-coordinator 0.3.5, when the
795
+ # original held a review, and otherwise under the rule task.create
752
796
  # applies to its mode. The coordinator reads no review_required
753
797
  # from the spec.
754
798
  mode = spec.get("mode") or (old.mode if old else None)
755
- keeps_review = bool(old is not None and old.review_required)
799
+ keeps_review = bool(old is not None and (old.review_required or old.reviews))
756
800
  inherited = ({"mode"} if not spec.get("mode") else set()) \
757
801
  | ({"kind"} if not spec.get("kind") else set()) \
758
802
  | ({"review_required"} if keeps_review else set())
@@ -1299,6 +1343,12 @@ def _merge_state(ix: _Index, chain: Chain) -> None: # noqa: C901 - one block pe
1299
1343
  # behind. The column is defined as null while open.
1300
1344
  if t.state not in _SETTLED:
1301
1345
  t.settled_at = None
1346
+ if t.held_round is not None and t.state == "review_requested":
1347
+ # State shows the completion opened a new pass: a coordinator from
1348
+ # 0.3.5 wrote the log, and the pass is still waiting.
1349
+ opened, to, rule, artefact = t.held_round
1350
+ t.open_review(opened, to, rule, artefact)
1351
+ t.held_round = None
1302
1352
  review = stored.get("review") or {}
1303
1353
  if review:
1304
1354
  # State carries the current pass only, which is the last one here.
@@ -1592,16 +1642,26 @@ def frames(chain: Chain) -> Frames:
1592
1642
  lat = None
1593
1643
  if d["ts"] is not None and r.requested_at is not None:
1594
1644
  lat = (d["ts"] - r.requested_at).total_seconds()
1645
+ seen = r.acknowledged.get(d["reviewer"])
1646
+ to_open = to_decide = None
1647
+ if seen is not None and r.requested_at is not None:
1648
+ to_open = (seen - r.requested_at).total_seconds()
1649
+ if seen is not None and d["ts"] is not None:
1650
+ to_decide = (d["ts"] - seen).total_seconds()
1595
1651
  decision_rows.append({
1596
1652
  "task_id": tid, "workspace": ws, "seq": d["seq"],
1597
1653
  "reviewer": d["reviewer"], "kind": d["kind"], "ts": d["ts"],
1598
1654
  "requested_at": r.requested_at, "latency_s": lat,
1655
+ "acknowledged_at": seen, "time_to_open_s": to_open,
1656
+ "time_to_decide_s": to_decide,
1599
1657
  "rule": r.rule, "review_index": pass_no,
1600
1658
  "decision_index": i, "is_final": d["is_final"],
1601
1659
  "comment": d["comment"], "tags": d["tags"], "n_tags": len(d["tags"]),
1602
1660
  "request_revision": d["request_revision"],
1603
1661
  "abstain_category": d["abstain_category"],
1604
1662
  "digest_bound": d["digest_bound"],
1663
+ "via": d["via"],
1664
+ "artefact": r.artefact,
1605
1665
  "task_kind": t.kind, "assignee": t.assignee,
1606
1666
  })
1607
1667
 
@@ -149,6 +149,9 @@ DECISIONS = Table(
149
149
  _c("ts", "datetime64[ns, UTC]", "envelopes", "When the decision was made."),
150
150
  _c("requested_at", "datetime64[ns, UTC]", "replay", "When the review pass this decision belongs to was opened."),
151
151
  _c("latency_s", "float64", "derived", "Seconds from the opening of this decision's own review pass. Elapsed time: a reviewer answering after three days may have spent ninety seconds on it."),
152
+ _c("acknowledged_at", "datetime64[ns, UTC]", "envelopes", "When this decision's reviewer opened the review in front of them, from their review.acknowledge in this pass. Null where the log holds none: a desk sends one as a reviewer opens a review, and coordinators before 0.3.5 record none."),
153
+ _c("time_to_open_s", "float64", "derived", "Seconds from the review being requested to this reviewer opening it: how long the work waited unseen."),
154
+ _c("time_to_decide_s", "float64", "derived", "Seconds from this reviewer opening the review to their decision: the time they took with the work in front of them."),
152
155
  _c("rule", "string", "replay", "The review rule in force: any_one_approves, all_approve or quorum:N."),
153
156
  _c("review_index", "Int64", "derived", "Which review pass on this task, from zero. A task sent back for revision is reviewed afresh, and a rate computed within a pass counts decisions about one artefact."),
154
157
  _c("decision_index", "Int64", "derived", "Order of this decision within its review pass, from zero."),
@@ -159,6 +162,8 @@ DECISIONS = Table(
159
162
  _c("request_revision", "boolean", "envelopes", "On a rejection, whether the task was sent back rather than declined."),
160
163
  _c("abstain_category", "string", "envelopes", "On an abstention, the stated category."),
161
164
  _c("digest_bound", "boolean", "derived", "Whether the decision carried an artefact digest, binding it to exact content."),
165
+ _c("via", "string", "envelopes", "How the decision reached the log, where its call says: bridge-record for a decision made in an interface outside CHAP and recorded in the person's name by a framework bridge, whose time on the log measures no review. Null for a decision the person sent from their own client, such as a desk."),
166
+ _c("artefact", "object", "replay", "The artefact the decision was made on: the one under review in its pass, as the agent submitted it."),
162
167
  _c("task_kind", "string", "derived", "Denormalised from tasks, so a reviewer analysis reads it here directly."),
163
168
  _c("assignee", "string", "derived", "Denormalised: who produced the work being judged."),
164
169
  ),
@@ -442,26 +442,82 @@ def _chain_end(f: Frames) -> pd.Timestamp | None:
442
442
  return ts.max() if not ts.empty else None
443
443
 
444
444
 
445
+ #: The ``via`` of a decision a framework bridge recorded in a person's name,
446
+ #: made in an interface outside CHAP. Its time on the log measures no review.
447
+ RECORDED = "bridge-record"
448
+
449
+
450
+ def _timed(lt: pd.DataFrame) -> pd.DataFrame:
451
+ """The passes of :func:`latency` whose times measure a review: all but
452
+ those a recorded decision settled."""
453
+ return lt[lt["via"] != RECORDED]
454
+
455
+
456
+ def _acknowledgements(f: Frames) -> dict[str, list[pd.Timestamp]]:
457
+ """The times of every review.acknowledge on the chain, by task."""
458
+ ev = f.events
459
+ out: dict[str, list[pd.Timestamp]] = {}
460
+ for r in ev[ev["method"] == "review.acknowledge"][["task_id", "ts"]].itertuples(index=False):
461
+ if isinstance(r.task_id, str) and pd.notna(r.ts):
462
+ out.setdefault(r.task_id, []).append(r.ts)
463
+ return out
464
+
465
+
466
+ def _first_acknowledgement(acks: dict[str, list[pd.Timestamp]], task_id: str,
467
+ start: Any, stop: Any) -> Any:
468
+ """The first acknowledgement of the pass requested at ``start``: the
469
+ earliest at or after it, and no later than ``stop`` where the pass was
470
+ decided."""
471
+ if start is None or pd.isna(start):
472
+ return pd.NaT
473
+ times = [t for t in acks.get(task_id, ())
474
+ if t >= start and (stop is None or pd.isna(stop) or t <= stop)]
475
+ return min(times) if times else pd.NaT
476
+
477
+
478
+ def _seconds(later: Any, earlier: Any) -> float:
479
+ if later is None or earlier is None or pd.isna(later) or pd.isna(earlier):
480
+ return float("nan")
481
+ return (later - earlier).total_seconds()
482
+
483
+
445
484
  def latency(f: Frames) -> pd.DataFrame:
446
485
  """
447
486
  One row per review pass: when it opened, how long until its first
448
487
  decision, and whether it is still open (``event`` False, ``duration_s``
449
488
  measured to the end of the chain).
450
489
 
490
+ Where the chain records ``review.acknowledge``, ``acknowledged_at`` is
491
+ when a reviewer first opened the pass, and the wait splits in two:
492
+ ``time_to_open_s``, from the request to that opening, and
493
+ ``time_to_decide_s``, from the opening to the first decision.
494
+
495
+ ``via`` is the first decision's: ``bridge-record`` where a framework
496
+ bridge recorded it from a decision made outside CHAP, so the pass's time
497
+ measures no review. :func:`latency_by`, :func:`survival` and the latency
498
+ brief leave those passes out.
499
+
451
500
  Open passes are found from the last ``review.request`` or ``task.complete``
452
501
  envelope on a task that is still awaiting a decision.
453
502
  """
454
503
  d = f.decisions
455
504
  end = _chain_end(f)
505
+ acks = _acknowledgements(f)
456
506
  rows: list[dict] = []
457
507
  if not d.empty:
458
- first = (d.sort_values("ts").groupby(["task_id", "review_index"], as_index=False)
508
+ ordered = d.sort_values("ts")
509
+ first = (ordered.groupby(["task_id", "review_index"], as_index=False)
459
510
  .first()[["task_id", "review_index", "requested_at", "ts", "latency_s", "reviewer", "task_kind", "assignee"]])
511
+ via = ordered.drop_duplicates(["task_id", "review_index"]).set_index(["task_id", "review_index"])["via"]
460
512
  for r in first.itertuples(index=False):
513
+ seen = _first_acknowledgement(acks, r.task_id, r.requested_at, r.ts)
461
514
  rows.append({"task_id": r.task_id, "review_index": r.review_index,
462
515
  "requested_at": r.requested_at, "decided_at": r.ts,
463
516
  "duration_s": r.latency_s, "event": True,
464
- "reviewer": r.reviewer, "task_kind": r.task_kind, "assignee": r.assignee})
517
+ "reviewer": r.reviewer, "task_kind": r.task_kind, "assignee": r.assignee,
518
+ "acknowledged_at": seen, "time_to_open_s": _seconds(seen, r.requested_at),
519
+ "time_to_decide_s": _seconds(r.ts, seen),
520
+ "via": via.get((r.task_id, r.review_index))})
465
521
  open_tasks = f.tasks[(f.tasks["outcome"] == "open") & f.tasks["was_reviewed"].fillna(False)]
466
522
  if not open_tasks.empty and end is not None:
467
523
  ev = f.events[f.events["method"].isin(("review.request", "task.complete"))]
@@ -475,12 +531,16 @@ def latency(f: Frames) -> pd.DataFrame:
475
531
  req = last_req.get(t.task_id)
476
532
  if req is None or pd.isna(req):
477
533
  continue
534
+ seen = _first_acknowledgement(acks, t.task_id, req, None)
478
535
  rows.append({"task_id": t.task_id, "review_index": idx, "requested_at": req,
479
536
  "decided_at": pd.NaT, "duration_s": (end - req).total_seconds(),
480
537
  "event": False, "reviewer": None, "task_kind": t.kind,
481
- "assignee": t.assignee})
538
+ "assignee": t.assignee, "acknowledged_at": seen,
539
+ "time_to_open_s": _seconds(seen, req), "time_to_decide_s": float("nan"),
540
+ "via": None})
482
541
  cols = ["task_id", "review_index", "requested_at", "decided_at", "duration_s", "event",
483
- "reviewer", "task_kind", "assignee"]
542
+ "reviewer", "task_kind", "assignee", "acknowledged_at", "time_to_open_s",
543
+ "time_to_decide_s", "via"]
484
544
  out = pd.DataFrame(rows, columns=cols)
485
545
  return out.sort_values(["requested_at", "task_id"]).reset_index(drop=True)
486
546
 
@@ -493,9 +553,10 @@ def survival(f: Frames, by: str | None = None) -> pd.DataFrame:
493
553
  a workspace with a long tail of waiting work shows it. ``survival`` at a
494
554
  time is the share of reviews still undecided after that long; ``low`` and
495
555
  ``high`` are Greenwood 95% bounds. Group with ``by`` on ``reviewer``,
496
- ``task_kind`` or ``assignee``.
556
+ ``task_kind`` or ``assignee``. A pass a recorded decision settled is left
557
+ out: its time measures no review.
497
558
  """
498
- lt = latency(f)
559
+ lt = _timed(latency(f))
499
560
  groups = [by] if by else []
500
561
  cols = groups + ["time_s", "at_risk", "events", "censored", "survival", "low", "high"]
501
562
  if lt.empty:
@@ -527,9 +588,10 @@ def survival(f: Frames, by: str | None = None) -> pd.DataFrame:
527
588
  def latency_by(f: Frames, by: str = "reviewer", *, minimum: int = 5) -> pd.DataFrame:
528
589
  """
529
590
  Time to first decision per group, on decided passes: count, median, 90th
530
- percentile and mean, in seconds, with the number of passes still open.
591
+ percentile and mean, in seconds, with the number of passes still open. A
592
+ pass a recorded decision settled is left out: its time measures no review.
531
593
  """
532
- lt = latency(f)
594
+ lt = _timed(latency(f))
533
595
  cols = [by, "n", "open", "median_s", "p90_s", "mean_s", "sufficient"]
534
596
  if lt.empty:
535
597
  return _with_minimum(pd.DataFrame(columns=cols), minimum)
@@ -550,9 +612,10 @@ def latency_by(f: Frames, by: str = "reviewer", *, minimum: int = 5) -> pd.DataF
550
612
 
551
613
 
552
614
  def open_queue(f: Frames) -> pd.DataFrame:
553
- """Reviews still waiting, oldest first, with their age at the end of the chain."""
615
+ """Reviews still waiting, oldest first, with their age at the end of the
616
+ chain and, where the chain records it, when a reviewer opened them."""
554
617
  lt = latency(f)
555
- cols = ["task_id", "task_kind", "assignee", "requested_at", "age_s"]
618
+ cols = ["task_id", "task_kind", "assignee", "requested_at", "age_s", "acknowledged_at"]
556
619
  if lt.empty:
557
620
  return pd.DataFrame(columns=cols)
558
621
  q = lt[~lt["event"].astype(bool)].rename(columns={"duration_s": "age_s"})