GeezerVison is showing github.com — feat(proof): harvest bounded per-trial harbor logs · CortexLM/cortex@92508b2
File treeExpand file treeCollapse file tree Open diff view settings guest/runners/rlm_fc_in_guest_harbor fixtures/harbor-trial-logs/jobs/job
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: crates/proof-results/fixtures/harbor-trials-v1.json +11-2Lines changed: 11 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 17 | 17 | "agent_exception_policy": "zero", | 18 | 18 | "harbor_exit": 0, | 19 | 19 | "trials": [ | 20 | | - {"name": "hello-world__1", "reward": 1.0, "outcome": "measured"}, | | 20 | + { | | 21 | + "name": "hello-world__1", | | 22 | + "reward": 1.0, | | 23 | + "outcome": "measured", | | 24 | + "agent_log": "hello-world agent stdout: ran ls\n", | | 25 | + "verifier_log": "verifier: reward=1.0\n", | | 26 | + "log_sources": ["trial.log", "verifier/test-stdout.txt"] | | 27 | + }, | 21 | 28 | {"name": "fix-git-diff__1", "reward": 1.0, "outcome": "measured"}, | 22 | 29 | {"name": "csv-to-parquet__1", "reward": 0.0, "outcome": "measured"}, | 23 | 30 | { | 24 | 31 | "name": "build-tmux__1", | 25 | 32 | "reward": 0.0, | 26 | 33 | "outcome": "agent_exception", | 27 | 34 | "exception_type": "RuntimeError", | 28 | | - "exception_message": "Command timed out after 120 seconds" | | 35 | + "exception_message": "Command timed out after 120 seconds", | | 36 | + "agent_log": "build-tmux agent raised during harness\n", | | 37 | + "log_sources": ["trial.log"] | 29 | 38 | }, | 30 | 39 | {"name": "nginx-config__1", "reward": 1.0, "outcome": "measured"}, | 31 | 40 | {"name": "sqlite-query__1", "reward": 1.0, "outcome": "measured"}, | |
Collapse file Copy file name to clipboardExpand all lines: crates/proof-results/src/lib.rs +94-2Lines changed: 94 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,7 +52,11 @@ pub const ORCH_RESULTS_ATTACH_HINT: &str = | 52 | 52 | pub const WRITE_RESULTS_EMIT: &str = "write_results_next_to_report"; | 53 | 53 |
| 54 | 54 | /// Largest results document accepted (bytes). | 55 | | -pub const MAX_RESULTS_BYTES: u64 = 256 * 1024; | | 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 | 60 |
| 57 | 61 | /// Signed `constraints.params` key pinning the results contract id. | 58 | 62 | pub const PARAM_RESULTS_CONTRACT: &str = "results_contract"; | @@ -470,6 +474,7 @@ fn validate_harbor(obj: &Map<String, Value>, primary: f64) -> Result<(), Results | 470 | 474 | )); | 471 | 475 | } | 472 | 476 | } | | 477 | + optional_trial_log_fields(t)?; | 473 | 478 | rewards.push(reward); | 474 | 479 | } | 475 | 480 | let n_scored = uint_field(obj, "n_scored")?; | @@ -513,6 +518,31 @@ fn validate_harbor(obj: &Map<String, Value>, primary: f64) -> Result<(), Results | 513 | 518 | Ok(()) | 514 | 519 | } | 515 | 520 |
| | 521 | +/// Optional per-trial Harbor logs. Absent is fine; a wrong type is not. | | 522 | +fn optional_trial_log_fields(t: &Map<String, Value>) -> Result<(), ResultsError> { | | 523 | + if t.get("agent_log").is_some_and(|v| !v.is_string()) { | | 524 | + return Err(ResultsError::Shape( | | 525 | + "trial.agent_log must be a string when present", | | 526 | + )); | | 527 | + } | | 528 | + if t.get("verifier_log").is_some_and(|v| !v.is_string()) { | | 529 | + return Err(ResultsError::Shape( | | 530 | + "trial.verifier_log must be a string when present", | | 531 | + )); | | 532 | + } | | 533 | + if let Some(v) = t.get("log_sources") { | | 534 | + let arr = v.as_array().ok_or(ResultsError::Shape( | | 535 | + "trial.log_sources must be an array of strings when present", | | 536 | + ))?; | | 537 | + if arr.iter().any(|item| !item.is_string()) { | | 538 | + return Err(ResultsError::Shape( | | 539 | + "trial.log_sources must be an array of strings when present", | | 540 | + )); | | 541 | + } | | 542 | + } | | 543 | + Ok(()) | | 544 | +} | | 545 | + | 516 | 546 | fn str_field<'a>(obj: &'a Map<String, Value>, key: &'static str) -> Result<&'a str, ResultsError> { | 517 | 547 | obj.get(key) | 518 | 548 | .and_then(Value::as_str) | @@ -621,7 +651,14 @@ mod tests { | 621 | 651 | "agent_exception_policy": "zero", | 622 | 652 | "harbor_exit": 0, | 623 | 653 | "trials": [ | 624 | | - {"name": "task-a__1", "reward": 1.0, "outcome": "measured"}, | | 654 | + { | | 655 | + "name": "task-a__1", | | 656 | + "reward": 1.0, | | 657 | + "outcome": "measured", | | 658 | + "agent_log": "agent: hello\n", | | 659 | + "verifier_log": "verifier: ok\n", | | 660 | + "log_sources": ["trial.log", "verifier/test-stdout.txt"] | | 661 | + }, | 625 | 662 | { | 626 | 663 | "name": "task-b__1", | 627 | 664 | "reward": 0.0, | @@ -731,6 +768,36 @@ mod tests { | 731 | 768 | ); | 732 | 769 | } | 733 | 770 |
| | 771 | + #[test] | | 772 | + fn harbor_optional_trial_logs_are_typed() { | | 773 | + let b = bind(); | | 774 | + validate(&harbor_ok(&b), &b, None).expect("optional logs allowed"); | | 775 | + let mut omitted = harbor_ok(&b); | | 776 | + let trial0 = omitted["trials"][0].as_object_mut().expect("trial 0"); | | 777 | + trial0.remove("agent_log"); | | 778 | + trial0.remove("verifier_log"); | | 779 | + trial0.remove("log_sources"); | | 780 | + validate(&omitted, &b, None).expect("omitted logs allowed"); | | 781 | + let mut bad_agent = harbor_ok(&b); | | 782 | + bad_agent["trials"][0]["agent_log"] = serde_json::json!(1); | | 783 | + assert!( | | 784 | + validate(&bad_agent, &b, None).is_err(), | | 785 | + "agent_log must be a string when present" | | 786 | + ); | | 787 | + let mut bad_verifier = harbor_ok(&b); | | 788 | + bad_verifier["trials"][0]["verifier_log"] = serde_json::json!(true); | | 789 | + assert!( | | 790 | + validate(&bad_verifier, &b, None).is_err(), | | 791 | + "verifier_log must be a string when present" | | 792 | + ); | | 793 | + let mut bad_sources = harbor_ok(&b); | | 794 | + bad_sources["trials"][0]["log_sources"] = serde_json::json!([1]); | | 795 | + assert!( | | 796 | + validate(&bad_sources, &b, None).is_err(), | | 797 | + "log_sources must be strings when present" | | 798 | + ); | | 799 | + } | | 800 | + | 734 | 801 | #[test] | 735 | 802 | fn generic_requires_displayable_content() { | 736 | 803 | let b = bind(); | @@ -792,6 +859,31 @@ mod tests { | 792 | 859 | validate(&value, &b, Some(CONTRACT_TBENCH_HARBOR)).expect("fixture"); | 793 | 860 | assert_eq!(value["n_scored"], 10); | 794 | 861 | assert_eq!(value["trials"].as_array().expect("trials").len(), 10); | | 862 | + let trials = value["trials"].as_array().expect("trials"); | | 863 | + assert_eq!( | | 864 | + trials[0]["agent_log"].as_str().expect("agent_log"), | | 865 | + "hello-world agent stdout: ran ls\n" | | 866 | + ); | | 867 | + assert_eq!( | | 868 | + trials[0]["verifier_log"].as_str().expect("verifier_log"), | | 869 | + "verifier: reward=1.0\n" | | 870 | + ); | | 871 | + assert_eq!( | | 872 | + trials[0]["log_sources"], | | 873 | + serde_json::json!(["trial.log", "verifier/test-stdout.txt"]) | | 874 | + ); | | 875 | + assert!( | | 876 | + trials[2].get("agent_log").is_none(), | | 877 | + "missing Harbor files stay omitted" | | 878 | + ); | | 879 | + assert_eq!( | | 880 | + trials[3]["exception_type"].as_str().expect("exc"), | | 881 | + "RuntimeError" | | 882 | + ); | | 883 | + assert_eq!( | | 884 | + trials[3]["agent_log"].as_str().expect("exc agent_log"), | | 885 | + "build-tmux agent raised during harness\n" | | 886 | + ); | 795 | 887 | } | 796 | 888 |
| 797 | 889 | #[test] | |
Collapse file Copy file name to clipboardExpand all lines: deploy/guest/runners/rlm_fc_in_guest_harbor/README.md +16-2Lines changed: 16 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -279,7 +279,14 @@ passed the suffix as `model_name`. | 279 | 279 | "claim_holds": true, | 280 | 280 | "evidence": { | 281 | 281 | "trials": [ | 282 | | - {"name": "task-a__1", "reward": 1.0, "outcome": "measured"}, | | 282 | + { | | 283 | + "name": "task-a__1", | | 284 | + "reward": 1.0, | | 285 | + "outcome": "measured", | | 286 | + "agent_log": "…", | | 287 | + "verifier_log": "…", | | 288 | + "log_sources": ["trial.log", "verifier/test-stdout.txt"] | | 289 | + }, | 283 | 290 | {"name": "task-b__1", "reward": 0.0, "outcome": "agent_exception", | 284 | 291 | "exception_type": "RuntimeError", "exception_message": "Command timed out after 120 seconds"} | 285 | 292 | ], | @@ -315,7 +322,14 @@ miner-authored results file is deleted with `report.json` before Harbor | 315 | 322 | runs. The guest refuses Done when this file is missing or does not bind | 316 | 323 | the scored report. Frontend consumers read the same object on | 317 | 324 | `GET /v1/submissions/{id}` as `results` and at the artefact zip root as | 318 | | -`results.json`. | | 325 | +`results.json`. Each `trials[]` row may also carry bounded, redacted | | 326 | +`agent_log` / `verifier_log` harvested from Harbor's native trial dir | | 327 | +(`trial.log`, else `agent/trajectory.json`, else `terminus_2.pane`; | | 328 | +verifier `verifier/test-stdout.txt`). Missing files are omitted, never | | 329 | +invented. Job-level `logs.harbor_run_log` / `logs.harbor_run_tail` stay | | 330 | +as today. This harvest lives in the in-guest adaptor — a live pin | | 331 | +needs a guest rebake + RE-LOCK; tipping gateway/challenge alone does not | | 332 | +update `/opt/proof/runners`. | 319 | 333 |
| 320 | 334 | `inspect` writes `$PROOF_OUTPUT_DIR/checklist.json` (no Harbor, no keys). | 321 | 335 |
| |
Collapse file Copy file name to clipboardExpand all lines: deploy/guest/runners/rlm_fc_in_guest_harbor/harness/summarize.py +53-4Lines changed: 53 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -347,6 +347,7 @@ def collect_trials( | 347 | 347 | jobs_dir: Path, | 348 | 348 | allow: frozenset[str] | None = None, | 349 | 349 | agent_exception_policy: str = POLICY_FAIL, | | 350 | + secrets: list[str] | None = None, | 350 | 351 | ) -> list[dict[str, Any]]: | 351 | 352 | """Load every scored Harbor trial. Do not cap here — the cap is evidence only. | 352 | 353 |
| @@ -363,12 +364,17 @@ def collect_trials( | 363 | 364 | When ``allow`` is a non-empty set, trials whose name is not a filtered | 364 | 365 | task (or ``task__attempt``) are dropped so a script that ran the | 365 | 366 | unfiltered pack cannot score excluded ids. | | 367 | +
| | 368 | + Each scored row also harvests bounded, redacted ``agent_log`` / | | 369 | + ``verifier_log`` from the trial dir when those files exist (FAIL / | | 370 | + incomplete Harbor included). Missing files are omitted. | 366 | 371 | """ | 367 | 372 | if agent_exception_policy not in EXCEPTION_POLICIES: | 368 | 373 | _fail(f"agent_exception_policy must be one of {EXCEPTION_POLICIES}, got {agent_exception_policy!r}") | 369 | 374 | by_dir: dict[str, dict[str, Any]] = {} | 370 | 375 | if not jobs_dir.is_dir(): | 371 | 376 | return [] | | 377 | + redact_secrets = secrets if secrets is not None else load_redact_values() | 372 | 378 |
| 373 | 379 | for result_path in sorted(jobs_dir.rglob("result.json")): | 374 | 380 | obj = _load_json(result_path) | @@ -378,23 +384,27 @@ def collect_trials( | 378 | 384 | continue | 379 | 385 | reward = trial_complete_reward(trial_dir, obj) | 380 | 386 | if reward is not None: | 381 | | - by_dir[key] = { | | 387 | + row: dict[str, Any] = { | 382 | 388 | "name": _trial_name(obj, trial_dir), | 383 | 389 | "reward": reward, | 384 | 390 | "outcome": "measured", | 385 | 391 | } | | 392 | + attach_trial_logs(row, trial_dir, redact_secrets) | | 393 | + by_dir[key] = row | 386 | 394 | continue | 387 | 395 | if agent_exception_policy != POLICY_ZERO: | 388 | 396 | continue | 389 | 397 | crashed = agent_phase_exception(trial_dir, obj) | 390 | 398 | if crashed is None: | 391 | 399 | continue | 392 | | - by_dir[key] = { | | 400 | + row = { | 393 | 401 | "name": _trial_name(obj, trial_dir), | 394 | 402 | "reward": 0.0, | 395 | 403 | "outcome": "agent_exception", | 396 | 404 | **crashed, | 397 | 405 | } | | 406 | + attach_trial_logs(row, trial_dir, redact_secrets) | | 407 | + by_dir[key] = row | 398 | 408 |
| 399 | 409 | rows = [by_dir[k] for k in sorted(by_dir)] | 400 | 410 | if not allow: | @@ -483,6 +493,45 @@ def read_tail(path: Path | None, secrets: list[str]) -> str: | 483 | 493 | return redact(text, secrets) | 484 | 494 |
| 485 | 495 |
| | 496 | +def _trial_pane_path(trial_dir: Path) -> tuple[str, Path]: | | 497 | + """Owner lock is ``terminus_2.pane``; metal retain also has ``agent/terminus_2.pane``.""" | | 498 | + root_pane = trial_dir / "terminus_2.pane" | | 499 | + if root_pane.is_file(): | | 500 | + return "terminus_2.pane", root_pane | | 501 | + return "agent/terminus_2.pane", trial_dir / "agent" / "terminus_2.pane" | | 502 | + | | 503 | + | | 504 | +def attach_trial_logs(row: dict[str, Any], trial_dir: Path, secrets: list[str]) -> None: | | 505 | + """Fill ``agent_log`` / ``verifier_log`` from Harbor's native trial dir. | | 506 | +
| | 507 | + Agent sources, first available, each already ≤ ``MAX_TAIL_CHARS`` and | | 508 | + redacted: ``trial.log``, then ``agent/trajectory.json``, then | | 509 | + ``terminus_2.pane`` (optional third). Verifier is only | | 510 | + ``verifier/test-stdout.txt``. Missing files are omitted — never invented. | | 511 | + Runs for measured, agent-exception, FAIL, and incomplete Harbor alike. | | 512 | + """ | | 513 | + sources: list[str] = [] | | 514 | + pane_rel, pane_path = _trial_pane_path(trial_dir) | | 515 | + for rel, path in ( | | 516 | + ("trial.log", trial_dir / "trial.log"), | | 517 | + ("agent/trajectory.json", trial_dir / "agent" / "trajectory.json"), | | 518 | + (pane_rel, pane_path), | | 519 | + ): | | 520 | + text = read_tail(path, secrets) | | 521 | + if not text: | | 522 | + continue | | 523 | + row["agent_log"] = text | | 524 | + sources.append(rel) | | 525 | + break | | 526 | + verifier_rel = "verifier/test-stdout.txt" | | 527 | + verifier_log = read_tail(trial_dir / "verifier" / "test-stdout.txt", secrets) | | 528 | + if verifier_log: | | 529 | + row["verifier_log"] = verifier_log | | 530 | + sources.append(verifier_rel) | | 531 | + if sources: | | 532 | + row["log_sources"] = sources | | 533 | + | | 534 | + | 486 | 535 | def mean_reward(trials: list[dict[str, Any]]) -> float: | 487 | 536 | rewards = [float(t["reward"]) for t in trials] | 488 | 537 | return sum(rewards) / float(len(rewards)) | @@ -685,7 +734,8 @@ def main(argv: list[str] | None = None) -> int: | 685 | 734 | f"allow-tasks-dir {args.allow_tasks_dir} has no task directories; " | 686 | 735 | "refusing to invent a primary_value" | 687 | 736 | ) | 688 | | - trials = collect_trials(jobs_dir, allow, policy) | | 737 | + secrets = load_redact_values() | | 738 | + trials = collect_trials(jobs_dir, allow, policy, secrets) | 689 | 739 | if not trials: | 690 | 740 | _fail( | 691 | 741 | f"no measured Harbor trials under {jobs_dir} " | @@ -701,7 +751,6 @@ def main(argv: list[str] | None = None) -> int: | 701 | 751 | f"{', '.join(missing)}; agent_exception_policy={policy}); " | 702 | 752 | "refusing a partial primary_value" | 703 | 753 | ) | 704 | | - secrets = load_redact_values() | 705 | 754 | log_path = Path(args.log) if args.log else None | 706 | 755 | report = build_report( | 707 | 756 | trials, | |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{"ignored": "trajectory must not displace trial.log"} |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{"trial_name": "hello-world__1", "verifier_result": {"rewards": {"reward": 1.0}}} |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +1.0 |
Collapse file Copy file name to clipboard +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +verifier: reward=1.0 | | 2 | +pytest passed |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{"trial_name": "no-logs__1", "verifier_result": {"rewards": {"reward": 0.0}}} |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +0.0 |
|