|
Download SYSTEM_LOGIC_REVIEW.md from pylxi/script: direct link, hf CLI and curl.
- Browser
- Download file 8.25 kB
-
https://huggingface.co/spaces/pylxi/script/resolve/main/SYSTEM_LOGIC_REVIEW.md
- Command line
-
hf download hf://spaces/pylxi/script/SYSTEM_LOGIC_REVIEW.md
-
curl -L -o SYSTEM_LOGIC_REVIEW.md https://huggingface.co/spaces/pylxi/script/resolve/main/SYSTEM_LOGIC_REVIEW.md
8.25 kB
| # 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 | | |