Repository navigation
Preserve integration concerns and diagnostics for large reviews #425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4fb8fb2
7e66d70
37f1ec8
57f1f0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1087,6 +1087,7 @@ class ReviewResult: | |
| calls: int = 1 | ||
| coverage: str | None = None | ||
| requests: tuple[ReviewResult, ...] = () | ||
| source_reviews: tuple[ReviewResult, ...] = () | ||
|
|
||
|
|
||
| def _review_messages( | ||
|
|
@@ -1207,7 +1208,9 @@ def _review_in_portions( | |
| manifest, [r.payload for r in results], shared | ||
| ) | ||
| final = _integrate_portions(diff, evidence, obligations, budget, prepare, send) | ||
| return replace(final, portions=len(results), coverage=manifest) | ||
| return replace( | ||
| final, portions=len(results), coverage=manifest, source_reviews=tuple(results) | ||
|
Comment on lines
+1211
to
+1212
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ) | ||
|
|
||
|
|
||
| def _integrate_portions( | ||
|
|
@@ -1233,13 +1236,11 @@ def _integrate_portions( | |
| ) | ||
| final = send(messages) | ||
| queries = final.payload.get("source_requests", []) | ||
| if ( | ||
| not isinstance(queries, list) | ||
| or len(queries) > 20 | ||
| or any(not isinstance(query, str) or not query.strip() for query in queries) | ||
| if not isinstance(queries, list) or any( | ||
| not isinstance(query, str) or not query.strip() for query in queries | ||
| ): | ||
| raise ValueError( | ||
| "Integration source requests must be at most 20 nonempty strings" | ||
| f"Integration source requests must be nonempty strings: {queries!r}" | ||
| ) | ||
|
Comment on lines
1238
to
1244
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A model response with many source requests now passes validation. Knowledge Base Used: Fit oversized pull-request diffs to the review budget |
||
| if not queries: | ||
| break | ||
|
|
@@ -1250,19 +1251,38 @@ def _integrate_portions( | |
| ) | ||
| ) | ||
| bundle["obligations"] = obligations | ||
| updated = prepare( | ||
| json.dumps(bundle, ensure_ascii=False), | ||
| review_portions.integration_instructions(), | ||
| ) | ||
| available = budget - _message_tokens(updated) | ||
| allowance = max(0, (available - 512) // len(queries)) | ||
| bundle["source_followups"].extend( | ||
| review_portions.source_excerpts(diff, query, allowance) for query in queries | ||
| ) | ||
| if not _fit_source_followups(diff, queries, bundle, budget, prepare): | ||
| break | ||
| payload = review_portions.enforce_resolutions(final.payload, obligations) | ||
| return replace(final, payload=payload) | ||
|
|
||
|
|
||
| def _fit_source_followups( | ||
| diff: str, queries: list[str], bundle: dict, budget: int, prepare: Callable | ||
| ) -> bool: | ||
| """Fit the serialized excerpts and their metadata within the next call.""" | ||
| rules = review_portions.integration_instructions() | ||
| available = budget - _message_tokens( | ||
| prepare(json.dumps(bundle, ensure_ascii=False), rules) | ||
| ) | ||
| allowance = max( | ||
| 0, int((available - 512) * CHARS_PER_TOKEN_ESTIMATE) // len(queries) | ||
| ) | ||
| for _ in range(20): | ||
| excerpts = [ | ||
| review_portions.source_excerpts(diff, query, allowance) for query in queries | ||
| ] | ||
| candidate = bundle | {"source_followups": bundle["source_followups"] + excerpts} | ||
| messages = prepare(json.dumps(candidate, ensure_ascii=False), rules) | ||
| if _message_tokens(messages) <= budget: | ||
| bundle["source_followups"] = candidate["source_followups"] | ||
| return True | ||
| if allowance == 0: | ||
| break | ||
| allowance //= 2 | ||
| return False | ||
|
|
||
|
|
||
| class _ReviewSession: | ||
| """Account for every call across concurrent portions and context retries.""" | ||
|
|
||
|
|
@@ -1279,6 +1299,9 @@ def send(self, messages: list[dict[str, str]]) -> ReviewResult: | |
| result = _send_review(self.model, messages, self.effort) | ||
| with self.lock: | ||
| self.completed.append(result) | ||
| if destination := os.environ.get("REVIEW_EVIDENCE_PATH"): | ||
| with Path(destination).with_suffix(".calls.jsonl").open("a") as stream: | ||
| stream.write(json.dumps(asdict(result), default=vars) + "\n") | ||
|
Comment on lines
+1302
to
+1304
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the artifact filesystem is full, unavailable, or misconfigured, this unguarded checkpoint write raises after the model call has succeeded. The filesystem error then aborts the entire review, so a best-effort diagnostic can discard a successful result and waste the completed model call. Handle checkpoint persistence failures separately from the review result. Knowledge Base Used: Continuous integration and repository automation |
||
| return result | ||
|
|
||
| def accounted(self, result: ReviewResult) -> ReviewResult: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.github/workflows/unless they were explicitly requested, so this requirement must be satisfied before merging.Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!