Commit a2cc513
committed
Sub-agent fanout architecture + supporting context-quality levers. Net
---
**Core mechanism**: `<parallel_edits>` XML protocol fans out independent file edits to child `_solve_attempt` calls via `ThreadPoolExecutor`. Children run in lean mode (skip preload) with the brief carrying target-file content + siblings + issue. Per-batch wall cap 200s, size cap `_RALPH_MAX_PER_BATCH=5`, `_RALPH_MAX_WORKERS=4`, child `max_steps=_RALPH_CHILD_MAX_STEPS=10`. Suppressed for single-file batches.
**Safety invariants**:
- **Recursion-depth guard**: children get `_lean_mode=True` + `_recursion_depth=1`. Triple-checked: (a) `_solve_attempt` entry asserts `_recursion_depth < 2`, (b) the `<parallel_edits>` extraction site sets `_is_child` and skips parsing, (c) `_ralph_subagent` dispatch site asserts child kwargs match the invariant before spawn.
- **Worst-case inference**: `_RALPH_MAX_WORKERS × _RALPH_CHILD_MAX_STEPS = 4 × 10 = 40` chat calls per round, bounded further by `WALL_CLOCK_BUDGET_SECONDS=248`.
- **Validator routing**: every child + critic `chat_completion` threads validator-supplied `(api_base, api_key, model)`. No new endpoints, no env reads.
**Context-quality levers**:
- Distinctive-phrase preload — grep issue-quoted strings + multilingual tokens.
- Read-cache short-circuit + pagination-loop detector — close pagination-evasion paths.
- Path-segment vs substring token matching.
- Canonical-file content grep — boost files containing issue-quoted snake_case keys; guides edits to where keys already live (avoids orphan-duplicate creation in parallel locations).
**Defensive passes**:
- `_revert_syntactically_broken_files` — `ast.parse` + brace-balance for JS/TS/Rust/Go/Java/C/Kotlin/C#/PHP. Reverts to HEAD on partial-edit breakage.
- `_revert_docker_mount_mode_artifacts` — restores HEAD mode on files whose diff is mode-only and content-empty (docker volume mounts emit spurious `100755 → 100644` on shell scripts the agent never touched). Validator generates the submitted diff from working tree, so the on-disk restore is required.
**Prompt work**: Style-task gate suppresses `_strip_low_signal_hunks` on formatting sweeps (those whitespace-only hunks are the work product).
---
**Base preserved unchanged**: `solve()` signature + return shape; `_resolve_inference_config`; all `DEFAULT_MODEL` / `API_BASE` / `API_KEY` constants; every refinement gate including companion-test execution; multi-shot wrapper; `DANGEROUS_PATTERNS`; `# MINER-EDITABLE` / `# VALIDATOR CONTRACT` markers; `_EDGECASE_GUARDRAIL`; `extract_command` / `_read_context_file` helpers. Stdlib only (`concurrent.futures`). No sampling/hostname/env changes.+1412/-221 in agent.py, single file, no contract / sampling / hostname changes. Companion-test gate and other base infrastructure preserved unchanged.1 parent fcab5aa commit a2cc513
1 file changed
Lines changed: 1397 additions & 221 deletions
0 commit comments