Lara Monteagudo Tubau commited on
Commit ·
ab719c7
1
Parent(s): ec3ff21
Fix 5 bugs: f-string crash, broken streaming, pending rules filter, chunk dedup, silent discard
Browse filesFiles changed (5)
354 unmodified lines355356357358359360361362363364365366367354 unmodified linesf"of ~{CHUNK_TURNS} with {overlap}-turn overlap)")all_segments: list[dict] = []seen_ids: set[str] = set()for idx, chunk in enumerate(chunks):segs = _call_single_pass(chunk, session_id, idx, system_prompt)for seg in segs:if seg["segment_id"] not in seen_ids:seen_ids.add(seg["segment_id"])all_segments.append(seg)print(f"[Agent 1] Complete. Total segments: {len(all_segments)}")354 unmodified lines355356357358359360361362363364365366367368369370371372373354 unmodified linesf"of ~{CHUNK_TURNS} with {overlap}-turn overlap)")all_segments: list[dict] = []# Track covered turn ranges by (start_turn_id, end_turn_id) to deduplicate# segments from overlapping chunks. Segment IDs cannot be used here because# each chunk gets a different prefix (c00_, c01_, …), so two segments covering# identical turns would have different IDs and both be included — a real bug# that creates duplicate coverage of the overlap zone.seen_turn_ranges: set[tuple[int, int]] = set()for idx, chunk in enumerate(chunks):segs = _call_single_pass(chunk, session_id, idx, system_prompt)for seg in segs:turn_range = (seg["start_turn_id"], seg["end_turn_id"])if turn_range not in seen_turn_ranges:seen_turn_ranges.add(turn_range)all_segments.append(seg)print(f"[Agent 1] Complete. Total segments: {len(all_segments)}")
452 unmodified lines453454455456457458459460461452 unmodified lines})n_uncertain = sum(1 for s in result if s.get("uncertain"))print(f"[Agent 1b] {section['section_id']}: {len(result)} coded, "f"{n_uncertain} uncertain "f"({last_stats.wall_time_s if last_stats else '?':.1f}s)")return result, last_stats452 unmodified lines453454455456457458459460461452 unmodified lines})n_uncertain = sum(1 for s in result if s.get("uncertain"))wall_str = f"{last_stats.wall_time_s:.1f}s" if last_stats else "?s"print(f"[Agent 1b] {section['section_id']}: {len(result)} coded, "f"{n_uncertain} uncertain ({wall_str})")return result, last_stats
740 unmodified lines741742743744745746747748749750751752740 unmodified lines# ---------------------------------------------------------------------------def list_pending_rules() -> list[dict]:"""Return all rules awaiting human approval."""rules_path = TIER2_PATH / "learned_rules.json"if not rules_path.exists():return []data = json.loads(rules_path.read_text(encoding="utf-8"))return [r for r in data.get("learned_rules", []) if not r.get("approved")]def print_pending_rules() -> None:740 unmodified lines741742743744745746747748749750751752753754755756757740 unmodified lines# ---------------------------------------------------------------------------def list_pending_rules() -> list[dict]:"""Return rules that are genuinely pending review (not yet approved or rejected)."""rules_path = TIER2_PATH / "learned_rules.json"if not rules_path.exists():return []data = json.loads(rules_path.read_text(encoding="utf-8"))return [r for r in data.get("learned_rules", [])if not r.get("approved")and not r.get("active")and not str(r.get("approval_note", "")).startswith("REJECTED:")]def print_pending_rules() -> None:
718 unmodified lines719720721722723724725726727728729718 unmodified linesdiscard_note: str,) -> dict:report = json.loads(report_path.read_text(encoding="utf-8"))for d in report["disagreements"]:if d["segment_id"] == segment_id:d["resolution_status"] = "discarded"d["resolved_dimension"] = Noned["resolution_note"] = discard_noteif all(d["resolution_status"] in ("resolved", "discarded")for d in report["disagreements"]) and report["gate_passed"]:718 unmodified lines719720721722723724725726727728729730731732733718 unmodified linesdiscard_note: str,) -> dict:report = json.loads(report_path.read_text(encoding="utf-8"))found = Falsefor d in report["disagreements"]:if d["segment_id"] == segment_id:d["resolution_status"] = "discarded"d["resolved_dimension"] = Noned["resolution_note"] = discard_notefound = Trueif not found:raise ValueError(f"Segment '{segment_id}' not found in disagreements.")if all(d["resolution_status"] in ("resolved", "discarded")for d in report["disagreements"]) and report["gate_passed"]:
289 unmodified lines290291292293294295296297298299300301302289 unmodified lines)result_q.put(sr)# Dispatch all workersexecutor = ThreadPoolExecutor(max_workers=max_workers)for sec in sections:executor.submit(_worker, sec)executor.shutdown(wait=True)# Collect and yield as results arriven_received = 0while n_received < len(sections):try:289 unmodified lines290291292293294295296297298299300301302303304305289 unmodified lines)result_q.put(sr)# Dispatch all workers without blocking — results stream into the queue# as each section completes, so the caller receives live updates.# (Calling shutdown(wait=True) here would block until ALL workers finish,# defeating the streaming purpose and freezing the UI for the full batch.)executor = ThreadPoolExecutor(max_workers=max_workers)for sec in sections:executor.submit(_worker, sec)executor.shutdown(wait=False) # non-blocking: workers run in background# Yield results in completion order as they arrive in the queuen_received = 0while n_received < len(sections):try:
agent1_segmenter.py+9-3
agent1b_coder.py+2-2
agent2_learner.py+7-2
kappa_calculator.py+4
pipeline.py+6-3