Spaces:
Sleeping

File size: 8,248 Bytes
a9de05b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# System Logic Review β€” CollabCode Pipeline

_Reviewed: 2026-06-16_

---

## 1. Kappa / AC1 gate uses the point estimate, not the CI lower bound

**File:** `kappa_calculator.py` β€” `calculate_kappa_report`

The gate decision is:

```python
gate_passed = ac1 >= AC1_GATE_THRESHOLD   # 0.70
```

The system already computes a 95 % bootstrap CI (`ac1_ci_95`), but ignores it for the gate. With N = 90 segments (the minimum), a point estimate of AC1 = 0.71 can easily have a CI of [0.52, 0.85]. Passing the gate on 0.71 when the lower bound is 0.52 is overconfident.

**Suggestion:** Gate on `ac1_ci_95[0] >= AC1_GATE_THRESHOLD` (lower bound), or at least flag a warning when the CI lower bound is below the threshold. This is especially important near the floor of 90 segments where variance is highest.

---

## 2. BELOW_THRESHOLD state has no recovery path

**File:** `orchestrator.py` β€” `advance_session`

When kappa fails the gate, the session moves to `BELOW_THRESHOLD` and stays there indefinitely:

```python
elif state_str in ("COMPLETE", "ERROR", "BELOW_THRESHOLD", "DISAGREEMENT_REVIEW"):
    pass  # these states require human intervention
```

There is no CLI command, watcher hook, or documented procedure for researchers to re-upload corrected codings and re-trigger kappa calculation. The session is silently stuck. Compare with `DISAGREEMENT_REVIEW`, which has `resolve` and `discard` CLI commands β€” `BELOW_THRESHOLD` needs an equivalent `resubmit` command that resets the state to `AWAITING_R1`, deletes the old coding files, and lets researchers re-code.

---

## 3. Agent 2 fires after every session β€” defeating the data accumulation design

**File:** `orchestrator.py` β€” `SessionWatcher.tick` and `step_run_agent2`

The watcher auto-advances any session in `READY_FOR_AGENT2`:

```python
elif state_str == "READY_FOR_AGENT2":
    advance_session(session_dir, self.sessions_root)
```

But `run_learning_cycle` inside `step_run_agent2` checks `n_sessions < MIN_SESSIONS_BEFORE_WRITING` (= 3) and blocks early runs. So sessions 1 and 2 correctly block, but session 3 triggers a full learning cycle against only the disagreements from sessions 1–3, then _marks all those candidates as consumed_. Session 4 then runs Agent 2 again with only the new disagreements from session 4 alone β€” potentially too sparse to produce reliable rules.

The design intent (accumulate data across many sessions before learning) is undermined because `consumed` candidates are never re-reviewed. Agent 2 should either:
- Run only on a schedule / manual trigger (not after every session), or
- Accumulate candidates until a configured N before triggering.

---

## 4. Discarded disagreements are silently dropped β€” not added to Tier 3

**File:** `orchestrator.py` β€” `discard_session_disagreement`

When a researcher discards an irresolvable disagreement, the function updates the kappa report and advances the session, but never calls `add_to_tier3`. So discarded cases β€” arguably the most ambiguous and informative edge cases for learning β€” are permanently lost. Agent 2 never sees them.

This is inconsistent with the `resolve_session_disagreement` path, which does call `add_to_tier3`. At minimum, discarded disagreements should be written to Tier 3 with a `resolution_note` of "discarded" so Agent 2 can inspect the pattern (e.g., a cluster of discards around D5/D6 might suggest the boundary between those dimensions needs clarification).

---

## 5. Global variable mutation is not thread-safe in parallel execution

**Files:** `agent1_segmenter.py`, `agent1b_coder.py`, `agent2_learner.py`

All three agents use this pattern:

```python
LIBRARY_ROOT = Path(__file__).parent / "library"

def some_fn(library_root=None):
    global LIBRARY_ROOT, TIER1_PATH, TIER2_PATH
    if library_root:
        LIBRARY_ROOT = library_root
        ...
```

`pipeline.py` runs Agent 1a sections in parallel via `ThreadPoolExecutor`. If different sections use different `library_root` overrides (e.g. in tests), these globals will race. In production with a single `library_root`, the race is benign β€” but it's fragile. The fix is to pass `library_root` as a parameter through the call stack rather than mutating a module global.

---

## 6. Agent 2 loads ALL unconsumed Tier 3 candidates in one LLM call β€” no pagination

**File:** `agent2_learner.py` β€” `run_learning_cycle`

```python
candidates = [c for c in load_tier3_candidates() if not c.get("consumed")]
...
user_prompt = build_user_prompt(candidates, reports)
```

After 20+ sessions with many disagreements, the candidate list can grow very large. There is no batching or cap. At Qwen 72B's context window (~32k tokens) and the verbose `_format_candidates` output (~150 chars per candidate), more than ~200 candidates will overflow the context or hit timeout limits.

**Suggestion:** Cap candidates per learning cycle (e.g. `candidates[:50]`) and process in batches, or sort by recency and only pass the most recent N.

---

## 7. The "only 2 researchers" assumption is hardcoded throughout

**Files:** `orchestrator.py`, `kappa_calculator.py`

The system assumes exactly 2 researchers (`R1` and `R2`) and 2 coding files. There's no path for a third researcher to break ties on especially difficult segments, or for a single-researcher validation mode during early piloting. The researcher_ids list is stored in state but the kappa calculator only accepts exactly two coding files. Making the system handle 3 researchers (majority vote) would require substantive changes.

---

## 8. Agent 0 X-Large sampling shows speaker attribution for skipped turns β€” misleading

**File:** `agent0_sectioner.py` β€” `_format_turns_compact`

For transcripts > 600 turns, every other turn is shown as `(…)` but the speaker name is still shown:

```
[ 42] 00:12:10  Alice: Actually I think we should…
[ 43] 00:12:15  Bob: (…)
[ 44] 00:12:20  Alice: OK let's just go with that
```

The LLM sees a speaker change at turn 43 (Bob) but no content β€” it may infer a boundary signal from the speaker alternation that doesn't exist. A cleaner approach is to show `[turn skipped]` without the speaker name, or to only skip turns from the same speaker as the preceding turn (where content is truly redundant).

---

## 9. Session watcher initial scan doesn't advance CREATED/PARSED/SEGMENTED sessions

**File:** `orchestrator.py` β€” `SessionWatcher.run`

The watcher's initial scan (lines 523–525) populates `_last_seen` to prevent false positives from pre-existing files. However, if the watcher restarts mid-session with a session already in `CREATED`, `PARSED`, or `SEGMENTED` state, `tick()` will correctly advance it on the first cycle. This is fine.

But if the watcher restarts with a session in `READY_FOR_AGENT2`, it will also correctly advance on the first `tick()`. The only gap is `CALCULATING_KAPPA` β€” a session stuck in that state (e.g., crash mid-calculation) will not be advanced by the watcher because there are no new files to trigger it. It needs a manual `python orchestrator.py advance <session_id>`.

**Suggestion:** Add `CALCULATING_KAPPA` to the auto-advance states in `tick()` so a restart can recover it:

```python
if state_str in ("CREATED", "PARSED", "SEGMENTED", "CALCULATING_KAPPA", "READY_FOR_AGENT2"):
    advance_session(session_dir, self.sessions_root)
```

---

## Summary of priority

| # | Issue | Impact | Effort |
|---|-------|--------|--------|
| 2 | No recovery from BELOW_THRESHOLD | High β€” sessions permanently stuck | Low |
| 3 | Agent 2 fires per-session, wastes candidates | High β€” undermines learning design | Medium |
| 4 | Discarded disagreements lost to Tier 3 | High β€” misses best training signal | Low |
| 1 | Gate on point estimate, not CI lower bound | Medium β€” overconfident gate decisions | Low |
| 9 | CALCULATING_KAPPA not auto-recovered | Medium β€” needs manual intervention | Low |
| 6 | No pagination on Tier 3 candidates | Medium β€” will break at scale | Medium |
| 5 | Global variable race in parallel workers | Low in prod, high in testing | Medium |
| 7 | 2-researcher assumption hardcoded | Low β€” known design constraint | High |
| 8 | Misleading X-Large sampling display | Low β€” affects Agent 0 only | Low |