Skip to content

Commit f8c243f

Browse files
authored
Merge pull request #385 from shssoichiro/remove-truncation
fix(judge): keep full workspace file context
2 parents 185073b + d928518 commit f8c243f

2 files changed

Lines changed: 52 additions & 5 deletions

File tree

‎scripts/lib_grading.py‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
DEFAULT_JUDGE_TIMEOUT_SECONDS = 300
2727

2828
# Judge result cache: maps cache_key -> GradeResult dict
29-
# Cache key = hash of (task_id, transcript_summary, rubric, judge_model)
29+
# Cache key = hash of (task_id, transcript_summary, rubric, judge_model, workspace_content)
3030
_judge_cache: Dict[str, Dict[str, Any]] = {}
3131
_judge_cache_dir: Optional[Path] = None
3232

@@ -65,9 +65,15 @@ def _save_judge_cache() -> None:
6565
logger.warning(f"Failed to save judge cache: {e}")
6666

6767

68-
def _compute_cache_key(task_id: str, transcript: str, rubric: str, model: str) -> str:
68+
def _compute_cache_key(
69+
task_id: str,
70+
transcript: str,
71+
rubric: str,
72+
model: str,
73+
workspace_content: str = "",
74+
) -> str:
6975
"""Compute a cache key from grading inputs."""
70-
content = f"{task_id}|{transcript}|{rubric}|{model}"
76+
content = f"{task_id}|{transcript}|{rubric}|{model}|{workspace_content}"
7177
return hashlib.sha256(content.encode()).hexdigest()[:16]
7278

7379

@@ -288,7 +294,13 @@ def _grade_llm_judge(
288294
rubric = task.llm_judge_rubric or _format_grading_criteria(task)
289295

290296
# Check cache before calling judge
291-
cache_key = _compute_cache_key(task.task_id, transcript_summary, rubric, judge_model)
297+
cache_key = _compute_cache_key(
298+
task.task_id,
299+
transcript_summary,
300+
rubric,
301+
judge_model,
302+
workspace_content,
303+
)
292304
if cache_key in _judge_cache:
293305
cached = _judge_cache[cache_key]
294306
if verbose:
@@ -534,7 +546,7 @@ def _read_workspace_files(workspace_path: str) -> str:
534546
continue
535547
try:
536548
content = f.read_text(encoding="utf-8")
537-
file_contents.append(f"### File: {rel}\n{content[:3000]}")
549+
file_contents.append(f"### File: {rel}\n{content}")
538550
except (OSError, UnicodeDecodeError):
539551
pass
540552
return "\n\n".join(file_contents)

‎tests/test_lib_grading.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import unittest
55
from pathlib import Path
6+
from tempfile import TemporaryDirectory
67

78

89
ROOT = Path(__file__).resolve().parents[1]
@@ -12,8 +13,10 @@
1213

1314
from lib_grading import ( # noqa: E402
1415
_combine_grades,
16+
_compute_cache_key,
1517
_normalize_judge_response,
1618
_parse_judge_response,
19+
_read_workspace_files,
1720
GradeResult,
1821
)
1922

@@ -147,5 +150,37 @@ def test_parse_judge_response_ignores_waiting_messages_before_final_json(self) -
147150
self.assertEqual(parsed["total"], 0.8)
148151

149152

153+
class WorkspaceFilesForJudgeTests(unittest.TestCase):
154+
def test_read_workspace_files_preserves_full_text_file_content(self) -> None:
155+
with TemporaryDirectory() as tmp_dir:
156+
workspace = Path(tmp_dir)
157+
long_content = "A" * 3000 + "TAIL_MARKER"
158+
(workspace / "report.md").write_text(long_content, encoding="utf-8")
159+
160+
content = _read_workspace_files(str(workspace))
161+
162+
self.assertIn("### File: report.md", content)
163+
self.assertIn("TAIL_MARKER", content)
164+
self.assertIn(long_content, content)
165+
166+
def test_compute_cache_key_changes_when_workspace_content_changes(self) -> None:
167+
first_key = _compute_cache_key(
168+
"task_report",
169+
"same transcript",
170+
"same rubric",
171+
"same model",
172+
"workspace version one",
173+
)
174+
second_key = _compute_cache_key(
175+
"task_report",
176+
"same transcript",
177+
"same rubric",
178+
"same model",
179+
"workspace version two",
180+
)
181+
182+
self.assertNotEqual(first_key, second_key)
183+
184+
150185
if __name__ == "__main__":
151186
unittest.main()

0 commit comments

Comments
 (0)