GeezerVison is showing github.com — fix(proof): cap per-trial logs at 2kib under 256kib · CortexLM/cortex@46a9ce1
File treeExpand file treeCollapse file tree Open diff view settings guest/runners/rlm_fc_in_guest_harbor
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: crates/proof-results/src/lib.rs +8-5Lines changed: 8 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,10 +53,11 @@ pub const WRITE_RESULTS_EMIT: &str = "write_results_next_to_report"; | 53 | 53 |
| 54 | 54 | /// Largest results document accepted (bytes). | 55 | 55 | /// | 56 | | -/// Sized for a typical Harbor pack (~10 trials) with optional 8 KiB | 57 | | -/// `agent_log` + `verifier_log` bodies after JSON escaping. A pack that | 58 | | -/// still overflows is fail-closed (`TooLarge`), never truncated here. | 59 | | -pub const MAX_RESULTS_BYTES: u64 = 512 * 1024; | | 56 | +/// Guest Harbor logs are sized to stay under this cap at 33 scored trials: | | 57 | +/// 2 KiB `agent_log` + 2 KiB `verifier_log` per trial (132 KiB) plus | | 58 | +/// `logs.harbor_run_tail` (8 KiB) and envelope. Overflow is fail-closed | | 59 | +/// (`TooLarge`), never truncated here. 8 KiB per field would not fit. | | 60 | +pub const MAX_RESULTS_BYTES: u64 = 256 * 1024; | 60 | 61 |
| 61 | 62 | /// Signed `constraints.params` key pinning the results contract id. | 62 | 63 | pub const PARAM_RESULTS_CONTRACT: &str = "results_contract"; | @@ -518,7 +519,9 @@ fn validate_harbor(obj: &Map<String, Value>, primary: f64) -> Result<(), Results | 518 | 519 | Ok(()) | 519 | 520 | } | 520 | 521 |
| 521 | | -/// Optional per-trial Harbor logs. Absent is fine; a wrong type is not. | | 522 | +/// Optional per-trial Harbor logs. Not required (`agent_log` / `verifier_log` | | 523 | +/// / `log_sources` may be omitted). A present value of the wrong JSON type | | 524 | +/// is fail-closed so the frontend never treats a non-string as a log body. | 522 | 525 | fn optional_trial_log_fields(t: &Map<String, Value>) -> Result<(), ResultsError> { | 523 | 526 | if t.get("agent_log").is_some_and(|v| !v.is_string()) { | 524 | 527 | return Err(ResultsError::Shape( | |
Collapse file Copy file name to clipboardExpand all lines: deploy/guest/runners/rlm_fc_in_guest_harbor/README.md +2-1Lines changed: 2 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -323,7 +323,8 @@ runs. The guest refuses Done when this file is missing or does not bind | 323 | 323 | the scored report. Frontend consumers read the same object on | 324 | 324 | `GET /v1/submissions/{id}` as `results` and at the artefact zip root as | 325 | 325 | `results.json`. Each `trials[]` row may also carry bounded, redacted | 326 | | -`agent_log` / `verifier_log` harvested from Harbor's native trial dir | | 326 | +`agent_log` / `verifier_log` (last 2 KiB each, so 33 trials stay under the | | 327 | +256 KiB `results.json` cap) harvested from Harbor's native trial dir | 327 | 328 | (`trial.log`, else `agent/trajectory.json`, else `terminus_2.pane`; | 328 | 329 | verifier `verifier/test-stdout.txt`). Missing files are omitted, never | 329 | 330 | invented. Job-level `logs.harbor_run_log` / `logs.harbor_run_tail` stay | |
Collapse file Copy file name to clipboardExpand all lines: deploy/guest/runners/rlm_fc_in_guest_harbor/harness/summarize.py +13-7Lines changed: 13 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 50 | 50 | from typing import Any | 51 | 51 |
| 52 | 52 | MAX_TAIL_CHARS = 8 * 1024 | | 53 | +# 33 trials × 2 KiB × 2 fields = 132 KiB, which fits proof-results | | 54 | +# MAX_RESULTS_BYTES (256 KiB) with harbor_run_tail (8 KiB) and envelope. | | 55 | +# 8 KiB per field would be 528 KiB and overflow that cap. | | 56 | +MAX_TRIAL_LOG_CHARS = 2 * 1024 | 53 | 57 | MAX_EVIDENCE_TRIALS = 256 | 54 | 58 | MAX_REWARD_TXT_BYTES = 64 * 1024 | 55 | 59 | MAX_EXCEPTION_CHARS = 400 | @@ -480,15 +484,15 @@ def redact(text: str, secrets: list[str]) -> str: | 480 | 484 | return out | 481 | 485 |
| 482 | 486 |
| 483 | | -def read_tail(path: Path | None, secrets: list[str]) -> str: | | 487 | +def read_tail(path: Path | None, secrets: list[str], max_chars: int = MAX_TAIL_CHARS) -> str: | 484 | 488 | if path is None or not path.is_file(): | 485 | 489 | return "" | 486 | 490 | try: | 487 | 491 | data = path.read_bytes() | 488 | 492 | except OSError: | 489 | 493 | return "" | 490 | | - if len(data) > MAX_TAIL_CHARS: | 491 | | - data = data[-MAX_TAIL_CHARS:] | | 494 | + if len(data) > max_chars: | | 495 | + data = data[-max_chars:] | 492 | 496 | text = data.decode("utf-8", errors="replace") | 493 | 497 | return redact(text, secrets) | 494 | 498 |
| @@ -504,8 +508,8 @@ def _trial_pane_path(trial_dir: Path) -> tuple[str, Path]: | 504 | 508 | def attach_trial_logs(row: dict[str, Any], trial_dir: Path, secrets: list[str]) -> None: | 505 | 509 | """Fill ``agent_log`` / ``verifier_log`` from Harbor's native trial dir. | 506 | 510 |
| 507 | | - Agent sources, first available, each already ≤ ``MAX_TAIL_CHARS`` and | 508 | | - redacted: ``trial.log``, then ``agent/trajectory.json``, then | | 511 | + Agent sources, first available, each already ≤ ``MAX_TRIAL_LOG_CHARS`` | | 512 | + and redacted: ``trial.log``, then ``agent/trajectory.json``, then | 509 | 513 | ``terminus_2.pane`` (optional third). Verifier is only | 510 | 514 | ``verifier/test-stdout.txt``. Missing files are omitted — never invented. | 511 | 515 | Runs for measured, agent-exception, FAIL, and incomplete Harbor alike. | @@ -517,14 +521,16 @@ def attach_trial_logs(row: dict[str, Any], trial_dir: Path, secrets: list[str]) | 517 | 521 | ("agent/trajectory.json", trial_dir / "agent" / "trajectory.json"), | 518 | 522 | (pane_rel, pane_path), | 519 | 523 | ): | 520 | | - text = read_tail(path, secrets) | | 524 | + text = read_tail(path, secrets, MAX_TRIAL_LOG_CHARS) | 521 | 525 | if not text: | 522 | 526 | continue | 523 | 527 | row["agent_log"] = text | 524 | 528 | sources.append(rel) | 525 | 529 | break | 526 | 530 | verifier_rel = "verifier/test-stdout.txt" | 527 | | - verifier_log = read_tail(trial_dir / "verifier" / "test-stdout.txt", secrets) | | 531 | + verifier_log = read_tail( | | 532 | + trial_dir / "verifier" / "test-stdout.txt", secrets, MAX_TRIAL_LOG_CHARS | | 533 | + ) | 528 | 534 | if verifier_log: | 529 | 535 | row["verifier_log"] = verifier_log | 530 | 536 | sources.append(verifier_rel) | |
Collapse file Copy file name to clipboardExpand all lines: deploy/guest/runners/rlm_fc_in_guest_harbor/tests/test_summarize.py +43-2Lines changed: 43 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1083,7 +1083,7 @@ def test_trial_logs_are_redacted_and_capped(self) -> None: | 1083 | 1083 | (secrets / "inference_key").write_text("sk-secret-owner\n", encoding="utf-8") | 1084 | 1084 | trial = root / "jobs" / "job" / "t__1" | 1085 | 1085 | write_complete_trial(trial, "t__1", 1.0) | 1086 | | - huge = "keep-me\n" + ("x" * (summarize.MAX_TAIL_CHARS + 64)) + "sk-secret-owner tail\n" | | 1086 | + huge = "keep-me\n" + ("x" * (summarize.MAX_TRIAL_LOG_CHARS + 64)) + "sk-secret-owner tail\n" | 1087 | 1087 | (trial / "trial.log").write_text(huge, encoding="utf-8") | 1088 | 1088 | (trial / "verifier" / "test-stdout.txt").write_text( | 1089 | 1089 | "verifier saw sk-secret-owner\n", encoding="utf-8" | @@ -1100,10 +1100,51 @@ def test_trial_logs_are_redacted_and_capped(self) -> None: | 1100 | 1100 | row = trials[0] | 1101 | 1101 | self.assertNotIn("sk-secret-owner", row["agent_log"]) | 1102 | 1102 | self.assertIn("[REDACTED]", row["agent_log"]) | 1103 | | - self.assertLessEqual(len(row["agent_log"]), summarize.MAX_TAIL_CHARS) | | 1103 | + self.assertLessEqual(len(row["agent_log"]), summarize.MAX_TRIAL_LOG_CHARS) | 1104 | 1104 | self.assertNotIn("sk-secret-owner", row["verifier_log"]) | 1105 | 1105 | self.assertIn("[REDACTED]", row["verifier_log"]) | 1106 | 1106 |
| | 1107 | + def test_thirty_three_trials_with_max_logs_fit_results_cap(self) -> None: | | 1108 | + """33 scored trials × 2 KiB × 2 fields must stay under 256 KiB results.json.""" | | 1109 | + with tempfile.TemporaryDirectory() as tmp: | | 1110 | + root = Path(tmp) | | 1111 | + jobs = root / "jobs" | | 1112 | + body_a = "A" * summarize.MAX_TRIAL_LOG_CHARS | | 1113 | + body_v = "V" * summarize.MAX_TRIAL_LOG_CHARS | | 1114 | + for i in range(33): | | 1115 | + trial = jobs / "job" / f"task-{i:02d}__1" | | 1116 | + write_complete_trial(trial, f"task-{i:02d}__1", 0.0) | | 1117 | + (trial / "trial.log").write_text(body_a, encoding="utf-8") | | 1118 | + (trial / "verifier" / "test-stdout.txt").write_text(body_v, encoding="utf-8") | | 1119 | + out = root / "report.json" | | 1120 | + rc = summarize.main( | | 1121 | + [ | | 1122 | + "--jobs-dir", | | 1123 | + str(jobs), | | 1124 | + "--output", | | 1125 | + str(out), | | 1126 | + "--harbor-exit", | | 1127 | + "23", | | 1128 | + ] | | 1129 | + ) | | 1130 | + self.assertEqual(rc, 0) | | 1131 | + results_path = root / "results.json" | | 1132 | + size = results_path.stat().st_size | | 1133 | + self.assertLessEqual( | | 1134 | + size, | | 1135 | + 256 * 1024, | | 1136 | + f"results.json {size} bytes exceeds proof-results 256 KiB cap", | | 1137 | + ) | | 1138 | + results = json.loads(results_path.read_text(encoding="utf-8")) | | 1139 | + self.assertEqual(len(results["trials"]), 33) | | 1140 | + for row in results["trials"]: | | 1141 | + self.assertEqual(len(row["agent_log"]), summarize.MAX_TRIAL_LOG_CHARS) | | 1142 | + self.assertEqual(len(row["verifier_log"]), summarize.MAX_TRIAL_LOG_CHARS) | | 1143 | + self.assertEqual( | | 1144 | + row["log_sources"], | | 1145 | + ["trial.log", "verifier/test-stdout.txt"], | | 1146 | + ) | | 1147 | + | 1107 | 1148 | def test_empty_log_files_are_omitted_never_invented(self) -> None: | 1108 | 1149 | with tempfile.TemporaryDirectory() as tmp: | 1109 | 1150 | root = Path(tmp) | |
Collapse file Copy file name to clipboardExpand all lines: deploy/scripts/assert-harbor-runner-results-emit.sh +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,7 +37,7 @@ need "$SUMMARIZE" 'atomic_write(out, dumped + "\n")' | 37 | 37 | need "$SUMMARIZE" 'def attach_trial_logs' | 38 | 38 | need "$SUMMARIZE" 'agent_log' | 39 | 39 | need "$SUMMARIZE" 'verifier/test-stdout.txt' | 40 | | -need "$SUMMARIZE" '"trial.log"' | | 40 | +need "$SUMMARIZE" 'MAX_TRIAL_LOG_CHARS = 2 * 1024' | 41 | 41 | need "$LIB_SH" 'proof_require_harbor_results' | 42 | 42 | need "$RUN_HARBOR" 'proof_require_harbor_results' | 43 | 43 |
| |
Collapse file Copy file name to clipboardExpand all lines: docs/external-miner/proof-tbench.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -511,7 +511,7 @@ replaces it. | 511 | 511 | A scored evaluate also carries **`results`**: the complete Harbor job | 512 | 512 | summary (`contract` `tbench-harbor-v1` / `harbor-trials-v1`). That is | 513 | 513 | what the Arcade frontend renders — every trial's reward and outcome, | 514 | | -optional bounded `agent_log` / `verifier_log` (UTF-8 from Harbor's | | 514 | +optional bounded `agent_log` / `verifier_log` (UTF-8 last 2 KiB from Harbor's | 515 | 515 | `trial.log` / `agent/trajectory.json` / `terminus_2.pane` and | 516 | 516 | `verifier/test-stdout.txt`; missing files are omitted, never invented), | 517 | 517 | `n_scored` / `n_measured` / `n_agent_exceptions`, `mean_reward` (equals | |
|