From f97e89f796725aa4261608e56ec9d9b7762a9154 Mon Sep 17 00:00:00 2001 From: kotama7 Date: Fri, 12 Jun 2026 17:25:57 +0900 Subject: [PATCH 1/4] docs: research plan for Artifact-Summary Handoff ablation (context-bounded state transfer in branching code agents) Adds ari-core/PLAN_artifact_summary_handoff.md: a research plan that formalizes ARI's parent->child node state transfer (work_dir artifact inheritance + structured node_report summaries) as a controllable handoff policy, and designs an ablation study (code_only / summary_only / code_plus_summary / full_log / truncated_log / rolling / failure-only) on CSR SpMV optimization with deterministic evaluation. Section 0 pins a verified audit of the current implementation (bfts_loop.py work_dir copy + _OUTPUT_BLACKLIST, node_report builder, _format_parent_report_block planner injection, cost_trace.jsonl token records) including seven divergences the plan must account for (no linear search, no search_trace.jsonl, planner-vs-agent injection surfaces, no memory-off switch, advisory-only node timeout, gitignored experiments/, no overflow detection). Co-Authored-By: Claude Fable 5 --- ari-core/PLAN_artifact_summary_handoff.md | 310 ++++++++++++++++++++++ 1 file changed, 310 insertions(+) create mode 100644 ari-core/PLAN_artifact_summary_handoff.md diff --git a/ari-core/PLAN_artifact_summary_handoff.md b/ari-core/PLAN_artifact_summary_handoff.md new file mode 100644 index 00000000..b9dde3ee --- /dev/null +++ b/ari-core/PLAN_artifact_summary_handoff.md @@ -0,0 +1,310 @@ +# PLAN: Artifact-Summary Handoff — 分岐型LLMコード生成におけるコンテキスト制約付き状態受け渡し + +Status: 研究計画(design 段階、未実装)。Origin: 2026-06-12 設計議論。 +削除条件: 本計画の Phase 1〜5(pilot 実験まで)が完了し、結果が論文ドラフトまたは +後継 PLAN に転記された時点で本ファイルを削除する。 + +英語題目: *Artifact-Summary Handoff for Context-Bounded Branching LLM Code Agents* + +--- + +## 0. 実装現状の検証結果(2026-06-12、コードベース監査済み) + +本計画は ARI を reference implementation として用いる。計画の前提となる既存実装を +検証した結果を先に固定する。**以降の節はこの検証結果を前提に読む。** + +### 0.1 計画の前提が実装と一致する点(検証済み) + +| 前提 | 実装 | 根拠 | +|---|---|---| +| per-node work directory | `PathManager.node_work_dir()` → `experiments/{run_id}/{node_id}/` | `ari/paths.py:175-181`, `ari/cli/bfts_loop.py:374-381` | +| 親→子のコード成果物継承(結果ファイル除外) | `_run_loop()` 内の selective copy。`_OUTPUT_BLACKLIST`(results.csv, run.log, slurm-\*.out, stdout/stderr, \*.metrics.json, node_report.json 等)+ `PathManager.is_meta_file()` の2段除外 | `ari/cli/bfts_loop.py:382-445`(blacklist は :400-413) | +| node_report.json の構造化レポート | `build_node_report()`/`write_node_report()`。`files_changed` / `delta_vs_parent` / `metrics` / `self_assessment` / `next_steps_hints` / `build_command` / `run_command` を含む(計7+24フィールド、JSON Schema あり) | `ari/orchestrator/node_report/builder.py:481-590`, `ari/schemas/node_report.schema.json` | +| node_report の子への還流 | `_format_parent_report_block()` が親の delta_vs_parent / files_changed / concerns / next_steps_hints を抽出し **BFTS planner の expand プロンプト**に注入。`_PromptBudget` で各フィールドを文字数キャップ(delta 240 / concern 200 / hint 200 chars) | `ari/orchestrator/bfts.py:64-108, 629-633, 755` | +| tree.json / cost_trace.jsonl | tree.json は `Node.to_dict()`(id, parent_id, children, depth, status, metrics)。cost_trace.jsonl は CallRecord(timestamp, **node_id**, phase, skill, model, **prompt_tokens**, completion_tokens, estimated_cost_usd, latency_ms)を per-call 記録 → 本計画のトークン系指標は追加実装なしで算出可能 | `ari/cli/bfts_loop.py:882-888`, `ari/cost_tracker.py:59-75` | +| ReAct loop の予算 | `max_react_steps`(default 80, `ARI_MAX_REACT`)、`max_parallel_nodes`(default 4, `ARI_PARALLEL`)。会話は node ごとに完全分離(`messages` は `AgentLoop.run()` ローカル) | `ari/agent/loop.py:356-374, 617-620`, `ari/config/__init__.py:66-158, 429-471` | +| 機能の段階 toggle | VirSci/idea・survey・paper・review・ORS・rubric 各 stage は workflow.yaml の pipeline stage `enabled` で off 可能 | `ari-core/config/workflow.yaml`, `ari/config/__init__.py`(ARIConfig, pydantic) | +| deterministic evaluator の前例 | Evaluator Protocol(async `evaluate()` → `{score, reason, has_real_data, metrics}`)。node.metrics は evaluator 戻り値から populate され BFTS の選択に使われる | `ari/protocols/evaluator.py:19-40`, `ari/agent/loop.py`, `ari/orchestrator/node.py:98` | + +### 0.2 計画が実装と食い違う点(本計画で修正済みの認識) + +1. **linear refinement は存在しない。** 探索は BFTS のみ(`ari/orchestrator/bfts.py`、 + リポジトリ唯一の探索クラス)。`frontier_score` の 4 variant + (scientific_only / scientific_plus_diversity / depth_penalized / ucb_like, + `ari/config/__init__.py:106-120`)は **LLM selector が解答不能な場合の + deterministic fallback のスコアリング**であり、探索方式の切替ではない + (一次選択は LLM-driven: `bfts.py:418-575`)。→ §13.5 の SearchPolicy は**新規実装**。 +2. **search_trace.jsonl は存在しない。** 既存は tree.json / cost_trace.jsonl / + memory_access.jsonl / lineage_decisions.jsonl。→ §13.9 から削除し、必要なら + handoff 実装時に新設する。 +3. **「親 summary が子に渡る」経路は2面に分かれており、子 agent 自身のプロンプトには + ほぼ何も入らない。** (a) node_report 由来 block は **planner の expand プロンプト** + (子の方向性を決める側)にのみ入る。(b) 子 agent の実行コンテキストに入るのは + ancestor memory 経由の `result_summary` エントリ(Tier-1b)と semantic 検索の + detail supplement(Tier-2, `loop.py:164-345`)のみで、子の最初の user message は + goal_text + node id/depth/label + 汎用 label 説明だけ(`loop.py:577-598`)。 + → 提案する「structured node summary を**子 agent のプロンプトへ**注入する」のは + 既存挙動の言い換えではなく**新規の handoff 面**である(§13.3)。 +4. **memory off は env 変数系で、完全 off スイッチは未実装。** バックエンド選択は + `ARI_MEMORY_BACKEND`(letta|in_memory)等。global memory は v0.6.0 で撤去済み。 + さらに loop は**全 tool 実行結果を node-scoped memory に自動保存**し + (`loop.py:909-914`)、Tier-2 検索は type フィルタなしで ancestor の tool trace + 断片を拾い得る。→ **code_only 条件を成立させるには Tier-1b/Tier-2 注入の明示的 + off スイッチが必須**(§13.4 は新規実装、かつ無効化しないと条件が汚染される)。 +5. **timeout_per_node は現状プロンプト文言のみで実行時強制されていない** + (`bfts_loop.py:532-541` の TimeoutError 分岐は `as_completed` 後のため実質 dead + code)。→ §12.1 の実験統制として使う場合は強制実装を直すか、統制変数から外す。 +6. **experiments/ は gitignore 済み**(`.gitignore:31`)で、ランタイム出力 + (`experiments/{run_id}/{node_id}`)と同居する。→ §13.6 のベンチマークハーネスは + tracked な場所に置く(`.gitignore` に例外を追加するか、ari-core 配下のテンプレート + ディレクトリから run 時に配布する)。 +7. **context overflow の明示的検出は存在しない。** 窓制御はヒューリスティック + (直近 50 msg、tool 結果 500 chars 超を圧縮、`_MAX_TOOL_OUTPUT=4000` 等)。 + → §11.3 の context overflow rate は「cost_trace.jsonl の prompt_tokens がモデルの + コンテキスト上限を超えた・窓圧縮が発動した回数」として計測器を定義して測る。 + +### 0.3 現状の de-facto handoff(= 本研究の出発点) + +ARI の現行デフォルトは、おおよそ +**code(workdir copy) + planner 側 summary(node_report block) + memory 側 summary +(ancestor result_summary + semantic supplement)** であり、本計画の用語では +code_plus_summary の変種に相当する。本研究はこれを「実装上の工夫」から +**制御可能な handoff policy** に抽出・定式化し、ablation で各成分の寄与を測る。 + +--- + +## 1. 研究概要 + +LLM コード生成エージェントでは、実装→ビルド→実行→評価→修正の反復ループに加え、 +複数の改善方針を並行して試す分岐型探索(BFTS, MCTS, evolutionary search)が +使われるようになっている。分岐型探索では**子ノードが親ノードの実験状態を何を介して +継承するか**が本質的な設計問題になる。全対話履歴・全 tool trace・全ログを渡せば +コンテキスト長が探索深度に比例して爆発し、何も渡さなければ失敗理由・改善方針・ +評価結果が失われて同じ失敗と重複試行が再発する。 + +本研究は、親→子へ渡す状態を +**code artifact state(実行可能なファイル群、work directory 経由)** と +**operational summary state(実験状態の構造化要約、プロンプト経由)** に分解し、 +この2つだけを渡す **Artifact-Summary Handoff** を提案・評価する。要約対象は会話履歴 +ではなく**実験状態**(何を実装し、どのファイルが変わり、どのコマンドでビルド・実行し、 +どの指標が得られ、どの失敗が残り、次に何を試すべきか)である点が特徴である。 + +主タスクは CSR SpMV 最適化とし、handoff 方式の違いが性能・正解性・トークン効率・ +失敗再発率・重複試行率に与える影響を統制実験で評価する。本会議投稿時には stencil / +FFT / GEMM micro-kernel 等へ拡張する。 + +## 2. 中心的主張 + +分岐型 LLM コード生成では、親ノードの全対話履歴や全ログを子へ渡す必要はない。 +実行可能なコード成果物と構造化されたノード要約を渡せば、性能改善に必要な情報を +十分に継承でき、かつ入力トークン数と最大コンテキスト長を探索深度から切り離せる。 + +## 3. 比較する handoff 方式 + +| mode | code (workdir) | summary (prompt) | log (prompt) | 備考 | +|---|---|---|---|---| +| code_only | ✓ | — | — | 実行可能状態のみ。memory 注入も off(§0.2-4) | +| summary_only | — | ✓ | — | 要約のみで状態継承できるか | +| **code_plus_summary(提案)** | ✓ | ✓(structured) | — | | +| code_plus_full_log | ✓ | — | ✓(tool trace / stdout / stderr / 評価理由を可能な限り) | 情報量上限 baseline。親の結果**ファイル**は workdir へコピーしない(ログは prompt のみ) | +| code_plus_truncated_log | ✓ | — | ✓(固定 token / tail truncation) | full_log の現実版 | +| rolling_summary | ✓ | ✓(自然言語逐次要約) | — | 一般的 conversation summary との差を測る | +| failure_only_summary | ✓ | ✓(known_failures のみ) | — | 失敗情報だけの寄与を測る | + +## 4. Summary schema ablation + +structured node summary のどの要素が効くかを分離する: +full / −metrics / −known_failures / −next_steps / −delta_vs_parent / −changed_files / +−build·run_command / 自然言語版 vs structured JSON 版 / LLM 生成 vs 決定論的抽出。 + +## 5. 実験対象タスク + +主タスク: **CSR SpMV 最適化**(y = Ax)。最適化方針の探索余地が広く +(OpenMP scheduling, row-length bucketing, SELL-C-σ, blocked CSR, unrolling, +prefetch, locality, load balance)、行列ファミリ +(uniform random / banded / power-law / block / diagonal-dominant / skewed、 +必要に応じ SuiteSparse)で条件を変えられる。リポジトリには CSR SpMM の既存 +checkpoint・metric_contract の運用実績があり(§0.1)、評価系の土地勘がある。 + +拡張タスク候補: stencil, FFT kernel, GEMM micro-kernel, graph BFS/PageRank, +JSON parser, compression kernel。本会議版では最低3タスク。 + +## 6. 評価指標 + +- **主性能**: best valid geomean speedup @ N nodes。valid = compile + run + + correctness(相対誤差閾値、**OpenMP reduction の FP 順序差を許容する ε を明記**)+ + no timeout + 全行列 benchmark 完了 + protocol violation なし。invalid は score 0。 +- **探索効率**: AUC of best-so-far, first valid node index, valid node rate, + compile/correctness rate, token-normalized score。 +- **コンテキスト効率(中心指標)**: mean/max input tokens per node, cumulative input + tokens, context growth rate vs depth, context overflow rate(§0.2-7 の定義), + summary compression ratio, selector token cost, LLM call 数, wall-clock。 + いずれも cost_trace.jsonl(prompt_tokens, node_id per call)から算出可能(§0.1)。 +- **handoff 品質**: useful inheritance rate, parent code modification rate, + from-scratch rewrite rate, repeated failure/strategy rate, stale-result reuse rate, + parent result misuse rate, duplicate attempt rate。 +- **failure recurrence**: 同一コンパイルエラー / 正解性エラー / protocol violation / + 性能劣化要因 / 無効方針 / 親結果ファイル誤用の再発分析。 + +## 7. 実験条件 + +### 7.1 主実験 +探索を BFTS に固定し handoff のみ変更。固定: 初期 experiment.md・初期コード・ +harness・LLM model・temperature・executed node 数・max ReAct steps・parallelism・ +deterministic evaluator。token 数は固定しない(input token 削減自体が評価対象)。 +timeout per node は §0.2-5 の通り現状非強制のため、強制実装を入れるか統制から外すかを +Phase 1 で決める。 + +**選択分散の統制**: BFTS の一次ノード選択は LLM-driven(§0.2-1)であり handoff 比較の +ノイズ源になるため、主実験では deterministic fallback selector +(`frontier_score: scientific_only` 相当)を**一次選択として使う option を新設**し、 +LLM selector は副実験で扱う。 + +### 7.2 補助実験 +1. **token budget 固定比較**: 同一トークン予算内で各方式が実行できた有効ノード数。 +2. **探索方式比較**: handoff を code_plus_summary に固定し、BFTS vs + linear refinement(**新規実装**、§13.5)。 +3. **複数モデル**: GPT 系 / Claude 系 / Gemini 系 / open-weight code model で再現性確認。 + +### 7.3 無効化する ARI 機能(主実験) +VirSci/idea, arXiv survey, Letta/ancestor memory 注入(§0.2-4 の新規 off スイッチ), +paper, review, ORS, rubric-derived axes, LLM-judge 最終評価。 +理由: handoff 効果を外部記憶・文献・仮説生成・論文生成の効果から分離するため。 + +## 8. ARI への実装計画 + +### 8.1 HandoffConfig(新規) +`ari/config/__init__.py` の ARIConfig(pydantic)に追加し、`apply_bfts_env_overrides` +と同型の env override を付ける。 + +```yaml +handoff: + mode: code_plus_summary # code_only | summary_only | code_plus_summary | + # code_plus_full_log | code_plus_truncated_log | + # rolling_summary | failure_only_summary + summary_max_tokens: 800 + summary_schema: structured_json # | natural_language + summary_source: deterministic # | llm + include_parent_outputs: false + inject_into: [agent] # agent | planner | both(§0.2-3 の2面を明示制御) + memory_injection: off # Tier-1b/Tier-2 注入の明示スイッチ(新規) +``` + +### 8.2 node_summary_view(新規) +node_report.json(§0.1 で全フィールド存在確認済み)から子へ渡す短い view を生成: + +```json +{ + "node_id": "...", "parent_id": "...", "label": "...", + "valid": true, "objective_score": 2.31, + "changed_files": ["spmv.c", "run.sh"], + "delta_vs_parent": "...", + "build_command": "make", "run_command": "./bench", + "key_metrics": {"valid_geomean_speedup": 2.31, "max_relative_error": 1e-7}, + "known_failures": ["dynamic scheduling degraded banded matrices"], + "next_steps": ["try row-length bucketing for skewed matrices"] +} +``` + +既存の `_PromptBudget`(§0.1)が planner 側 block の文字数キャップとして同思想の +先行実装になっており、これを handoff 全面に一般化する。 + +### 8.3 注入面の配線(§0.2-3 が根拠) +- **agent 面(新規)**: `AgentLoop.run()` の最初の user message + (`loop.py:577-598`)に mode に応じて node_summary_view / log block を注入。 +- **planner 面(既存改修)**: `_format_parent_report_block()`(`bfts.py:64-108`)を + HandoffConfig 配下に置き、mode で on/off。 +- **workdir 面(既存)**: `bfts_loop.py:382-445` の copy + `_OUTPUT_BLACKLIST` を + mode(code を含むか)で on/off。 +- full_log / truncated_log は cost をかけず node の transcript / tool trace 保存から + 構成する(結果ファイルは workdir へコピーしない)。 + +### 8.4 memory 注入の明示 off(新規) +`build_working_context_messages()`(`loop.py:164-345`)の Tier-1b / Tier-2 を +`handoff.memory_injection` で制御。off にしないと tool trace が memory 経由で +子に漏れ、code_only 条件が成立しない(§0.2-4)。 + +### 8.5 SearchPolicy(新規) +`bfts`(現状)に加え `linear_latest` / `linear_best` を新規実装。 +`bfts_score_only` は「LLM selector を使わず `_fallback_score` を一次選択にする」 +mode として実装(§7.1 の統制にも使う)。 + +### 8.6 SpMV harness(tracked な置き場所に、§0.2-6) +`experiments/handoff_spmv/` 相当を tracked 化(`.gitignore` 例外 or ari-core 配下の +テンプレート + run 時配布)。内容: experiment.md, baseline_spmv.c, candidate_spmv.c, +Makefile, run_candidate.sh, matrix_generators.py, benchmark.py, evaluate_node.py, +README.md。**LLM が編集してよいファイルと benchmark/evaluator(編集禁止)を分離**し、 +編集禁止側は checksum で protocol violation を検出する。 + +### 8.7 deterministic evaluator(新規、Protocol 準拠) +`ari/protocols/evaluator.py` の Evaluator Protocol に準拠(§0.1)。出力例: + +```json +{"valid": true, "score": 2.41, "metric_name": "valid_geomean_speedup", + "compile_success": true, "correctness_pass": true, "max_relative_error": 3.2e-7, + "timeout": false, + "speedups": {"uniform": 1.9, "banded": 2.7, "powerlaw": 2.2, "block": 2.9}} +``` + +### 8.8 実行・集計スクリプト +- `scripts/run_handoff_ablation.py`: mode 切替 / 複数 seed / node・step budget 固定 / + 不要機能 off / checkpoint path 整理(`workspace/checkpoints/_/` 規約)。 +- `scripts/analyze_handoff_ablation.py`: tree.json, cost_trace.jsonl, + node_report.json, results.json, evaluator 出力を読み、§6 の全指標 + bootstrap CI を + 集計(search_trace.jsonl は存在しないため対象外、必要なら handoff_trace.jsonl を新設)。 + +## 9. Research Questions + +- **RQ1**: Artifact-Summary Handoff は full log handoff と同等の性能 + (best valid geomean speedup, AUC, valid node rate)を維持できるか。 +- **RQ2**: 入力トークン数と最大コンテキスト長(cumulative/mean/max input tokens, + context growth rate, overflow rate)を削減できるか。 +- **RQ3**: code only では失敗再発・重複試行(failure recurrence, duplicate attempt, + repeated strategy, invalid node rate)が増えるか。 +- **RQ4**: structured summary のどの要素が寄与するか(field ablation による + performance drop / token reduction / failure recurrence increase)。 +- **RQ5**: 効果は探索方式・タスク・モデル・seed を超えて再現するか。 + +## 10. 投稿戦略 + +HPC SpMV 論文ではなく LLM code agent / automated software engineering の論文として +投稿する。初期: ASE/ICSE workshop, MLSys workshop, LLM for HPC workshop。 +本会議: ASE Research Track(最有力), ICSE, MLSys, OOPSLA。 +ジャーナル: ASE Journal, TOSEM, TSE, TMLR。 + +**Related work の必須差別化**(reviewer リスク対策): AIDE(tree search + +journal/summary 継承)、SWE-agent / OpenHands の context condensation、 +MLE-bench 系 agent、agent workflow memory。差別化軸は「handoff 方式そのものを +独立変数として統制 ablation し、operational state の要素別寄与を測る初の +empirical study」であり、特定手法の提案勝負にしない。 + +## 11. スケジュール + +- **Phase 1 設計**: §0 の食い違い7点の解消方針確定(timeout 強制、harness 置き場所、 + memory off スイッチ、handoff_trace 要否)、HandoffConfig schema 確定。 +- **Phase 2 最小実装**: HandoffConfig / node_summary_view / agent 面注入 / + memory off / code_only・code_plus_summary・code_plus_full_log。 +- **Phase 3 SpMV harness**: baseline 実装、matrix generator、correctness checker + (ε 設計込み)、timing harness、results.json schema、編集禁止ファイルの checksum。 +- **Phase 4 evaluator**: Protocol 準拠 deterministic evaluator、node.metrics 保存。 +- **Phase 5 pilot**: code_only / code_plus_summary / code_plus_full_log / + code_plus_truncated_log の小規模比較(deterministic selector、複数 seed 最小構成)。 +- **Phase 6 本実験**: 全 mode、summary ablation、token budget 固定、複数 seed。 +- **Phase 7 拡張**: linear refinement 実装比較、追加タスク、複数モデル。 +- **Phase 8 論文化**: related work、RQ 別結果、qualitative failure analysis、 + threats to validity、replication package。 + +## 12. リスクと対策 + +1. **ARI 固有の engineering に見える** → state transfer model として抽象化し、ARI は + reference implementation と位置づける。 +2. **SpMV 単一タスクに見える** → 行列ファミリ多様化 + 追加タスク(Phase 7)。 +3. **full log baseline が弱い** → truncated / rolling / failure-only / retrieval + baseline を併設。 +4. **structured summary の設計が恣意的** → field ablation(§4)で要素別寄与を示す。 +5. **LLM の偶然性** → 複数 seed、bootstrap CI、paired comparison、per-task breakdown、 + deterministic selector(§7.1)で選択分散を遮断。 +6. **LLM Judge 依存に見える** → 主評価は deterministic evaluator のみ。LLM Judge は + 主評価から除外。 +7. **先行研究(AIDE 等)との近接** → §10 の差別化軸で統制 empirical study として + 位置づける。 From f179b7f98ac69c0d454960e4ecb8dee2e702a0b7 Mon Sep 17 00:00:00 2001 From: kotama7 Date: Sun, 14 Jun 2026 03:12:37 +0900 Subject: [PATCH 2/4] docs: reframe handoff plan + per-subtask implementation plans MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update PLAN_artifact_summary_handoff.md to the controlled artifact/history study (RQ-A scaffold; RQ-B field-level content; RQ-C cross-node transfer; RQ-D capability x handoff), and fix the §0.2 premises that block a clean comparison: B1 memory third-channel, B2 deterministic evaluator drives selection, B3 exogenize the LLM-self-determined metric contract, plus sterile-gate asymmetry, dead timeout, full_log overflow, seed/digest. Add MASTER_PLAN_handoff_impl.md (dependency DAG, critical path, MVP cut) and a per-subtask Plan.md under each affected directory. Each Plan.md records its inter-plan dependencies and deletion requirements. Per-dir README Contents indexes synced for the new files. Co-Authored-By: Claude Opus 4.8 (1M context) --- ari-core/MASTER_PLAN_handoff_impl.md | 47 +++ ari-core/PLAN_artifact_summary_handoff.md | 364 +++++----------------- ari-core/ari/README.md | 6 + ari-core/ari/agent/Plan.md | 23 ++ ari-core/ari/agent/README.md | 1 + ari-core/ari/cli/Plan.md | 21 ++ ari-core/ari/cli/README.md | 1 + ari-core/ari/config/Plan.md | 23 ++ ari-core/ari/config/README.md | 1 + ari-core/ari/evaluator/Plan.md | 22 ++ ari-core/ari/evaluator/README.md | 1 + ari-core/ari/llm/Plan.md | 25 ++ ari-core/ari/llm/README.md | 1 + ari-core/ari/orchestrator/Plan.md | 21 ++ ari-core/ari/orchestrator/README.md | 1 + scripts/Plan.md | 27 ++ scripts/README.md | 1 + 17 files changed, 297 insertions(+), 289 deletions(-) create mode 100644 ari-core/MASTER_PLAN_handoff_impl.md create mode 100644 ari-core/ari/agent/Plan.md create mode 100644 ari-core/ari/cli/Plan.md create mode 100644 ari-core/ari/config/Plan.md create mode 100644 ari-core/ari/evaluator/Plan.md create mode 100644 ari-core/ari/llm/Plan.md create mode 100644 ari-core/ari/orchestrator/Plan.md create mode 100644 scripts/Plan.md diff --git a/ari-core/MASTER_PLAN_handoff_impl.md b/ari-core/MASTER_PLAN_handoff_impl.md new file mode 100644 index 00000000..e3c00cd3 --- /dev/null +++ b/ari-core/MASTER_PLAN_handoff_impl.md @@ -0,0 +1,47 @@ +# MASTER PLAN — Artifact/History Handoff 統制研究の実装マスター + +Status: 実装マスター計画(未実装)。Origin: 2026-06 設計議論+コードベース監査+関連研究調査。 +研究計画(why/what): [`PLAN_artifact_summary_handoff.md`](PLAN_artifact_summary_handoff.md)。本書は how/order(依存 DAG・クリティカルパス・削除要件・subtask 索引)。 + +## 削除要件 +配下の全 subtask Plan.md が削除要件を満たして削除され(全 subtask が main に land+実機検証)、結果が論文ドラフトまたは後継 PLAN に転記された時点で本マスターと研究計画を削除する。 + +## 原則 +1. 測定は evaluator が独占所有(agent は固定シグネチャ kernel のみ提供)。 +2. 評価契約は実験者が固定し全アーム・全モデルで同一(B3)。 +3. 各 handoff チャネルは per-arm で明示 gate。 +4. 機械情報(host/partition/port/path)は tracked artifact・commit に一切入れない(最優先規約)。 + +## Subtask 索引と依存 DAG +| subtask | Plan.md | 主担当 | 上流依存 | +|---|---|---|---| +| B2 deterministic evaluator+測定器 | [`ari/evaluator/Plan.md`](ari/evaluator/Plan.md) | evaluator | (根) | +| G1 HandoffConfig | [`ari/config/Plan.md`](ari/config/Plan.md) | config | (根) | +| ローカル決定性(seed/digest) | [`ari/llm/Plan.md`](ari/llm/Plan.md) | llm | (根) | +| B1 memory gate / B3 契約凍結 / G4 注入 | [`ari/agent/Plan.md`](ari/agent/Plan.md) | agent | config, evaluator, orchestrator | +| G3 node_summary_view / G9a selector | [`ari/orchestrator/Plan.md`](ari/orchestrator/Plan.md) | orchestrator | config, evaluator | +| G5 copy / G7 sterile / G12 timeout・overflow | [`ari/cli/Plan.md`](ari/cli/Plan.md) | cli | config | +| ハーネス / run・analyze / scrub / cost | [`../scripts/Plan.md`](../scripts/Plan.md) | scripts | 上記すべて | + +依存の要点: **B2 → B3 → B1 が背骨**。B2 で採点固定 → B3 で契約外生化(しないと B2 が `agent/loop.py:1190` で上書きされる)→ B1 で memory 第3経路を gate(しないと全アームが state 共有)。 + +## クリティカルパス(ビルド順) +- **Stage 0(コード前)**: タスク確定(SpMV/SpMM、既存 fixture は全 SpMM)/事前登録 doc 凍結(ε・C/`_scientific_score` 正規化/invalid floor/N/failure codebook/単一 primary 対比/H-B・H-C・H-D の向き/model 水準)/seed kernel 固定/pilot 予約(qwen3:8b validity floor・最大サイズ infra 適合)。 +- **Stage 1**: B2+測定器(evaluator)/B3 契約凍結(agent)/G1 HandoffConfig(config)/ローカル決定性(llm)。 +- **Stage 2**: B1 memory gate/G4 注入(agent)/G3 node_summary_view(orchestrator)/G5・G7・G12(cli)/side-channel 凍結。 +- **Stage 3**: G9a deterministic selector(orchestrator)。 +- **Stage 4**: tracked ハーネス/run・analyze スクリプト/instrumentation/収集時スクラブ/cost ゲート(scripts)。 +- **Stage 5**: 推論(run 単位 cluster bootstrap・TOST・多重性・log 効果量・RQ-D 交差検定)・図表。 + +## MVP カット(Phase A/workshop 級) +Stage 0 全部 + Stage 1 全部 + Stage 2 の B1・G3・G4・G5・G7 + Stage 3 G9a + Stage 4 の tracked ハーネス・run/analyze・scrub・instrumentation 最小。 +これで **3 アーム(code_only / code_plus_summary / code_plus_full_log)×1 タスク×ローカル large×deterministic selector** を、契約固定・memory off・選択決定・valid 定義ありで回せる。落としてよい: linear search、memory topology ノブ、capability 勾配(RQ-D)、aide_journal、dosage、overflow 精緻化。 + +## 完了ログ(land 時に追記) +- [ ] B2 / 測定器 — land __ / 実機 gate __ +- [ ] G1 HandoffConfig — land __ / gate __ +- [ ] ローカル決定性 — land __ / gate __ +- [ ] B1 / B3 / G4 — land __ / 実機 gate __ +- [ ] G3 / G9a — land __ / 実機 gate __ +- [ ] G5 / G7 / G12 — land __ / 実機 gate __ +- [ ] ハーネス / scripts / scrub — land __ / 実機 gate __ diff --git a/ari-core/PLAN_artifact_summary_handoff.md b/ari-core/PLAN_artifact_summary_handoff.md index b9dde3ee..97b756c8 100644 --- a/ari-core/PLAN_artifact_summary_handoff.md +++ b/ari-core/PLAN_artifact_summary_handoff.md @@ -1,310 +1,96 @@ -# PLAN: Artifact-Summary Handoff — 分岐型LLMコード生成におけるコンテキスト制約付き状態受け渡し +# PLAN: What Should Branching LLM Code Agents Inherit? — Artifact / History Handoff の統制研究 -Status: 研究計画(design 段階、未実装)。Origin: 2026-06-12 設計議論。 -削除条件: 本計画の Phase 1〜5(pilot 実験まで)が完了し、結果が論文ドラフトまたは -後継 PLAN に転記された時点で本ファイルを削除する。 - -英語題目: *Artifact-Summary Handoff for Context-Bounded Branching LLM Code Agents* +Status: 研究計画(design 段階・未実装)。Origin: 2026-06 設計議論+コードベース監査+関連研究調査。 +削除条件: Phase A〜C(MVP pilot まで)完了し、結果が論文ドラフトまたは後継 PLAN に転記された時点で本ファイルを削除する。 +実装マスター: [`MASTER_PLAN_handoff_impl.md`](MASTER_PLAN_handoff_impl.md)(how/order と subtask Plan.md 索引)。 +英語題目: **What Should Branching LLM Code Agents Inherit? A Controlled Study of Artifact and History Handoff** --- -## 0. 実装現状の検証結果(2026-06-12、コードベース監査済み) - -本計画は ARI を reference implementation として用いる。計画の前提となる既存実装を -検証した結果を先に固定する。**以降の節はこの検証結果を前提に読む。** - -### 0.1 計画の前提が実装と一致する点(検証済み) - -| 前提 | 実装 | 根拠 | -|---|---|---| -| per-node work directory | `PathManager.node_work_dir()` → `experiments/{run_id}/{node_id}/` | `ari/paths.py:175-181`, `ari/cli/bfts_loop.py:374-381` | -| 親→子のコード成果物継承(結果ファイル除外) | `_run_loop()` 内の selective copy。`_OUTPUT_BLACKLIST`(results.csv, run.log, slurm-\*.out, stdout/stderr, \*.metrics.json, node_report.json 等)+ `PathManager.is_meta_file()` の2段除外 | `ari/cli/bfts_loop.py:382-445`(blacklist は :400-413) | -| node_report.json の構造化レポート | `build_node_report()`/`write_node_report()`。`files_changed` / `delta_vs_parent` / `metrics` / `self_assessment` / `next_steps_hints` / `build_command` / `run_command` を含む(計7+24フィールド、JSON Schema あり) | `ari/orchestrator/node_report/builder.py:481-590`, `ari/schemas/node_report.schema.json` | -| node_report の子への還流 | `_format_parent_report_block()` が親の delta_vs_parent / files_changed / concerns / next_steps_hints を抽出し **BFTS planner の expand プロンプト**に注入。`_PromptBudget` で各フィールドを文字数キャップ(delta 240 / concern 200 / hint 200 chars) | `ari/orchestrator/bfts.py:64-108, 629-633, 755` | -| tree.json / cost_trace.jsonl | tree.json は `Node.to_dict()`(id, parent_id, children, depth, status, metrics)。cost_trace.jsonl は CallRecord(timestamp, **node_id**, phase, skill, model, **prompt_tokens**, completion_tokens, estimated_cost_usd, latency_ms)を per-call 記録 → 本計画のトークン系指標は追加実装なしで算出可能 | `ari/cli/bfts_loop.py:882-888`, `ari/cost_tracker.py:59-75` | -| ReAct loop の予算 | `max_react_steps`(default 80, `ARI_MAX_REACT`)、`max_parallel_nodes`(default 4, `ARI_PARALLEL`)。会話は node ごとに完全分離(`messages` は `AgentLoop.run()` ローカル) | `ari/agent/loop.py:356-374, 617-620`, `ari/config/__init__.py:66-158, 429-471` | -| 機能の段階 toggle | VirSci/idea・survey・paper・review・ORS・rubric 各 stage は workflow.yaml の pipeline stage `enabled` で off 可能 | `ari-core/config/workflow.yaml`, `ari/config/__init__.py`(ARIConfig, pydantic) | -| deterministic evaluator の前例 | Evaluator Protocol(async `evaluate()` → `{score, reason, has_real_data, metrics}`)。node.metrics は evaluator 戻り値から populate され BFTS の選択に使われる | `ari/protocols/evaluator.py:19-40`, `ari/agent/loop.py`, `ari/orchestrator/node.py:98` | - -### 0.2 計画が実装と食い違う点(本計画で修正済みの認識) - -1. **linear refinement は存在しない。** 探索は BFTS のみ(`ari/orchestrator/bfts.py`、 - リポジトリ唯一の探索クラス)。`frontier_score` の 4 variant - (scientific_only / scientific_plus_diversity / depth_penalized / ucb_like, - `ari/config/__init__.py:106-120`)は **LLM selector が解答不能な場合の - deterministic fallback のスコアリング**であり、探索方式の切替ではない - (一次選択は LLM-driven: `bfts.py:418-575`)。→ §13.5 の SearchPolicy は**新規実装**。 -2. **search_trace.jsonl は存在しない。** 既存は tree.json / cost_trace.jsonl / - memory_access.jsonl / lineage_decisions.jsonl。→ §13.9 から削除し、必要なら - handoff 実装時に新設する。 -3. **「親 summary が子に渡る」経路は2面に分かれており、子 agent 自身のプロンプトには - ほぼ何も入らない。** (a) node_report 由来 block は **planner の expand プロンプト** - (子の方向性を決める側)にのみ入る。(b) 子 agent の実行コンテキストに入るのは - ancestor memory 経由の `result_summary` エントリ(Tier-1b)と semantic 検索の - detail supplement(Tier-2, `loop.py:164-345`)のみで、子の最初の user message は - goal_text + node id/depth/label + 汎用 label 説明だけ(`loop.py:577-598`)。 - → 提案する「structured node summary を**子 agent のプロンプトへ**注入する」のは - 既存挙動の言い換えではなく**新規の handoff 面**である(§13.3)。 -4. **memory off は env 変数系で、完全 off スイッチは未実装。** バックエンド選択は - `ARI_MEMORY_BACKEND`(letta|in_memory)等。global memory は v0.6.0 で撤去済み。 - さらに loop は**全 tool 実行結果を node-scoped memory に自動保存**し - (`loop.py:909-914`)、Tier-2 検索は type フィルタなしで ancestor の tool trace - 断片を拾い得る。→ **code_only 条件を成立させるには Tier-1b/Tier-2 注入の明示的 - off スイッチが必須**(§13.4 は新規実装、かつ無効化しないと条件が汚染される)。 -5. **timeout_per_node は現状プロンプト文言のみで実行時強制されていない** - (`bfts_loop.py:532-541` の TimeoutError 分岐は `as_completed` 後のため実質 dead - code)。→ §12.1 の実験統制として使う場合は強制実装を直すか、統制変数から外す。 -6. **experiments/ は gitignore 済み**(`.gitignore:31`)で、ランタイム出力 - (`experiments/{run_id}/{node_id}`)と同居する。→ §13.6 のベンチマークハーネスは - tracked な場所に置く(`.gitignore` に例外を追加するか、ari-core 配下のテンプレート - ディレクトリから run 時に配布する)。 -7. **context overflow の明示的検出は存在しない。** 窓制御はヒューリスティック - (直近 50 msg、tool 結果 500 chars 超を圧縮、`_MAX_TOOL_OUTPUT=4000` 等)。 - → §11.3 の context overflow rate は「cost_trace.jsonl の prompt_tokens がモデルの - コンテキスト上限を超えた・窓圧縮が発動した回数」として計測器を定義して測る。 - -### 0.3 現状の de-facto handoff(= 本研究の出発点) - -ARI の現行デフォルトは、おおよそ -**code(workdir copy) + planner 側 summary(node_report block) + memory 側 summary -(ancestor result_summary + semantic supplement)** であり、本計画の用語では -code_plus_summary の変種に相当する。本研究はこれを「実装上の工夫」から -**制御可能な handoff policy** に抽出・定式化し、ablation で各成分の寄与を測る。 +## 0. 実装現状(監査済, paths=`ari-core/ari/`) + +以降は本検証を前提に読む。**0.2 は論文の前に必ず塞ぐ穴**で、塞がない限り統制比較は成立しない。各項目の実装計画は [`MASTER_PLAN_handoff_impl.md`](MASTER_PLAN_handoff_impl.md) と各 dir の `Plan.md` を参照。 + +### 0.1 流用可能な土台(検証済) +| 前提 | 実装 | +|---|---| +| per-node work_dir = `experiments/{run_id}/{node_id}/` | `paths.py:175-181`, `cli/bfts_loop.py:373-381` | +| 親→子 code 継承+結果除外(2段) | `_OUTPUT_BLACKLIST`+`is_meta_file()`, `cli/bfts_loop.py:398-445` | +| node_report.json(31 prop) | `orchestrator/node_report/builder.py:551-586` | +| cost_trace.jsonl(per-call node_id+prompt_tokens) | `cost_tracker.py` | +| 評価信号 `node.metrics["_scientific_score"]` | `orchestrator/bfts.py:336` 他、生成 `evaluator/llm_evaluator.py:662,713` | +| ancestor-scoped memory(Tier-1b/2) | `agent/loop.py:295-353`, scope 強制 `in_memory.py:101-106` | +| ローカル backend 既定(ollama, qwen3:8b/32b) | `config/__init__.py:581-582` | + +### 0.2 先に塞ぐ食い違い(=統制比較の前提条件) +1. **B1 第3 handoff 経路**: Tier-1a(`loop.py:193-216`)+Tier-1c(metric-contract obligation+`build_coverage_status`, `loop.py:218-290`)が ancestor ガード(`loop.py:292`)より前で無条件発火、`_PINNED_USER_MARKERS`(`loop.py:766-775`)で window を生存。塞がないと全アームが operational state を共有。→ [`ari/agent/Plan.md`](ari/agent/Plan.md)。 +2. **B2 evaluator が選択を回せない**: `node.metrics = eval_result["metrics"]`(`loop.py:1461`)で `metrics._scientific_score` 不在なら全ノード 0.0。evaluator は `core.py:195` ハードコード、loop は Protocol 外 `evaluate_sync`。→ [`ari/evaluator/Plan.md`](ari/evaluator/Plan.md)。 +3. **B3 契約が LLM 自己決定・run/model 依存**: `make_metric_spec`(core/pinned ツール, `workflow.py:172`/`loop.py:719`)が evaluator の metric_spec を実行時に上書き(`loop.py:1162-1196`)し、per-run 契約を `metric_contract.json` に書き Tier-1c で全子孫に注入。契約が条件ごとに変わると capability×handoff が capability×自己生成契約品質と交絡。→ 固定契約の外生化が必須。[`ari/agent/Plan.md`](ari/agent/Plan.md)。 +4. **sterile-gate の意味反転**: `compute_files_changed(parent,child)` 無条件 clamp(`cli/bfts_loop.py:631-656`)。copy-OFF では子 dir 空→全 deleted→sterile にならない。→ [`ari/cli/Plan.md`](ari/cli/Plan.md)。 +5. **timeout dead code**(`cli/bfts_loop.py:532-541`)/**full_log overflow 検出なし**で窓圧縮が黙って truncated 化(`loop.py:725,803-804`)。→ [`ari/cli/Plan.md`](ari/cli/Plan.md)。 +6. **バックエンド非決定性**: seed 不渡し(`client.py:180`)、gpt-5* は temp drop(`client.py:130`)。ローカルは seed plumb で再現性が立つ。→ [`ari/llm/Plan.md`](ari/llm/Plan.md)。 +7. 既存 fixture は全 SpMM(Y=AX)。タスクは Stage 0 で確定。 +8. harness が gitignore 全体無視(`.gitignore:31-37`)→ force-negate 必須。→ [`../scripts/Plan.md`](../scripts/Plan.md)。 +9. `search_trace.jsonl` 不在/`memory_access.jsonl` は取得テキスト非記録。 + +### 0.3 de-facto handoff(出発点) +ARI 既定は code(workdir copy)+ planner 側 summary(`bfts.py:64-108`)+ memory 側(Tier-1a/1b/1c/2)の混合。本研究はこれを制御可能な handoff policy に分解・統制比較する。 --- -## 1. 研究概要 - -LLM コード生成エージェントでは、実装→ビルド→実行→評価→修正の反復ループに加え、 -複数の改善方針を並行して試す分岐型探索(BFTS, MCTS, evolutionary search)が -使われるようになっている。分岐型探索では**子ノードが親ノードの実験状態を何を介して -継承するか**が本質的な設計問題になる。全対話履歴・全 tool trace・全ログを渡せば -コンテキスト長が探索深度に比例して爆発し、何も渡さなければ失敗理由・改善方針・ -評価結果が失われて同じ失敗と重複試行が再発する。 - -本研究は、親→子へ渡す状態を -**code artifact state(実行可能なファイル群、work directory 経由)** と -**operational summary state(実験状態の構造化要約、プロンプト経由)** に分解し、 -この2つだけを渡す **Artifact-Summary Handoff** を提案・評価する。要約対象は会話履歴 -ではなく**実験状態**(何を実装し、どのファイルが変わり、どのコマンドでビルド・実行し、 -どの指標が得られ、どの失敗が残り、次に何を試すべきか)である点が特徴である。 - -主タスクは CSR SpMV 最適化とし、handoff 方式の違いが性能・正解性・トークン効率・ -失敗再発率・重複試行率に与える影響を統制実験で評価する。本会議投稿時には stencil / -FFT / GEMM micro-kernel 等へ拡張する。 - -## 2. 中心的主張 - -分岐型 LLM コード生成では、親ノードの全対話履歴や全ログを子へ渡す必要はない。 -実行可能なコード成果物と構造化されたノード要約を渡せば、性能改善に必要な情報を -十分に継承でき、かつ入力トークン数と最大コンテキスト長を探索深度から切り離せる。 - -## 3. 比較する handoff 方式 - -| mode | code (workdir) | summary (prompt) | log (prompt) | 備考 | -|---|---|---|---|---| -| code_only | ✓ | — | — | 実行可能状態のみ。memory 注入も off(§0.2-4) | -| summary_only | — | ✓ | — | 要約のみで状態継承できるか | -| **code_plus_summary(提案)** | ✓ | ✓(structured) | — | | -| code_plus_full_log | ✓ | — | ✓(tool trace / stdout / stderr / 評価理由を可能な限り) | 情報量上限 baseline。親の結果**ファイル**は workdir へコピーしない(ログは prompt のみ) | -| code_plus_truncated_log | ✓ | — | ✓(固定 token / tail truncation) | full_log の現実版 | -| rolling_summary | ✓ | ✓(自然言語逐次要約) | — | 一般的 conversation summary との差を測る | -| failure_only_summary | ✓ | ✓(known_failures のみ) | — | 失敗情報だけの寄与を測る | - -## 4. Summary schema ablation - -structured node summary のどの要素が効くかを分離する: -full / −metrics / −known_failures / −next_steps / −delta_vs_parent / −changed_files / -−build·run_command / 自然言語版 vs structured JSON 版 / LLM 生成 vs 決定論的抽出。 - -## 5. 実験対象タスク +## 1. 中心的問い +分岐型 LLM コード生成で**子ノードが親から何を継承すべきか**。「code/summary/両方」の3択は自明(both 最良)かつ単一 trajectory で実質既出のため貢献ではない。貢献は1段深い粒度——summary の**どのフィールド**を**どの形式**で継承すれば必要十分か、その結論が**分岐継承で・モデル能力を超えて転移するか**——に置く。最も強い結末は「**最適な継承法は条件(capability/task/depth)で食い違う**」という contingency の発見であり、本研究はそれを confirmatory に検出する設計にする。 -主タスク: **CSR SpMV 最適化**(y = Ax)。最適化方針の探索余地が広く -(OpenMP scheduling, row-length bucketing, SELL-C-σ, blocked CSR, unrolling, -prefetch, locality, load balance)、行列ファミリ -(uniform random / banded / power-law / block / diagonal-dominant / skewed、 -必要に応じ SuiteSparse)で条件を変えられる。リポジトリには CSR SpMM の既存 -checkpoint・metric_contract の運用実績があり(§0.1)、評価系の土地勘がある。 - -拡張タスク候補: stencil, FFT kernel, GEMM micro-kernel, graph BFS/PageRank, -JSON parser, compression kernel。本会議版では最低3タスク。 - -## 6. 評価指標 - -- **主性能**: best valid geomean speedup @ N nodes。valid = compile + run + - correctness(相対誤差閾値、**OpenMP reduction の FP 順序差を許容する ε を明記**)+ - no timeout + 全行列 benchmark 完了 + protocol violation なし。invalid は score 0。 -- **探索効率**: AUC of best-so-far, first valid node index, valid node rate, - compile/correctness rate, token-normalized score。 -- **コンテキスト効率(中心指標)**: mean/max input tokens per node, cumulative input - tokens, context growth rate vs depth, context overflow rate(§0.2-7 の定義), - summary compression ratio, selector token cost, LLM call 数, wall-clock。 - いずれも cost_trace.jsonl(prompt_tokens, node_id per call)から算出可能(§0.1)。 -- **handoff 品質**: useful inheritance rate, parent code modification rate, - from-scratch rewrite rate, repeated failure/strategy rate, stale-result reuse rate, - parent result misuse rate, duplicate attempt rate。 -- **failure recurrence**: 同一コンパイルエラー / 正解性エラー / protocol violation / - 性能劣化要因 / 無効方針 / 親結果ファイル誤用の再発分析。 - -## 7. 実験条件 - -### 7.1 主実験 -探索を BFTS に固定し handoff のみ変更。固定: 初期 experiment.md・初期コード・ -harness・LLM model・temperature・executed node 数・max ReAct steps・parallelism・ -deterministic evaluator。token 数は固定しない(input token 削減自体が評価対象)。 -timeout per node は §0.2-5 の通り現状非強制のため、強制実装を入れるか統制から外すかを -Phase 1 で決める。 - -**選択分散の統制**: BFTS の一次ノード選択は LLM-driven(§0.2-1)であり handoff 比較の -ノイズ源になるため、主実験では deterministic fallback selector -(`frontier_score: scientific_only` 相当)を**一次選択として使う option を新設**し、 -LLM selector は副実験で扱う。 - -### 7.2 補助実験 -1. **token budget 固定比較**: 同一トークン予算内で各方式が実行できた有効ノード数。 -2. **探索方式比較**: handoff を code_plus_summary に固定し、BFTS vs - linear refinement(**新規実装**、§13.5)。 -3. **複数モデル**: GPT 系 / Claude 系 / Gemini 系 / open-weight code model で再現性確認。 - -### 7.3 無効化する ARI 機能(主実験) -VirSci/idea, arXiv survey, Letta/ancestor memory 注入(§0.2-4 の新規 off スイッチ), -paper, review, ORS, rubric-derived axes, LLM-judge 最終評価。 -理由: handoff 効果を外部記憶・文献・仮説生成・論文生成の効果から分離するため。 - -## 8. ARI への実装計画 - -### 8.1 HandoffConfig(新規) -`ari/config/__init__.py` の ARIConfig(pydantic)に追加し、`apply_bfts_env_overrides` -と同型の env override を付ける。 - -```yaml -handoff: - mode: code_plus_summary # code_only | summary_only | code_plus_summary | - # code_plus_full_log | code_plus_truncated_log | - # rolling_summary | failure_only_summary - summary_max_tokens: 800 - summary_schema: structured_json # | natural_language - summary_source: deterministic # | llm - include_parent_outputs: false - inject_into: [agent] # agent | planner | both(§0.2-3 の2面を明示制御) - memory_injection: off # Tier-1b/Tier-2 注入の明示スイッチ(新規) -``` - -### 8.2 node_summary_view(新規) -node_report.json(§0.1 で全フィールド存在確認済み)から子へ渡す短い view を生成: - -```json -{ - "node_id": "...", "parent_id": "...", "label": "...", - "valid": true, "objective_score": 2.31, - "changed_files": ["spmv.c", "run.sh"], - "delta_vs_parent": "...", - "build_command": "make", "run_command": "./bench", - "key_metrics": {"valid_geomean_speedup": 2.31, "max_relative_error": 1e-7}, - "known_failures": ["dynamic scheduling degraded banded matrices"], - "next_steps": ["try row-length bucketing for skewed matrices"] -} -``` - -既存の `_PromptBudget`(§0.1)が planner 側 block の文字数キャップとして同思想の -先行実装になっており、これを handoff 全面に一般化する。 - -### 8.3 注入面の配線(§0.2-3 が根拠) -- **agent 面(新規)**: `AgentLoop.run()` の最初の user message - (`loop.py:577-598`)に mode に応じて node_summary_view / log block を注入。 -- **planner 面(既存改修)**: `_format_parent_report_block()`(`bfts.py:64-108`)を - HandoffConfig 配下に置き、mode で on/off。 -- **workdir 面(既存)**: `bfts_loop.py:382-445` の copy + `_OUTPUT_BLACKLIST` を - mode(code を含むか)で on/off。 -- full_log / truncated_log は cost をかけず node の transcript / tool trace 保存から - 構成する(結果ファイルは workdir へコピーしない)。 - -### 8.4 memory 注入の明示 off(新規) -`build_working_context_messages()`(`loop.py:164-345`)の Tier-1b / Tier-2 を -`handoff.memory_injection` で制御。off にしないと tool trace が memory 経由で -子に漏れ、code_only 条件が成立しない(§0.2-4)。 - -### 8.5 SearchPolicy(新規) -`bfts`(現状)に加え `linear_latest` / `linear_best` を新規実装。 -`bfts_score_only` は「LLM selector を使わず `_fallback_score` を一次選択にする」 -mode として実装(§7.1 の統制にも使う)。 - -### 8.6 SpMV harness(tracked な置き場所に、§0.2-6) -`experiments/handoff_spmv/` 相当を tracked 化(`.gitignore` 例外 or ari-core 配下の -テンプレート + run 時配布)。内容: experiment.md, baseline_spmv.c, candidate_spmv.c, -Makefile, run_candidate.sh, matrix_generators.py, benchmark.py, evaluate_node.py, -README.md。**LLM が編集してよいファイルと benchmark/evaluator(編集禁止)を分離**し、 -編集禁止側は checksum で protocol violation を検出する。 +## 2. 新規性の位置づけ(RQ-A は scaffold、RQ-B/C/D が貢献) +| 先行研究 | 何をしたか | 本研究が埋める白地 | +|---|---|---| +| AIDE(2502.13138)/AI-Scientist-v2(2504.08066) | 分岐探索+親→子に code+単一サマリ Σ(T) | summary を固定し中身を割らない、retrieval/非親 reach 無し | +| Lindenbauer "Complexity Trap"(2508.21433) | raw/masking/summary 統制比較・masking≈summary(**単一 trajectory**) | 分岐/cross-node・モデル能力への転移は未検証 | +| MEMOIR(2605.17539, 並行) | tree-search の階層 memory ablation | 別ドメイン(組合せ最適化)・tier 有無を ablate(field 別でない)・surface 非対象 | +| AWM(2409.07429)/MemGPT/Context-Eng survey(2507.13334) | agent-memory の枠を所有 | content 固定で surface/topology/capability を振る統制は無し | -### 8.7 deterministic evaluator(新規、Protocol 準拠) -`ari/protocols/evaluator.py` の Evaluator Protocol に準拠(§0.1)。出力例: +差別化(1文): 先行研究は handoff サマリを固定し単一 run・単一モデルで文脈圧縮を比較したに留まる。本研究は **artifact と history チャネルを分離**し、**history の content を field 別に ablate** し、**masking≈summary が分岐継承で・モデル能力を超えて転移するか**を、LLM-judge を排した決定論評価で測る初の統制研究。⚠「分岐型 agent memory を統制した初」は MEMOIR が先取り済みのため主張しない。 -```json -{"valid": true, "score": 2.41, "metric_name": "valid_geomean_speedup", - "compile_success": true, "correctness_pass": true, "max_relative_error": 3.2e-7, - "timeout": false, - "speedups": {"uniform": 1.9, "banded": 2.7, "powerlaw": 2.2, "block": 2.9}} -``` +## 3. handoff の分解 +- **artifact チャネル**(唯一直交): 親 code を work_dir で継承するか否か。 +- **history チャネル**: **FORM**(none→masked→truncated→extractive-summary→rolling、上限 full-trace)× **CONTENT**(field 別: delta_vs_parent/changed_files/concerns/next_steps/**known_failures**(導出)/key_metrics)× **SURFACE**(in-prompt push / memory-retrieval pull)。 +- **memory の扱い(確定)**: 第5チャネルにも headline にもしない。(i) RQ-A/B では off に統制すべき confound(B1)。(ii) RQ-C 配下に従属ノブ=inheritance TOPOLOGY(parent-only vs full-ancestor、content 固定。`loop.py:301`+`in_memory.py:103`、ARI 固有・未所有)。 -### 8.8 実行・集計スクリプト -- `scripts/run_handoff_ablation.py`: mode 切替 / 複数 seed / node・step budget 固定 / - 不要機能 off / checkpoint path 整理(`workspace/checkpoints/_/` 規約)。 -- `scripts/analyze_handoff_ablation.py`: tree.json, cost_trace.jsonl, - node_report.json, results.json, evaluator 出力を読み、§6 の全指標 + bootstrap CI を - 集計(search_trace.jsonl は存在しないため対象外、必要なら handoff_trace.jsonl を新設)。 +## 4. 比較アーム +code_only / summary_only / code+summary / code+masked / code+full_trace / code+truncated / code+rolling / **aide_journal**(Σ 相当 baseline) / **+CONTENT ablation**(summary −1 field ずつ=RQ-B)/ **+TOPOLOGY ノブ**(RQ-C 従属)。上記を **model_size∈{small,large(同一ファミリ; 勾配なら 8/14/32 等)}** で交差(RQ-D)。 -## 9. Research Questions +## 5. Research Questions +- **RQ-A(scaffold・貢献ではない)**: artifact と history のどちらが必要か。clean 比較の土台。 +- **RQ-B(primary・本命)**: history summary の**どの field** が効くか。**H-B: failure/concern 系が支配的で next_steps は寄与しない。** +- **RQ-C(differentiator)**: masking≈summary は分岐継承で転移するか。**H-C: 単一 trajectory では masking で足りるが、分岐では失敗情報が直近窓外に落ち extractive-failure-summary が masking 単独より有意に優る。** +- **RQ-D(capability × handoff・新規)**: handoff の価値はモデル能力に依存するか。**H-D(FORM×capability 交差): large は masking で足り small は failure-summary が必須**(RQ-C と接続)。勾配≥3点で「形(閾値/順位反転)」を検出。 +- sanity(格下げ・非 headline): S1 code+summary は code+full_trace と parity(TOST)。S2 注入トークン分離計測の上で削減確認。 -- **RQ1**: Artifact-Summary Handoff は full log handoff と同等の性能 - (best valid geomean speedup, AUC, valid node rate)を維持できるか。 -- **RQ2**: 入力トークン数と最大コンテキスト長(cumulative/mean/max input tokens, - context growth rate, overflow rate)を削減できるか。 -- **RQ3**: code only では失敗再発・重複試行(failure recurrence, duplicate attempt, - repeated strategy, invalid node rate)が増えるか。 -- **RQ4**: structured summary のどの要素が寄与するか(field ablation による - performance drop / token reduction / failure recurrence increase)。 -- **RQ5**: 効果は探索方式・タスク・モデル・seed を超えて再現するか。 +## 6. タスク・測定器・モデル +- **6.1 タスク**: SpMV(y=Ax) か SpMM(Y=AX) を Stage 0 で確定(既存 fixture は全 SpMM)。 +- **6.2 deterministic evaluator が測定器を独占所有**: oracle(fp64 参照解)+ε(行ごと `C·γ_{nnz}·Σ|A||x|`)+timing(warmup/reps median+分散, pin, freq, OMP, NUMA)+checksum 固定 baseline+anti-gaming(matrix/timing/baseline/correctness 独占, correctness 用 x は call 時供給)+geomean 集計+hardware fingerprint。→ [`ari/evaluator/Plan.md`](ari/evaluator/Plan.md)。 +- **6.3 モデル**: 主バックボーン=ローカル qwen3(small/large、seed・temp 固定・digest pin)で確認的 run を高 n・無コスト・再現可能に。frontier API は robustness 1本。Stage 0 で qwen3:8b の validity floor を pilot。→ [`ari/llm/Plan.md`](ari/llm/Plan.md)。 -## 10. 投稿戦略 +## 7. 実験計画と統計 +事前登録(Stage 0 で凍結): ε・C/`_scientific_score` 正規化/invalid floor/N/failure codebook/単一 primary 対比/H-B・H-C・H-D の向き/model 水準。単位=run(1木=1スカラ)。run 単位 cluster bootstrap、speedup は log 領域、parity は TOST+事前マージン、多重性 Holm/BH。selector は deterministic 固定(G9a)。注入トークンを per-node prompt_tokens と分離計測。RQ-D は**交互作用基準の検出力**で順位反転を検定。summary 忠実性(導出 known_failures vs evaluator failure_signature)で「表現の差」と「生成品質の差」を分離。 -HPC SpMV 論文ではなく LLM code agent / automated software engineering の論文として -投稿する。初期: ASE/ICSE workshop, MLSys workshop, LLM for HPC workshop。 -本会議: ASE Research Track(最有力), ICSE, MLSys, OOPSLA。 -ジャーナル: ASE Journal, TOSEM, TSE, TMLR。 +## 8. 実装計画 +クリティカルパス(Stage 0-5)・依存 DAG・subtask 索引・MVP カットは [`MASTER_PLAN_handoff_impl.md`](MASTER_PLAN_handoff_impl.md) に集約。背骨は **B2 → B3 → B1**。各 subtask は該当 dir の `Plan.md` 参照。 -**Related work の必須差別化**(reviewer リスク対策): AIDE(tree search + -journal/summary 継承)、SWE-agent / OpenHands の context condensation、 -MLE-bench 系 agent、agent workflow memory。差別化軸は「handoff 方式そのものを -独立変数として統制 ablation し、operational state の要素別寄与を測る初の -empirical study」であり、特定手法の提案勝負にしない。 +## 9. スコープとフェーズ +- Phase A(MVP/workshop): 3 アーム×1 タスク×ローカル large×deterministic selector、事前登録、run 単位 n≥~8–10、cluster bootstrap、scrub+gitignore negation。 +- Phase B: RQ-B(field 別)+ masked/aide_journal(RQ-C)+ dosage sweep。 +- Phase C: RQ-D(small/large 勾配)+ topology ノブ+ frontier robustness+追加タスク(SE タスク or MLSys 判断)。 +- 各 Phase 入口で cost go/no-go(ローカル主体で大幅緩和)。 -## 11. スケジュール +## 10. Threats to Validity +internal: B1 第3経路/sterile 非対称/dead timeout/selector 確率性/full_log overflow 自壊/side-channel/GPU 残留非決定性。construct: 主指標は handoff 質か selection 運か(selection-invariant 指標併報)/summary 忠実性交絡/starting kernel 交絡(全アーム同一・事前登録)/capability 操作が規模のみか(同一ファミリで担保)。external: 単一カーネル・単一言語(C/OpenMP)・主にローカル qwen3(→ frontier アームで補強)。 -- **Phase 1 設計**: §0 の食い違い7点の解消方針確定(timeout 強制、harness 置き場所、 - memory off スイッチ、handoff_trace 要否)、HandoffConfig schema 確定。 -- **Phase 2 最小実装**: HandoffConfig / node_summary_view / agent 面注入 / - memory off / code_only・code_plus_summary・code_plus_full_log。 -- **Phase 3 SpMV harness**: baseline 実装、matrix generator、correctness checker - (ε 設計込み)、timing harness、results.json schema、編集禁止ファイルの checksum。 -- **Phase 4 evaluator**: Protocol 準拠 deterministic evaluator、node.metrics 保存。 -- **Phase 5 pilot**: code_only / code_plus_summary / code_plus_full_log / - code_plus_truncated_log の小規模比較(deterministic selector、複数 seed 最小構成)。 -- **Phase 6 本実験**: 全 mode、summary ablation、token budget 固定、複数 seed。 -- **Phase 7 拡張**: linear refinement 実装比較、追加タスク、複数モデル。 -- **Phase 8 論文化**: related work、RQ 別結果、qualitative failure analysis、 - threats to validity、replication package。 +## 11. 再現性・アーティファクト・データ管理 +固定 commit/per-call の model digest/temp/seed 記録/frozen-trace から図表再生成/harness tracked(force-negate)/SuiteSparse は name+group+SHA256+snapshot 日付 pin/生成 native code の sandbox/timeout/**収集時の機械情報スクラブ**(tracked artifact・図・commit に機械情報を一切入れない)/GB 級 trace の保管。→ [`../scripts/Plan.md`](../scripts/Plan.md)。 ## 12. リスクと対策 +最大リスク(cost×検出力)→ ローカル主バックボーンで緩和。新リスク=small の capability floor → Stage 0 pilot。新規性が弱い/3択縮退 → §2 差別化+RQ-B/C/D を主役+contingency(条件で食い違う)を背骨に+aide_journal baseline。null → H-B/H-C/H-D を向き付き事前登録で informative に。venue → SE タスク追加 or MLSys 明確化。 -1. **ARI 固有の engineering に見える** → state transfer model として抽象化し、ARI は - reference implementation と位置づける。 -2. **SpMV 単一タスクに見える** → 行列ファミリ多様化 + 追加タスク(Phase 7)。 -3. **full log baseline が弱い** → truncated / rolling / failure-only / retrieval - baseline を併設。 -4. **structured summary の設計が恣意的** → field ablation(§4)で要素別寄与を示す。 -5. **LLM の偶然性** → 複数 seed、bootstrap CI、paired comparison、per-task breakdown、 - deterministic selector(§7.1)で選択分散を遮断。 -6. **LLM Judge 依存に見える** → 主評価は deterministic evaluator のみ。LLM Judge は - 主評価から除外。 -7. **先行研究(AIDE 等)との近接** → §10 の差別化軸で統制 empirical study として - 位置づける。 +## 13. 投稿戦略 +初期: DL4C / MLSys・ASE workshop(Phase A)。本会議: MLSys(context 効率+capability 軸)または ASE/ICSE(要 SE タスク追加)。冒頭で AIDE・AI-Scientist-v2・Lindenbauer・MEMOIR(並行) を引き、「summary を発明したのでなく、何を・どの形式で継承すべきかを field 粒度で初めて統制分離し、分岐継承とモデル能力をまたぐ転移(および条件依存性)を検証した」と位置づける。 diff --git a/ari-core/ari/README.md b/ari-core/ari/README.md index 31a3d327..7550f5a3 100644 --- a/ari-core/ari/README.md +++ b/ari-core/ari/README.md @@ -24,6 +24,7 @@ Core engine package for ARI. Each sub-package carries its own `README.md` - `guidance.py` — per-stage step-guidance + metrics-validation helpers. - `loop.py` — `AgentLoop` driver + per-node prompt builder. - `message_utils.py` — ReAct-message helpers (`_extract_job_ids`, `_tool_was_called`). + - `Plan.md` — B1 memory gate / B3 契約凍結 / G4 agent 面注入の実装計画(handoff study). - `react_driver.py` — generic ReAct driver for pipeline `react:` stages, with sandbox enforcement. - `run_env.py` — capture/read helper for `_run_env.json`. - `tool_manager.py` — OpenAI tool conversion, dispatch, phase-aware filtering. @@ -39,6 +40,7 @@ Core engine package for ARI. Each sub-package carries its own `README.md` - `commands.py` — misc top-level commands + `_safe_backup`. - `lineage.py` — end-of-phase lineage-decision helpers. - `migrate.py` — `ari migrate` sub-app. + - `Plan.md` — G5 copy / G7 sterile / G12 timeout・overflow の実装計画(handoff study). - `projects.py` — `ari paper` / `status` / `projects` / `show` commands. - `run.py` — `ari run` / `ari resume` commands. - `clone/` — `ari clone`: fetch + verify + extract curated EAR bundles. @@ -56,6 +58,7 @@ Core engine package for ARI. Each sub-package carries its own `README.md` - `README.md` — config index. - `__init__.py` — Pydantic config models + env-var overrides. - `finder.py` — workflow / profile YAML discovery. + - `Plan.md` — G1 HandoffConfig+env override の実装計画(handoff study). - `configs/` — external config tables (Phase PC). - `README.md` — configs index. - `__init__.py` — config-table exports + loader plumbing. @@ -67,11 +70,13 @@ Core engine package for ARI. Each sub-package carries its own `README.md` - `__init__.py` — public symbols + axis design. - `dynamic_axes.py` — venue/run-specific evaluation-axis derivation. - `llm_evaluator.py` — `LLMEvaluator`: extraction + multi-axis composite scoring. + - `Plan.md` — B2 deterministic evaluator+測定器ユニットの実装計画(handoff study). - `llm/` — thin LiteLLM wrappers for the agent loop and skills. - `README.md` — llm index. - `__init__.py` — public `LLMClient` + contract. - `cli_server.py` — OpenAI-compatible HTTP shim for agentic CLIs. - `client.py` — `LLMClient`/`LLMMessage`: completion + tool calling + cost recording. + - `Plan.md` — ローカルモデル決定性(seed/digest/thinking)の実装計画(handoff study). - `routing.py` — TODO - `mcp/` — MCP client talking to `ari-skill-*` subprocesses. - `README.md` — mcp index. @@ -101,6 +106,7 @@ Core engine package for ARI. Each sub-package carries its own `README.md` - `lineage_decision.py` — LLM lineage action + `lineage_decisions.jsonl` log. - `node.py` — `Node` data model + `NodeStatus` / `NodeLabel` enums. - `node_selection.py` — shared node-selection helpers + publication source-file selection. + - `Plan.md` — G3 node_summary_view / G9a deterministic selector の実装計画(handoff study). - `root_idea_selector.py` — run-start LLM root-idea pick + selection log. - `node_report/` — per-node `node_report.json` package. - `README.md` — node_report index. diff --git a/ari-core/ari/agent/Plan.md b/ari-core/ari/agent/Plan.md new file mode 100644 index 00000000..7e215b49 --- /dev/null +++ b/ari-core/ari/agent/Plan.md @@ -0,0 +1,23 @@ +# Plan — B1 memory gate / B3 契約凍結 / G4 agent 面注入 / ローカル決定性(loop側) + +Status: 実装計画(未実装)。Origin: 2026-06 handoff study 設計。 +親計画: [`../../MASTER_PLAN_handoff_impl.md`](../../MASTER_PLAN_handoff_impl.md)、研究計画 [`../../PLAN_artifact_summary_handoff.md`](../../PLAN_artifact_summary_handoff.md) §0.2(B1/B3) / §8 Stage 1-2。 + +## 依存関係(他 Plan.md) +- 上流依存: + - [`config/Plan.md`](../config/Plan.md)(G1 HandoffConfig)— gate/注入の全トグルを読む。 + - [`evaluator/Plan.md`](../evaluator/Plan.md)(B2)— **B3 の前提**(契約を凍結しても採点が壊れないのは固定 evaluator があるから)。 + - [`orchestrator/Plan.md`](../orchestrator/Plan.md)(G3 `node_summary_view`)— G4 が注入する view の生成元。 +- 下流: [`cli/Plan.md`](../cli/Plan.md)(copy/sterile)、[`../../scripts/Plan.md`](../../scripts/Plan.md)。 + +## 削除要件 +B1(memory per-arm gate)・B3(契約外生化)・G4(agent 面注入)・seed/thinking 統制が main に land し、**実機**で「code_only の子プロンプトに operational state ゼロ」「契約が run/model 間で不変」を確認、MASTER 完了ログに記録された時点で本 Plan.md を削除する。 + +## 実装項目 +1. **B1 memory gate**: monolithic `loop.py:164-355` の `build_working_context_messages` を **Tier-1a/1b/1c/2 の per-arm 独立 emit に分割**し `handoff.memory_off` で gate。ガード `loop.py:292` より上で無条件発火する Tier-1a(`193-216`)/1c(`218-290`) を必ず gate、**`_PINNED_USER_MARKERS`(`766-775`) の pin 対象も消す**(消さないと window 圧縮を生存)。`search_global_memory`(`650-672`)・auto-save(`920-930`) も対象に含める。 +2. **B3 契約外生化**: `ARI_FREEZE_CONTRACT` で `loop.py:1162-1196` の make_metric_spec 自己決定変異(`self.evaluator.metric_spec=` / `metric_extractor`)を封じ、`loop.py:1207-1219` の per-run 契約 obligation 生成も停止。固定 `metric_contract.json` を pin(or 無し)。`make_metric_spec` は core/pinned ツール(`workflow.py:172`,`loop.py:719`)なので survey/idea off では消えない=明示無効化必須。Tier-1c が残る場合は**固定契約のみ**注入。 +3. **G4 agent 面注入**: `handoff.inject_agent_block`/`log_mode` に応じ、子初回 user message(`loop.py:587-608`)に `node_summary_view`/log を `build_working_context_messages` 経由で append(`loop.py:640-647`)。log は **copy 除外前に親 work_dir から読む**。 +4. **ローカル決定性(loop側)**: qwen3 thinking-mode(`loop.py` 系)を全アーム一貫に(client 側は [`../llm/Plan.md`](../llm/Plan.md))。 + +## 検証ゲート(実機) +`code_only` の子プロンプトをダンプ → Tier-1a/1c/1b/2・契約 narrative が**ゼロ**。`code_plus_summary`/`code_plus_full_log` は view/log が子に届く。`ARI_FREEZE_CONTRACT` 下で同一 input の契約・採点 spec が run/model 間で不変。 diff --git a/ari-core/ari/agent/README.md b/ari-core/ari/agent/README.md index bfbfb258..62edcf56 100644 --- a/ari-core/ari/agent/README.md +++ b/ari-core/ari/agent/README.md @@ -11,6 +11,7 @@ MCP skills. - `guidance.py` — per-stage step-guidance + metrics-validation helpers. - `loop.py` — `AgentLoop` driver + per-node prompt builder. - `message_utils.py` — ReAct-message helpers (`_extract_job_ids`, `_tool_was_called`). +- `Plan.md` — B1 memory gate / B3 契約凍結 / G4 agent 面注入の実装計画(handoff study). - `react_driver.py` — generic ReAct driver for pipeline `react:` stages, with sandbox enforcement. - `run_env.py` — capture/read helper for `_run_env.json`. - `tool_manager.py` — OpenAI tool conversion, dispatch, phase-aware filtering. diff --git a/ari-core/ari/cli/Plan.md b/ari-core/ari/cli/Plan.md new file mode 100644 index 00000000..9ace883a --- /dev/null +++ b/ari-core/ari/cli/Plan.md @@ -0,0 +1,21 @@ +# Plan — G5 copy トグル / G7 sterile-gate 対称化 / G12 timeout・overflow + +Status: 実装計画(未実装)。Origin: 2026-06 handoff study 設計。 +親計画: [`../../MASTER_PLAN_handoff_impl.md`](../../MASTER_PLAN_handoff_impl.md)、研究計画 [`../../PLAN_artifact_summary_handoff.md`](../../PLAN_artifact_summary_handoff.md) §0.2 / §8 Stage 2。 + +## 依存関係(他 Plan.md) +- 上流依存: + - [`../config/Plan.md`](../config/Plan.md)(G1/配線)— `copy_workdir` 等を `agent.handoff` 経由で読む。 +- 関連: [`../agent/Plan.md`](../agent/Plan.md)(配線の対側)。 +- 下流: [`../../scripts/Plan.md`](../../scripts/Plan.md)。 + +## 削除要件 +G5・G7・G12 が main に land し、実機で「copy on/off がアームで効く」「sterile 判定がアーム不変」「per-node 予算が強制 or 明示除外」を確認、MASTER 完了ログに記録された時点で本 Plan.md を削除する。 + +## 実装項目(すべて `bfts_loop.py`) +1. **G5 copy トグル**: 親→子 work_dir copy(`bfts_loop.py:414-445`)を `getattr(agent,"handoff",None).copy_workdir` で gate(既定 True で現状維持)。`_OUTPUT_BLACKLIST` はそのまま。 +2. **G7 sterile-gate 対称化**: `compute_files_changed(parent,child)`(`bfts_loop.py:631-656`)は無条件で score を 0 clamp。copy-OFF アームでは子 dir 空 → 全ファイル「deleted」→ sterile 判定が反転する。**copy-OFF では空 baseline 基準**(子が自分で書いた added/modified のみ数え、幽霊 deleted を無視)にし、アーム間で「no-op」の意味を一定化。 +3. **G12 timeout / overflow**: dead code の TimeoutError 分岐(`bfts_loop.py:532-541`、`as_completed` 後で発火不能)を、(a) 実 wall-clock kill(子をキャンセル可能プロセスで)に直すか、(b) 統制変数から明示除外し `max_react_steps` を唯一予算とする。いずれか事前登録。あわせて **full_log overflow カウンタ**と「overflow 時の full_log 定義」を導入(窓圧縮 `agent/loop.py:725` で full_log が黙って truncated 化するのを明示)。 + +## 検証ゲート(実機) +`copy_workdir=False` アームで親 code が子に来ない。do-nothing 子が copy-ON/OFF 両アームで同じ「sterile」判定。per-node 予算が全アーム同一で強制(or 明示除外を文書化)。 diff --git a/ari-core/ari/cli/README.md b/ari-core/ari/cli/README.md index bb19dcd5..d60cb898 100644 --- a/ari-core/ari/cli/README.md +++ b/ari-core/ari/cli/README.md @@ -12,6 +12,7 @@ construction logic is delegated to `ari.core`. - `commands.py` — misc top-level commands + `_safe_backup`. - `lineage.py` — end-of-phase lineage-decision helpers. - `migrate.py` — `ari migrate` sub-app. +- `Plan.md` — G5 copy / G7 sterile / G12 timeout・overflow の実装計画(handoff study). - `projects.py` — `ari paper` / `status` / `projects` / `show` commands. - `run.py` — `ari run` / `ari resume` commands. diff --git a/ari-core/ari/config/Plan.md b/ari-core/ari/config/Plan.md new file mode 100644 index 00000000..6b268455 --- /dev/null +++ b/ari-core/ari/config/Plan.md @@ -0,0 +1,23 @@ +# Plan — G1: HandoffConfig + env override + 配線 + +Status: 実装計画(未実装)。Origin: 2026-06 handoff study 設計。 +親計画: [`../../MASTER_PLAN_handoff_impl.md`](../../MASTER_PLAN_handoff_impl.md)、研究計画 [`../../PLAN_artifact_summary_handoff.md`](../../PLAN_artifact_summary_handoff.md) §8.1。 + +## 依存関係(他 Plan.md) +- 上流依存: なし(Stage 1 の根)。 +- 下流(本 subtask の単一情報源を読む): + - [`../agent/Plan.md`](../agent/Plan.md) — B1 memory gate / G4 agent 注入 / B3。 + - [`../orchestrator/Plan.md`](../orchestrator/Plan.md) — G3 field トグル。 + - [`../cli/Plan.md`](../cli/Plan.md) — G5 copy トグル / G7 / G12。 + +## 削除要件 +HandoffConfig・`apply_handoff_env_overrides`・呼出配線が main に land し、7 モードが env から再現選択でき、MASTER の完了ログに記録された時点で本 Plan.md を削除する。 + +## 実装項目 +1. **`HandoffConfig`(pydantic, `__init__.py:66-139` の `BFTSConfig` 兄弟)**: `mode`(7値)/`copy_workdir`/`inject_agent_block`/`inject_planner_block`/`log_mode`(none|full|truncated|masked)/`log_truncate_chars`/`summary_form`(extractive|rolling|failure_only)/`summary_fields_enabled: list[str]`/`memory_off`。 +2. **`resolve_mode()`**: 7 モード名 → 上記 bool 集合の写像(`ARI_HANDOFF_MODE` 1 値で run が完全特定)。 +3. **`apply_handoff_env_overrides(cfg)`**: `__init__.py:440-471` の `apply_bfts_env_overrides` を模倣。Literal の env ホワイトリスト検証も踏襲。**同じ呼出箇所から必ず呼ぶ**(定義だけで未配線にしない)。 +4. **配線**: `ARIConfig`(`__init__.py:281` は `extra:allow`)に `handoff:` を追加 → `../core.py:83` で `cfg.handoff` を読む。 + +## 検証ゲート +`ARI_HANDOFF_MODE=code_only|code_plus_summary|code_plus_full_log` の3値で、解決された bool 集合がログに正しく出ることを確認([`../agent/Plan.md`](../agent/Plan.md) の gate と連結)。 diff --git a/ari-core/ari/config/README.md b/ari-core/ari/config/README.md index a07ab2a4..00fc8065 100644 --- a/ari-core/ari/config/README.md +++ b/ari-core/ari/config/README.md @@ -8,6 +8,7 @@ their env-var overrides (`ARI_BACKEND`, `ARI_MODEL`, …). - `README.md` — this file. - `__init__.py` — Pydantic config models + env-var overrides. - `finder.py` — workflow / profile YAML discovery. +- `Plan.md` — G1 HandoffConfig+env override の実装計画(handoff study). ## See also diff --git a/ari-core/ari/evaluator/Plan.md b/ari-core/ari/evaluator/Plan.md new file mode 100644 index 00000000..bc263d96 --- /dev/null +++ b/ari-core/ari/evaluator/Plan.md @@ -0,0 +1,22 @@ +# Plan — B2: deterministic evaluator + 測定器ユニット + +Status: 実装計画(未実装)。Origin: 2026-06 handoff study 設計。 +親計画: [`../../MASTER_PLAN_handoff_impl.md`](../../MASTER_PLAN_handoff_impl.md)、研究計画 [`../../PLAN_artifact_summary_handoff.md`](../../PLAN_artifact_summary_handoff.md) §6.2 / §8 Stage 1。 + +## 依存関係(他 Plan.md) +- 上流依存: なし(Stage 1 の根)。 +- 下流(本 subtask を前提にする): + - [`../orchestrator/Plan.md`](../orchestrator/Plan.md) — G9a は `_scientific_score` を必要とする。 + - [`../agent/Plan.md`](../agent/Plan.md) — B3(契約凍結)は本 evaluator が固定採点を持つことを前提。 + - [`../../scripts/Plan.md`](../../scripts/Plan.md) — analyze は evaluator 出力を集計。 + +## 削除要件 +本 subtask(`deterministic_evaluator.py` + `core.py` の evaluator dispatch + 測定器ユニット)が main に land し、**実機 compute node** で検証ゲートを通過し、MASTER の完了ログに記録された時点で本 Plan.md を削除する。 + +## 実装項目 +1. **`deterministic_evaluator.py`(新規, 本 dir)**: `ari/protocols/evaluator.py` の `Evaluator` Protocol に準拠し、**`evaluate_sync(goal, artifacts, summary, node_id=None, node_label=None)` を必ず実装**(loop は `agent/loop.py:1454/1532/1600` で sync 版を呼ぶ)。戻り値 `{"metrics": {"_scientific_score": s∈[0,1], …}, "has_real_data": bool, "reason": str}`。`node.metrics = eval_result["metrics"]`(`agent/loop.py:1461`)経由で BFTS 選択(`orchestrator/bfts.py:336`)に効くため、**`metrics._scientific_score` を [0,1] 正規化して必ず格納**。 +2. **測定器ユニット(evaluator が独占所有)**: 参照解 oracle(fp64 / 補償加算)、行ごと ε(`C·γ_{nnz}·Σ|A||x|`)、timing(W warmup+R reps median+分散、core pin、freq 固定、OMP 明示、NUMA)、checksum 固定 baseline(candidate と同一フラグ)、anti-gaming(matrix/timing/baseline/correctness を独占、correctness 用 x は call 時供給)。 +3. **dispatch(`../core.py:195`)**: 現状 `LLMEvaluator(...)` ハードコード。`ARI_EVALUATOR` で差し替え可能に(`../core.py:155-182` の `axis_mode` dispatch を模倣)。 + +## 検証ゲート(実機) +固定タスクで `code+summary` を1本実行し、(i) valid node>0、(ii) selector が**非ゼロ** `_scientific_score` を消費、(iii) LLMEvaluator 非経由で採点が完走、を確認。 diff --git a/ari-core/ari/evaluator/README.md b/ari-core/ari/evaluator/README.md index 967e8f53..f521117d 100644 --- a/ari-core/ari/evaluator/README.md +++ b/ari-core/ari/evaluator/README.md @@ -10,6 +10,7 @@ orchestrator consumes. - `__init__.py` — public symbols + axis design. - `dynamic_axes.py` — venue/run-specific evaluation-axis derivation. - `llm_evaluator.py` — `LLMEvaluator`: extraction + multi-axis composite scoring. +- `Plan.md` — B2 deterministic evaluator+測定器ユニットの実装計画(handoff study). ## See also diff --git a/ari-core/ari/llm/Plan.md b/ari-core/ari/llm/Plan.md new file mode 100644 index 00000000..5724a472 --- /dev/null +++ b/ari-core/ari/llm/Plan.md @@ -0,0 +1,25 @@ +# Plan — ローカルモデル決定性: seed plumb / digest pin / thinking-mode 統制 + +Status: 実装計画(未実装)。Origin: 2026-06 handoff study 設計。 +親計画: [`../../MASTER_PLAN_handoff_impl.md`](../../MASTER_PLAN_handoff_impl.md)、研究計画 [`../../PLAN_artifact_summary_handoff.md`](../../PLAN_artifact_summary_handoff.md) §6.3 / §7 / §8 Stage 1。 + +## 依存関係(他 Plan.md) +- 上流依存: なし(Stage 1 の根、独立)。 +- 下流(再現性・統計が本 subtask に依存): [`../../scripts/Plan.md`](../../scripts/Plan.md)(分析の paired/seed 設計)、研究計画 §7。 + +## 削除要件 +seed plumb・digest pin・thinking-mode 統制・per-call provenance 記録が main に land し、実機で「同一 seed/digest で再現性が成立(GPU 非 bit 決定性は n で吸収)」を確認、MASTER 完了ログに記録された時点で本 Plan.md を削除する。 + +## 背景(検証済の現状) +- ローカル backend が既定(`config/__init__.py:581-582`、`ARI_BACKEND=ollama`、既定 `qwen3:8b`、`qwen3:32b` も使用)。 +- temperature はローカルに渡る(`client.py:131`、drop は gpt-5* のみ `client.py:130`)。 +- **seed は `litellm.completion`(`client.py:180`)に未 plumb**。qwen3 thinking-mode 抑制あり(`client.py:141`)。 + +## 実装項目(主に `client.py`) +1. **seed plumb**: `client.py:180/230` の completion kwargs に `seed` を追加(ollama/litellm が pass-through)。 +2. **digest pin**: モデルはタグでなく digest 固定で参照(タグは中身が動く)。 +3. **thinking-mode 統制**: qwen3 thinking を全アーム一貫に(`client.py:141`)。 +4. **provenance**: `cost_tracker.py` の per-call 記録に **resolved model digest / seed / temperature** を追加(現状 model 名のみ)。capability 勾配(small/large、研究計画 RQ-D)はこの provenance で識別。 + +## 検証ゲート(実機) +同一 (seed, digest, temperature, prompt) で複数回実行し、出力分散が API backend より大幅に小さいこと、provenance が trace に正しく残ることを確認。 diff --git a/ari-core/ari/llm/README.md b/ari-core/ari/llm/README.md index 1b61d2e4..35eaba38 100644 --- a/ari-core/ari/llm/README.md +++ b/ari-core/ari/llm/README.md @@ -10,6 +10,7 @@ templates here (those live under `ari/prompts/`). - `__init__.py` — public `LLMClient` + contract. - `cli_server.py` — OpenAI-compatible HTTP shim for agentic CLIs. - `client.py` — `LLMClient`/`LLMMessage`: completion + tool calling + cost recording. +- `Plan.md` — ローカルモデル決定性(seed/digest/thinking)の実装計画(handoff study). - `routing.py` — TODO ## See also diff --git a/ari-core/ari/orchestrator/Plan.md b/ari-core/ari/orchestrator/Plan.md new file mode 100644 index 00000000..cf79b576 --- /dev/null +++ b/ari-core/ari/orchestrator/Plan.md @@ -0,0 +1,21 @@ +# Plan — G3 node_summary_view / G9a deterministic selector + +Status: 実装計画(未実装)。Origin: 2026-06 handoff study 設計。 +親計画: [`../../MASTER_PLAN_handoff_impl.md`](../../MASTER_PLAN_handoff_impl.md)、研究計画 [`../../PLAN_artifact_summary_handoff.md`](../../PLAN_artifact_summary_handoff.md) §3 / §8 Stage 2-3。 + +## 依存関係(他 Plan.md) +- 上流依存: + - [`../config/Plan.md`](../config/Plan.md)(G1)— `summary_fields_enabled` / `summary_form` を読む。 + - [`../evaluator/Plan.md`](../evaluator/Plan.md)(B2)— **G9a の前提**(`_scientific_score` が無いと fallback selector が全 0.0 に縮退)。 +- 下流: [`../agent/Plan.md`](../agent/Plan.md)(G4 が `node_summary_view` を注入)、[`../../scripts/Plan.md`](../../scripts/Plan.md)。 + +## 削除要件 +`node_summary_view`(field 別+FORM 変種)と `bfts_score_only` が main に land し、実機で「field トグルが view に反映」「同一 input で選択が再現」を確認、MASTER 完了ログに記録された時点で本 Plan.md を削除する。 + +## 実装項目 +1. **`node_summary_view.py`(新規, 本 dir)**: `node_report.json`(`node_report/builder.py:551-586`)から field 選択可能な view を生成。source=`delta_vs_parent`/`files_changed`/`self_assessment.concerns`/`next_steps_hints`/`metrics._scientific_score`。**`known_failures` は native field 非存在 → failed-node の evaluator_reason / concerns から導出**。FORM 変種: extractive / rolling(祖先要約の有界畳み込み)/ failure_only / masked / truncated。 + ※ 既存 `bfts.py:64-108` `_format_parent_report_block` は **planner プロンプト結合・field 非選択**のため流用不可(新規)。 +2. **G9a `bfts_score_only`**: `bfts.py:418-575` の LLM 一次選択を flag で bypass し、常に `_select_fallback`(`bfts.py:356-369`, `frontier_score=scientific_only`)を一次選択に。これで selector 由来分散を除去。 + +## 検証ゲート(実機) +`summary_fields_enabled` から1 field 落とすと view から当該 field が消える。`bfts_score_only` 下で同一 input の選択が決定的に再現。 diff --git a/ari-core/ari/orchestrator/README.md b/ari-core/ari/orchestrator/README.md index 00a63f73..ae3589d5 100644 --- a/ari-core/ari/orchestrator/README.md +++ b/ari-core/ari/orchestrator/README.md @@ -11,6 +11,7 @@ LLM node scoring, lineage decisions, and root-idea selection. - `lineage_decision.py` — LLM lineage action + `lineage_decisions.jsonl` log. - `node.py` — `Node` data model + `NodeStatus` / `NodeLabel` enums. - `node_selection.py` — shared node-selection helpers + publication source-file selection. +- `Plan.md` — G3 node_summary_view / G9a deterministic selector の実装計画(handoff study). - `root_idea_selector.py` — run-start LLM root-idea pick + selection log. - `node_report/` — per-node `node_report.json` package. - `README.md` — node_report index. diff --git a/scripts/Plan.md b/scripts/Plan.md new file mode 100644 index 00000000..03855c11 --- /dev/null +++ b/scripts/Plan.md @@ -0,0 +1,27 @@ +# Plan — 実験ハーネス・run/analyze スクリプト・provenance・コストゲート + +Status: 実装計画(未実装)。Origin: 2026-06 handoff study 設計。 +親計画: [`../ari-core/MASTER_PLAN_handoff_impl.md`](../ari-core/MASTER_PLAN_handoff_impl.md)、研究計画 [`../ari-core/PLAN_artifact_summary_handoff.md`](../ari-core/PLAN_artifact_summary_handoff.md) §8 Stage 4-5 / §11。 + +## 依存関係(他 Plan.md) +- 上流依存(チェーン末端=下記すべてが land 済を前提): + - [`../ari-core/ari/evaluator/Plan.md`](../ari-core/ari/evaluator/Plan.md)(B2) + - [`../ari-core/ari/config/Plan.md`](../ari-core/ari/config/Plan.md)(G1) + - [`../ari-core/ari/agent/Plan.md`](../ari-core/ari/agent/Plan.md)(B1/B3/G4) + - [`../ari-core/ari/orchestrator/Plan.md`](../ari-core/ari/orchestrator/Plan.md)(G3/G9a) + - [`../ari-core/ari/cli/Plan.md`](../ari-core/ari/cli/Plan.md)(G5/G7/G12) + - [`../ari-core/ari/llm/Plan.md`](../ari-core/ari/llm/Plan.md)(seed/digest/provenance) + +## 削除要件 +run/analyze スクリプト・tracked ハーネス・スクラブ・instrumentation が main に land し、実機で end-to-end(run→trace→analyze→図表)が回り、MASTER 完了ログに記録された時点で本 Plan.md を削除する。 + +## 実装項目 +1. **tracked ハーネス**: `.gitignore:31-37`(`*.c`/`benchmarks/`/`experiments/` 等を repo 全体で無視)を**個別 `!` 否定**で例外化し、固定 baseline/candidate kernel・Makefile・seeded matrix generator(families+SuiteSparse SHA256 pin)・README(Contents 同期)を tracked 化。`git check-ignore -v ` で各 fixture が tracked であることを確認。 +2. **`run_handoff_ablation.py`**: arm × model_size × seed を固定予算で sweep。`ARI_HANDOFF_MODE` / `ARI_FREEZE_CONTRACT` / `ARI_EVALUATOR` / deterministic selector flag / `memory_off` / model+digest+seed を設定。出力は `workspace/checkpoints/_/`(リポジトリ規約、$HOME 直下・/tmp 禁止)。 +3. **`analyze_handoff_ablation.py`**: `tree.json` / `cost_trace.jsonl` / `node_report.json` / evaluator 出力(+新設 `handoff_trace.jsonl`)を集計。**`search_trace.jsonl` は存在しないので使わない**。run 単位 cluster bootstrap、parity は TOST、**注入トークンを per-node prompt_tokens と分離計測**、図表。 +4. **instrumentation**: `handoff_trace.jsonl`(per-node 注入トークン/チャネル別)、summary 忠実性(導出 known_failures vs evaluator failure_signature)、provenance([`../ari-core/ari/llm/Plan.md`](../ari-core/ari/llm/Plan.md) と連結)。 +5. **機械情報スクラブ(収集時)**: `node_report` 等に実在する hostname/partition 系(`ari-core/ari/schemas/node_report.schema.json` / `builder.py`)を**収集時にスクラブ**+commit 前 grep ゲート。tracked artifact・図・commit message に機械情報を一切入れない(リポジトリ最優先規約)。 +6. **cost go/no-go ゲート**: `cost_tracker` の `estimated_cost_usd` を集計し per-cell/全体の予算ゲート。ローカル主体・frontier アームのみ予算管理。 + +## 検証ゲート(実機) +`git check-ignore -v` で全 fixture が tracked。スクラブ後 trace に機械情報ゼロ(grep)。run→analyze が end-to-end で図表生成。 diff --git a/scripts/README.md b/scripts/README.md index 6ca2ecd1..fe77a387 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -7,6 +7,7 @@ Operational and utility scripts for building images, running services, and dev t - `README.md` — this file. - `build_pb_images.sh` — build the vendor PaperBench Docker images (`pb-env`, `pb-reproducer`). - `gpu_ollama_monitor.sh` — monitor the SLURM GPU node running Ollama and re-tunnel it. +- `Plan.md` — ハーネス・run/analyze・scrub・cost ゲートの実装計画(handoff study). - `readme_sync.py` — sync per-directory README `## Contents` indexes with the tree (`--check` gates drift, `--write` regenerates; no LLM/API). - `run_all_tests.sh` — run each skill's pytest suite in its own process. - `run_ollama_gpu.sh` — start Ollama on a SLURM GPU node and tunnel it to the login node. From 1a9dcca420ae5e2907b2a9e26e3d59eb6047c596 Mon Sep 17 00:00:00 2001 From: kotama7 Date: Sun, 14 Jun 2026 03:47:47 +0900 Subject: [PATCH 3/4] docs: fill remaining per-subtask plans (root files, memory backend) Close the two coverage gaps in the per-subtask implementation plans: - ari-core/ari/Plan.md: root-file edits (core.py evaluator dispatch, cost_tracker.py provenance) that had only been cross-referenced. - ari-skill-memory/Plan.md: memory backend side of RQ-C (push/pull surface, ancestor-scoped topology, retrieved-text logging; Phase C). Both carry inter-plan dependencies and deletion requirements. MASTER subtask index + completion log updated; ari/ README Contents synced. Co-Authored-By: Claude Opus 4.8 (1M context) --- ari-core/MASTER_PLAN_handoff_impl.md | 4 ++++ ari-core/ari/Plan.md | 22 ++++++++++++++++++++++ ari-core/ari/README.md | 1 + ari-skill-memory/Plan.md | 24 ++++++++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 ari-core/ari/Plan.md create mode 100644 ari-skill-memory/Plan.md diff --git a/ari-core/MASTER_PLAN_handoff_impl.md b/ari-core/MASTER_PLAN_handoff_impl.md index e3c00cd3..34e126f0 100644 --- a/ari-core/MASTER_PLAN_handoff_impl.md +++ b/ari-core/MASTER_PLAN_handoff_impl.md @@ -21,6 +21,8 @@ Status: 実装マスター計画(未実装)。Origin: 2026-06 設計議論 | B1 memory gate / B3 契約凍結 / G4 注入 | [`ari/agent/Plan.md`](ari/agent/Plan.md) | agent | config, evaluator, orchestrator | | G3 node_summary_view / G9a selector | [`ari/orchestrator/Plan.md`](ari/orchestrator/Plan.md) | orchestrator | config, evaluator | | G5 copy / G7 sterile / G12 timeout・overflow | [`ari/cli/Plan.md`](ari/cli/Plan.md) | cli | config | +| root 横断: core.py dispatch / cost_tracker provenance | [`ari/Plan.md`](ari/Plan.md) | ari(root) | evaluator, agent, llm | +| memory backend: RQ-C surface/topology / retrieved-text log | [`../ari-skill-memory/Plan.md`](../ari-skill-memory/Plan.md) | ari-skill-memory | agent, orchestrator(Phase C 主体) | | ハーネス / run・analyze / scrub / cost | [`../scripts/Plan.md`](../scripts/Plan.md) | scripts | 上記すべて | 依存の要点: **B2 → B3 → B1 が背骨**。B2 で採点固定 → B3 で契約外生化(しないと B2 が `agent/loop.py:1190` で上書きされる)→ B1 で memory 第3経路を gate(しないと全アームが state 共有)。 @@ -44,4 +46,6 @@ Stage 0 全部 + Stage 1 全部 + Stage 2 の B1・G3・G4・G5・G7 + Sta - [ ] B1 / B3 / G4 — land __ / 実機 gate __ - [ ] G3 / G9a — land __ / 実機 gate __ - [ ] G5 / G7 / G12 — land __ / 実機 gate __ +- [ ] root 横断 (core.py dispatch / cost_tracker provenance) — land __ / 実機 gate __ +- [ ] memory backend (RQ-C surface/topology・Phase C) — land __ / 実機 gate __ - [ ] ハーネス / scripts / scrub — land __ / 実機 gate __ diff --git a/ari-core/ari/Plan.md b/ari-core/ari/Plan.md new file mode 100644 index 00000000..80540866 --- /dev/null +++ b/ari-core/ari/Plan.md @@ -0,0 +1,22 @@ +# Plan — root ファイル横断: core.py evaluator dispatch / cost_tracker.py provenance + +Status: 実装計画(未実装)。Origin: 2026-06 handoff study 設計。 +親計画: [`../MASTER_PLAN_handoff_impl.md`](../MASTER_PLAN_handoff_impl.md)、研究計画 [`PLAN_artifact_summary_handoff.md`](PLAN_artifact_summary_handoff.md) §6.2 / §8 Stage 1 / §11。 +対象は `ari-core/ari/` **直下のファイル**(サブパッケージに属さない横断的改修)。 + +## 依存関係(他 Plan.md) +- 上流依存: + - [`evaluator/Plan.md`](evaluator/Plan.md)(B2)— dispatch が**選ぶ**対象(deterministic evaluator クラス)はそちらで定義。 + - [`agent/Plan.md`](agent/Plan.md)(B3)— make_metric_spec 自己決定の封じ込めは loop 側。本書は build 時 spec 構築(`core.py`)との整合のみ扱う。 + - [`llm/Plan.md`](llm/Plan.md)— provenance に載せる seed/digest/temperature の出所。 +- 下流: [`../../scripts/Plan.md`](../../scripts/Plan.md)(analyze が provenance を読む)。 + +## 削除要件 +core.py の evaluator dispatch と cost_tracker.py の provenance 拡張が main に land し、実機で「`ARI_EVALUATOR` で deterministic evaluator に切替わる」「per-call で seed/digest/temp が trace に残る」を確認、MASTER 完了ログに記録された時点で本 Plan.md を削除する。 + +## 実装項目 +1. **`core.py` evaluator dispatch**: `core.py:195` は現状 `LLMEvaluator(...)` ハードコード(`axis_mode` dispatch `core.py:155-182` は軸のみ)。`ARI_EVALUATOR`(or `cfg.evaluator.kind`)で [`evaluator/Plan.md`](evaluator/Plan.md) の deterministic evaluator に差し替え可能化。B3([`agent/Plan.md`](agent/Plan.md))で make_metric_spec の自己決定を封じた上で、build 時 spec(`core.py:62,151` `_make_metric_spec`)は固定/generic のまま evaluator が採点を所有する形に整合させる。 +2. **`cost_tracker.py` provenance 拡張**: per-call 記録(現状 model 名・token 数等)に **resolved model digest / seed / temperature** を追加(値の供給は [`llm/Plan.md`](llm/Plan.md))。capability 勾配(研究計画 RQ-D)と再現性(§11)はこの provenance で識別・検証する。 + +## 検証ゲート(実機) +`ARI_EVALUATOR` 切替で deterministic evaluator が使われること、`cost_trace` 各行に digest/seed/temperature が入ること、同一 (digest, seed) で再現性が立つことを確認。 diff --git a/ari-core/ari/README.md b/ari-core/ari/README.md index 5d1a922f..d2c90d0d 100644 --- a/ari-core/ari/README.md +++ b/ari-core/ari/README.md @@ -18,6 +18,7 @@ Core engine package for ARI. Each sub-package carries its own `README.md` - `memory_cli.py` — `ari memory` subcommand (migrate / backup / …). - `paths.py` — centralised `PathManager` for directory layout/resolution. - `pidfile.py` — `.ari_pid` write/read/cleanup for run-liveness detection. +- `Plan.md` — root ファイル横断(core.py evaluator dispatch / cost_tracker.py provenance)の実装計画(handoff study). - `agent/` — ReAct loop, environment capture, per-stage workflow guidance. - `README.md` — agent index. - `__init__.py` — package module-map docstring. diff --git a/ari-skill-memory/Plan.md b/ari-skill-memory/Plan.md new file mode 100644 index 00000000..9292b9dc --- /dev/null +++ b/ari-skill-memory/Plan.md @@ -0,0 +1,24 @@ +# Plan — memory backend 側: RQ-C surface/topology + retrieved-text ロギング + +Status: 実装計画(未実装、Phase C 主体)。Origin: 2026-06 handoff study 設計。 +親計画: [`../ari-core/MASTER_PLAN_handoff_impl.md`](../ari-core/MASTER_PLAN_handoff_impl.md)、研究計画 [`../ari-core/PLAN_artifact_summary_handoff.md`](../ari-core/PLAN_artifact_summary_handoff.md) §3(SURFACE/TOPOLOGY)/ §5 RQ-C / §8 Stage 4。 + +## 位置づけ +RQ-A/B(MVP)の memory **gate**(注入の on/off)は loop 側 [`../ari-core/ari/agent/Plan.md`](../ari-core/ari/agent/Plan.md)(B1)が担当する。本書は **memory backend 側**=RQ-C の「同一 content を push か pull か(surface)」「any-ancestor reach(topology)」を**統制可能にし検証する**ための backend 改修で、**Phase C 主体・MVP では不要**。 + +## 依存関係(他 Plan.md) +- 上流依存: + - [`../ari-core/ari/agent/Plan.md`](../ari-core/ari/agent/Plan.md)(B1 gate / G4 注入)— pure-PULL は loop 側で push ブロックを抑制して初めて成立。 + - [`../ari-core/ari/orchestrator/Plan.md`](../ari-core/ari/orchestrator/Plan.md)(G3)— surface 比較で「同一 content」を固定するため、view 生成と整合。 +- 下流: [`../scripts/Plan.md`](../scripts/Plan.md)(analyze が surface 検証ログを読む)。 + +## 削除要件 +retrieved-text ロギングと pure-PULL/topology の per-arm 制御が main に land し、実機で「push と pull で同一 content が届いたことを検証できる」「parent-only / full-ancestor の reach を arm で切替えられる」を確認、MASTER 完了ログに記録された時点で本 Plan.md を削除する。RQ-C を実施しない判断なら、その旨を MASTER に記録して削除。 + +## 実装項目(`src/ari_skill_memory/`) +1. **retrieved-text ロギング**: `access_log.py` の `build_read_event` は現状 entry_id / score(または type)のみ記録し**取得テキストを残さない**(write preview は約 200 字 cap)。read イベントに**取得テキスト**を記録し、「push 面と pull 面で同一 content が子に届いた」ことを事後検証可能にする。両 backend(`backends/in_memory.py`、`backends/letta_backend.py`)の read 経路に対応。 +2. **pure-PULL の成立条件(backend 側)**: backend は既に `search_memory` を提供。loop 側(B1)で Tier-1b/2 の in-prompt push を抑制した上で、agent 駆動 PULL が安定動作することを担保(ancestor-scope は `backends/in_memory.py:101-106` で既にサーバ側強制)。 +3. **topology ノブ**: reach は `ancestor_ids` 引数で決まる(`backends/in_memory.py:103` `allowed=set(ancestor_ids)`)。parent-only=`[parent_id]` / full=全祖先 / none=`[]` を arm で切替えられることを確認・必要なら明示 API 化(backend 改修は最小)。 + +## 検証ゲート(実機) +content を固定して push-only / pull-only / both を切替え、read ログから「同一 content が両 surface で配送された」ことを確認。`ancestor_ids` で parent-only と full-ancestor の reach 差が出ることを確認。 From c2f72531bc9670326de692f7d4cdb5786fd1a908 Mon Sep 17 00:00:00 2001 From: kotama7 Date: Sun, 14 Jun 2026 03:57:12 +0900 Subject: [PATCH 4/4] docs: freeze Stage 0 pre-registration (PREREG_handoff_study.md) Adopt the more-detailed-implementation options on delegation: task=SpMM, implementation branch=bfts_compare. Freeze valid predicate, epsilon model (C=8), _scientific_score normalization (TARGET=4.0x), N=10, failure codebook, primary contrast, H-B/H-C/H-D directions, qwen3 8/14/32B gradient, run-level stats (n>=10, cluster bootstrap, TOST margin=log(1.05)), timing W=3/R=10. Co-Authored-By: Claude Opus 4.8 (1M context) --- ari-core/PREREG_handoff_study.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 ari-core/PREREG_handoff_study.md diff --git a/ari-core/PREREG_handoff_study.md b/ari-core/PREREG_handoff_study.md new file mode 100644 index 00000000..fb3808e0 --- /dev/null +++ b/ari-core/PREREG_handoff_study.md @@ -0,0 +1,29 @@ +# PREREG — Stage 0 凍結(What Should Branching LLM Code Agents Inherit?) + +Status: 事前登録(凍結値。実験開始後は変更しない)。Origin: 2026-06、ユーザ委任により推奨デフォルトを採択。 +親: [`MASTER_PLAN_handoff_impl.md`](MASTER_PLAN_handoff_impl.md)、研究計画 [`PLAN_artifact_summary_handoff.md`](PLAN_artifact_summary_handoff.md) §7。 +削除条件: 本研究の confirmatory run が完了し、凍結値と結果が論文ドラフトまたは後継 PLAN に転記された時点で削除。 + +## 採択した実行方針 +- **主タスク**: **SpMM(Y=AX, A=CSR)**。既存 fixture・評価運用実績があり MVP を最短で実物まで詰められるため。SpMV は Phase C。 +- **実装ブランチ**: **`bfts_compare`**(実装コード専用)。計画/PREREG は PR #31(`plan-artifact-summary-handoff`)に温存。 + +## 凍結値 +| # | 項目 | 凍結値 | +|---|---|---| +| 1 | valid 述語 | compile ∧ run ∧ correctness(ε) ∧ no-timeout ∧ 全必須行列完了 ∧ no protocol-violation。invalid=score 0 | +| 2 | ε 誤差モデル | 出力要素ごと `|y_cand−y_ref| ≤ C·γ_k·Σ|A||x|`、`γ_k=k·u/(1−k·u)`、`u`=fp64 unit roundoff、**C=8** | +| 3 | `_scientific_score` 正規化 | `s = min(geomean_speedup / TARGET, 1.0)`、**TARGET=4.0×** | +| 4 | invalid-family 規則 | 必須 family を1つでも落とせば node-invalid(geomean に 0 を混ぜない) | +| 5 | N(best valid @ N nodes) | **10** | +| 6 | failure codebook | COMPILE{syntax,linker,header} / CORRECTNESS{eps_exceeded,nan} / PROTOCOL{frozen_checksum} / TIMEOUT / NOOP_STERILE / PARENT_OUTPUT_MISUSE | +| 7 | primary 対比(単一) | **code_plus_summary vs code_plus_full_log**(SpMM・large モデル・deterministic selector) | +| 8 | 仮説の向き | H-B: failure/concern 系が支配・next_steps 寄与せず/H-C: 分岐で extractive-failure-summary > masking 単独/H-D(FORM×capability 交差): large=masking 十分・small=failure-summary 必須 | +| 9 | モデル水準 | 主=ローカル qwen3 dense **8B / 14B / 32B**(同一ファミリ)、large=32B が MVP。frontier API は robustness 1本 | +| 10 | 統計 | 単位=run(1木=1スカラ)、**n≥10/cell**、run クラスタ bootstrap、parity は TOST(**margin=log(1.05)**)、多重性 Holm | +| 11 | 固定定数 | seed kernel+最適化フラグ(全アーム同一・checksum)、timing **W=3 warmup / R=10 reps(median)**、`OMP_NUM_THREADS` 固定、turbo off、単一アーキ | + +## pilot ゲート(confirmatory 前に確認) +- (a) qwen3:8b が SpMM で validity を非ゼロで超えるか(床打ちなら small を 14B に上げる)。 +- (b) 最大サイズ(32B)が GPU 経路に載るか。 +- (c) deterministic selector が非ゼロ `_scientific_score` を消費するか(B2 land 後)。