From 42c89c48b4639402f9a176b1a2c518969feec725 Mon Sep 17 00:00:00 2001 From: Holon Intent Agent Date: Wed, 2 Dec 2026 23:26:35 +0000 Subject: [PATCH 01/10] intent: created I-1796253987-hac-split-test-local-llm/_ Description: apps/sandbox-executor/tests/test_local_llm.py has grown to 1,289 lines above the 1,000-line test modularity threshold. Goal: Split apps/sandbox-executor/tests/test_local_llm.py into focused test modules each under 700 lines (test_local_llm_config.py, test_local_llm_health.py, test_local_llm_rewrites.py) while keeping shared helper symbols re-exported from apps/sandbox-executor/tests/test_local_llm.py so external callers remain unaffected and updating apps/sandbox-executor/tests/test_self_doc_gate_coverage.py for the new self-explaining test modules. Preserve every test case verbatim, verify zero tests lost, and pass uv run task lint and uv run pytest. Code is self-explaining: no docstrings and no comments except '# why:' comments that record a reason the code cannot show. Generated by Holon Intent Agent at 2026-12-02T23:26:35Z --- .../pending/intents/I-1796253987-hac-split-test-local-llm.jsonl | 1 + 1 file changed, 1 insertion(+) create mode 100644 holon-knowledge/ledger/pending/intents/I-1796253987-hac-split-test-local-llm.jsonl diff --git a/holon-knowledge/ledger/pending/intents/I-1796253987-hac-split-test-local-llm.jsonl b/holon-knowledge/ledger/pending/intents/I-1796253987-hac-split-test-local-llm.jsonl new file mode 100644 index 000000000..aa2dd0088 --- /dev/null +++ b/holon-knowledge/ledger/pending/intents/I-1796253987-hac-split-test-local-llm.jsonl @@ -0,0 +1 @@ +{"slug": "hac-split-test-local-llm", "target_branch": "main", "description": "apps/sandbox-executor/tests/test_local_llm.py has grown to 1,289 lines above the 1,000-line test modularity threshold.", "goal": "Split apps/sandbox-executor/tests/test_local_llm.py into focused test modules each under 700 lines (test_local_llm_config.py, test_local_llm_health.py, test_local_llm_rewrites.py) while keeping shared helper symbols re-exported from apps/sandbox-executor/tests/test_local_llm.py so external callers remain unaffected and updating apps/sandbox-executor/tests/test_self_doc_gate_coverage.py for the new self-explaining test modules. Preserve every test case verbatim, verify zero tests lost, and pass uv run task lint and uv run pytest. Code is self-explaining: no docstrings and no comments except '# why:' comments that record a reason the code cannot show.", "rationale": "Shrinks oversized local-llm test file below 700 lines per module to improve Aspect 7 modularity.", "scope": ["apps/sandbox-executor/tests/test_local_llm.py", "apps/sandbox-executor/tests/test_local_llm_config.py", "apps/sandbox-executor/tests/test_local_llm_health.py", "apps/sandbox-executor/tests/test_local_llm_rewrites.py", "apps/sandbox-executor/tests/test_self_doc_gate_coverage.py"], "acceptance_criteria": ["apps/sandbox-executor/tests/test_local_llm.py (1,289L) is split into focused test modules (test_local_llm_config.py, test_local_llm_health.py, test_local_llm_rewrites.py) each under 700 lines with zero tests lost, and test_self_doc_gate_coverage.py includes the new modules.", "All tests pass under uv run pytest and uv run task lint passes."], "assumptions": [{"id": "A1", "statement": "External tests (tests/cli/test_doctor.py and tests/test_cli_unlimited_budgets.py) import HEALTH_COLD, HEALTH_OFF, HEALTH_SMALL_PROMPT, HEALTH_WARM, _config, and _fetcher from tests.test_local_llm (verified by grep on origin/main).", "impact": "high"}, {"id": "A2", "statement": "test_self_doc_gate_coverage.py pins test module lists under tests/ and checks self-explaining comment hygiene.", "impact": "medium"}], "assumption_validation": [{"assumption_id": "A1", "method": "Keep those helper symbols importable from tests.test_local_llm and run pytest on tests/test_local_llm*.py, tests/cli/test_doctor.py, and tests/test_cli_unlimited_budgets.py."}, {"assumption_id": "A2", "method": "Run pytest on test_self_doc_gate_coverage.py and test_self_doc_modules.py in Stage 3."}], "assumption_risk": [{"assumption_id": "A1", "likelihood": "low", "testability": "testable", "score": 1, "response": "Re-export shared helpers explicitly in test_local_llm.py so downstream tests require zero changes."}, {"assumption_id": "A2", "likelihood": "low", "testability": "testable", "score": 1, "response": "Add the split filenames in sorted order to PINNED_MODULES_BY_DIR['tests'] inside test_self_doc_gate_coverage.py."}], "branch": "I-1796253987-hac-split-test-local-llm", "status": "proposed", "created_at": "2026-12-02T23:26:35.415Z"} From 5297abf7b5ce0e18a4fa079a3ab4b9f8a7663828 Mon Sep 17 00:00:00 2001 From: Holon Planner Agent Date: Wed, 2 Dec 2026 23:29:05 +0000 Subject: [PATCH 02/10] plan: P-1796254011-CLA-CO5.5 created by claude-agent (claude-opus-5-5) --- ...-1796253987-hac-split-test-local-llm.jsonl | 1 + .../P-1796254011-CLA-CO5.5.md | 425 ++++++++++++++++++ 2 files changed, 426 insertions(+) create mode 100644 holon-knowledge/ledger/pending/plans/I-1796253987-hac-split-test-local-llm.jsonl create mode 100644 plans/I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5.md diff --git a/holon-knowledge/ledger/pending/plans/I-1796253987-hac-split-test-local-llm.jsonl b/holon-knowledge/ledger/pending/plans/I-1796253987-hac-split-test-local-llm.jsonl new file mode 100644 index 000000000..94e1b5f56 --- /dev/null +++ b/holon-knowledge/ledger/pending/plans/I-1796253987-hac-split-test-local-llm.jsonl @@ -0,0 +1 @@ +{"plan_id": "P-1796254011-CLA-CO5.5", "intent_branch": "I-1796253987-hac-split-test-local-llm/_", "agent": "claude-agent", "agent_version": "2.1.302", "model": "claude-opus-5-5", "p_success": 0.9, "entropy": 2.6, "impact": 35.0, "cost": 5.0, "learning_value": 1.5, "ev": 26.47, "created_at": "2026-12-02T23:29:03.101Z", "plan_file": "plans/I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5.md", "status": "proposed", "entropy_budget": 15.0, "decomposition_decision": "execute", "touch_set": [{"path": "apps/sandbox-executor/tests/test_local_llm.py"}, {"path": "apps/sandbox-executor/tests/test_local_llm_config.py"}, {"path": "apps/sandbox-executor/tests/test_local_llm_health.py"}, {"path": "apps/sandbox-executor/tests/test_local_llm_rewrites.py"}, {"path": "apps/sandbox-executor/tests/test_self_doc_gate_coverage.py"}]} diff --git a/plans/I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5.md b/plans/I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5.md new file mode 100644 index 000000000..1dece50aa --- /dev/null +++ b/plans/I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5.md @@ -0,0 +1,425 @@ +# Plan for I-1796253987-hac-split-test-local-llm + +- **Plan ID:** P-1796254011-CLA-CO5.5 +- **Parent Intent ID:** NONE +- **Agent:** claude-agent/claude-opus-5-5 (version: 2.1.302) +- **Created At:** 2026-12-02T23:26:52.716Z + +## Planner Autonomy Summary + +- **Intent handling:** ACCEPT_AS_IS +- **Reframed intent (if applicable):** N/A. One clarification inside the stated goal: `test_local_llm.py` keeps + `TestLauncherIntegration` (about 236 lines, launcher wiring) next to the re-exports, so it stays a real test module + well under 700 lines. The three new modules take everything else. +- **Exploration stance:** conservative. This is a mechanical move of test code. The only open questions (import shape, + collection count, the self-doc registry count) can be checked with a test run. +- **Safety priority level:** standard +- **Priority Justification:** Only test files change. No ledger, env-overlay, git-config, sandbox or governance surface + is touched. `holon-config/world/ruleset.md` §3 says test changes must be declared in the plan, and the touch set below + declares them. The frozen module budget config stays out of the touch set: tests are not covered by it (`SOURCE_ROOTS` + in `scripts/check_module_budgets.py` covers only `apps/*/src/**` and `scripts/**`). + +## Exploration + +- **Proportion of steps that are exploratory:** 0.0 +- **Justification:** The structure is known in full from reading the file: 12 test classes, 102 `def test_` methods and + three shared helpers. A before/after collection diff measures the risk directly, so exploratory steps would add + nothing. + +## Overall Plan Metrics + +| metric | value | +| ------------------- | ----- | +| p_success_pred | 0.90 | +| entropy_pred | 2.6 | +| impact_pred | 35.0 | +| cost_pred | 5.0 | +| learning_value_pred | 1.5 | +| ev_pred | 26.47 | + +## Plan Description & Strategy + +Current layout of `apps/sandbox-executor/tests/test_local_llm.py` (1,289 lines, 102 test methods): + +| lines | block | destination | +| --------- | ------------------------------------------------------------------------------- | ---------------------------- | +| 22-97 | `TestRewriteAuthority` | `test_local_llm_rewrites.py` | +| 98-121 | `TestOptIn` | `test_local_llm_rewrites.py` | +| 122-263 | `TestBuildContainerConfig` | `test_local_llm_config.py` | +| 264-317 | `TestBaseUrlEchoRedaction` | `test_local_llm_rewrites.py` | +| 318-390 | `TestPrepareAgentDir` | `test_local_llm_config.py` | +| 391-626 | `TestLauncherIntegration` | stays in `test_local_llm.py` | +| 627-731 | `TestRunnerValidation` | `test_local_llm_config.py` | +| 732-734 | `_config` helper | `test_local_llm_config.py` | +| 736-850 | `TestModelEnvelope` | `test_local_llm_config.py` | +| 851-880 | `# why:` line, `HEALTH_OFF/COLD/WARM/SMALL_PROMPT/MALFORMED`, `_fetcher` helper | `test_local_llm_health.py` | +| 882-910 | `TestHostGateways` | `test_local_llm_health.py` | +| 911-1136 | `TestGatewayHealth` (includes the `redact_url` cases) | `test_local_llm_health.py` | +| 1137-1289 | `TestValidatedModelsConfig` | `test_local_llm_config.py` | + +Projected sizes, including imports: `test_local_llm_config.py` about 615 lines, `test_local_llm_health.py` about 300, +`test_local_llm_rewrites.py` about 180, and `test_local_llm.py` about 260 (the launcher class plus imports and the +re-export list). All are under 700. The config module goes past the ~400 preference, but it is a test module outside the +module budget and under the intent's 700 ceiling. If it lands over 650, move `TestRunnerValidation` into +`test_local_llm.py` next to the launcher tests, which brings both under 520. + +Helper ownership, so that no import cycle is possible: + +- `_config` is defined once in `test_local_llm_config.py`. The rewrites, health and hub modules import it from there. +- `HEALTH_*` and `_fetcher` are defined once in `test_local_llm_health.py`. +- `test_local_llm.py` imports `_config` from config and + `HEALTH_COLD, HEALTH_OFF, HEALTH_SMALL_PROMPT, HEALTH_WARM, _fetcher` from health. It lists them in `__all__`, so ruff + F401 treats them as re-exports. `tests/cli/test_doctor.py` and `tests/test_cli_unlimited_budgets.py` then work + unchanged (assumption A1). +- Import only non-test names across modules. Importing a `Test*` class into another module would make pytest collect it + twice. + +Test bodies, `# why:` comments and the existing `# noqa: PLR0913` move byte-for-byte. Moved `# why:` lines pass +`scripts/check_self_explaining.py`, because that prefix is the allowed form. No docstrings or new explanatory comments +are added. + +Self-doc registry (assumption A2): add `test_local_llm_config.py test_local_llm_health.py test_local_llm_rewrites.py` in +sorted position after `test_local_llm.py` in `PINNED_MODULES_BY_DIR["tests"]`. Change the pinned count assertion in +`test_covered_modules_registry_is_unique_and_non_empty` from `326` to `329`. The intent's assumption response leaves out +the count change, and without it the test fails. + +Zero-loss proof: before editing, record `uv run pytest --collect-only -q` node IDs for `tests/test_local_llm.py` and +reduce each to `Class::method`. After the split, collect `tests/test_local_llm*.py` the same way. The two sorted +`Class::method` sets must be identical: 102 methods and no duplicates. + +## Touch Set + +- `apps/sandbox-executor/tests/test_local_llm.py` +- `apps/sandbox-executor/tests/test_local_llm_config.py` +- `apps/sandbox-executor/tests/test_local_llm_health.py` +- `apps/sandbox-executor/tests/test_local_llm_rewrites.py` +- `apps/sandbox-executor/tests/test_self_doc_gate_coverage.py` + +--- + +## Step 1: Snapshot the baseline test collection + +- **Sub‑intent recommendation:** NO +- **Reasoning:** This is a read-only measurement that takes seconds. It is the reference for the zero-loss check, so it + belongs inside the same execution. +- **Step Type:** INFO_GATHERING +- **Exploration level:** EXPLOIT + +### Intent & Git Integration + +- **Step Intent:** Record exactly which tests exist before anything moves. +- **Git branch:** `I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-{timestamp}-CLA-CO5.5/_` +- **Sub‑intent:** NONE + +### Implementation Details (No code blocks, only logic/steps) + +1. From `apps/sandbox-executor`, run `uv run pytest --collect-only -q tests/test_local_llm.py` in the foreground. +2. Strip the `tests/test_local_llm.py::` prefix from each node ID. Save the sorted `Class::method` list to a scratch + file outside the repository, for example under the system temp dir. Never commit it. +3. Confirm the list has 102 entries, matching `grep -c "def test_"`. Note the passing count from + `uv run pytest tests/test_local_llm.py tests/cli/test_doctor.py tests/test_cli_unlimited_budgets.py tests/test_self_doc_gate_coverage.py` + as the green baseline. + +### Dependencies & Criticality + +- **Depends on:** NONE +- **Is Bottleneck:** NO + +### Safety & Constraint Considerations + +- **Relevant rules:** `holon-config/world/constraints.md` §1 (stay on the execution branch). +- **Potential failure modes for this step:** The baseline is already red on main. +- **Guardrails and early‑abort checks:** If the baseline fails, record which tests fail and continue only if the + failures are unrelated to these files. The same tests must fail the same way afterwards. + +### Success & Discard Criteria + +- **Success:** A 102-entry sorted list exists, and the baseline pass/fail counts are recorded. +- **Discard:** Collection errors in `test_local_llm.py` on a clean tree. Stop and report, because the split cannot be + proven lossless. + +### Metrics + +| metric | value | +| ------------------- | ----- | +| p_success_pred | 0.99 | +| entropy_pred | 0.2 | +| impact_pred | 5.0 | +| cost_pred | 0.5 | +| learning_value_pred | 0.5 | +| ev_pred | 4.64 | + +### Step Metrics Rationale + +`EV = 0.99 * 5.0 + 0.5 * 0.5 - 0.3 * 0.2 - 0.5 = 4.95 + 0.25 - 0.06 - 0.5 = 4.64`. This is a deterministic read-only +command, so entropy is close to zero. + +--- + +## Step 2: Move test classes into three focused modules and slim the hub to launcher tests plus re-exports + +- **Sub‑intent recommendation:** NO +- **Reasoning:** The move is verbatim and stays inside five test files. One execution covers it, and splitting it + further would only add merge overhead. +- **Step Type:** REFACTOR +- **Exploration level:** EXPLOIT + +### Intent & Git Integration + +- **Step Intent:** Bring every local-llm test module under 700 lines with each test body unchanged, while + `from tests.test_local_llm import HEALTH_COLD, HEALTH_OFF, HEALTH_SMALL_PROMPT, HEALTH_WARM, _config, _fetcher` keeps + working. +- **Git branch:** same execution branch as Step 1 +- **Sub‑intent:** NONE + +### Implementation Details (No code blocks, only logic/steps) + +1. Create `tests/test_local_llm_config.py` with the `_config` helper first (verbatim, lines 732-734), then + `TestBuildContainerConfig`, `TestPrepareAgentDir`, `TestRunnerValidation`, `TestModelEnvelope` and + `TestValidatedModelsConfig`, in their original relative order. Imports are only those these bodies use: `json`, `os`, + `stat`, `sys`, `io`, `tempfile`, `unittest`, `patch`, `local_llm`, `get_runner`, `make_probe`, `assert_no_fragment`, + and `cli` if referenced. Let `ruff check --fix` for F401 only and `ruff format` settle the exact import set and + order. +2. Create `tests/test_local_llm_health.py` with the `# why: frozen fixtures ...` line, the five `HEALTH_*` constants and + `_fetcher` (lines 851-880) verbatim. Follow them with `TestHostGateways` and `TestGatewayHealth`. Import `_config` + from `tests.test_local_llm_config`. Other imports include `contextlib`, `http.server`, `json`, `secrets` if used, + `unittest`, `patch`, `local_llm`, `serve_on_loopback`, `make_probe` and `assert_no_fragment`. +3. Create `tests/test_local_llm_rewrites.py` with `TestRewriteAuthority`, `TestOptIn` and `TestBaseUrlEchoRedaction`. + Import `_config` from `tests.test_local_llm_config`, plus `os`, `secrets`, `unittest`, `patch`, `local_llm`, + `make_probe` and `assert_no_fragment`. +4. Rewrite `tests/test_local_llm.py` to hold its original imports, minus those it no longer uses, and + `TestLauncherIntegration` verbatim, including its `setUp`, `_run` with the existing `# noqa: PLR0913`, and all + `# why:` lines. Add `from tests.test_local_llm_config import _config` and + `from tests.test_local_llm_health import HEALTH_COLD, HEALTH_OFF, HEALTH_SMALL_PROMPT, HEALTH_WARM, _fetcher`, plus a + module-level `__all__` naming exactly those six symbols, so ruff sees them as intentional re-exports. Do not import + any `Test*` class across modules. +5. Move each class with copy-by-line-range (for example a short script slicing the original file by the line ranges in + the strategy table) rather than retyping, so that bodies stay byte-identical. Then run `uv run ruff format` and + `uv run ruff check --fix --select F401,I` on the four files only. +6. Check `wc -l` on all four files: each must be under 700. If `test_local_llm_config.py` is over 650, apply the + documented fallback and move `TestRunnerValidation` into `test_local_llm.py`. +7. Do not add docstrings or comments. The only comment lines in the new files are the moved `# why:` lines. + +### Dependencies & Criticality + +- **Depends on:** Step 1 +- **Is Bottleneck:** YES (p_success_pred 0.92, above 0.6, so no sub-intent needed) + +### Safety & Constraint Considerations + +- **Relevant rules:** `holon-config/world/ruleset.md` §2 (no wildcard imports), §3 (test changes declared in the plan); + the planner contract on self-explaining code (moved `# why:` lines are allowed; nothing else); repository ruff + complexity limits (bodies unchanged, existing `# noqa` carried over, no new suppressions). +- **Potential failure modes for this step:** A missing import in a destination module (NameError at collection). pytest + collects a test twice because a `Test*` class was imported across modules. A circular import if config imports from + the hub. The ruff `I` rule reorders `tests.*` imports differently from the original. +- **Guardrails and early‑abort checks:** Run `uv run pytest --collect-only -q tests/test_local_llm*.py` right after the + edit. Any collection error or count other than 102 stops the step for correction. Dependencies only point from the + hub, rewrites and health towards config (and from the hub towards health), never back. + +### Success & Discard Criteria + +- **Success:** Four files each under 700 lines. Collection yields the same 102 `Class::method` IDs as Step 1, with no + duplicates. `ruff check` and `ruff format --check` are clean on them. +- **Discard:** If verbatim moving still fails collection after two correction passes, or cost exceeds `1.5 * 2.5`, + revert to the original file and report. + +### Metrics + +| metric | value | +| ------------------- | ----- | +| p_success_pred | 0.92 | +| entropy_pred | 1.4 | +| impact_pred | 25.0 | +| cost_pred | 2.5 | +| learning_value_pred | 0.5 | +| ev_pred | 20.33 | + +### Step Metrics Rationale + +`EV = 0.92 * 25.0 + 0.5 * 0.5 - 0.3 * 1.4 - 2.5 = 23.0 + 0.25 - 0.42 - 2.5 = 20.33`. This step carries almost all of the +intent's value. The residual risk is import bookkeeping, which the collection check catches at once. + +--- + +## Step 3: Register the new modules in the self-doc gate coverage list + +- **Sub‑intent recommendation:** NO +- **Reasoning:** This is a three-token list insertion plus a one-number count change in a single test file. +- **Step Type:** CONFIG +- **Exploration level:** EXPLOIT + +### Intent & Git Integration + +- **Step Intent:** Have the self-explaining gate scan the three new modules, and keep the pinned registry count + consistent. +- **Git branch:** same execution branch +- **Sub‑intent:** NONE + +### Implementation Details (No code blocks, only logic/steps) + +1. In `tests/test_self_doc_gate_coverage.py`, `PINNED_MODULES_BY_DIR["tests"]`, insert + `test_local_llm_config.py test_local_llm_health.py test_local_llm_rewrites.py` right after `test_local_llm.py`, which + is their sorted position before `test_makefile.py`. Rewrap the implicit string concatenation so that each fragment + ends with a trailing space, as the existing lines do, and stays within the ruff line length. +2. Change `assert len(COVERED_MODULES) == 326` to `329`. +3. Keep `test_local_llm.py` in the list, because it still exists and holds `TestLauncherIntegration`. + +### Dependencies & Criticality + +- **Depends on:** Step 2 (the files must exist for `test_covered_module_exists`) +- **Is Bottleneck:** NO + +### Safety & Constraint Considerations + +- **Relevant rules:** Assumption A2 of the intent. `scripts/check_self_explaining.py` checks the edited lines. +- **Potential failure modes for this step:** A missing trailing space glues two filenames into one bogus path. The count + is not updated. +- **Guardrails and early‑abort checks:** + `uv run pytest tests/test_self_doc_gate_coverage.py tests/test_self_doc_modules.py` must pass, including the three new + `test_covered_module_is_self_explaining[...]` parameters. + +### Success & Discard Criteria + +- **Success:** The registry count assert passes at 329. All three new modules appear as parameters and pass both exists + and self-explaining checks. +- **Discard:** Not expected. If `test_self_doc_modules.py` pins a separate tests list that rejects the new names, extend + the touch set only after re-planning, because that file is out of scope. + +### Metrics + +| metric | value | +| ------------------- | ----- | +| p_success_pred | 0.95 | +| entropy_pred | 0.4 | +| impact_pred | 5.0 | +| cost_pred | 0.5 | +| learning_value_pred | 0.3 | +| ev_pred | 4.28 | + +### Step Metrics Rationale + +`EV = 0.95 * 5.0 + 0.5 * 0.3 - 0.3 * 0.4 - 0.5 = 4.75 + 0.15 - 0.12 - 0.5 = 4.28`. The count-change trap is known in +advance. Checking `test_self_doc_modules.py` found `local_llm.py` only in its src list, so the risk is small. + +--- + +## Step 4: Verify zero test loss, run the affected tests, lint, then the full suite once + +- **Sub‑intent recommendation:** NO +- **Reasoning:** These are the acceptance gates. They are cheap and deterministic, and they must run in the same + execution as the change. +- **Step Type:** TEST +- **Exploration level:** EXPLOIT + +### Intent & Git Integration + +- **Step Intent:** Prove both acceptance criteria: the split is lossless and under 700 lines per module, and pytest and + lint pass. +- **Git branch:** same execution branch +- **Sub‑intent:** NONE + +### Implementation Details (No code blocks, only logic/steps) + +1. Zero-loss diff: collect + `tests/test_local_llm.py tests/test_local_llm_config.py tests/test_local_llm_health.py tests/test_local_llm_rewrites.py` + with `--collect-only -q`. Strip the file prefixes, sort, and compare to the Step 1 list. The diff must be empty and + the total must be 102. Record the per-file counts in the execution notes. +2. Affected tests, in the foreground: + `uv run pytest tests/test_local_llm.py tests/test_local_llm_config.py tests/test_local_llm_health.py tests/test_local_llm_rewrites.py tests/cli/test_doctor.py tests/test_cli_unlimited_budgets.py tests/test_self_doc_gate_coverage.py tests/test_self_doc_modules.py`. + This also validates assumption A1. +3. `uv run task lint` from the repository root, in the foreground. It must pass ruff check and format, the module budget + check (unaffected) and `check_self_explaining.py` on the added lines. +4. Full suite once: `uv run task test` in the foreground. Report the pass/fail count and the pytest-reported time. No + repeated runs, because the intent has no timing or performance target. +5. `npx prettier --check` on the execution notes before committing them. + +### Dependencies & Criticality + +- **Depends on:** Steps 2 and 3 +- **Is Bottleneck:** YES (gate; p_success_pred 0.93) + +### Safety & Constraint Considerations + +- **Relevant rules:** Test-run discipline (foreground only, full suite once, `-n auto --dist worksteal` via + `task test`). No environment overlay changes, so no child-process environment test is needed. +- **Potential failure modes for this step:** `check_self_explaining.py` objects to a moved line. The full suite shows an + unrelated flaky failure. A hidden dependency on test-module name, such as patch targets or tmp-dir naming using + `__name__`. +- **Guardrails and early‑abort checks:** Compare a full-suite failure to the Step 1 baseline. Rerun only the failing + node once to tell flakiness from regression, and report both results. + +### Success & Discard Criteria + +- **Success:** Empty collection diff (102 tests). All listed tests are green. `uv run task lint` exits 0. + `uv run task test` exits 0. +- **Discard:** A failure attributable to the split that is not fixed within one correction loop back to Step 2. + +### Metrics + +| metric | value | +| ------------------- | ----- | +| p_success_pred | 0.93 | +| entropy_pred | 0.6 | +| impact_pred | 5.0 | +| cost_pred | 1.5 | +| learning_value_pred | 0.2 | +| ev_pred | 3.07 | + +### Step Metrics Rationale + +`EV = 0.93 * 5.0 + 0.5 * 0.2 - 0.3 * 0.6 - 1.5 = 4.65 + 0.1 - 0.18 - 1.5 = 3.07`. The cost is mostly full-suite wall +time. The probability allows for unrelated suite noise. + +--- + +### Strategy Rationale + +The intent is accepted as is. It is a low-risk, mechanical modularity improvement with clear acceptance checks, and both +stated assumptions were checked during planning: + +- A1: the external imports exist exactly as stated, at `tests/cli/test_doctor.py:14` and + `tests/test_cli_unlimited_budgets.py:14`. +- A2: the registry exists. It also needs the pinned count changed from 326 to 329, which the intent did not mention and + this plan adds. + +Two design choices raise EV over the literal reading: + +1. Each helper has one owner (`_config` in config, `HEALTH_*`/`_fetcher` in health), and the hub re-exports them through + `__all__`. This keeps the import graph acyclic and prevents duplicate collection. +2. `TestLauncherIntegration` stays in `test_local_llm.py`, so the hub remains a real test module. This also keeps the + largest class, with its `# noqa` and several `# why:` lines, unmoved, which shrinks the diff the self-explaining gate + inspects. + +Aggregation: overall `entropy_pred` is the sum of step entropies, `0.2 + 1.4 + 0.4 + 0.6 = 2.6`. Overall +`p_success_pred` (0.90) follows the bottleneck chain Step 2 then Step 4. Their errors are strongly correlated, since +Step 4 mostly re-detects Step 2 issues that the one-loop correction fixes, so the result is above the raw product +`0.92 * 0.93 = 0.86`. Overall impact (35.0) is a qualitative judgement: an Aspect 7 modularity gain on one test file, +not the sum of step impacts, which double-count the same outcome. Cost is the summed step cost of 5.0. Learning value is +low (1.5) because this is a well-worn split pattern. Overall +`EV = 0.90 * 35.0 + 0.5 * 1.5 - 0.3 * 2.6 - 5.0 = 31.5 + 0.75 - 0.78 - 5.0 = 26.47`, about 26.5. + +## Safety & Constraint Alignment + +- **Key world ruleset constraints that affect this plan:** + - `holon-config/world/constraints.md` §1: execution-branch isolation, no commits to `main`. + - `holon-config/world/constraints.md` §3: ledgers are append-only and untouched here. + - `holon-config/world/ruleset.md` §2: no wildcard imports. + - `holon-config/world/ruleset.md` §3: test-file changes must be declared in the plan, and they are in the touch set. + - `docs/safety.md`: process-sandbox tier (entropy below 10), with only `uv`/`pytest`/`ruff`/`git` invoked. + - Planner contract: self-explaining code, frozen `holon-config/hygiene/module_budgets.json`, foreground test runs. +- **Potential violations or edge cases:** A moved `# why:` comment counts as an added line for the self-explaining gate. + A cross-module import of a `Test*` class would duplicate tests. The intent's assumption response leaves out the pinned + count change. Ruff's import sorter could reorder `tests.*` imports. +- **Mitigations built into the plan:** + - Only `# why:`-prefixed comments move, and that form is allowed. + - `__all__` limits re-exports to the six helper names. + - The collection diff against the Step 1 baseline is mandatory. + - The count is explicitly changed to 329. + - ruff fix/format runs only on touched files. +- **Residual risk accepted (and why):** `test_local_llm_config.py` lands at about 615 lines, above the soft ~400 + preference. Test modules are outside the line budget, the intent's ceiling is 700, and there is a documented fallback + (move `TestRunnerValidation` to the hub) if it exceeds 650. +- **Allocated Entropy Budget:** 15.0 +- **Predicted Plan Entropy:** 2.6 +- **Budget Compliance:** The strategy fits within budget. It runs as one plan with no sub-intent list. From 91503ffc8910ffdde4f013d3ccab4dfed7a5632b Mon Sep 17 00:00:00 2001 From: Holon Executor Agent Date: Wed, 2 Dec 2026 23:30:05 +0000 Subject: [PATCH 03/10] Step 1: snapshot baseline test collection --- executions/E-1796254177-CLA-CO5.5.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 executions/E-1796254177-CLA-CO5.5.md diff --git a/executions/E-1796254177-CLA-CO5.5.md b/executions/E-1796254177-CLA-CO5.5.md new file mode 100644 index 000000000..34aca29ae --- /dev/null +++ b/executions/E-1796254177-CLA-CO5.5.md @@ -0,0 +1,26 @@ +# Execution Record: E-1796254177-CLA-CO5.5 + +## Summary + +Implements plan `P-1796254011-CLA-CO5.5` for intent `I-1796253987-hac-split-test-local-llm`: split +`apps/sandbox-executor/tests/test_local_llm.py` (1,289 lines) into focused test modules under 700 lines each, with the +shared helpers re-exported from the hub module and the new modules registered in the self-doc gate coverage list. + +## Actual Metrics + +| metric | value | +| --------------------- | ----- | +| success_actual | 0.0 | +| entropy_actual | 0.0 | +| impact_actual | 0.0 | +| cost_actual | 0.0 | +| learning_value_actual | 0.0 | + +## Steps Executed + +### Step 1: Snapshot the baseline test collection + +- `uv run pytest --collect-only -q apps/sandbox-executor/tests/test_local_llm.py` yields 102 `Class::method` IDs, + matching `grep -c "def test_"` (102). The sorted list is kept outside the repository. +- Green baseline: `test_local_llm.py`, `cli/test_doctor.py`, `test_cli_unlimited_budgets.py` and + `test_self_doc_gate_coverage.py`: 778 passed, 589 subtests passed in 3.69s. From 8f48bef0f3165995dfee75077bbc84fbd3797c05 Mon Sep 17 00:00:00 2001 From: Holon Executor Agent Date: Wed, 2 Dec 2026 23:30:35 +0000 Subject: [PATCH 04/10] Step 2: split test_local_llm into config, health and rewrites modules --- apps/sandbox-executor/tests/test_local_llm.py | 888 +----------------- .../tests/test_local_llm_config.py | 448 +++++++++ .../tests/test_local_llm_health.py | 295 ++++++ .../tests/test_local_llm_rewrites.py | 162 ++++ 4 files changed, 908 insertions(+), 885 deletions(-) create mode 100644 apps/sandbox-executor/tests/test_local_llm_config.py create mode 100644 apps/sandbox-executor/tests/test_local_llm_health.py create mode 100644 apps/sandbox-executor/tests/test_local_llm_rewrites.py diff --git a/apps/sandbox-executor/tests/test_local_llm.py b/apps/sandbox-executor/tests/test_local_llm.py index e4aad0d7d..adecd3c02 100644 --- a/apps/sandbox-executor/tests/test_local_llm.py +++ b/apps/sandbox-executor/tests/test_local_llm.py @@ -1,391 +1,19 @@ -import contextlib -import http.server import io -import json import os -import secrets -import stat import sys import tempfile import unittest from unittest.mock import MagicMock, patch from sandbox_executor import cli, local_llm -from sandbox_executor.agent_runner import get_runner from sandbox_executor.launcher import proxy_paths, root_ca, sidecar from tests.env_file_capture import DockerEnvFileRecorder from tests.leak_assertions import assert_no_fragment, make_probe -from tests.loopback_http import serve_on_loopback +from tests.test_local_llm_config import _config +from tests.test_local_llm_health import HEALTH_COLD, HEALTH_OFF, HEALTH_SMALL_PROMPT, HEALTH_WARM, _fetcher - -class TestRewriteAuthority(unittest.TestCase): - def test_loopback_hosts_are_rewritten(self): - cases = { - "http://localhost:11434/v1": "http://host.docker.internal:11434/v1", - "http://127.0.0.1:8081/v1": "http://host.docker.internal:8081/v1", - "http://127.0.0.2:8081/v1": "http://host.docker.internal:8081/v1", - "http://127.1.2.3:8081/v1": "http://host.docker.internal:8081/v1", - "http://0.0.0.0:8081/v1": "http://host.docker.internal:8081/v1", - "http://[::1]:8081/v1": "http://host.docker.internal:8081/v1", - } - for url, expected in cases.items(): - with self.subTest(url=url): - self.assertEqual(local_llm.rewrite_authority(url), expected) - - def test_port_path_and_scheme_are_preserved(self): - self.assertEqual( - local_llm.rewrite_authority("https://localhost:11434/v1?stream=1"), - "https://host.docker.internal:11434/v1?stream=1", - ) - - def test_declared_host_local_authority_is_rewritten(self): - self.assertEqual( - local_llm.rewrite_authority("http://192.168.2.13:8081/v1", {"192.168.2.13"}), - "http://host.docker.internal:8081/v1", - ) - - def test_undeclared_lan_authority_is_untouched(self): - # why: safety invariant from the server-connect rewrite: never blanket-rewrite RFC1918 ranges - self.assertEqual( - local_llm.rewrite_authority("http://192.168.2.13:8081/v1"), - "http://192.168.2.13:8081/v1", - ) - self.assertEqual( - local_llm.rewrite_authority("http://192.168.2.99:8081/v1", {"192.168.2.13"}), - "http://192.168.2.99:8081/v1", - ) - - def test_public_authority_is_untouched(self): - self.assertEqual( - local_llm.rewrite_authority("https://api.openai.com/v1", {"192.168.2.13"}), - "https://api.openai.com/v1", - ) - - def test_gateway_authority_is_idempotent(self): - self.assertEqual( - local_llm.rewrite_authority("http://host.docker.internal:8081/v1"), - "http://host.docker.internal:8081/v1", - ) - - def test_malformed_authority_is_untouched(self): - self.assertEqual(local_llm.rewrite_authority("not a url"), "not a url") - self.assertEqual(local_llm.rewrite_authority(""), "") - - def test_allow_list_is_case_insensitive(self): - self.assertEqual( - local_llm.rewrite_authority("http://MyBox.lan:8081/v1", {"mybox.lan"}), - "http://host.docker.internal:8081/v1", - ) - - def test_port_qualified_authority_in_allow_list(self): - self.assertEqual( - local_llm.rewrite_authority("http://192.168.2.13:8081/v1", {"192.168.2.13:8081"}), - "http://host.docker.internal:8081/v1", - ) - self.assertEqual( - local_llm.rewrite_authority("http://192.168.2.13:9999/v1", {"192.168.2.13:8081"}), - "http://192.168.2.13:9999/v1", - ) - - def test_rewrite_authority_preserves_fragment(self): - self.assertEqual( - local_llm.rewrite_authority("http://127.0.0.1:8080/v1#section"), - "http://host.docker.internal:8080/v1#section", - ) - - -class TestOptIn(unittest.TestCase): - def test_off_by_default_and_never_inferred(self): - with patch.dict(os.environ, {}, clear=True): - self.assertFalse(local_llm.local_llm_requested()) - - def test_truthy_values(self): - for value in ("1", "true", "TRUE", "yes", "on"): - with self.subTest(value=value), patch.dict(os.environ, {"HOLON_LOCAL_LLM": value}, clear=True): - self.assertTrue(local_llm.local_llm_requested()) - - def test_falsy_values(self): - for value in ("0", "false", "off", ""): - with self.subTest(value=value), patch.dict(os.environ, {"HOLON_LOCAL_LLM": value}, clear=True): - self.assertFalse(local_llm.local_llm_requested()) - - def test_allow_list_parsing_drops_blanks_and_lowercases(self): - with patch.dict(os.environ, {"HOLON_HOST_LOCAL_HOSTS": " MyBox.lan, ,192.168.2.13,"}, clear=True): - self.assertEqual(local_llm.host_local_allow_list(), {"mybox.lan", "192.168.2.13"}) - - def test_allow_list_parsing_strips_paths(self): - with patch.dict(os.environ, {"HOLON_HOST_LOCAL_HOSTS": " 192.168.1.50:8081/v1, 10.0.0.1/ "}, clear=True): - self.assertEqual(local_llm.host_local_allow_list(), {"192.168.1.50:8081", "10.0.0.1"}) - - -class TestBuildContainerConfig(unittest.TestCase): - def test_every_provider_base_url_is_rewritten_and_other_fields_survive(self): - host_config = { - "providers": { - "vmlx": { - "baseUrl": "http://192.168.2.13:8081/v1", - "api": "openai-completions", - "apiKey": "placeholder", - "models": [{"id": "Qwen/Test", "contextWindow": 999424}], - }, - "cloud": { - "baseUrl": "https://api.example.com/v1", - "apiKey": "$MY_KEY", - "models": [{"id": "gpt-x"}], - }, - }, - } - config = local_llm.build_container_config(host_config, {"192.168.2.13"}) - providers = config["providers"] - self.assertEqual(providers["vmlx"]["baseUrl"], "http://host.docker.internal:8081/v1") - self.assertEqual(providers["vmlx"]["api"], "openai-completions") - self.assertEqual(providers["vmlx"]["models"][0]["contextWindow"], 999424) - # why: host credentials must never cross the sandbox boundary - self.assertNotIn("cloud", providers) - - def test_cloud_providers_with_api_keys_are_pruned(self): - host_config = { - "providers": { - "openai": { - "baseUrl": "https://api.openai.com/v1", - "apiKey": "sk-secret-token", - "models": [{"id": "gpt-4o"}], - }, - "anthropic": { - "baseUrl": "https://api.anthropic.com/v1", - "apiKey": "sk-ant-secret", - "models": [{"id": "claude-3-5-sonnet"}], - }, - "local_ollama": { - "baseUrl": "http://127.0.0.1:11434/v1", - "models": [{"id": "llama3.2"}], - }, - }, - } - config = local_llm.build_container_config(host_config) - self.assertIn("local_ollama", config["providers"]) - self.assertNotIn("openai", config["providers"]) - self.assertNotIn("anthropic", config["providers"]) - self.assertEqual( - config["providers"]["local_ollama"]["baseUrl"], - "http://host.docker.internal:11434/v1", - ) - self.assertEqual(config["providers"]["local_ollama"]["apiKey"], "holon-local") - - def test_local_provider_preserves_existing_api_key(self): - host_config = { - "providers": { - "local_vllm": { - "baseUrl": "http://127.0.0.1:8000/v1", - "apiKey": "custom-secret-key", - "models": [{"id": "llama3"}], - }, - }, - } - config = local_llm.build_container_config(host_config) - self.assertEqual(config["providers"]["local_vllm"]["apiKey"], "custom-secret-key") - - def test_only_cloud_providers_falls_back_to_synthesis(self): - host_config = { - "providers": { - "openai": { - "baseUrl": "https://api.openai.com/v1", - "apiKey": "sk-secret", - } - } - } - env = { - "HOLON_LOCAL_BASE_URL": "http://localhost:8081/v1", - "HOLON_LOCAL_MODELS": "qwen3:8b", - } - with patch.dict(os.environ, env, clear=True): - config = local_llm.build_container_config(host_config) - self.assertIn("local", config["providers"]) - self.assertNotIn("openai", config["providers"]) - self.assertEqual(config["providers"]["local"]["baseUrl"], "http://host.docker.internal:8081/v1") - - def test_host_config_is_not_mutated(self): - host_config = {"providers": {"local": {"baseUrl": "http://localhost:11434/v1"}}} - local_llm.build_container_config(host_config) - self.assertEqual(host_config["providers"]["local"]["baseUrl"], "http://localhost:11434/v1") - - def test_synthesized_from_environment_when_no_host_config(self): - env = { - "HOLON_LOCAL_LLM": "1", - "HOLON_LOCAL_BASE_URL": "http://localhost:11434/v1", - "HOLON_LOCAL_MODELS": "llama3.2, qwen3:8b", - "HOLON_LOCAL_PROVIDER": "ollama", - } - with patch.dict(os.environ, env, clear=True): - config = local_llm.build_container_config(None) - self.assertEqual(config["providers"]["ollama"]["baseUrl"], "http://host.docker.internal:11434/v1") - self.assertEqual( - [model["id"] for model in config["providers"]["ollama"]["models"]], - ["llama3.2", "qwen3:8b"], - ) - - def test_missing_base_url_raises_actionable_error(self): - with ( - patch.dict(os.environ, {"HOLON_LOCAL_LLM": "1"}, clear=True), - self.assertRaises(local_llm.LocalLLMConfigError) as ctx, - ): - local_llm.build_container_config(None) - self.assertIn("HOLON_LOCAL_BASE_URL", str(ctx.exception)) - - def test_missing_model_ids_raises_actionable_error(self): - env = {"HOLON_LOCAL_BASE_URL": "http://localhost:11434/v1"} - with ( - patch.dict(os.environ, env, clear=True), - self.assertRaises(local_llm.LocalLLMConfigError) as ctx, - ): - local_llm.build_container_config(None) - self.assertIn("HOLON_LOCAL_MODELS", str(ctx.exception)) - - def test_empty_providers_fall_back_to_synthesis(self): - env = {"HOLON_LOCAL_BASE_URL": "http://127.0.0.1:8081/v1", "HOLON_LOCAL_MODELS": "m1"} - with patch.dict(os.environ, env, clear=True): - config = local_llm.build_container_config({"providers": {}}) - self.assertEqual(config["providers"]["local"]["baseUrl"], "http://host.docker.internal:8081/v1") - - def test_synthesized_config_unrewritable_endpoint_raises(self): - env = { - "HOLON_LOCAL_BASE_URL": "http://192.168.2.13:8081/v1", - "HOLON_LOCAL_MODELS": "m1", - } - with ( - patch.dict(os.environ, env, clear=True), - self.assertRaises(local_llm.LocalLLMConfigError) as ctx, - ): - local_llm.build_container_config(None) - self.assertIn("HOLON_HOST_LOCAL_HOSTS", str(ctx.exception)) - - -class TestBaseUrlEchoRedaction(unittest.TestCase): - def _url(self, probe: str, authority: str) -> str: - return f"http://alice:{probe}@{authority}/v1" - - def test_rewrite_log_masks_userinfo(self): - probe = make_probe() - host_config = {"providers": {"vmlx": {"baseUrl": self._url(probe, "localhost:8081"), "models": [{"id": "m"}]}}} - with self.assertLogs(local_llm.logger, level="INFO") as logs: - local_llm.build_container_config(host_config) - text = "\n".join(logs.output) - self.assertIn("Rewrote provider", text) - self.assertIn("localhost:8081", text) - assert_no_fragment(text, probe) - - def test_unparseable_url_warnings_mask_userinfo(self): - probe = make_probe() - with self.assertLogs(local_llm.logger, level="WARNING") as logs: - self.assertEqual( - local_llm.rewrite_authority(self._url(probe, "localhost:notaport")), - self._url(probe, "localhost:notaport"), - ) - text = "\n".join(logs.output) - self.assertIn("invalid port or host", text) - self.assertIn("unparseable base URL", text) - self.assertIn("value withheld", text) - assert_no_fragment(text, probe) - - def test_unparseable_endpoint_error_withholds_value(self): - head = str(secrets.randbelow(900000) + 100000) - value = f"http://alice:{head}?{make_probe()}@localhost:8081/v1" - env = {"HOLON_LOCAL_BASE_URL": value, "HOLON_LOCAL_MODELS": "m1"} - with ( - patch.dict(os.environ, env, clear=True), - self.assertLogs(local_llm.logger, level="WARNING") as logs, - self.assertRaises(local_llm.LocalLLMConfigError) as ctx, - ): - local_llm.build_container_config(None) - text = "\n".join(logs.output) + "\n" + str(ctx.exception) - self.assertIn("HOLON_LOCAL_BASE_URL is not a valid URL", text) - self.assertNotIn(head, text) - assert_no_fragment(text, value) - - def test_unrewritable_endpoint_error_masks_userinfo(self): - probe = make_probe() - env = {"HOLON_LOCAL_BASE_URL": self._url(probe, "192.168.2.13:8081"), "HOLON_LOCAL_MODELS": "m1"} - with ( - patch.dict(os.environ, env, clear=True), - self.assertRaises(local_llm.LocalLLMConfigError) as ctx, - ): - local_llm.build_container_config(None) - self.assertIn("192.168.2.13:8081", str(ctx.exception)) - assert_no_fragment(str(ctx.exception), probe) - - -class TestPrepareAgentDir(unittest.TestCase): - def test_writes_rewritten_models_json_with_safe_container_permissions(self): - old_umask = os.umask(0o077) - try: - host_config = { - "providers": { - "vmlx": {"baseUrl": "http://localhost:8081/v1", "models": [{"id": "m", "contextWindow": 32768}]} - } - } - with tempfile.TemporaryDirectory() as tmp: - dest = os.path.join(tmp, "agent") - config = local_llm.prepare_agent_dir(dest, host_config=host_config) - path = os.path.join(dest, "models.json") - with open(path) as handle: - on_disk = json.load(handle) - self.assertEqual(on_disk, config) - self.assertEqual(on_disk["providers"]["vmlx"]["baseUrl"], "http://host.docker.internal:8081/v1") - # why: a non-root container user (uid=1000) must be able to read these on Linux - self.assertEqual(stat.S_IMODE(os.stat(dest).st_mode), 0o777) - self.assertEqual(stat.S_IMODE(os.stat(path).st_mode), 0o644) - finally: - os.umask(old_umask) - - def test_container_mount_and_env_point_at_the_same_directory(self): - mounts = local_llm.container_mount_args("/host/tmp/agent") - self.assertEqual(mounts, ["-v", f"/host/tmp/agent:{local_llm.CONTAINER_AGENT_DIR}:rw"]) - self.assertEqual( - local_llm.container_env("/host/tmp/agent"), - {local_llm.ENV_PI_AGENT_DIR: local_llm.CONTAINER_AGENT_DIR}, - ) - - def test_rewritten_local_hosts_reports_only_gateway_authorities(self): - config = { - "providers": { - "local": {"baseUrl": "http://host.docker.internal:8081/v1"}, - "cloud": {"baseUrl": "https://api.example.com/v1"}, - "other": {"baseUrl": "http://host.docker.internal/v1"}, - }, - } - self.assertEqual( - local_llm.rewritten_local_hosts(config), - ["host.docker.internal", "host.docker.internal:8081"], - ) - - def test_host_models_json_reads_preferred_layout_first(self): - with tempfile.TemporaryDirectory() as tmp: - new_dir = os.path.join(tmp, ".pi", "agent") - os.makedirs(new_dir) - with open(os.path.join(new_dir, "models.json"), "w") as handle: - json.dump({"providers": {"vmlx": {"baseUrl": "http://localhost:8081/v1"}}}, handle) - with patch.object(local_llm, "pi_agent_dirs", lambda: [new_dir, os.path.join(tmp, "missing")]): - self.assertEqual( - local_llm.host_models_json()["providers"]["vmlx"]["baseUrl"], "http://localhost:8081/v1" - ) - - def test_host_models_json_invalid_raises_naming_the_file(self): - with tempfile.TemporaryDirectory() as tmp: - with open(os.path.join(tmp, "models.json"), "w") as handle: - handle.write("{not json") - with ( - patch.object(local_llm, "pi_agent_dirs", lambda: [tmp]), - self.assertRaises(local_llm.LocalLLMConfigError) as ctx, - ): - local_llm.host_models_json() - self.assertIn("models.json is not valid JSON", str(ctx.exception)) - self.assertNotIn("not json", str(ctx.exception)) - - def test_pi_agent_dirs_respects_env_var(self): - with patch.dict(os.environ, {local_llm.ENV_PI_AGENT_DIR: "/custom/pi/dir"}, clear=True): - dirs = local_llm.pi_agent_dirs() - self.assertEqual(dirs[0], "/custom/pi/dir") +__all__ = ["HEALTH_COLD", "HEALTH_OFF", "HEALTH_SMALL_PROMPT", "HEALTH_WARM", "_config", "_fetcher"] class TestLauncherIntegration(unittest.TestCase): @@ -624,516 +252,6 @@ def test_non_pi_runner_warns_and_ignores_local_mode(self): self.assertNotIn(f"PI_CODING_AGENT_DIR={local_llm.CONTAINER_AGENT_DIR}", args) -class TestRunnerValidation(unittest.TestCase): - def test_pi_validates_without_key_when_local_endpoint_is_configured(self): - env = {"HOLON_LOCAL_LLM": "1", "PI_CODING_AGENT_DIR": "/home/holon/.holon-pi-agent"} - with patch.dict(os.environ, env, clear=True), patch("os.path.exists", return_value=False): - get_runner("pi-agent").validate() - - def test_pi_still_requires_a_key_without_local_mode(self): - with ( - patch.dict(os.environ, {}, clear=True), - patch("os.path.exists", return_value=False), - self.assertRaises(SystemExit), - ): - get_runner("pi-agent").validate() - - def test_stray_opt_in_without_endpoint_does_not_mask_missing_key(self): - env = {"HOLON_LOCAL_LLM": "1"} - with ( - patch.dict(os.environ, env, clear=True), - patch("os.path.exists", return_value=False), - self.assertRaises(SystemExit), - ): - get_runner("pi-agent").validate() - - def test_non_pi_runners_still_require_keys_in_local_mode(self): - # why: host-local model mode is currently pi-only - env = { - "HOLON_LOCAL_LLM": "1", - "HOLON_LOCAL_BASE_URL": "http://localhost:8081/v1", - "PI_CODING_AGENT_DIR": "/home/holon/.holon-pi-agent", - } - for agent_name in ("claude-agent", "opencode-agent"): - with ( - self.subTest(agent=agent_name), - patch.dict(os.environ, env, clear=True), - patch("os.path.exists", return_value=False), - self.assertRaises(SystemExit), - ): - get_runner(agent_name).validate() - - def test_pi_build_cmd_defaults_provider_from_local_provider(self): - env = { - "HOLON_LOCAL_LLM": "1", - "HOLON_LOCAL_PROVIDER": "vmlx", - "PI_CODING_AGENT_DIR": "/home/holon/.holon-pi-agent", - } - with patch.dict(os.environ, env, clear=True), patch("os.path.exists", return_value=False): - cmd = get_runner("pi-agent").build_cmd("test-model", "prompt.txt", "intent.json", "Hello") - self.assertIn("--provider", cmd) - self.assertIn("vmlx", cmd) - - def test_pi_build_cmd_aligns_single_provider_from_models_json(self): - with tempfile.TemporaryDirectory() as tmp: - models_file = os.path.join(tmp, "models.json") - with open(models_file, "w") as handle: - json.dump({"providers": {"vmlx": {"baseUrl": "http://localhost:8081/v1"}}}, handle) - env = {"HOLON_LOCAL_LLM": "1", "PI_CODING_AGENT_DIR": tmp} - with patch.dict(os.environ, env, clear=True), patch("os.path.exists", return_value=False): - cmd = get_runner("pi-agent").build_cmd("test-model", "prompt.txt", "intent.json", "Hello") - self.assertIn("--provider", cmd) - self.assertIn("vmlx", cmd) - - def test_pi_build_cmd_aligns_local_named_provider_from_models_json(self): - with tempfile.TemporaryDirectory() as tmp: - models_file = os.path.join(tmp, "models.json") - with open(models_file, "w") as handle: - json.dump( - { - "providers": { - "local": {"baseUrl": "http://localhost:8081/v1"}, - "ollama": {"baseUrl": "http://localhost:11434/v1"}, - } - }, - handle, - ) - env = {"HOLON_LOCAL_LLM": "1", "PI_CODING_AGENT_DIR": tmp} - with patch.dict(os.environ, env, clear=True), patch("os.path.exists", return_value=False): - cmd = get_runner("pi-agent").build_cmd("test-model", "prompt.txt", "intent.json", "Hello") - self.assertIn("--provider", cmd) - self.assertIn("local", cmd) - - def test_pi_build_cmd_multiple_providers_without_local_or_env_does_not_set_provider(self): - with tempfile.TemporaryDirectory() as tmp: - models_file = os.path.join(tmp, "models.json") - with open(models_file, "w") as handle: - json.dump( - { - "providers": { - "vmlx": {"baseUrl": "http://localhost:8081/v1"}, - "ollama": {"baseUrl": "http://localhost:11434/v1"}, - } - }, - handle, - ) - env = {"HOLON_LOCAL_LLM": "1", "PI_CODING_AGENT_DIR": tmp} - with patch.dict(os.environ, env, clear=True), patch("os.path.exists", return_value=False): - cmd = get_runner("pi-agent").build_cmd("test-model", "prompt.txt", "intent.json", "Hello") - self.assertNotIn("--provider", cmd) - - def test_normalize_agent_id(self): - self.assertEqual(local_llm.normalize_agent_id("pi-agent"), "pi") - self.assertEqual(local_llm.normalize_agent_id("agent-pi"), "pi") - self.assertEqual(local_llm.normalize_agent_id("Pi"), "pi") - self.assertEqual(local_llm.normalize_agent_id("claude-agent"), "claude") - - -def _config(*models, base_url="http://localhost:8081/v1"): - return {"providers": {"vmlx": {"baseUrl": base_url, "apiKey": "holon-local", "models": list(models)}}} - - -class TestModelEnvelope(unittest.TestCase): - def apply(self, config, env=None): - return local_llm.apply_model_envelope(config, env or {}) - - def test_synthesises_quarter_of_context_window(self): - config = _config({"id": "small", "contextWindow": 32768}) - with self.assertLogs("sandbox_executor.local_llm", level="INFO") as logs: - (envelope,) = self.apply(config) - entry = config["providers"]["vmlx"]["models"][0] - self.assertEqual(entry["maxTokens"], 8192) - self.assertEqual((envelope.max_tokens, envelope.max_tokens_source), (8192, "synthesised")) - self.assertTrue( - any("'small'" in line and "8192" in line and "absent in host config" in line for line in logs.output) - ) - - def test_synthesis_is_capped(self): - config = _config({"id": "big", "contextWindow": 999424}) - (envelope,) = self.apply(config) - self.assertEqual(envelope.max_tokens, 16384) - self.assertEqual(config["providers"]["vmlx"]["models"][0]["maxTokens"], 16384) - - def test_valid_host_value_passes_through(self): - config = _config({"id": "m", "contextWindow": 32768, "maxTokens": 4000}) - (envelope,) = self.apply(config) - self.assertEqual(config["providers"]["vmlx"]["models"][0]["maxTokens"], 4000) - self.assertEqual(envelope.envelope_line(), "model=m context=32768 max_tokens=4000 source=host") - - def test_rejects_invalid_max_tokens(self): - for bad in (0, -1, 1.5, 4096.0, "4096", True, None, 32768 - 4096 + 1): - with self.subTest(bad=bad), self.assertRaises(local_llm.LocalLLMConfigError) as ctx: - self.apply(_config({"id": "m", "contextWindow": 32768, "maxTokens": bad})) - self.assertIn("'m'", str(ctx.exception)) - - def test_reserve_is_configurable(self): - config = _config({"id": "m", "contextWindow": 32768, "maxTokens": 30000}) - (envelope,) = self.apply(config, {"HOLON_CONTEXT_RESERVE_TOKENS": "1024"}) - self.assertEqual(envelope.max_tokens, 30000) - - def test_missing_context_window_uses_env_or_fails(self): - config = _config({"id": "m"}) - (envelope,) = self.apply(config, {"HOLON_LOCAL_CONTEXT_WINDOW": "65536"}) - self.assertEqual((envelope.context_window, envelope.max_tokens), (65536, 16384)) - self.assertEqual(config["providers"]["vmlx"]["models"][0]["contextWindow"], 65536) - with self.assertRaises(local_llm.LocalLLMConfigError) as ctx: - self.apply(_config({"id": "m"})) - self.assertIn("HOLON_LOCAL_CONTEXT_WINDOW", str(ctx.exception)) - - def test_invalid_context_window(self): - for bad in (0, -5, "32768", 3.5, False): - with self.subTest(bad=bad), self.assertRaises(local_llm.LocalLLMConfigError): - self.apply(_config({"id": "m", "contextWindow": bad})) - - def test_reasoning_mode_from_env_host_and_default(self): - cases = [ - ({"HOLON_REASONING_MODE": "LOW"}, {"reasoning": True}, ("low", "env"), True), - ({}, {"reasoning": "medium"}, ("medium", "host"), True), - ({}, {"reasoning": False}, ("off", "host"), False), - ({}, {"reasoning": True}, ("off", "default"), False), - ({}, {}, ("off", "default"), False), - ] - for env, extra, expected, flag in cases: - with self.subTest(env=env, extra=extra): - config = _config({"id": "m", "contextWindow": 32768, **extra}) - (envelope,) = self.apply(config, env) - self.assertEqual((envelope.reasoning, envelope.reasoning_source), expected) - self.assertIs(config["providers"]["vmlx"]["models"][0]["reasoning"], flag) - self.assertEqual(envelope.reasoning_line(), f"reasoning={expected[0]} source={expected[1]}") - - def test_env_reasoning_mode_never_overrides_host_reasoning_false(self): - config = _config( - {"id": "plain", "contextWindow": 32768, "reasoning": False}, - {"id": "thinker", "contextWindow": 32768, "reasoning": True}, - ) - with self.assertLogs("sandbox_executor.local_llm", level="WARNING") as logs: - plain, thinker = self.apply(config, {"HOLON_REASONING_MODE": "high"}) - self.assertEqual((plain.reasoning, plain.reasoning_source), ("off", "host")) - self.assertEqual((thinker.reasoning, thinker.reasoning_source), ("high", "env")) - models = config["providers"]["vmlx"]["models"] - self.assertIs(models[0]["reasoning"], False) - self.assertIs(models[1]["reasoning"], True) - self.assertTrue(any("'plain'" in line and "reasoning: false" in line for line in logs.output)) - with self.assertNoLogs("sandbox_executor.local_llm", level="WARNING"): - (envelope,) = self.apply( - _config({"id": "m", "contextWindow": 32768, "reasoning": False}), {"HOLON_REASONING_MODE": "off"} - ) - self.assertEqual((envelope.reasoning, envelope.reasoning_source), ("off", "host")) - - def test_invalid_reasoning_mode_raises(self): - with self.assertRaises(local_llm.LocalLLMConfigError): - self.apply(_config({"id": "m", "contextWindow": 32768}), {"HOLON_REASONING_MODE": "turbo"}) - with self.assertRaises(local_llm.LocalLLMConfigError): - self.apply(_config({"id": "m", "contextWindow": 32768, "reasoning": "max"})) - - def test_prepare_agent_dir_writes_envelope_and_thinking_level(self): - host_config = _config({"id": "m", "contextWindow": 32768}) - with ( - tempfile.TemporaryDirectory() as tmp, - patch.dict(os.environ, {"HOLON_REASONING_MODE": "minimal"}, clear=True), - ): - dest = os.path.join(tmp, "agent") - config = local_llm.prepare_agent_dir(dest, host_config=host_config) - with open(os.path.join(dest, "models.json")) as f: - on_disk = json.load(f) - with open(os.path.join(dest, "settings.json")) as f: - settings = json.load(f) - self.assertEqual(on_disk["providers"]["vmlx"]["baseUrl"], "http://host.docker.internal:8081/v1") - self.assertEqual(on_disk, config) - entry = on_disk["providers"]["vmlx"]["models"][0] - self.assertIsInstance(entry["maxTokens"], int) - self.assertIs(entry["reasoning"], True) - self.assertEqual(settings, {"defaultThinkingLevel": "minimal"}) - self.assertEqual(stat.S_IMODE(os.stat(os.path.join(dest, "settings.json")).st_mode), 0o644) - self.assertEqual(local_llm.container_env(dest), {"PI_CODING_AGENT_DIR": local_llm.CONTAINER_AGENT_DIR}) - - -# why: frozen fixtures for parser coverage only, not performance claims -HEALTH_OFF = {"status": "ok", "prefill_cache": {"enabled": False}, "effective_defaults": {"max_output_tokens": 8192}} -HEALTH_COLD = { - "status": "ok", - "prefill_cache": {"enabled": True, "entries": 0, "cached_tokens": 0, "memory_bytes": 0}, - "memory": {"used_bytes": 1048576, "limit_bytes": 8589934592}, - "effective_defaults": {"max_output_tokens": 8192}, -} -HEALTH_WARM = { - "status": "ok", - "prefill_cache": {"enabled": True, "entries": 3, "cached_tokens": 41234, "memory_bytes": 536870912}, - "memory": {"used_bytes": 2147483648, "limit_bytes": 8589934592}, - "effective_defaults": {"max_output_tokens": 4096}, -} -HEALTH_SMALL_PROMPT = { - "status": "ok", - "prefill_cache": {"enabled": True, "entries": 0}, - "effective_defaults": {"max_output_tokens": 16384, "max_prompt_tokens": 32768}, -} -HEALTH_MALFORMED = "not json" - - -def _fetcher(payload, calls=None): - def fetch(url, timeout): - if calls is not None: - calls.append((url, timeout)) - return payload if isinstance(payload, str) else json.dumps(payload).encode() - - return fetch - - -class TestHostGateways(unittest.TestCase): - def test_groups_providers_by_server_and_skips_unprobeable_endpoints(self): - host_config = { - "providers": { - "a": {"baseUrl": "http://127.0.0.1:8000/v1", "models": [{"id": "x"}]}, - "b": {"baseUrl": "http://127.0.0.1:8000/anthropic", "models": [{"id": "y"}]}, - "c": {"baseUrl": "http://gpu.lan:9000/v1", "models": [{"id": "z"}]}, - "cloud": {"baseUrl": "https://api.example.com/v1", "models": [{"id": "w"}]}, - } - } - allow_list = {"gpu.lan"} - config = local_llm.build_container_config(host_config, allow_list) - gateways = local_llm.host_gateways(host_config, config, {}, allow_list) - self.assertEqual( - gateways, - [ - ("http://127.0.0.1:8000/v1", frozenset({"a", "b"})), - ("http://gpu.lan:9000/v1", frozenset({"c"})), - ], - ) - - def test_synthesised_provider_maps_to_configured_base_url(self): - env = {"HOLON_LOCAL_BASE_URL": "http://localhost:11434/v1", "HOLON_LOCAL_MODELS": "m"} - with patch.dict(os.environ, env, clear=True): - config = local_llm.build_container_config(None) - gateways = local_llm.host_gateways(None, config, env) - self.assertEqual(gateways, [("http://localhost:11434/v1", frozenset(config["providers"]))]) - - -class TestGatewayHealth(unittest.TestCase): - def test_off_cold_warm_classification(self): - for payload, expected in ((HEALTH_OFF, "off"), (HEALTH_COLD, "cold"), (HEALTH_WARM, "warm")): - with self.subTest(expected=expected): - health = local_llm.probe_gateway_health("http://localhost:8081/v1", fetch=_fetcher(payload)) - self.assertEqual(health.prefill_cache, expected) - self.assertTrue(health.cache_line().startswith(f"prefill_cache={expected}")) - - def test_memory_figures_and_output_default(self): - health = local_llm.probe_gateway_health("http://localhost:8081/v1", fetch=_fetcher(HEALTH_WARM)) - self.assertEqual(health.max_output_tokens, 4096) - self.assertEqual(health.memory["memory_used_bytes"], 2147483648) - self.assertEqual(health.memory["cache_memory_bytes"], 536870912) - self.assertIn("memory_limit_bytes=8589934592", health.cache_line()) - - def test_malformed_response_is_unknown(self): - health = local_llm.probe_gateway_health("http://localhost:8081/v1", fetch=_fetcher(HEALTH_MALFORMED)) - self.assertEqual(health.prefill_cache, "unknown") - self.assertEqual(local_llm.parse_gateway_health("u", ["list"]).prefill_cache, "unknown") - self.assertEqual(local_llm.parse_gateway_health("u", {"status": "ok"}).prefill_cache, "unknown") - - def test_network_failure_is_unknown(self): - def failing(url, timeout): - raise OSError("connection refused") - - health = local_llm.probe_gateway_health("http://127.0.0.1:8081/v1", fetch=failing) - self.assertEqual(health.prefill_cache, "unknown") - self.assertIn("connection refused", health.cache_line()) - - def test_malformed_http_response_is_unknown(self): - import http.client - - for exc in (http.client.BadStatusLine("garbage"), http.client.IncompleteRead(b"{")): - with self.subTest(exc=type(exc).__name__): - - def failing(url, timeout, exc=exc): - raise exc - - health = local_llm.probe_gateway_health("http://127.0.0.1:8081/v1", fetch=failing) - self.assertEqual(health.prefill_cache, "unknown") - self.assertIn("health probe failed", health.cache_line()) - - def test_probe_targets_health_path_with_short_timeout(self): - calls = [] - local_llm.probe_gateway_health("http://localhost:8081/v1", fetch=_fetcher(HEALTH_OFF, calls)) - self.assertEqual(calls, [("http://localhost:8081/health", 2.0)]) - - def test_never_probes_remote_or_gateway_hosts(self): - calls = [] - for url in ("https://api.example.com/v1", "http://192.168.1.20:8081/v1", "http://host.docker.internal:8081/v1"): - with self.subTest(url=url): - self.assertIsNone(local_llm.probe_gateway_health(url, fetch=_fetcher(HEALTH_OFF, calls))) - self.assertEqual(calls, []) - allowed = local_llm.probe_gateway_health( - "http://192.168.1.20:8081/v1", fetch=_fetcher(HEALTH_OFF, calls), allow_list={"192.168.1.20"} - ) - self.assertEqual(allowed.prefill_cache, "off") - - def test_probe_url_drops_userinfo(self): - calls = [] - url = "http://user:s3cret@localhost:8081/v1" - health = local_llm.probe_gateway_health(url, fetch=_fetcher(HEALTH_OFF, calls)) - self.assertEqual(calls, [("http://localhost:8081/health", 2.0)]) - self.assertNotIn("s3cret", health.url) - self.assertEqual(local_llm.health_url("http://[::1]:8081/v1"), "http://[::1]:8081/health") - - def test_redact_url_drops_userinfo_query_and_fragment(self): - # why: probe credentials are built at runtime rather than written as literals - sample = "pw-" + "x" * 8 - url = f"http://someone:{sample}@gpu.example.com:8000/v1?key={sample}#{sample}" - self.assertEqual(local_llm.redact_url(url), "http://***@gpu.example.com:8000/v1") - self.assertEqual(local_llm.redact_url("http://localhost:11434/v1"), "http://localhost:11434/v1") - unparseable = f"http://someone:{sample}@[::1/v1?key={sample}" - self.assertNotIn(sample, local_llm.redact_url(unparseable)) - with self.assertRaises(ValueError) as caught: - local_llm._default_fetch(f"file://someone:{sample}@localhost/etc", 1.0) - self.assertNotIn(sample, str(caught.exception)) - - def test_redact_url_drops_userinfo_with_unencoded_delimiters(self): - # why: urlsplit ends the authority at the first / ? or #, so the host after it cannot be trusted - sample = "pw-" + "x" * 8 - head = "hd-" + "q" * 5 - for sep in ("/", "?", "#"): - for prefix in ("http://", "//", ""): - url = f"{prefix}someone:{head}{sep}{sample}@gpu.example.com:8000/v1?key={sample}#{sample}" - with self.subTest(sep=sep, prefix=prefix): - redacted = local_llm.redact_url(url) - self.assertEqual(redacted, f"{prefix}***") - for fragment in (sample, head, "someone", "gpu.example.com"): - self.assertNotIn(fragment, redacted) - bracketed = f"http://someone:{head}/{sample}@[::1]:8081/v1" - self.assertEqual(local_llm.redact_url(bracketed), "http://***") - plain = f"http://someone:{head}{sample}@[::1]:8081/v1" - self.assertEqual(local_llm.redact_url(plain), "http://***@[::1]:8081/v1") - - def test_redact_url_keeps_credential_free_urls_readable(self): - for url in ( - "http://localhost:11434/v1", - "https://gpu.example.com:8443/api/v1/", - "http://[::1]:8081/v1", - "host.docker.internal:8000/v1", - ): - with self.subTest(url=url): - self.assertEqual(local_llm.redact_url(url), url) - self.assertEqual(local_llm.redact_url("http://[::1/v1"), "http://***") - self.assertEqual(local_llm.redact_url("HTTP://Host.Example:80/a/b"), "HTTP://Host.Example:80/a/b") - self.assertEqual(local_llm.redact_url("http://localhost:8000/v1?key=k#f"), "http://localhost:8000/v1") - # why: withholding the host beats presenting a believable wrong one - other = "other" + ".example.net" - for url in ( - "http://localhost:8000/v1/@scope/models", - "http://localhost:8000/v1?owner=a@", - f"http://gpu.lan:8000/v1?owner=ops@{other}", - f"http://gpu.lan:8000/v1#ops@{other}", - f"http://gpu.lan:8000/v1/ops@{other}/x", - ): - with self.subTest(url=url): - self.assertEqual(local_llm.redact_url(url), "http://***") - self.assertEqual(local_llm.redact_url(f"//gpu.lan/v1?owner=ops@{other}"), "//***") - self.assertEqual(local_llm.redact_url(f"gpu.lan:8000/v1?owner=ops@{other}"), "***") - - def test_redact_url_never_leaks_userinfo_over_probe_matrix(self): - # why: the strip up to the last @ is unconditional, so no host shape may gate it - head = "hd-" + "q" * 5 - sample = "pw-" + "x" * 8 - name = "some" + "one" - hosts = ( - "gpu.example.com:8000/v1", - "[::1]:8081/v1", - "127.0.0.1:59999/v1", - "gpu.example.com:abc/v1", - "h\u00f4st.example/v1", - "[::1/v1", - "/v1", - "", - "gpu example.com/v1", - ) - validated = {"gpu.example.com:8000/v1", "[::1]:8081/v1", "127.0.0.1:59999/v1"} - for sep in ("", "/", "?", "#", "@", ":", "%", "%2F"): - for userinfo in (f"{name}:{head}{sep}{sample}", f"{head}{sep}{sample}"): - for host in hosts: - for prefix in ("http://", "//", ""): - url = f"{prefix}{userinfo}@{host}?key={sample}#{sample}" - with self.subTest(url=url): - redacted = local_llm.redact_url(url) - ambiguous = any(c in userinfo for c in "/?#") - # why: #96 message rule: a host that does not validate is withheld - withheld = ambiguous or host not in validated - expected = f"{prefix}***" if withheld else f"{prefix}***@{host}" - self.assertEqual(redacted, expected) - for fragment in (head, sample, name): - self.assertNotIn(fragment, redacted) - - def test_config_error_and_logs_never_echo_userinfo(self): - sample = "pw-" + "y" * 8 - env = { - "HOLON_LOCAL_BASE_URL": f"http://someone:{sample}@gpu.example.com:8000/v1?key={sample}", - "HOLON_LOCAL_MODELS": "m", - } - with patch.dict(os.environ, env, clear=True), self.assertRaises(local_llm.LocalLLMConfigError) as caught: - local_llm.build_container_config(None) - self.assertNotIn(sample, str(caught.exception)) - self.assertIn("(host gpu.example.com:8000)", str(caught.exception)) - host_config = {"providers": {"p": {"baseUrl": f"http://someone:{sample}@localhost:8081/v1", "models": []}}} - with self.assertLogs(local_llm.logger, level="INFO") as logs: - local_llm.build_container_config(host_config) - local_llm.rewrite_authority(f"http://someone:{sample}@localhost:bad/v1") - self.assertTrue(logs.output) - self.assertFalse(any(sample in line for line in logs.output)) - - def test_only_http_and_https_are_probed(self): - calls = [] - for url in ("file://localhost/etc", "ftp://127.0.0.1:21/x", "gopher://localhost:70/x"): - with self.subTest(url=url): - self.assertIsNone(local_llm.health_url(url)) - self.assertIsNone(local_llm.probe_gateway_health(url, fetch=_fetcher(HEALTH_OFF, calls))) - self.assertEqual(calls, []) - self.assertEqual(local_llm.health_url("HTTPS://localhost:8443/v1"), "https://localhost:8443/health") - with self.assertRaises(ValueError): - local_llm._default_fetch("file:///etc/hosts", 1.0) - - def test_default_fetch_caps_the_response_read(self): - size = local_llm.HEALTH_MAX_BYTES * 3 - - class Flood(http.server.BaseHTTPRequestHandler): - def do_GET(self): - self.send_response(200) - self.send_header("Content-Length", str(size)) - self.end_headers() - # why: the client hangs up at the cap, so the rest of the write may fail - with contextlib.suppress(OSError): - self.wfile.write(b"x" * size) - - def log_message(self, *args): - pass - - port = serve_on_loopback(self, Flood) - with self.assertRaises(ValueError): - local_llm._default_fetch(f"http://127.0.0.1:{port}/health", 2.0) - health = local_llm.probe_gateway_health(f"http://127.0.0.1:{port}/v1") - self.assertEqual(health.prefill_cache, "unknown") - self.assertIn("exceeds", health.error) - - def test_default_fetch_refuses_redirects(self): - class Redirector(http.server.BaseHTTPRequestHandler): - def do_GET(self): - self.send_response(302) - self.send_header("Location", "http://198.51.100.7/health") - self.end_headers() - - def log_message(self, *args): - pass - - port = serve_on_loopback(self, Redirector) - health = local_llm.probe_gateway_health(f"http://127.0.0.1:{port}/v1") - self.assertEqual(health.prefill_cache, "unknown") - self.assertIn("redirect refused", health.error) - - def test_max_prompt_tokens_parsed_from_defaults_or_top_level(self): - nested = {"effective_defaults": {"max_output_tokens": 16384, "max_prompt_tokens": 262144}} - self.assertEqual(local_llm.parse_gateway_health("u", nested).max_prompt_tokens, 262144) - top = {"effective_defaults": {"max_output_tokens": 16384}, "max_prompt_tokens": 32768} - self.assertEqual(local_llm.parse_gateway_health("u", top).max_prompt_tokens, 32768) - self.assertIsNone(local_llm.parse_gateway_health("u", HEALTH_OFF).max_prompt_tokens) - - class TestValidatedModelsConfig(unittest.TestCase): def _write(self, tmp, raw: bytes) -> str: path = os.path.join(tmp, "models.json") diff --git a/apps/sandbox-executor/tests/test_local_llm_config.py b/apps/sandbox-executor/tests/test_local_llm_config.py new file mode 100644 index 000000000..d742e799e --- /dev/null +++ b/apps/sandbox-executor/tests/test_local_llm_config.py @@ -0,0 +1,448 @@ +import json +import os +import stat +import tempfile +import unittest +from unittest.mock import patch + +from sandbox_executor import local_llm +from sandbox_executor.agent_runner import get_runner + + +def _config(*models, base_url="http://localhost:8081/v1"): + return {"providers": {"vmlx": {"baseUrl": base_url, "apiKey": "holon-local", "models": list(models)}}} + + +class TestBuildContainerConfig(unittest.TestCase): + def test_every_provider_base_url_is_rewritten_and_other_fields_survive(self): + host_config = { + "providers": { + "vmlx": { + "baseUrl": "http://192.168.2.13:8081/v1", + "api": "openai-completions", + "apiKey": "placeholder", + "models": [{"id": "Qwen/Test", "contextWindow": 999424}], + }, + "cloud": { + "baseUrl": "https://api.example.com/v1", + "apiKey": "$MY_KEY", + "models": [{"id": "gpt-x"}], + }, + }, + } + config = local_llm.build_container_config(host_config, {"192.168.2.13"}) + providers = config["providers"] + self.assertEqual(providers["vmlx"]["baseUrl"], "http://host.docker.internal:8081/v1") + self.assertEqual(providers["vmlx"]["api"], "openai-completions") + self.assertEqual(providers["vmlx"]["models"][0]["contextWindow"], 999424) + # why: host credentials must never cross the sandbox boundary + self.assertNotIn("cloud", providers) + + def test_cloud_providers_with_api_keys_are_pruned(self): + host_config = { + "providers": { + "openai": { + "baseUrl": "https://api.openai.com/v1", + "apiKey": "sk-secret-token", + "models": [{"id": "gpt-4o"}], + }, + "anthropic": { + "baseUrl": "https://api.anthropic.com/v1", + "apiKey": "sk-ant-secret", + "models": [{"id": "claude-3-5-sonnet"}], + }, + "local_ollama": { + "baseUrl": "http://127.0.0.1:11434/v1", + "models": [{"id": "llama3.2"}], + }, + }, + } + config = local_llm.build_container_config(host_config) + self.assertIn("local_ollama", config["providers"]) + self.assertNotIn("openai", config["providers"]) + self.assertNotIn("anthropic", config["providers"]) + self.assertEqual( + config["providers"]["local_ollama"]["baseUrl"], + "http://host.docker.internal:11434/v1", + ) + self.assertEqual(config["providers"]["local_ollama"]["apiKey"], "holon-local") + + def test_local_provider_preserves_existing_api_key(self): + host_config = { + "providers": { + "local_vllm": { + "baseUrl": "http://127.0.0.1:8000/v1", + "apiKey": "custom-secret-key", + "models": [{"id": "llama3"}], + }, + }, + } + config = local_llm.build_container_config(host_config) + self.assertEqual(config["providers"]["local_vllm"]["apiKey"], "custom-secret-key") + + def test_only_cloud_providers_falls_back_to_synthesis(self): + host_config = { + "providers": { + "openai": { + "baseUrl": "https://api.openai.com/v1", + "apiKey": "sk-secret", + } + } + } + env = { + "HOLON_LOCAL_BASE_URL": "http://localhost:8081/v1", + "HOLON_LOCAL_MODELS": "qwen3:8b", + } + with patch.dict(os.environ, env, clear=True): + config = local_llm.build_container_config(host_config) + self.assertIn("local", config["providers"]) + self.assertNotIn("openai", config["providers"]) + self.assertEqual(config["providers"]["local"]["baseUrl"], "http://host.docker.internal:8081/v1") + + def test_host_config_is_not_mutated(self): + host_config = {"providers": {"local": {"baseUrl": "http://localhost:11434/v1"}}} + local_llm.build_container_config(host_config) + self.assertEqual(host_config["providers"]["local"]["baseUrl"], "http://localhost:11434/v1") + + def test_synthesized_from_environment_when_no_host_config(self): + env = { + "HOLON_LOCAL_LLM": "1", + "HOLON_LOCAL_BASE_URL": "http://localhost:11434/v1", + "HOLON_LOCAL_MODELS": "llama3.2, qwen3:8b", + "HOLON_LOCAL_PROVIDER": "ollama", + } + with patch.dict(os.environ, env, clear=True): + config = local_llm.build_container_config(None) + self.assertEqual(config["providers"]["ollama"]["baseUrl"], "http://host.docker.internal:11434/v1") + self.assertEqual( + [model["id"] for model in config["providers"]["ollama"]["models"]], + ["llama3.2", "qwen3:8b"], + ) + + def test_missing_base_url_raises_actionable_error(self): + with ( + patch.dict(os.environ, {"HOLON_LOCAL_LLM": "1"}, clear=True), + self.assertRaises(local_llm.LocalLLMConfigError) as ctx, + ): + local_llm.build_container_config(None) + self.assertIn("HOLON_LOCAL_BASE_URL", str(ctx.exception)) + + def test_missing_model_ids_raises_actionable_error(self): + env = {"HOLON_LOCAL_BASE_URL": "http://localhost:11434/v1"} + with ( + patch.dict(os.environ, env, clear=True), + self.assertRaises(local_llm.LocalLLMConfigError) as ctx, + ): + local_llm.build_container_config(None) + self.assertIn("HOLON_LOCAL_MODELS", str(ctx.exception)) + + def test_empty_providers_fall_back_to_synthesis(self): + env = {"HOLON_LOCAL_BASE_URL": "http://127.0.0.1:8081/v1", "HOLON_LOCAL_MODELS": "m1"} + with patch.dict(os.environ, env, clear=True): + config = local_llm.build_container_config({"providers": {}}) + self.assertEqual(config["providers"]["local"]["baseUrl"], "http://host.docker.internal:8081/v1") + + def test_synthesized_config_unrewritable_endpoint_raises(self): + env = { + "HOLON_LOCAL_BASE_URL": "http://192.168.2.13:8081/v1", + "HOLON_LOCAL_MODELS": "m1", + } + with ( + patch.dict(os.environ, env, clear=True), + self.assertRaises(local_llm.LocalLLMConfigError) as ctx, + ): + local_llm.build_container_config(None) + self.assertIn("HOLON_HOST_LOCAL_HOSTS", str(ctx.exception)) + + +class TestPrepareAgentDir(unittest.TestCase): + def test_writes_rewritten_models_json_with_safe_container_permissions(self): + old_umask = os.umask(0o077) + try: + host_config = { + "providers": { + "vmlx": {"baseUrl": "http://localhost:8081/v1", "models": [{"id": "m", "contextWindow": 32768}]} + } + } + with tempfile.TemporaryDirectory() as tmp: + dest = os.path.join(tmp, "agent") + config = local_llm.prepare_agent_dir(dest, host_config=host_config) + path = os.path.join(dest, "models.json") + with open(path) as handle: + on_disk = json.load(handle) + self.assertEqual(on_disk, config) + self.assertEqual(on_disk["providers"]["vmlx"]["baseUrl"], "http://host.docker.internal:8081/v1") + # why: a non-root container user (uid=1000) must be able to read these on Linux + self.assertEqual(stat.S_IMODE(os.stat(dest).st_mode), 0o777) + self.assertEqual(stat.S_IMODE(os.stat(path).st_mode), 0o644) + finally: + os.umask(old_umask) + + def test_container_mount_and_env_point_at_the_same_directory(self): + mounts = local_llm.container_mount_args("/host/tmp/agent") + self.assertEqual(mounts, ["-v", f"/host/tmp/agent:{local_llm.CONTAINER_AGENT_DIR}:rw"]) + self.assertEqual( + local_llm.container_env("/host/tmp/agent"), + {local_llm.ENV_PI_AGENT_DIR: local_llm.CONTAINER_AGENT_DIR}, + ) + + def test_rewritten_local_hosts_reports_only_gateway_authorities(self): + config = { + "providers": { + "local": {"baseUrl": "http://host.docker.internal:8081/v1"}, + "cloud": {"baseUrl": "https://api.example.com/v1"}, + "other": {"baseUrl": "http://host.docker.internal/v1"}, + }, + } + self.assertEqual( + local_llm.rewritten_local_hosts(config), + ["host.docker.internal", "host.docker.internal:8081"], + ) + + def test_host_models_json_reads_preferred_layout_first(self): + with tempfile.TemporaryDirectory() as tmp: + new_dir = os.path.join(tmp, ".pi", "agent") + os.makedirs(new_dir) + with open(os.path.join(new_dir, "models.json"), "w") as handle: + json.dump({"providers": {"vmlx": {"baseUrl": "http://localhost:8081/v1"}}}, handle) + with patch.object(local_llm, "pi_agent_dirs", lambda: [new_dir, os.path.join(tmp, "missing")]): + self.assertEqual( + local_llm.host_models_json()["providers"]["vmlx"]["baseUrl"], "http://localhost:8081/v1" + ) + + def test_host_models_json_invalid_raises_naming_the_file(self): + with tempfile.TemporaryDirectory() as tmp: + with open(os.path.join(tmp, "models.json"), "w") as handle: + handle.write("{not json") + with ( + patch.object(local_llm, "pi_agent_dirs", lambda: [tmp]), + self.assertRaises(local_llm.LocalLLMConfigError) as ctx, + ): + local_llm.host_models_json() + self.assertIn("models.json is not valid JSON", str(ctx.exception)) + self.assertNotIn("not json", str(ctx.exception)) + + def test_pi_agent_dirs_respects_env_var(self): + with patch.dict(os.environ, {local_llm.ENV_PI_AGENT_DIR: "/custom/pi/dir"}, clear=True): + dirs = local_llm.pi_agent_dirs() + self.assertEqual(dirs[0], "/custom/pi/dir") + + +class TestRunnerValidation(unittest.TestCase): + def test_pi_validates_without_key_when_local_endpoint_is_configured(self): + env = {"HOLON_LOCAL_LLM": "1", "PI_CODING_AGENT_DIR": "/home/holon/.holon-pi-agent"} + with patch.dict(os.environ, env, clear=True), patch("os.path.exists", return_value=False): + get_runner("pi-agent").validate() + + def test_pi_still_requires_a_key_without_local_mode(self): + with ( + patch.dict(os.environ, {}, clear=True), + patch("os.path.exists", return_value=False), + self.assertRaises(SystemExit), + ): + get_runner("pi-agent").validate() + + def test_stray_opt_in_without_endpoint_does_not_mask_missing_key(self): + env = {"HOLON_LOCAL_LLM": "1"} + with ( + patch.dict(os.environ, env, clear=True), + patch("os.path.exists", return_value=False), + self.assertRaises(SystemExit), + ): + get_runner("pi-agent").validate() + + def test_non_pi_runners_still_require_keys_in_local_mode(self): + # why: host-local model mode is currently pi-only + env = { + "HOLON_LOCAL_LLM": "1", + "HOLON_LOCAL_BASE_URL": "http://localhost:8081/v1", + "PI_CODING_AGENT_DIR": "/home/holon/.holon-pi-agent", + } + for agent_name in ("claude-agent", "opencode-agent"): + with ( + self.subTest(agent=agent_name), + patch.dict(os.environ, env, clear=True), + patch("os.path.exists", return_value=False), + self.assertRaises(SystemExit), + ): + get_runner(agent_name).validate() + + def test_pi_build_cmd_defaults_provider_from_local_provider(self): + env = { + "HOLON_LOCAL_LLM": "1", + "HOLON_LOCAL_PROVIDER": "vmlx", + "PI_CODING_AGENT_DIR": "/home/holon/.holon-pi-agent", + } + with patch.dict(os.environ, env, clear=True), patch("os.path.exists", return_value=False): + cmd = get_runner("pi-agent").build_cmd("test-model", "prompt.txt", "intent.json", "Hello") + self.assertIn("--provider", cmd) + self.assertIn("vmlx", cmd) + + def test_pi_build_cmd_aligns_single_provider_from_models_json(self): + with tempfile.TemporaryDirectory() as tmp: + models_file = os.path.join(tmp, "models.json") + with open(models_file, "w") as handle: + json.dump({"providers": {"vmlx": {"baseUrl": "http://localhost:8081/v1"}}}, handle) + env = {"HOLON_LOCAL_LLM": "1", "PI_CODING_AGENT_DIR": tmp} + with patch.dict(os.environ, env, clear=True), patch("os.path.exists", return_value=False): + cmd = get_runner("pi-agent").build_cmd("test-model", "prompt.txt", "intent.json", "Hello") + self.assertIn("--provider", cmd) + self.assertIn("vmlx", cmd) + + def test_pi_build_cmd_aligns_local_named_provider_from_models_json(self): + with tempfile.TemporaryDirectory() as tmp: + models_file = os.path.join(tmp, "models.json") + with open(models_file, "w") as handle: + json.dump( + { + "providers": { + "local": {"baseUrl": "http://localhost:8081/v1"}, + "ollama": {"baseUrl": "http://localhost:11434/v1"}, + } + }, + handle, + ) + env = {"HOLON_LOCAL_LLM": "1", "PI_CODING_AGENT_DIR": tmp} + with patch.dict(os.environ, env, clear=True), patch("os.path.exists", return_value=False): + cmd = get_runner("pi-agent").build_cmd("test-model", "prompt.txt", "intent.json", "Hello") + self.assertIn("--provider", cmd) + self.assertIn("local", cmd) + + def test_pi_build_cmd_multiple_providers_without_local_or_env_does_not_set_provider(self): + with tempfile.TemporaryDirectory() as tmp: + models_file = os.path.join(tmp, "models.json") + with open(models_file, "w") as handle: + json.dump( + { + "providers": { + "vmlx": {"baseUrl": "http://localhost:8081/v1"}, + "ollama": {"baseUrl": "http://localhost:11434/v1"}, + } + }, + handle, + ) + env = {"HOLON_LOCAL_LLM": "1", "PI_CODING_AGENT_DIR": tmp} + with patch.dict(os.environ, env, clear=True), patch("os.path.exists", return_value=False): + cmd = get_runner("pi-agent").build_cmd("test-model", "prompt.txt", "intent.json", "Hello") + self.assertNotIn("--provider", cmd) + + def test_normalize_agent_id(self): + self.assertEqual(local_llm.normalize_agent_id("pi-agent"), "pi") + self.assertEqual(local_llm.normalize_agent_id("agent-pi"), "pi") + self.assertEqual(local_llm.normalize_agent_id("Pi"), "pi") + self.assertEqual(local_llm.normalize_agent_id("claude-agent"), "claude") + + +class TestModelEnvelope(unittest.TestCase): + def apply(self, config, env=None): + return local_llm.apply_model_envelope(config, env or {}) + + def test_synthesises_quarter_of_context_window(self): + config = _config({"id": "small", "contextWindow": 32768}) + with self.assertLogs("sandbox_executor.local_llm", level="INFO") as logs: + (envelope,) = self.apply(config) + entry = config["providers"]["vmlx"]["models"][0] + self.assertEqual(entry["maxTokens"], 8192) + self.assertEqual((envelope.max_tokens, envelope.max_tokens_source), (8192, "synthesised")) + self.assertTrue( + any("'small'" in line and "8192" in line and "absent in host config" in line for line in logs.output) + ) + + def test_synthesis_is_capped(self): + config = _config({"id": "big", "contextWindow": 999424}) + (envelope,) = self.apply(config) + self.assertEqual(envelope.max_tokens, 16384) + self.assertEqual(config["providers"]["vmlx"]["models"][0]["maxTokens"], 16384) + + def test_valid_host_value_passes_through(self): + config = _config({"id": "m", "contextWindow": 32768, "maxTokens": 4000}) + (envelope,) = self.apply(config) + self.assertEqual(config["providers"]["vmlx"]["models"][0]["maxTokens"], 4000) + self.assertEqual(envelope.envelope_line(), "model=m context=32768 max_tokens=4000 source=host") + + def test_rejects_invalid_max_tokens(self): + for bad in (0, -1, 1.5, 4096.0, "4096", True, None, 32768 - 4096 + 1): + with self.subTest(bad=bad), self.assertRaises(local_llm.LocalLLMConfigError) as ctx: + self.apply(_config({"id": "m", "contextWindow": 32768, "maxTokens": bad})) + self.assertIn("'m'", str(ctx.exception)) + + def test_reserve_is_configurable(self): + config = _config({"id": "m", "contextWindow": 32768, "maxTokens": 30000}) + (envelope,) = self.apply(config, {"HOLON_CONTEXT_RESERVE_TOKENS": "1024"}) + self.assertEqual(envelope.max_tokens, 30000) + + def test_missing_context_window_uses_env_or_fails(self): + config = _config({"id": "m"}) + (envelope,) = self.apply(config, {"HOLON_LOCAL_CONTEXT_WINDOW": "65536"}) + self.assertEqual((envelope.context_window, envelope.max_tokens), (65536, 16384)) + self.assertEqual(config["providers"]["vmlx"]["models"][0]["contextWindow"], 65536) + with self.assertRaises(local_llm.LocalLLMConfigError) as ctx: + self.apply(_config({"id": "m"})) + self.assertIn("HOLON_LOCAL_CONTEXT_WINDOW", str(ctx.exception)) + + def test_invalid_context_window(self): + for bad in (0, -5, "32768", 3.5, False): + with self.subTest(bad=bad), self.assertRaises(local_llm.LocalLLMConfigError): + self.apply(_config({"id": "m", "contextWindow": bad})) + + def test_reasoning_mode_from_env_host_and_default(self): + cases = [ + ({"HOLON_REASONING_MODE": "LOW"}, {"reasoning": True}, ("low", "env"), True), + ({}, {"reasoning": "medium"}, ("medium", "host"), True), + ({}, {"reasoning": False}, ("off", "host"), False), + ({}, {"reasoning": True}, ("off", "default"), False), + ({}, {}, ("off", "default"), False), + ] + for env, extra, expected, flag in cases: + with self.subTest(env=env, extra=extra): + config = _config({"id": "m", "contextWindow": 32768, **extra}) + (envelope,) = self.apply(config, env) + self.assertEqual((envelope.reasoning, envelope.reasoning_source), expected) + self.assertIs(config["providers"]["vmlx"]["models"][0]["reasoning"], flag) + self.assertEqual(envelope.reasoning_line(), f"reasoning={expected[0]} source={expected[1]}") + + def test_env_reasoning_mode_never_overrides_host_reasoning_false(self): + config = _config( + {"id": "plain", "contextWindow": 32768, "reasoning": False}, + {"id": "thinker", "contextWindow": 32768, "reasoning": True}, + ) + with self.assertLogs("sandbox_executor.local_llm", level="WARNING") as logs: + plain, thinker = self.apply(config, {"HOLON_REASONING_MODE": "high"}) + self.assertEqual((plain.reasoning, plain.reasoning_source), ("off", "host")) + self.assertEqual((thinker.reasoning, thinker.reasoning_source), ("high", "env")) + models = config["providers"]["vmlx"]["models"] + self.assertIs(models[0]["reasoning"], False) + self.assertIs(models[1]["reasoning"], True) + self.assertTrue(any("'plain'" in line and "reasoning: false" in line for line in logs.output)) + with self.assertNoLogs("sandbox_executor.local_llm", level="WARNING"): + (envelope,) = self.apply( + _config({"id": "m", "contextWindow": 32768, "reasoning": False}), {"HOLON_REASONING_MODE": "off"} + ) + self.assertEqual((envelope.reasoning, envelope.reasoning_source), ("off", "host")) + + def test_invalid_reasoning_mode_raises(self): + with self.assertRaises(local_llm.LocalLLMConfigError): + self.apply(_config({"id": "m", "contextWindow": 32768}), {"HOLON_REASONING_MODE": "turbo"}) + with self.assertRaises(local_llm.LocalLLMConfigError): + self.apply(_config({"id": "m", "contextWindow": 32768, "reasoning": "max"})) + + def test_prepare_agent_dir_writes_envelope_and_thinking_level(self): + host_config = _config({"id": "m", "contextWindow": 32768}) + with ( + tempfile.TemporaryDirectory() as tmp, + patch.dict(os.environ, {"HOLON_REASONING_MODE": "minimal"}, clear=True), + ): + dest = os.path.join(tmp, "agent") + config = local_llm.prepare_agent_dir(dest, host_config=host_config) + with open(os.path.join(dest, "models.json")) as f: + on_disk = json.load(f) + with open(os.path.join(dest, "settings.json")) as f: + settings = json.load(f) + self.assertEqual(on_disk["providers"]["vmlx"]["baseUrl"], "http://host.docker.internal:8081/v1") + self.assertEqual(on_disk, config) + entry = on_disk["providers"]["vmlx"]["models"][0] + self.assertIsInstance(entry["maxTokens"], int) + self.assertIs(entry["reasoning"], True) + self.assertEqual(settings, {"defaultThinkingLevel": "minimal"}) + self.assertEqual(stat.S_IMODE(os.stat(os.path.join(dest, "settings.json")).st_mode), 0o644) + self.assertEqual(local_llm.container_env(dest), {"PI_CODING_AGENT_DIR": local_llm.CONTAINER_AGENT_DIR}) diff --git a/apps/sandbox-executor/tests/test_local_llm_health.py b/apps/sandbox-executor/tests/test_local_llm_health.py new file mode 100644 index 000000000..d4200407a --- /dev/null +++ b/apps/sandbox-executor/tests/test_local_llm_health.py @@ -0,0 +1,295 @@ +import contextlib +import http.server +import json +import os +import unittest +from unittest.mock import patch + +from sandbox_executor import local_llm + +from tests.loopback_http import serve_on_loopback + +# why: frozen fixtures for parser coverage only, not performance claims +HEALTH_OFF = {"status": "ok", "prefill_cache": {"enabled": False}, "effective_defaults": {"max_output_tokens": 8192}} +HEALTH_COLD = { + "status": "ok", + "prefill_cache": {"enabled": True, "entries": 0, "cached_tokens": 0, "memory_bytes": 0}, + "memory": {"used_bytes": 1048576, "limit_bytes": 8589934592}, + "effective_defaults": {"max_output_tokens": 8192}, +} +HEALTH_WARM = { + "status": "ok", + "prefill_cache": {"enabled": True, "entries": 3, "cached_tokens": 41234, "memory_bytes": 536870912}, + "memory": {"used_bytes": 2147483648, "limit_bytes": 8589934592}, + "effective_defaults": {"max_output_tokens": 4096}, +} +HEALTH_SMALL_PROMPT = { + "status": "ok", + "prefill_cache": {"enabled": True, "entries": 0}, + "effective_defaults": {"max_output_tokens": 16384, "max_prompt_tokens": 32768}, +} +HEALTH_MALFORMED = "not json" + + +def _fetcher(payload, calls=None): + def fetch(url, timeout): + if calls is not None: + calls.append((url, timeout)) + return payload if isinstance(payload, str) else json.dumps(payload).encode() + + return fetch + + +class TestHostGateways(unittest.TestCase): + def test_groups_providers_by_server_and_skips_unprobeable_endpoints(self): + host_config = { + "providers": { + "a": {"baseUrl": "http://127.0.0.1:8000/v1", "models": [{"id": "x"}]}, + "b": {"baseUrl": "http://127.0.0.1:8000/anthropic", "models": [{"id": "y"}]}, + "c": {"baseUrl": "http://gpu.lan:9000/v1", "models": [{"id": "z"}]}, + "cloud": {"baseUrl": "https://api.example.com/v1", "models": [{"id": "w"}]}, + } + } + allow_list = {"gpu.lan"} + config = local_llm.build_container_config(host_config, allow_list) + gateways = local_llm.host_gateways(host_config, config, {}, allow_list) + self.assertEqual( + gateways, + [ + ("http://127.0.0.1:8000/v1", frozenset({"a", "b"})), + ("http://gpu.lan:9000/v1", frozenset({"c"})), + ], + ) + + def test_synthesised_provider_maps_to_configured_base_url(self): + env = {"HOLON_LOCAL_BASE_URL": "http://localhost:11434/v1", "HOLON_LOCAL_MODELS": "m"} + with patch.dict(os.environ, env, clear=True): + config = local_llm.build_container_config(None) + gateways = local_llm.host_gateways(None, config, env) + self.assertEqual(gateways, [("http://localhost:11434/v1", frozenset(config["providers"]))]) + + +class TestGatewayHealth(unittest.TestCase): + def test_off_cold_warm_classification(self): + for payload, expected in ((HEALTH_OFF, "off"), (HEALTH_COLD, "cold"), (HEALTH_WARM, "warm")): + with self.subTest(expected=expected): + health = local_llm.probe_gateway_health("http://localhost:8081/v1", fetch=_fetcher(payload)) + self.assertEqual(health.prefill_cache, expected) + self.assertTrue(health.cache_line().startswith(f"prefill_cache={expected}")) + + def test_memory_figures_and_output_default(self): + health = local_llm.probe_gateway_health("http://localhost:8081/v1", fetch=_fetcher(HEALTH_WARM)) + self.assertEqual(health.max_output_tokens, 4096) + self.assertEqual(health.memory["memory_used_bytes"], 2147483648) + self.assertEqual(health.memory["cache_memory_bytes"], 536870912) + self.assertIn("memory_limit_bytes=8589934592", health.cache_line()) + + def test_malformed_response_is_unknown(self): + health = local_llm.probe_gateway_health("http://localhost:8081/v1", fetch=_fetcher(HEALTH_MALFORMED)) + self.assertEqual(health.prefill_cache, "unknown") + self.assertEqual(local_llm.parse_gateway_health("u", ["list"]).prefill_cache, "unknown") + self.assertEqual(local_llm.parse_gateway_health("u", {"status": "ok"}).prefill_cache, "unknown") + + def test_network_failure_is_unknown(self): + def failing(url, timeout): + raise OSError("connection refused") + + health = local_llm.probe_gateway_health("http://127.0.0.1:8081/v1", fetch=failing) + self.assertEqual(health.prefill_cache, "unknown") + self.assertIn("connection refused", health.cache_line()) + + def test_malformed_http_response_is_unknown(self): + import http.client + + for exc in (http.client.BadStatusLine("garbage"), http.client.IncompleteRead(b"{")): + with self.subTest(exc=type(exc).__name__): + + def failing(url, timeout, exc=exc): + raise exc + + health = local_llm.probe_gateway_health("http://127.0.0.1:8081/v1", fetch=failing) + self.assertEqual(health.prefill_cache, "unknown") + self.assertIn("health probe failed", health.cache_line()) + + def test_probe_targets_health_path_with_short_timeout(self): + calls = [] + local_llm.probe_gateway_health("http://localhost:8081/v1", fetch=_fetcher(HEALTH_OFF, calls)) + self.assertEqual(calls, [("http://localhost:8081/health", 2.0)]) + + def test_never_probes_remote_or_gateway_hosts(self): + calls = [] + for url in ("https://api.example.com/v1", "http://192.168.1.20:8081/v1", "http://host.docker.internal:8081/v1"): + with self.subTest(url=url): + self.assertIsNone(local_llm.probe_gateway_health(url, fetch=_fetcher(HEALTH_OFF, calls))) + self.assertEqual(calls, []) + allowed = local_llm.probe_gateway_health( + "http://192.168.1.20:8081/v1", fetch=_fetcher(HEALTH_OFF, calls), allow_list={"192.168.1.20"} + ) + self.assertEqual(allowed.prefill_cache, "off") + + def test_probe_url_drops_userinfo(self): + calls = [] + url = "http://user:s3cret@localhost:8081/v1" + health = local_llm.probe_gateway_health(url, fetch=_fetcher(HEALTH_OFF, calls)) + self.assertEqual(calls, [("http://localhost:8081/health", 2.0)]) + self.assertNotIn("s3cret", health.url) + self.assertEqual(local_llm.health_url("http://[::1]:8081/v1"), "http://[::1]:8081/health") + + def test_redact_url_drops_userinfo_query_and_fragment(self): + # why: probe credentials are built at runtime rather than written as literals + sample = "pw-" + "x" * 8 + url = f"http://someone:{sample}@gpu.example.com:8000/v1?key={sample}#{sample}" + self.assertEqual(local_llm.redact_url(url), "http://***@gpu.example.com:8000/v1") + self.assertEqual(local_llm.redact_url("http://localhost:11434/v1"), "http://localhost:11434/v1") + unparseable = f"http://someone:{sample}@[::1/v1?key={sample}" + self.assertNotIn(sample, local_llm.redact_url(unparseable)) + with self.assertRaises(ValueError) as caught: + local_llm._default_fetch(f"file://someone:{sample}@localhost/etc", 1.0) + self.assertNotIn(sample, str(caught.exception)) + + def test_redact_url_drops_userinfo_with_unencoded_delimiters(self): + # why: urlsplit ends the authority at the first / ? or #, so the host after it cannot be trusted + sample = "pw-" + "x" * 8 + head = "hd-" + "q" * 5 + for sep in ("/", "?", "#"): + for prefix in ("http://", "//", ""): + url = f"{prefix}someone:{head}{sep}{sample}@gpu.example.com:8000/v1?key={sample}#{sample}" + with self.subTest(sep=sep, prefix=prefix): + redacted = local_llm.redact_url(url) + self.assertEqual(redacted, f"{prefix}***") + for fragment in (sample, head, "someone", "gpu.example.com"): + self.assertNotIn(fragment, redacted) + bracketed = f"http://someone:{head}/{sample}@[::1]:8081/v1" + self.assertEqual(local_llm.redact_url(bracketed), "http://***") + plain = f"http://someone:{head}{sample}@[::1]:8081/v1" + self.assertEqual(local_llm.redact_url(plain), "http://***@[::1]:8081/v1") + + def test_redact_url_keeps_credential_free_urls_readable(self): + for url in ( + "http://localhost:11434/v1", + "https://gpu.example.com:8443/api/v1/", + "http://[::1]:8081/v1", + "host.docker.internal:8000/v1", + ): + with self.subTest(url=url): + self.assertEqual(local_llm.redact_url(url), url) + self.assertEqual(local_llm.redact_url("http://[::1/v1"), "http://***") + self.assertEqual(local_llm.redact_url("HTTP://Host.Example:80/a/b"), "HTTP://Host.Example:80/a/b") + self.assertEqual(local_llm.redact_url("http://localhost:8000/v1?key=k#f"), "http://localhost:8000/v1") + # why: withholding the host beats presenting a believable wrong one + other = "other" + ".example.net" + for url in ( + "http://localhost:8000/v1/@scope/models", + "http://localhost:8000/v1?owner=a@", + f"http://gpu.lan:8000/v1?owner=ops@{other}", + f"http://gpu.lan:8000/v1#ops@{other}", + f"http://gpu.lan:8000/v1/ops@{other}/x", + ): + with self.subTest(url=url): + self.assertEqual(local_llm.redact_url(url), "http://***") + self.assertEqual(local_llm.redact_url(f"//gpu.lan/v1?owner=ops@{other}"), "//***") + self.assertEqual(local_llm.redact_url(f"gpu.lan:8000/v1?owner=ops@{other}"), "***") + + def test_redact_url_never_leaks_userinfo_over_probe_matrix(self): + # why: the strip up to the last @ is unconditional, so no host shape may gate it + head = "hd-" + "q" * 5 + sample = "pw-" + "x" * 8 + name = "some" + "one" + hosts = ( + "gpu.example.com:8000/v1", + "[::1]:8081/v1", + "127.0.0.1:59999/v1", + "gpu.example.com:abc/v1", + "h\u00f4st.example/v1", + "[::1/v1", + "/v1", + "", + "gpu example.com/v1", + ) + validated = {"gpu.example.com:8000/v1", "[::1]:8081/v1", "127.0.0.1:59999/v1"} + for sep in ("", "/", "?", "#", "@", ":", "%", "%2F"): + for userinfo in (f"{name}:{head}{sep}{sample}", f"{head}{sep}{sample}"): + for host in hosts: + for prefix in ("http://", "//", ""): + url = f"{prefix}{userinfo}@{host}?key={sample}#{sample}" + with self.subTest(url=url): + redacted = local_llm.redact_url(url) + ambiguous = any(c in userinfo for c in "/?#") + # why: #96 message rule: a host that does not validate is withheld + withheld = ambiguous or host not in validated + expected = f"{prefix}***" if withheld else f"{prefix}***@{host}" + self.assertEqual(redacted, expected) + for fragment in (head, sample, name): + self.assertNotIn(fragment, redacted) + + def test_config_error_and_logs_never_echo_userinfo(self): + sample = "pw-" + "y" * 8 + env = { + "HOLON_LOCAL_BASE_URL": f"http://someone:{sample}@gpu.example.com:8000/v1?key={sample}", + "HOLON_LOCAL_MODELS": "m", + } + with patch.dict(os.environ, env, clear=True), self.assertRaises(local_llm.LocalLLMConfigError) as caught: + local_llm.build_container_config(None) + self.assertNotIn(sample, str(caught.exception)) + self.assertIn("(host gpu.example.com:8000)", str(caught.exception)) + host_config = {"providers": {"p": {"baseUrl": f"http://someone:{sample}@localhost:8081/v1", "models": []}}} + with self.assertLogs(local_llm.logger, level="INFO") as logs: + local_llm.build_container_config(host_config) + local_llm.rewrite_authority(f"http://someone:{sample}@localhost:bad/v1") + self.assertTrue(logs.output) + self.assertFalse(any(sample in line for line in logs.output)) + + def test_only_http_and_https_are_probed(self): + calls = [] + for url in ("file://localhost/etc", "ftp://127.0.0.1:21/x", "gopher://localhost:70/x"): + with self.subTest(url=url): + self.assertIsNone(local_llm.health_url(url)) + self.assertIsNone(local_llm.probe_gateway_health(url, fetch=_fetcher(HEALTH_OFF, calls))) + self.assertEqual(calls, []) + self.assertEqual(local_llm.health_url("HTTPS://localhost:8443/v1"), "https://localhost:8443/health") + with self.assertRaises(ValueError): + local_llm._default_fetch("file:///etc/hosts", 1.0) + + def test_default_fetch_caps_the_response_read(self): + size = local_llm.HEALTH_MAX_BYTES * 3 + + class Flood(http.server.BaseHTTPRequestHandler): + def do_GET(self): + self.send_response(200) + self.send_header("Content-Length", str(size)) + self.end_headers() + # why: the client hangs up at the cap, so the rest of the write may fail + with contextlib.suppress(OSError): + self.wfile.write(b"x" * size) + + def log_message(self, *args): + pass + + port = serve_on_loopback(self, Flood) + with self.assertRaises(ValueError): + local_llm._default_fetch(f"http://127.0.0.1:{port}/health", 2.0) + health = local_llm.probe_gateway_health(f"http://127.0.0.1:{port}/v1") + self.assertEqual(health.prefill_cache, "unknown") + self.assertIn("exceeds", health.error) + + def test_default_fetch_refuses_redirects(self): + class Redirector(http.server.BaseHTTPRequestHandler): + def do_GET(self): + self.send_response(302) + self.send_header("Location", "http://198.51.100.7/health") + self.end_headers() + + def log_message(self, *args): + pass + + port = serve_on_loopback(self, Redirector) + health = local_llm.probe_gateway_health(f"http://127.0.0.1:{port}/v1") + self.assertEqual(health.prefill_cache, "unknown") + self.assertIn("redirect refused", health.error) + + def test_max_prompt_tokens_parsed_from_defaults_or_top_level(self): + nested = {"effective_defaults": {"max_output_tokens": 16384, "max_prompt_tokens": 262144}} + self.assertEqual(local_llm.parse_gateway_health("u", nested).max_prompt_tokens, 262144) + top = {"effective_defaults": {"max_output_tokens": 16384}, "max_prompt_tokens": 32768} + self.assertEqual(local_llm.parse_gateway_health("u", top).max_prompt_tokens, 32768) + self.assertIsNone(local_llm.parse_gateway_health("u", HEALTH_OFF).max_prompt_tokens) diff --git a/apps/sandbox-executor/tests/test_local_llm_rewrites.py b/apps/sandbox-executor/tests/test_local_llm_rewrites.py new file mode 100644 index 000000000..c16790852 --- /dev/null +++ b/apps/sandbox-executor/tests/test_local_llm_rewrites.py @@ -0,0 +1,162 @@ +import os +import secrets +import unittest +from unittest.mock import patch + +from sandbox_executor import local_llm + +from tests.leak_assertions import assert_no_fragment, make_probe + + +class TestRewriteAuthority(unittest.TestCase): + def test_loopback_hosts_are_rewritten(self): + cases = { + "http://localhost:11434/v1": "http://host.docker.internal:11434/v1", + "http://127.0.0.1:8081/v1": "http://host.docker.internal:8081/v1", + "http://127.0.0.2:8081/v1": "http://host.docker.internal:8081/v1", + "http://127.1.2.3:8081/v1": "http://host.docker.internal:8081/v1", + "http://0.0.0.0:8081/v1": "http://host.docker.internal:8081/v1", + "http://[::1]:8081/v1": "http://host.docker.internal:8081/v1", + } + for url, expected in cases.items(): + with self.subTest(url=url): + self.assertEqual(local_llm.rewrite_authority(url), expected) + + def test_port_path_and_scheme_are_preserved(self): + self.assertEqual( + local_llm.rewrite_authority("https://localhost:11434/v1?stream=1"), + "https://host.docker.internal:11434/v1?stream=1", + ) + + def test_declared_host_local_authority_is_rewritten(self): + self.assertEqual( + local_llm.rewrite_authority("http://192.168.2.13:8081/v1", {"192.168.2.13"}), + "http://host.docker.internal:8081/v1", + ) + + def test_undeclared_lan_authority_is_untouched(self): + # why: safety invariant from the server-connect rewrite: never blanket-rewrite RFC1918 ranges + self.assertEqual( + local_llm.rewrite_authority("http://192.168.2.13:8081/v1"), + "http://192.168.2.13:8081/v1", + ) + self.assertEqual( + local_llm.rewrite_authority("http://192.168.2.99:8081/v1", {"192.168.2.13"}), + "http://192.168.2.99:8081/v1", + ) + + def test_public_authority_is_untouched(self): + self.assertEqual( + local_llm.rewrite_authority("https://api.openai.com/v1", {"192.168.2.13"}), + "https://api.openai.com/v1", + ) + + def test_gateway_authority_is_idempotent(self): + self.assertEqual( + local_llm.rewrite_authority("http://host.docker.internal:8081/v1"), + "http://host.docker.internal:8081/v1", + ) + + def test_malformed_authority_is_untouched(self): + self.assertEqual(local_llm.rewrite_authority("not a url"), "not a url") + self.assertEqual(local_llm.rewrite_authority(""), "") + + def test_allow_list_is_case_insensitive(self): + self.assertEqual( + local_llm.rewrite_authority("http://MyBox.lan:8081/v1", {"mybox.lan"}), + "http://host.docker.internal:8081/v1", + ) + + def test_port_qualified_authority_in_allow_list(self): + self.assertEqual( + local_llm.rewrite_authority("http://192.168.2.13:8081/v1", {"192.168.2.13:8081"}), + "http://host.docker.internal:8081/v1", + ) + self.assertEqual( + local_llm.rewrite_authority("http://192.168.2.13:9999/v1", {"192.168.2.13:8081"}), + "http://192.168.2.13:9999/v1", + ) + + def test_rewrite_authority_preserves_fragment(self): + self.assertEqual( + local_llm.rewrite_authority("http://127.0.0.1:8080/v1#section"), + "http://host.docker.internal:8080/v1#section", + ) + + +class TestOptIn(unittest.TestCase): + def test_off_by_default_and_never_inferred(self): + with patch.dict(os.environ, {}, clear=True): + self.assertFalse(local_llm.local_llm_requested()) + + def test_truthy_values(self): + for value in ("1", "true", "TRUE", "yes", "on"): + with self.subTest(value=value), patch.dict(os.environ, {"HOLON_LOCAL_LLM": value}, clear=True): + self.assertTrue(local_llm.local_llm_requested()) + + def test_falsy_values(self): + for value in ("0", "false", "off", ""): + with self.subTest(value=value), patch.dict(os.environ, {"HOLON_LOCAL_LLM": value}, clear=True): + self.assertFalse(local_llm.local_llm_requested()) + + def test_allow_list_parsing_drops_blanks_and_lowercases(self): + with patch.dict(os.environ, {"HOLON_HOST_LOCAL_HOSTS": " MyBox.lan, ,192.168.2.13,"}, clear=True): + self.assertEqual(local_llm.host_local_allow_list(), {"mybox.lan", "192.168.2.13"}) + + def test_allow_list_parsing_strips_paths(self): + with patch.dict(os.environ, {"HOLON_HOST_LOCAL_HOSTS": " 192.168.1.50:8081/v1, 10.0.0.1/ "}, clear=True): + self.assertEqual(local_llm.host_local_allow_list(), {"192.168.1.50:8081", "10.0.0.1"}) + + +class TestBaseUrlEchoRedaction(unittest.TestCase): + def _url(self, probe: str, authority: str) -> str: + return f"http://alice:{probe}@{authority}/v1" + + def test_rewrite_log_masks_userinfo(self): + probe = make_probe() + host_config = {"providers": {"vmlx": {"baseUrl": self._url(probe, "localhost:8081"), "models": [{"id": "m"}]}}} + with self.assertLogs(local_llm.logger, level="INFO") as logs: + local_llm.build_container_config(host_config) + text = "\n".join(logs.output) + self.assertIn("Rewrote provider", text) + self.assertIn("localhost:8081", text) + assert_no_fragment(text, probe) + + def test_unparseable_url_warnings_mask_userinfo(self): + probe = make_probe() + with self.assertLogs(local_llm.logger, level="WARNING") as logs: + self.assertEqual( + local_llm.rewrite_authority(self._url(probe, "localhost:notaport")), + self._url(probe, "localhost:notaport"), + ) + text = "\n".join(logs.output) + self.assertIn("invalid port or host", text) + self.assertIn("unparseable base URL", text) + self.assertIn("value withheld", text) + assert_no_fragment(text, probe) + + def test_unparseable_endpoint_error_withholds_value(self): + head = str(secrets.randbelow(900000) + 100000) + value = f"http://alice:{head}?{make_probe()}@localhost:8081/v1" + env = {"HOLON_LOCAL_BASE_URL": value, "HOLON_LOCAL_MODELS": "m1"} + with ( + patch.dict(os.environ, env, clear=True), + self.assertLogs(local_llm.logger, level="WARNING") as logs, + self.assertRaises(local_llm.LocalLLMConfigError) as ctx, + ): + local_llm.build_container_config(None) + text = "\n".join(logs.output) + "\n" + str(ctx.exception) + self.assertIn("HOLON_LOCAL_BASE_URL is not a valid URL", text) + self.assertNotIn(head, text) + assert_no_fragment(text, value) + + def test_unrewritable_endpoint_error_masks_userinfo(self): + probe = make_probe() + env = {"HOLON_LOCAL_BASE_URL": self._url(probe, "192.168.2.13:8081"), "HOLON_LOCAL_MODELS": "m1"} + with ( + patch.dict(os.environ, env, clear=True), + self.assertRaises(local_llm.LocalLLMConfigError) as ctx, + ): + local_llm.build_container_config(None) + self.assertIn("192.168.2.13:8081", str(ctx.exception)) + assert_no_fragment(str(ctx.exception), probe) From 8792775cf953c6e2f0ded134f77ce9995f908101 Mon Sep 17 00:00:00 2001 From: Holon Executor Agent Date: Wed, 2 Dec 2026 23:31:04 +0000 Subject: [PATCH 05/10] Step 3: register split local-llm test modules in self-doc gate coverage --- apps/sandbox-executor/tests/test_self_doc_gate_coverage.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/sandbox-executor/tests/test_self_doc_gate_coverage.py b/apps/sandbox-executor/tests/test_self_doc_gate_coverage.py index 55bfac5ba..72265eea0 100644 --- a/apps/sandbox-executor/tests/test_self_doc_gate_coverage.py +++ b/apps/sandbox-executor/tests/test_self_doc_gate_coverage.py @@ -78,7 +78,8 @@ "test_executor_agent_output_redaction.py test_executor_commands.py test_executor_outcome.py " "test_executor_sub_intents.py test_flow_default_branch_worktree.py test_flow_e2e_harness.py test_git.py " "test_host_worktree_sandbox.py test_init.py test_knowledge.py test_launcher_sidecar.py " - "test_ledger_append_only.py test_ledger_lock.py test_ledger_query.py test_local_llm.py test_makefile.py " + "test_ledger_append_only.py test_ledger_lock.py test_ledger_query.py test_local_llm.py " + "test_local_llm_config.py test_local_llm_health.py test_local_llm_rewrites.py test_makefile.py " "test_malformed_config_never_crashes.py test_planner.py test_preflight.py test_promotion_idempotence.py " "test_review_ensemble.py test_review_failure.py test_review_failure_detail.py " "test_review_loop_budget_guard.py test_review_loop_git_identity.py test_review_loop_worktree_head.py " @@ -137,7 +138,7 @@ def test_covered_modules_registry_is_unique_and_non_empty() -> None: - assert len(COVERED_MODULES) == 326 + assert len(COVERED_MODULES) == 329 assert len(set(COVERED_MODULES)) == len(COVERED_MODULES) assert f"{APP_PREFIX}/tests/test_self_doc_gate_coverage.py" in COVERED_MODULES From 1987d8842db4f8ba146c23e5fff271bd1d280a7e Mon Sep 17 00:00:00 2001 From: Holon Executor Agent Date: Wed, 2 Dec 2026 23:35:23 +0000 Subject: [PATCH 06/10] Step 4: verify split and record execution notes --- executions/E-1796254177-CLA-CO5.5.md | 55 +++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/executions/E-1796254177-CLA-CO5.5.md b/executions/E-1796254177-CLA-CO5.5.md index 34aca29ae..4b6edea31 100644 --- a/executions/E-1796254177-CLA-CO5.5.md +++ b/executions/E-1796254177-CLA-CO5.5.md @@ -10,11 +10,11 @@ shared helpers re-exported from the hub module and the new modules registered in | metric | value | | --------------------- | ----- | -| success_actual | 0.0 | -| entropy_actual | 0.0 | -| impact_actual | 0.0 | -| cost_actual | 0.0 | -| learning_value_actual | 0.0 | +| success_actual | 0.9 | +| entropy_actual | 2.4 | +| impact_actual | 35.0 | +| cost_actual | 4.5 | +| learning_value_actual | 1.2 | ## Steps Executed @@ -24,3 +24,48 @@ shared helpers re-exported from the hub module and the new modules registered in matching `grep -c "def test_"` (102). The sorted list is kept outside the repository. - Green baseline: `test_local_llm.py`, `cli/test_doctor.py`, `test_cli_unlimited_budgets.py` and `test_self_doc_gate_coverage.py`: 778 passed, 589 subtests passed in 3.69s. + +### Step 2: Move test classes into three focused modules and slim the hub + +- Classes were moved by line-range slicing with a scratch script outside the repository, followed by + `ruff check --fix --select F401,I` and `ruff format` on the four files. +- `test_local_llm_config.py` (448 lines): `_config`, `TestBuildContainerConfig`, `TestPrepareAgentDir`, + `TestRunnerValidation`, `TestModelEnvelope`. +- `test_local_llm_health.py` (295 lines): the `# why:` fixture line, `HEALTH_*`, `_fetcher`, `TestHostGateways`, + `TestGatewayHealth`; imports `_config` from config. +- `test_local_llm_rewrites.py` (162 lines): `TestRewriteAuthority`, `TestOptIn`, `TestBaseUrlEchoRedaction`; imports + `_config` from config. +- `test_local_llm.py` (407 lines): `TestLauncherIntegration` and `TestValidatedModelsConfig`, plus the re-exports of + `HEALTH_COLD`, `HEALTH_OFF`, `HEALTH_SMALL_PROMPT`, `HEALTH_WARM`, `_config`, `_fetcher` in `__all__`. +- Deviation: the plan put `TestValidatedModelsConfig` in the config module, but one of its tests calls + `TestLauncherIntegration._run`. Importing that `Test*` class would collect it twice, and importing the hub from config + would be circular, so `TestValidatedModelsConfig` stays in the hub next to the launcher tests. Bodies stay + byte-identical and every module is still under 700 lines. +- Zero-loss check: the sorted `Class::method` IDs after the split equal the 102-entry baseline (per file: hub 28, config + 36, health 19, rewrites 19; no duplicates). A sorted non-blank, non-import line diff against the original file is + empty. + +### Step 3: Register the new modules in the self-doc gate coverage list + +- Added `test_local_llm_config.py test_local_llm_health.py test_local_llm_rewrites.py` after `test_local_llm.py` in + `PINNED_MODULES_BY_DIR["tests"]` and changed the pinned count from 326 to 329. + +### Step 4: Verify zero test loss, run the affected tests, lint, then the full suite once + +- See `## Tests Run`. + +## Tests Run + +- Baseline (before the split): `test_local_llm.py`, `cli/test_doctor.py`, `test_cli_unlimited_budgets.py`, + `test_self_doc_gate_coverage.py`: 778 passed, 589 subtests passed in 3.69s. +- `uv run pytest --collect-only -q` on the four `test_local_llm*.py` modules: 102 tests, identical to the baseline. +- `uv run pytest -q` on the four `test_local_llm*.py` modules, `cli/test_doctor.py`, `test_cli_unlimited_budgets.py`: + 122 passed, 589 subtests passed in 1.96s. +- `uv run pytest -q test_self_doc_gate_coverage.py test_self_doc_modules.py`: 1162 passed in 16.87s. +- Affected set (four local-llm modules, `cli/test_doctor.py`, `test_cli_unlimited_budgets.py`, + `test_self_doc_gate_coverage.py`, `test_self_doc_modules.py`): 1284 passed, 589 subtests passed in 15.23s. +- `uv run task lint`: exit 0 (ruff, module budgets 441 modules passed, self-explaining check passed). +- `uv run task test` (one run, `-n auto --dist worksteal`): 1 failed, 11336 passed, 8 skipped in 210.91s. The failure is + `test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave`, a multi-process concurrency test unrelated + to the touched files. Rerunning that single node once: 1 passed in 4.98s, so it is treated as load-related flakiness. + Median of the single full-suite run: 210.91s. From 9005a6777d5fc9f5364f8542ff231e1b4263dcd1 Mon Sep 17 00:00:00 2001 From: Holon Executor Agent Date: Wed, 2 Dec 2026 23:46:31 +0000 Subject: [PATCH 07/10] execute: E-1796254177-CLA-CO5.5 completed for plan I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/_ --- .../executions/I-1796253987-hac-split-test-local-llm.jsonl | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl diff --git a/holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl b/holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl new file mode 100644 index 000000000..78a9e3694 --- /dev/null +++ b/holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl @@ -0,0 +1,7 @@ +{"action_id": "ACT-1796254528-be14c6a4", "execution_id": "E-1796254177-CLA-CO5.5", "action": "Executed agent claude-agent with model claude-opus-5-5", "category": "code", "target": "claude-agent:claude-opus-5-5", "outcome": "success", "entry_type": "action", "parent_action_id": null, "event_type": "command_execution", "labels": ["agent", "claude-agent", "execution"], "error_context": null, "mistake_category": null, "action_origin": "initial_implementation", "review_severity": null, "review_iteration": null, "review_finding_ids": null, "review_disposition": null, "rejection_reason": null, "introduced_by_action_id": null, "created_at": "2026-12-02T23:35:28.662159Z"} +{"execution_id": "E-1796254177-CLA-CO5.5", "action": "test_failure", "category": "test", "target": "stage_3", "outcome": "failure", "action_origin": "initial_implementation", "event_type": "test_run", "stage": "stage_3", "branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "run_id": "96415db9df7e", "head_sha": "1987d8842db4f8ba146c23e5fff271bd1d280a7e", "failing_test_ids": ["apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave", "apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_thread_appends_do_not_interleave"], "test_excerpts": {"apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave": "FAILED apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave\n______________ test_concurrent_process_appends_do_not_interleave _______________\n[gw15] linux -- Python 3.13.14 /home/holon/.cache/holon-venv/bin/python\ntmp_path = PosixPath('/tmp/pytest-of-holon/pytest-9/popen-gw15/test_concurrent_process_append0')\n def test_concurrent_process_appends_do_not_interleave(tmp_path: Path) -> None:\n ledger_file = str(tmp_path / \"executions.jsonl\")\n # why: fresh interpreters importing only sandbox_executor; forking a threaded xdist worker can h", "apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_thread_appends_do_not_interleave": "FAILED apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_thread_appends_do_not_interleave\n_______________ test_concurrent_thread_appends_do_not_interleave _______________\n[gw15] linux -- Python 3.13.14 /home/holon/.cache/holon-venv/bin/python\nself = \nfd = 15\n def _acquire_exclusive_lock(self, fd: int) -> None:\n start_time = time.monotonic()\n delay = self.initial_delay\n while True:\n try:\n> fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)\nE BlockingIOError"}, "environment": {"variables": ["HOLON_AGENT_ID", "HOLON_AGENT_SETTINGS", "HOLON_CONFIG_RESOLVED", "HOLON_ROLE", "HOLON_SKIP_PREFLIGHT", "HOLON_STAGE_BUDGET_EXECUTE_MINUTES", "HOLON_STAGE_BUDGET_SECONDS", "HOLON_TARGET_WORKTREE", "HOLON_TOKEN_REDUCE", "PYTHONPATH", "PYTHON_SHA256", "PYTHON_VERSION", "UV_FROZEN", "UV_PROJECT_ENVIRONMENT"], "values": {"UV_FROZEN": "1"}, "identity_overrides": [], "HOME_set": true, "TMPDIR_set": false}, "classification": "flaky", "failure_signature": "f2681da753a44cfc", "iteration": 0, "model_tier": "claude-opus-5-5", "base_check": "not_run", "error_context": "FAILED apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave\n______________ test_concurrent_process_appends_do_not_interleave _______________\n[gw15] linux -- Python 3.13.14 /home/holon/.cache/holon-venv/bin/python\ntmp_path = PosixPath('/tmp/pytest-of-holon/pytest-9/popen-gw15/test_concurrent_process_append0')\n def test_concurrent_process_appends_do_not_interleave(tmp_path: Path) -> None:\n ledger_file = str(tmp_path / \"executions.jsonl\")\n # why: fresh interpreters importing only sandbox_executor; forking a threaded xdist worker can h", "entry_type": "action", "action_id": "ACT-1796254829-6c1151ab", "created_at": "2026-12-02T23:40:29.624424Z"} +{"execution_id": "E-1796254177-CLA-CO5.5", "action": "test_failure", "category": "test", "target": "stage_3", "outcome": "success", "action_origin": "initial_implementation", "event_type": "test_run", "stage": "stage_3", "branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "run_id": "96415db9df7e", "head_sha": "1987d8842db4f8ba146c23e5fff271bd1d280a7e", "failing_test_ids": ["apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave", "apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_thread_appends_do_not_interleave"], "test_excerpts": {"apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave": "FAILED apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave\n______________ test_concurrent_process_appends_do_not_interleave _______________\n[gw15] linux -- Python 3.13.14 /home/holon/.cache/holon-venv/bin/python\ntmp_path = PosixPath('/tmp/pytest-of-holon/pytest-9/popen-gw15/test_concurrent_process_append0')\n def test_concurrent_process_appends_do_not_interleave(tmp_path: Path) -> None:\n ledger_file = str(tmp_path / \"executions.jsonl\")\n # why: fresh interpreters importing only sandbox_executor; forking a threaded xdist worker can h", "apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_thread_appends_do_not_interleave": "FAILED apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_thread_appends_do_not_interleave\n_______________ test_concurrent_thread_appends_do_not_interleave _______________\n[gw15] linux -- Python 3.13.14 /home/holon/.cache/holon-venv/bin/python\nself = \nfd = 15\n def _acquire_exclusive_lock(self, fd: int) -> None:\n start_time = time.monotonic()\n delay = self.initial_delay\n while True:\n try:\n> fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)\nE BlockingIOError"}, "environment": {"variables": ["HOLON_AGENT_ID", "HOLON_AGENT_SETTINGS", "HOLON_CONFIG_RESOLVED", "HOLON_ROLE", "HOLON_SKIP_PREFLIGHT", "HOLON_STAGE_BUDGET_EXECUTE_MINUTES", "HOLON_STAGE_BUDGET_SECONDS", "HOLON_TARGET_WORKTREE", "HOLON_TOKEN_REDUCE", "PYTHONPATH", "PYTHON_SHA256", "PYTHON_VERSION", "UV_FROZEN", "UV_PROJECT_ENVIRONMENT"], "values": {"UV_FROZEN": "1"}, "identity_overrides": [], "HOME_set": true, "TMPDIR_set": false}, "classification": "flaky", "failure_signature": "f2681da753a44cfc", "iteration": 0, "model_tier": "claude-opus-5-5", "base_check": "not_run", "error_context": "FAILED apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave\n______________ test_concurrent_process_appends_do_not_interleave _______________\n[gw15] linux -- Python 3.13.14 /home/holon/.cache/holon-venv/bin/python\ntmp_path = PosixPath('/tmp/pytest-of-holon/pytest-9/popen-gw15/test_concurrent_process_append0')\n def test_concurrent_process_appends_do_not_interleave(tmp_path: Path) -> None:\n ledger_file = str(tmp_path / \"executions.jsonl\")\n # why: fresh interpreters importing only sandbox_executor; forking a threaded xdist worker can h", "entry_type": "action", "action_id": "ACT-1796254836-22794c9b", "created_at": "2026-12-02T23:40:36.234546Z"} +{"execution_id": "E-1796254177-CLA-CO5.5", "action": "test_failure", "category": "test", "target": "stage_3", "outcome": "success", "action_origin": "initial_implementation", "event_type": "test_run", "stage": "stage_3", "branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "run_id": "96415db9df7e", "head_sha": "1987d8842db4f8ba146c23e5fff271bd1d280a7e", "failing_test_ids": ["apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave", "apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_thread_appends_do_not_interleave"], "test_excerpts": {"apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave": "FAILED apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave\n______________ test_concurrent_process_appends_do_not_interleave _______________\n[gw15] linux -- Python 3.13.14 /home/holon/.cache/holon-venv/bin/python\ntmp_path = PosixPath('/tmp/pytest-of-holon/pytest-9/popen-gw15/test_concurrent_process_append0')\n def test_concurrent_process_appends_do_not_interleave(tmp_path: Path) -> None:\n ledger_file = str(tmp_path / \"executions.jsonl\")\n # why: fresh interpreters importing only sandbox_executor; forking a threaded xdist worker can h", "apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_thread_appends_do_not_interleave": "FAILED apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_thread_appends_do_not_interleave\n_______________ test_concurrent_thread_appends_do_not_interleave _______________\n[gw15] linux -- Python 3.13.14 /home/holon/.cache/holon-venv/bin/python\nself = \nfd = 15\n def _acquire_exclusive_lock(self, fd: int) -> None:\n start_time = time.monotonic()\n delay = self.initial_delay\n while True:\n try:\n> fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)\nE BlockingIOError"}, "environment": {"variables": ["HOLON_AGENT_ID", "HOLON_AGENT_SETTINGS", "HOLON_CONFIG_RESOLVED", "HOLON_ROLE", "HOLON_SKIP_PREFLIGHT", "HOLON_STAGE_BUDGET_EXECUTE_MINUTES", "HOLON_STAGE_BUDGET_SECONDS", "HOLON_TARGET_WORKTREE", "HOLON_TOKEN_REDUCE", "PYTHONPATH", "PYTHON_SHA256", "PYTHON_VERSION", "UV_FROZEN", "UV_PROJECT_ENVIRONMENT"], "values": {"UV_FROZEN": "1"}, "identity_overrides": [], "HOME_set": true, "TMPDIR_set": false}, "classification": "flaky", "failure_signature": "f2681da753a44cfc", "iteration": 0, "model_tier": "claude-opus-5-5", "base_check": "not_run", "error_context": "FAILED apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave\n______________ test_concurrent_process_appends_do_not_interleave _______________\n[gw15] linux -- Python 3.13.14 /home/holon/.cache/holon-venv/bin/python\ntmp_path = PosixPath('/tmp/pytest-of-holon/pytest-9/popen-gw15/test_concurrent_process_append0')\n def test_concurrent_process_appends_do_not_interleave(tmp_path: Path) -> None:\n ledger_file = str(tmp_path / \"executions.jsonl\")\n # why: fresh interpreters importing only sandbox_executor; forking a threaded xdist worker can h", "entry_type": "action", "action_id": "ACT-1796254842-d66d9d28", "created_at": "2026-12-02T23:40:42.069176Z"} +{"execution_id": "E-1796254177-CLA-CO5.5", "action": "test_failure", "category": "test", "target": "stage_3", "outcome": "failure", "action_origin": "initial_implementation", "event_type": "test_run", "stage": "stage_3", "branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "run_id": "96415db9df7e", "head_sha": "1987d8842db4f8ba146c23e5fff271bd1d280a7e", "failing_test_ids": ["apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave", "apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_thread_appends_do_not_interleave"], "test_excerpts": {"apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave": "FAILED apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave\n______________ test_concurrent_process_appends_do_not_interleave _______________\n[gw0] linux -- Python 3.13.14 /home/holon/.cache/holon-venv/bin/python\ntmp_path = PosixPath('/tmp/pytest-of-holon/pytest-15/popen-gw0/test_concurrent_process_append0')\n def test_concurrent_process_appends_do_not_interleave(tmp_path: Path) -> None:\n ledger_file = str(tmp_path / \"executions.jsonl\")\n # why: fresh interpreters importing only sandbox_executor; forking a threaded xdist worker can ha", "apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_thread_appends_do_not_interleave": "FAILED apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_thread_appends_do_not_interleave\n_______________ test_concurrent_thread_appends_do_not_interleave _______________\n[gw0] linux -- Python 3.13.14 /home/holon/.cache/holon-venv/bin/python\nself = \nfd = 14\n def _acquire_exclusive_lock(self, fd: int) -> None:\n start_time = time.monotonic()\n delay = self.initial_delay\n while True:\n try:\n> fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)\nE BlockingIOError:"}, "environment": {"variables": ["HOLON_AGENT_ID", "HOLON_AGENT_SETTINGS", "HOLON_CONFIG_RESOLVED", "HOLON_ROLE", "HOLON_SKIP_PREFLIGHT", "HOLON_STAGE_BUDGET_EXECUTE_MINUTES", "HOLON_STAGE_BUDGET_SECONDS", "HOLON_TARGET_WORKTREE", "HOLON_TOKEN_REDUCE", "PYTHONPATH", "PYTHON_SHA256", "PYTHON_VERSION", "UV_FROZEN", "UV_PROJECT_ENVIRONMENT"], "values": {"UV_FROZEN": "1"}, "identity_overrides": [], "HOME_set": true, "TMPDIR_set": false}, "classification": "flaky", "failure_signature": "f422a36bcb936395", "iteration": 0, "model_tier": "claude-opus-5-5", "base_check": "not_run", "error_context": "FAILED apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave\n______________ test_concurrent_process_appends_do_not_interleave _______________\n[gw0] linux -- Python 3.13.14 /home/holon/.cache/holon-venv/bin/python\ntmp_path = PosixPath('/tmp/pytest-of-holon/pytest-15/popen-gw0/test_concurrent_process_append0')\n def test_concurrent_process_appends_do_not_interleave(tmp_path: Path) -> None:\n ledger_file = str(tmp_path / \"executions.jsonl\")\n # why: fresh interpreters importing only sandbox_executor; forking a threaded xdist worker can ha", "entry_type": "action", "action_id": "ACT-1796255188-8a699da7", "created_at": "2026-12-02T23:46:28.846174Z"} +{"entry_type": "summary", "execution_id": "E-1796254177-CLA-CO5.5", "plan_branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/_", "agent": "claude-agent", "agent_version": "2.1.302", "model": "claude-opus-5-5", "status": "success", "summary": "Plan executed successfully", "created_at": "2026-12-02T23:29:37.966982Z", "agent_output_truncated": false, "agent_output_bytes": 495, "ledger_revision": 1, "execution_notes": "executions/E-1796254177-CLA-CO5.5.md", "execution_notes_valid": true, "elapsed_seconds": 1013.3, "budget_seconds": 604719.0, "test_pass_rate": 0.9998235864867249, "tests_passed": 11335, "tests_failed": 2, "tests_errored": 0, "test_exit_code": 1, "test_source": "stage_3", "test_failure_classification": "flaky", "test_failure_status": "blocked", "test_failure_blocked_reason": "persistent flakiness", "test_failure_rows": ["ACT-1796254829-6c1151ab", "ACT-1796254836-22794c9b", "ACT-1796254842-d66d9d28", "ACT-1796255188-8a699da7"], "test_fix_tier": "claude-opus-5-5"} +{"action_id": "ACT-1796255191-95ad7208", "execution_id": "E-1796254177-CLA-CO5.5", "action": "Committed execution changes: execute: E-1796254177-CLA-CO5.5 completed for plan I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/_", "category": "code", "target": "HEAD", "outcome": "success", "entry_type": "action", "parent_action_id": null, "event_type": "git_mutation", "labels": ["commit", "git"], "error_context": null, "mistake_category": null, "action_origin": "initial_implementation", "review_severity": null, "review_iteration": null, "review_finding_ids": null, "review_disposition": null, "rejection_reason": null, "introduced_by_action_id": null, "created_at": "2026-12-02T23:46:31.288613Z"} From ebeb16c2f1317f2714794ce1eee9ab4c82ec9886 Mon Sep 17 00:00:00 2001 From: Holon Review Loop Agent Date: Thu, 3 Dec 2026 11:23:42 +1100 Subject: [PATCH 08/10] chore(review): record review ledger rows (iteration 1) Action-Origin: pr_review Review-Iteration: 1 --- .../I-1796253987-hac-split-test-local-llm.jsonl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl b/holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl index 78a9e3694..b3db9b248 100644 --- a/holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl +++ b/holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl @@ -5,3 +5,13 @@ {"execution_id": "E-1796254177-CLA-CO5.5", "action": "test_failure", "category": "test", "target": "stage_3", "outcome": "failure", "action_origin": "initial_implementation", "event_type": "test_run", "stage": "stage_3", "branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "run_id": "96415db9df7e", "head_sha": "1987d8842db4f8ba146c23e5fff271bd1d280a7e", "failing_test_ids": ["apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave", "apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_thread_appends_do_not_interleave"], "test_excerpts": {"apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave": "FAILED apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave\n______________ test_concurrent_process_appends_do_not_interleave _______________\n[gw0] linux -- Python 3.13.14 /home/holon/.cache/holon-venv/bin/python\ntmp_path = PosixPath('/tmp/pytest-of-holon/pytest-15/popen-gw0/test_concurrent_process_append0')\n def test_concurrent_process_appends_do_not_interleave(tmp_path: Path) -> None:\n ledger_file = str(tmp_path / \"executions.jsonl\")\n # why: fresh interpreters importing only sandbox_executor; forking a threaded xdist worker can ha", "apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_thread_appends_do_not_interleave": "FAILED apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_thread_appends_do_not_interleave\n_______________ test_concurrent_thread_appends_do_not_interleave _______________\n[gw0] linux -- Python 3.13.14 /home/holon/.cache/holon-venv/bin/python\nself = \nfd = 14\n def _acquire_exclusive_lock(self, fd: int) -> None:\n start_time = time.monotonic()\n delay = self.initial_delay\n while True:\n try:\n> fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)\nE BlockingIOError:"}, "environment": {"variables": ["HOLON_AGENT_ID", "HOLON_AGENT_SETTINGS", "HOLON_CONFIG_RESOLVED", "HOLON_ROLE", "HOLON_SKIP_PREFLIGHT", "HOLON_STAGE_BUDGET_EXECUTE_MINUTES", "HOLON_STAGE_BUDGET_SECONDS", "HOLON_TARGET_WORKTREE", "HOLON_TOKEN_REDUCE", "PYTHONPATH", "PYTHON_SHA256", "PYTHON_VERSION", "UV_FROZEN", "UV_PROJECT_ENVIRONMENT"], "values": {"UV_FROZEN": "1"}, "identity_overrides": [], "HOME_set": true, "TMPDIR_set": false}, "classification": "flaky", "failure_signature": "f422a36bcb936395", "iteration": 0, "model_tier": "claude-opus-5-5", "base_check": "not_run", "error_context": "FAILED apps/sandbox-executor/tests/test_ledger_lock.py::test_concurrent_process_appends_do_not_interleave\n______________ test_concurrent_process_appends_do_not_interleave _______________\n[gw0] linux -- Python 3.13.14 /home/holon/.cache/holon-venv/bin/python\ntmp_path = PosixPath('/tmp/pytest-of-holon/pytest-15/popen-gw0/test_concurrent_process_append0')\n def test_concurrent_process_appends_do_not_interleave(tmp_path: Path) -> None:\n ledger_file = str(tmp_path / \"executions.jsonl\")\n # why: fresh interpreters importing only sandbox_executor; forking a threaded xdist worker can ha", "entry_type": "action", "action_id": "ACT-1796255188-8a699da7", "created_at": "2026-12-02T23:46:28.846174Z"} {"entry_type": "summary", "execution_id": "E-1796254177-CLA-CO5.5", "plan_branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/_", "agent": "claude-agent", "agent_version": "2.1.302", "model": "claude-opus-5-5", "status": "success", "summary": "Plan executed successfully", "created_at": "2026-12-02T23:29:37.966982Z", "agent_output_truncated": false, "agent_output_bytes": 495, "ledger_revision": 1, "execution_notes": "executions/E-1796254177-CLA-CO5.5.md", "execution_notes_valid": true, "elapsed_seconds": 1013.3, "budget_seconds": 604719.0, "test_pass_rate": 0.9998235864867249, "tests_passed": 11335, "tests_failed": 2, "tests_errored": 0, "test_exit_code": 1, "test_source": "stage_3", "test_failure_classification": "flaky", "test_failure_status": "blocked", "test_failure_blocked_reason": "persistent flakiness", "test_failure_rows": ["ACT-1796254829-6c1151ab", "ACT-1796254836-22794c9b", "ACT-1796254842-d66d9d28", "ACT-1796255188-8a699da7"], "test_fix_tier": "claude-opus-5-5"} {"action_id": "ACT-1796255191-95ad7208", "execution_id": "E-1796254177-CLA-CO5.5", "action": "Committed execution changes: execute: E-1796254177-CLA-CO5.5 completed for plan I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/_", "category": "code", "target": "HEAD", "outcome": "success", "entry_type": "action", "parent_action_id": null, "event_type": "git_mutation", "labels": ["commit", "git"], "error_context": null, "mistake_category": null, "action_origin": "initial_implementation", "review_severity": null, "review_iteration": null, "review_finding_ids": null, "review_disposition": null, "rejection_reason": null, "introduced_by_action_id": null, "created_at": "2026-12-02T23:46:31.288613Z"} +{"action_id": "ACT-REV-1796257407-7cdef611", "execution_id": "REV-ITR-1-1796257407", "action": "Review Loop iteration 1 reviewer 1 completed", "category": "code", "target": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "outcome": "success", "entry_type": "action", "action_origin": "pr_review", "review_severity": null, "review_iteration": 1, "review_finding_ids": null, "labels": ["review", "reviewer", "iteration-1"], "error_context": null, "review_reviewer_index": 1, "review_agent": "claude-agent", "review_model": "claude-opus-5-5", "review_status": "COMPLETED", "review_verdict": "APPROVED", "review_counts": {"critical": 0, "important": 0, "nit": 0}, "created_at": "2026-12-03T00:23:27.905867Z"} +{"action_id": "ACT-REV-1796257407-8c272798", "execution_id": "REV-ITR-1-1796257407", "action": "Review Loop iteration 1 reviewer 2 completed", "category": "code", "target": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "outcome": "success", "entry_type": "action", "action_origin": "pr_review", "review_severity": null, "review_iteration": 1, "review_finding_ids": null, "labels": ["review", "reviewer", "iteration-1"], "error_context": null, "review_reviewer_index": 2, "review_agent": "claude-agent", "review_model": "claude-opus-5-5", "review_status": "COMPLETED", "review_verdict": "APPROVED", "review_counts": {"critical": 0, "important": 0, "nit": 0}, "created_at": "2026-12-03T00:23:27.924195Z"} +{"action_id": "ACT-REV-1796257407-b55741ce", "execution_id": "REV-ITR-1-1796257407", "action": "Review Loop iteration 1 reviewer 3 completed", "category": "code", "target": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "outcome": "success", "entry_type": "action", "action_origin": "pr_review", "review_severity": null, "review_iteration": 1, "review_finding_ids": null, "labels": ["review", "reviewer", "iteration-1"], "error_context": null, "review_reviewer_index": 3, "review_agent": "claude-agent", "review_model": "claude-opus-5-5", "review_status": "COMPLETED", "review_verdict": "APPROVED", "review_counts": {"critical": 0, "important": 0, "nit": 0}, "created_at": "2026-12-03T00:23:27.935270Z"} +{"action_id": "ACT-REV-1796257414-dd562483", "execution_id": "REV-ITR-1-1796257414", "action": "Review Loop iteration 1 evaluation for I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "category": "code", "target": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "outcome": "success", "entry_type": "action", "action_origin": "pr_review", "review_severity": null, "review_iteration": 1, "review_finding_ids": null, "labels": ["review", "review-loop", "iteration-1"], "error_context": null, "created_at": "2026-12-03T00:23:34.048851Z"} +{"action_id": "ACT-REV-1796257414-a31ec237", "execution_id": "REV-ITR-1-1796257414", "action": "Review Loop iteration 1 reviewer 1 completed", "category": "code", "target": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "outcome": "success", "entry_type": "action", "action_origin": "pr_review", "review_severity": null, "review_iteration": 1, "review_finding_ids": null, "labels": ["review", "reviewer", "iteration-1"], "error_context": null, "review_reviewer_index": 1, "review_agent": "claude-agent", "review_model": "claude-opus-5-5", "review_status": "COMPLETED", "review_verdict": "APPROVED", "review_counts": {"critical": 0, "important": 0, "nit": 0}, "created_at": "2026-12-03T00:23:34.050046Z"} +{"action_id": "ACT-REV-1796257414-c2974f86", "execution_id": "REV-ITR-1-1796257414", "action": "Review Loop iteration 1 reviewer 2 completed", "category": "code", "target": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "outcome": "success", "entry_type": "action", "action_origin": "pr_review", "review_severity": null, "review_iteration": 1, "review_finding_ids": null, "labels": ["review", "reviewer", "iteration-1"], "error_context": null, "review_reviewer_index": 2, "review_agent": "claude-agent", "review_model": "claude-opus-5-5", "review_status": "COMPLETED", "review_verdict": "APPROVED", "review_counts": {"critical": 0, "important": 0, "nit": 0}, "created_at": "2026-12-03T00:23:34.050847Z"} +{"action_id": "ACT-REV-1796257414-011b22ad", "execution_id": "REV-ITR-1-1796257414", "action": "Review Loop iteration 1 reviewer 3 completed", "category": "code", "target": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "outcome": "success", "entry_type": "action", "action_origin": "pr_review", "review_severity": null, "review_iteration": 1, "review_finding_ids": null, "labels": ["review", "reviewer", "iteration-1"], "error_context": null, "review_reviewer_index": 3, "review_agent": "claude-agent", "review_model": "claude-opus-5-5", "review_status": "COMPLETED", "review_verdict": "APPROVED", "review_counts": {"critical": 0, "important": 0, "nit": 0}, "created_at": "2026-12-03T00:23:34.051610Z"} +{"action_id": "ACT-POST-1796257417-ef855f4e", "execution_id": "REV-POST-1796257417", "action": "Review consensus dual-posted to GitHub for I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "category": "code", "target": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "outcome": "success", "entry_type": "action", "action_origin": "pr_review", "review_iteration": 1, "labels": ["review", "github", "dual-post"], "created_at": "2026-12-03T00:23:37.966295Z"} +{"execution_id": "REV-1796257420-7de3e2bf-claude-agent", "plan_branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/_", "execution_branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "agent": "claude-agent", "agent_version": "1.4.0", "model": "claude-opus-5-5", "status": "approved", "entry_type": "summary", "summary": "Review Loop reached consensus approval after 1 iteration(s); PR ready for maintainer merge; final verdicts: Reviewer 1 APPROVED (0/0/0); Reviewer 2 APPROVED (0/0/0); Reviewer 3 APPROVED (0/0/0)", "created_at": "2026-12-03T00:23:40.556Z", "total_iterations": 1, "max_iterations": 25, "ci_checks_summary": {"source": "github_cli", "total": 16, "passed": 16, "failed": 0, "pending": 0, "skipped": 0, "all_passed": true, "checks": [{"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313115/job/143887254670", "name": "unit (macos-latest, shard 2 of 2)", "state": "SUCCESS", "workflow": "Test - Unit"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313090/job/143887254378", "name": "build (macos-latest)", "state": "SUCCESS", "workflow": "Run Make"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313115/job/143887254453", "name": "unit (macos-latest, shard 1 of 2)", "state": "SUCCESS", "workflow": "Test - Unit"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313002/job/143887255311", "name": "build", "state": "SUCCESS", "workflow": "Docker Build"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313008/job/143887253156", "name": "hygiene (ubuntu-latest)", "state": "SUCCESS", "workflow": "Test - Hygiene"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313090/job/143887254106", "name": "build (ubuntu-latest)", "state": "SUCCESS", "workflow": "Run Make"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313115/job/143887254680", "name": "unit (ubuntu-latest)", "state": "SUCCESS", "workflow": "Test - Unit"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313078/job/143887253776", "name": "Workspace survival (ubuntu-latest)", "state": "SUCCESS", "workflow": "Test - Stress"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313240/job/143887255346", "name": "commit-trailers", "state": "SUCCESS", "workflow": "Test - Commit Trailers"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999312965/job/143887254097", "name": "self-doc-behavior", "state": "SUCCESS", "workflow": "Test - Self-Doc Behavior"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313019/job/143887253493", "name": "integration (ubuntu-latest)", "state": "SUCCESS", "workflow": "Test - Integration"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313045/job/143887253026", "name": "scan", "state": "SUCCESS", "workflow": "Test - No Harness References"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313029/job/143887253972", "name": "ledger-invariants", "state": "SUCCESS", "workflow": "Test - Ledger Invariants"}, {"bucket": "pass", "event": "", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/runs/143887504291", "name": "CodeQL", "state": "SUCCESS", "workflow": ""}, {"bucket": "pass", "event": "dynamic", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999306801/job/143887239688", "name": "Analyze (python)", "state": "SUCCESS", "workflow": "CodeQL"}, {"bucket": "pass", "event": "dynamic", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999306801/job/143887239316", "name": "Analyze (actions)", "state": "SUCCESS", "workflow": "CodeQL"}], "test_source": "ci_head", "test_head_sha": "9005a6777d5fc9f5364f8542ff231e1b4263dcd1"}, "trailers": {"action_origin": "pr_review", "review_severity": null, "review_iteration": 1, "review_finding_ids": ["none"], "review_disposition": null, "rejection_reason": null, "introduced_by_action_id": null, "consulted_knowledge_ids": null}, "review_post_withheld": null} +{"execution_id": "REV-1796257420-7de3e2bf-claude-agent", "action": "Review Loop executed for I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "category": "test", "target": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "verdict": "success", "outcome": "success", "entry_type": "action", "context_fingerprint": "a6fb125f2a43429a", "labels": ["review", "review-loop", "claude-agent"], "error_context": null, "action_id": "ACT-1796257420-d21268f8", "created_at": "2026-12-03T00:23:40.556792Z"} From 9e89227ade3277248cefb6f2e0cb3556d542024d Mon Sep 17 00:00:00 2001 From: Holon Calibrate Agent Date: Thu, 3 Dec 2026 11:24:11 +1100 Subject: [PATCH 09/10] chore(calibration): add calibration report for P-1796254011-CLA-CO5.5 --- ...-1796253987-hac-split-test-local-llm.jsonl | 1 + .../P-1796254011-CLA-CO5.5_calibration.md | 103 ++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 plans/I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5_calibration.md diff --git a/holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl b/holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl index b3db9b248..ecd5ca840 100644 --- a/holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl +++ b/holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl @@ -15,3 +15,4 @@ {"action_id": "ACT-POST-1796257417-ef855f4e", "execution_id": "REV-POST-1796257417", "action": "Review consensus dual-posted to GitHub for I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "category": "code", "target": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "outcome": "success", "entry_type": "action", "action_origin": "pr_review", "review_iteration": 1, "labels": ["review", "github", "dual-post"], "created_at": "2026-12-03T00:23:37.966295Z"} {"execution_id": "REV-1796257420-7de3e2bf-claude-agent", "plan_branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/_", "execution_branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "agent": "claude-agent", "agent_version": "1.4.0", "model": "claude-opus-5-5", "status": "approved", "entry_type": "summary", "summary": "Review Loop reached consensus approval after 1 iteration(s); PR ready for maintainer merge; final verdicts: Reviewer 1 APPROVED (0/0/0); Reviewer 2 APPROVED (0/0/0); Reviewer 3 APPROVED (0/0/0)", "created_at": "2026-12-03T00:23:40.556Z", "total_iterations": 1, "max_iterations": 25, "ci_checks_summary": {"source": "github_cli", "total": 16, "passed": 16, "failed": 0, "pending": 0, "skipped": 0, "all_passed": true, "checks": [{"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313115/job/143887254670", "name": "unit (macos-latest, shard 2 of 2)", "state": "SUCCESS", "workflow": "Test - Unit"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313090/job/143887254378", "name": "build (macos-latest)", "state": "SUCCESS", "workflow": "Run Make"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313115/job/143887254453", "name": "unit (macos-latest, shard 1 of 2)", "state": "SUCCESS", "workflow": "Test - Unit"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313002/job/143887255311", "name": "build", "state": "SUCCESS", "workflow": "Docker Build"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313008/job/143887253156", "name": "hygiene (ubuntu-latest)", "state": "SUCCESS", "workflow": "Test - Hygiene"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313090/job/143887254106", "name": "build (ubuntu-latest)", "state": "SUCCESS", "workflow": "Run Make"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313115/job/143887254680", "name": "unit (ubuntu-latest)", "state": "SUCCESS", "workflow": "Test - Unit"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313078/job/143887253776", "name": "Workspace survival (ubuntu-latest)", "state": "SUCCESS", "workflow": "Test - Stress"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313240/job/143887255346", "name": "commit-trailers", "state": "SUCCESS", "workflow": "Test - Commit Trailers"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999312965/job/143887254097", "name": "self-doc-behavior", "state": "SUCCESS", "workflow": "Test - Self-Doc Behavior"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313019/job/143887253493", "name": "integration (ubuntu-latest)", "state": "SUCCESS", "workflow": "Test - Integration"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313045/job/143887253026", "name": "scan", "state": "SUCCESS", "workflow": "Test - No Harness References"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313029/job/143887253972", "name": "ledger-invariants", "state": "SUCCESS", "workflow": "Test - Ledger Invariants"}, {"bucket": "pass", "event": "", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/runs/143887504291", "name": "CodeQL", "state": "SUCCESS", "workflow": ""}, {"bucket": "pass", "event": "dynamic", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999306801/job/143887239688", "name": "Analyze (python)", "state": "SUCCESS", "workflow": "CodeQL"}, {"bucket": "pass", "event": "dynamic", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999306801/job/143887239316", "name": "Analyze (actions)", "state": "SUCCESS", "workflow": "CodeQL"}], "test_source": "ci_head", "test_head_sha": "9005a6777d5fc9f5364f8542ff231e1b4263dcd1"}, "trailers": {"action_origin": "pr_review", "review_severity": null, "review_iteration": 1, "review_finding_ids": ["none"], "review_disposition": null, "rejection_reason": null, "introduced_by_action_id": null, "consulted_knowledge_ids": null}, "review_post_withheld": null} {"execution_id": "REV-1796257420-7de3e2bf-claude-agent", "action": "Review Loop executed for I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "category": "test", "target": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "verdict": "success", "outcome": "success", "entry_type": "action", "context_fingerprint": "a6fb125f2a43429a", "labels": ["review", "review-loop", "claude-agent"], "error_context": null, "action_id": "ACT-1796257420-d21268f8", "created_at": "2026-12-03T00:23:40.556792Z"} +{"action_id": "ACT-CAL-1796257451-e00470f3", "execution_id": "CAL-P-1796254011-CLA-CO5.5-1796257451-99fd4e4b", "action": "Calibration report generated for plan P-1796254011-CLA-CO5.5", "category": "doc", "target": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/calibrated", "outcome": "success", "entry_type": "action", "action_origin": "calibration", "labels": ["calibration", "stage-5", "P-1796254011-CLA-CO5.5"], "error_context": null, "plan_branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/_", "execution_branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "evaluated_commit_sha": "ebeb16c2f1317f2714794ce1eee9ab4c82ec9886", "predicted_metrics": {"p_success": 0.9, "entropy": 2.6, "impact": 35.0, "cost": 5.0, "learning_value": 1.5, "ev": 26.47}, "actual_metrics": {"p_success": 1.0, "entropy": 3.04, "impact": 35.0, "cost": 4.25, "learning_value": 1.5, "ev": 30.59, "duration_seconds": null, "tokens": null, "exit_code": 0, "test_pass_rate": 0.9998235864867249, "files_changed": 5, "insertions": 911, "deletions": 887, "ev_clean": 30.59, "ev_with_bugs": 30.59, "p_success_clean": 1.0, "p_success_with_bugs": 1.0, "impact_clean": 35.0, "impact_with_bugs": 35.0, "bug_ev_drag": 0.0}, "calibration_deltas": {"p_success_error": 0.1, "entropy_error": 0.44, "impact_error": 0.0, "cost_error": 0.75, "learning_value_error": 0.0, "ev_error": 4.12, "delta_ev": 4.12, "delta_ev_clean": 4.12, "delta_ev_with_bugs": 4.12, "bug_ev_drag": 0.0}, "calibration_report_path": "plans/I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5_calibration.md", "created_at": "2026-12-03T00:24:11.853845Z", "touch_set_accuracy": {"precision": 1.0, "recall": 1.0, "unpredicted_paths": [], "unused_entries": []}, "calibration_agent": "claude-agent", "calibration_model": "claude-opus-5-5", "plan_agent": "claude-agent", "plan_model": "claude-opus-5-5"} diff --git a/plans/I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5_calibration.md b/plans/I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5_calibration.md new file mode 100644 index 000000000..26a520c7b --- /dev/null +++ b/plans/I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5_calibration.md @@ -0,0 +1,103 @@ +# Plan Calibration Report: P-1796254011-CLA-CO5.5 + +- **Plan Reference:** + [`plans/I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5.md`](P-1796254011-CLA-CO5.5.md) +- **Execution ID:** `E-1796254177-CLA-CO5.5` +- **Execution Branch:** `I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_` +- **Intent Branch:** `I-1796253987-hac-split-test-local-llm/_` +- **Evaluating Agent:** `claude-agent/claude-opus-5-5` +- **Plan Agent:** `claude-agent/claude-opus-5-5` +- **Evaluation Timestamp:** `2026-12-03T00:24:09.000Z` +- **Evaluated Commit SHA:** `ebeb16c2f1317f2714794ce1eee9ab4c82ec9886` +- **Base SHA:** `5297abf7b5ce0e18a4fa079a3ab4b9f8a7663828` +- **Merge-Base SHA:** `5297abf7b5ce0e18a4fa079a3ab4b9f8a7663828` +- **Merged Commits:** `0` +- **Patch Size Base:** `plan` + +--- + +## 1. Executive Calibration Summary + +| Metric | Predicted (`pred`) | Actual (`actual`) | Absolute Error (`abs(pred - actual)`) | Accuracy Rating | Bias Direction | +| :------------------------------------------------- | :----------------- | :---------------- | :------------------------------------ | :-------------- | :------------------------- | +| **$P(\text{success})$** | `0.90` | `1.00` | `0.10` | Moderate | Slight Underconfidence | +| **Entropy ($\Delta S$)** | `2.60` | `3.04` | `0.44` | High (≤ 1.0) | Underestimated Risk | +| **Impact** | `35.00` | `35.00` | `0.00` | Exact | Perfectly Calibrated | +| **Cost** | `5.00` | `4.25` | `0.75` | High (≤ 1.0) | Highly Accurate | +| **Learning Value** | `1.50` | `1.50` | `0.00` | Exact | Perfectly Calibrated | +| **Expected Value — Clean (without bugs)** | `26.47` | `30.59` | `4.12` | High | Conservative Underestimate | +| **Expected Value — Observed (with bugs included)** | `26.47` | `30.59` | `4.12` | High | Conservative Underestimate | +| **Bug EV Drag** | `0.00` | `0.00` | `0.00` | - | Drag Penalty | + +--- + +## 2. Mathematical Derivations & Calibration Errors + +- **Success Probability Error:** $|0.90 - 1.00| = 0.10$ +- **Entropy Error:** $|2.60 - 3.04| = 0.44$ +- **Impact Error:** $|35.00 - 35.00| = 0.00$ +- **Cost Error:** $|5.00 - 4.25| = 0.75$ +- **Learning Value Error:** $|1.50 - 1.50| = 0.00$ +- **Expected Value Realization:** + $$EV_{\text{pred}} = 0.90 \times 35.0 + 0.5 \times 1.5 - 0.3 \times 2.60 - 5.00 = 26.47$$ + $$EV_{\text{actual}} = EV_{\text{clean}} = 1.00 \times 35.0 + 0.5 \times 1.5 - 0.3 \times 3.04 - 4.25 = 30.59$$ + $$EV_{\text{with\_bugs}} = 1.00 \times 35.0 + 0.5 \times 1.5 - 0.3 \times 3.04 - 4.25 = 30.59$$ + $$\text{Bug EV Drag} = round(EV_{\text{clean}} - EV_{\text{with\_bugs}}, 2) = 0.00$$ $$\Delta EV = +4.12$$ + +--- + +## 3. Entropy Factor Breakdown + +- **State Surface Area (SSA):** Predicted `0.6` vs Observed `10.0` (5 files modified). +- **Irreversibility (IRR):** Predicted `0.0` vs Observed `0.0` (Zero destructive or stateful changes). +- **Conflict Likelihood (CL):** Predicted `0.1` vs Observed `0.0` (Clean sequential branch merges). +- **Sandbox Escape Risk (SER):** Predicted `0.0` vs Observed `0.0` (Zero security exceptions). +- **Novelty (NOV):** Predicted `0.4` vs Observed `0.4` (Standard calibration reporting schema). + +--- + +## 4. Calibration Assessment + +Plan `P-1796254011-CLA-CO5.5` executed with minimal error ($p\_success\_error = 0.10$, $cost\_error = 0.75$). The +calibration step successfully completed the execution lifecycle and delivered verified post-execution analysis. + +--- + +## 5. Touch Set Accuracy + +- **Precision (declared entries the diff touched):** `100.0%` +- **Recall (changed files the touch set covered):** `100.0%` + +Changed files outside the touch set: + +- none + +Declared entries the diff did not touch: + +- none + +--- + +## 6. Review Churn + +- **Full reviews:** `1` +- **Scoped reviews:** `0` +- **Approval carry-overs:** `0` +- **Pipeline runs:** `1` +- **Pipeline reruns:** `0` +- **Non-defect churn (target merge):** `0` +- **Non-defect churn (bookkeeping):** `0` +- **Non-defect churn (CI noise):** `0` + +--- + +## 7. Self-Explaining Code Counts + +Against the merge base with origin/main: added 0 docstring(s), added 0 comment(s), removed 0 docstring(s) and removed 0 +comment(s) across 10 changed file(s). + +- Changed files checked: 10 +- Added docstrings: 0 +- Added comments (not '# why:'): 0 +- Removed docstrings: 0 +- Removed comments (not '# why:'): 0 From f8bbde5cc93b3ed4de8f19c9252259c99d10ecd7 Mon Sep 17 00:00:00 2001 From: Holon Calibrate Agent Date: Thu, 3 Dec 2026 11:24:12 +1100 Subject: [PATCH 10/10] chore(calibration): record stage 5 reconciliation --- .../executions/I-1796253987-hac-split-test-local-llm.jsonl | 1 + 1 file changed, 1 insertion(+) diff --git a/holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl b/holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl index ecd5ca840..666ff40b6 100644 --- a/holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl +++ b/holon-knowledge/ledger/pending/executions/I-1796253987-hac-split-test-local-llm.jsonl @@ -16,3 +16,4 @@ {"execution_id": "REV-1796257420-7de3e2bf-claude-agent", "plan_branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/_", "execution_branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "agent": "claude-agent", "agent_version": "1.4.0", "model": "claude-opus-5-5", "status": "approved", "entry_type": "summary", "summary": "Review Loop reached consensus approval after 1 iteration(s); PR ready for maintainer merge; final verdicts: Reviewer 1 APPROVED (0/0/0); Reviewer 2 APPROVED (0/0/0); Reviewer 3 APPROVED (0/0/0)", "created_at": "2026-12-03T00:23:40.556Z", "total_iterations": 1, "max_iterations": 25, "ci_checks_summary": {"source": "github_cli", "total": 16, "passed": 16, "failed": 0, "pending": 0, "skipped": 0, "all_passed": true, "checks": [{"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313115/job/143887254670", "name": "unit (macos-latest, shard 2 of 2)", "state": "SUCCESS", "workflow": "Test - Unit"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313090/job/143887254378", "name": "build (macos-latest)", "state": "SUCCESS", "workflow": "Run Make"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313115/job/143887254453", "name": "unit (macos-latest, shard 1 of 2)", "state": "SUCCESS", "workflow": "Test - Unit"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313002/job/143887255311", "name": "build", "state": "SUCCESS", "workflow": "Docker Build"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313008/job/143887253156", "name": "hygiene (ubuntu-latest)", "state": "SUCCESS", "workflow": "Test - Hygiene"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313090/job/143887254106", "name": "build (ubuntu-latest)", "state": "SUCCESS", "workflow": "Run Make"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313115/job/143887254680", "name": "unit (ubuntu-latest)", "state": "SUCCESS", "workflow": "Test - Unit"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313078/job/143887253776", "name": "Workspace survival (ubuntu-latest)", "state": "SUCCESS", "workflow": "Test - Stress"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313240/job/143887255346", "name": "commit-trailers", "state": "SUCCESS", "workflow": "Test - Commit Trailers"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999312965/job/143887254097", "name": "self-doc-behavior", "state": "SUCCESS", "workflow": "Test - Self-Doc Behavior"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313019/job/143887253493", "name": "integration (ubuntu-latest)", "state": "SUCCESS", "workflow": "Test - Integration"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313045/job/143887253026", "name": "scan", "state": "SUCCESS", "workflow": "Test - No Harness References"}, {"bucket": "pass", "event": "pull_request", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999313029/job/143887253972", "name": "ledger-invariants", "state": "SUCCESS", "workflow": "Test - Ledger Invariants"}, {"bucket": "pass", "event": "", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/runs/143887504291", "name": "CodeQL", "state": "SUCCESS", "workflow": ""}, {"bucket": "pass", "event": "dynamic", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999306801/job/143887239688", "name": "Analyze (python)", "state": "SUCCESS", "workflow": "CodeQL"}, {"bucket": "pass", "event": "dynamic", "link": "https://github.com/Holon-Agentic-Coder/holon-agentic-coder/actions/runs/46999306801/job/143887239316", "name": "Analyze (actions)", "state": "SUCCESS", "workflow": "CodeQL"}], "test_source": "ci_head", "test_head_sha": "9005a6777d5fc9f5364f8542ff231e1b4263dcd1"}, "trailers": {"action_origin": "pr_review", "review_severity": null, "review_iteration": 1, "review_finding_ids": ["none"], "review_disposition": null, "rejection_reason": null, "introduced_by_action_id": null, "consulted_knowledge_ids": null}, "review_post_withheld": null} {"execution_id": "REV-1796257420-7de3e2bf-claude-agent", "action": "Review Loop executed for I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "category": "test", "target": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "verdict": "success", "outcome": "success", "entry_type": "action", "context_fingerprint": "a6fb125f2a43429a", "labels": ["review", "review-loop", "claude-agent"], "error_context": null, "action_id": "ACT-1796257420-d21268f8", "created_at": "2026-12-03T00:23:40.556792Z"} {"action_id": "ACT-CAL-1796257451-e00470f3", "execution_id": "CAL-P-1796254011-CLA-CO5.5-1796257451-99fd4e4b", "action": "Calibration report generated for plan P-1796254011-CLA-CO5.5", "category": "doc", "target": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/calibrated", "outcome": "success", "entry_type": "action", "action_origin": "calibration", "labels": ["calibration", "stage-5", "P-1796254011-CLA-CO5.5"], "error_context": null, "plan_branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/_", "execution_branch": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "evaluated_commit_sha": "ebeb16c2f1317f2714794ce1eee9ab4c82ec9886", "predicted_metrics": {"p_success": 0.9, "entropy": 2.6, "impact": 35.0, "cost": 5.0, "learning_value": 1.5, "ev": 26.47}, "actual_metrics": {"p_success": 1.0, "entropy": 3.04, "impact": 35.0, "cost": 4.25, "learning_value": 1.5, "ev": 30.59, "duration_seconds": null, "tokens": null, "exit_code": 0, "test_pass_rate": 0.9998235864867249, "files_changed": 5, "insertions": 911, "deletions": 887, "ev_clean": 30.59, "ev_with_bugs": 30.59, "p_success_clean": 1.0, "p_success_with_bugs": 1.0, "impact_clean": 35.0, "impact_with_bugs": 35.0, "bug_ev_drag": 0.0}, "calibration_deltas": {"p_success_error": 0.1, "entropy_error": 0.44, "impact_error": 0.0, "cost_error": 0.75, "learning_value_error": 0.0, "ev_error": 4.12, "delta_ev": 4.12, "delta_ev_clean": 4.12, "delta_ev_with_bugs": 4.12, "bug_ev_drag": 0.0}, "calibration_report_path": "plans/I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5_calibration.md", "created_at": "2026-12-03T00:24:11.853845Z", "touch_set_accuracy": {"precision": 1.0, "recall": 1.0, "unpredicted_paths": [], "unused_entries": []}, "calibration_agent": "claude-agent", "calibration_model": "claude-opus-5-5", "plan_agent": "claude-agent", "plan_model": "claude-opus-5-5"} +{"action_id": "ACT-1796257452-d0da55bb", "parent_action_id": "I-1796253987-hac-split-test-local-llm/P-1796254011-CLA-CO5.5/E-1796254177-CLA-CO5.5/_", "event_type": "reconciliation", "verdict": "success", "outcome": "success", "reason": "Stage 5 calibration reconciled execution outcome to success", "created_at": "2026-12-03T00:24:12.249741Z"}