Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 83 additions & 21 deletions docs/workflow.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,85 @@
# 单步模式工作流

```mermaid
flowchart TD
A["ta-kickoff"]
A --> B["Phase 0: Initialize"]
B --> C["Phase 1: Detect Commits"]
C -->|no new commits| D["Done: Already Up-to-Date"]
C -->|new commits found| E["Phase 2A: Merge Upstream"]
E -->|conflicts| F["Phase 2B: AI Resolve Conflicts"]
E -->|no conflicts| G["Phase 2C: Build and Test"]
F -->|resolved| G
F -->|max retries| H["Failure: write FAILURE.md"]
G --> G1["Build: setup.py install"]
G1 -->|failed| I["AI Fix Code"]
G1 -->|passed| G2["Test: pytest"]
G2 -->|failed| I
G2 -->|passed| J["Commit Fixes"]
I -->|retry| G1
I -->|max retries| H
J --> K["Phase 2D: Finalize"]
K --> L["Success"]
L -->|push enabled| M["Push Branch and Create PR"]
L -->|push disabled| N["Done: work branch kept"]
```
A["ta-kickoff"] --> B["Phase 0: Prepare"]
B --> C["Phase 1: Detect"]
C -->|无新 commit| D["Done"]
C -->|有新 commit| E["Phase 2: Plan"]
E --> F["Phase 3: Per-Step Loop"]

subgraph STEP["每个步骤"]
F1["Merge"] --> F2{冲突?}
F2 -->|是| F3["AI Resolve"]
F2 -->|否| F4{LLVM 变更?}
F3 --> F4
F4 -->|是| F5["IR Patch Pipeline"]
F4 -->|否| F6["Build + Fix"]
F5 --> F7{通过?}
F6 --> F7
F7 -->|否| FAIL["UpgradeFailed"]
F7 -->|是| F8["Test + Fix"]
F8 -->|失败| FAIL
F8 -->|通过| F9["Commit"]
F9 --> F10["current_step += 1"]
end

STEP --> G["Phase 4: Finalize"]
G -->|push| PR["Create PR"]

style FAIL fill:#d73
style D fill:#4a9
```

## IR Patch Pipeline(LLVM hash 变更时)

```mermaid
flowchart TD
MERGE["Merge 后发现 LLVM hash 变更"] --> P1["1. 切换到目标 LLVM commit<br/>确保工作区干净"]
P1 --> P2["2. 直接应用现有补丁<br/>llvm_patch_f6ded0b.patch"]
P2 --> P3{应用成功?}
P3 -->|否| P4["AI 分析失败原因<br/>根据当前 LLVM commit 调整补丁"]
P4 --> P2
P3 -->|是| P5["3. 编译 LLVM<br/>(编译失败则 AI 修复补丁)"]
P5 --> P6{编译成功?}
P6 -->|否| P7["AI 根据编译错误修复补丁"]
P7 --> P5
P6 -->|是| P8["4. 编译 TA + AI 修复编译错误"]
P8 --> P9["5. Run pytest"]
P9 --> P10{测试通过?}
P10 -->|是| DONE["Done"]
P10 -->|否| P11["AI 分类: IR 问题 vs 代码问题"]
P11 -->|IR 问题| P12["AI 在现有补丁基础上<br/>补充缺失 OP 的适配<br/>(不重新生成)"]
P12 --> P13["重新编译 LLVM"]
P13 --> P8
P11 -->|代码问题| P14["AI 修复代码 -> Rebuild"]
P14 --> P9

style DONE fill:#4a9
```

## 关键变化(vs 旧流程)

| 旧流程 | 新流程 |
|--------|--------|
| 先做 OP 分析 + 变更分析 | 直接应用现有补丁 |
| AI 从零生成补丁 | AI 在现有补丁上调整/补充 |
| 分析阶段在补丁之前 | 分析阶段在测试发现问题后 |
| 每次重新生成完整补丁 | 保留已有内容,只补充缺失 OP |

## 修复代码评价机制

```
AI 修复
|
Layer 1: AI 自检 (prompt.md step 6)
|-- 检查文件路径 -> 不在允许目录则自行回退
|
Layer 2: 代码校验 (validate_fix)
|-- 硬检查 -> 不通过则 git revert + 反馈 + 不消耗 attempt
|
Layer 3: 实际验证
|-- 编译/测试结果 -> 失败则继续 fix loop
```

详见 [fix-validation-flow.md](fix-validation-flow.md)
40 changes: 40 additions & 0 deletions src/TA_main2main_workflow/agent/prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,46 @@ The active mode is: {mode}
Output ONLY by modifying `{ascend_patch_file}` in-place — the existing
patch file. Do NOT write analysis.md, step_summary.md, or review.md.

── ir_fix_patch_apply mode ──────────────────────────────────────────────

Trigger: {mode} is "ir_fix_patch_apply" (fix patch that failed to apply).

The existing `{ascend_patch_file}` failed to apply to LLVM at
`{target_llvm_hash}`. Analyze the error and adjust the patch:

1. Read the current patch file: `{ascend_patch_file}`
2. Read the apply error: {patch_error_msg}
3. For each failing hunk, use git show to see the target file:
git -C {llvm_project_path} show {target_llvm_hash}:<path>
4. Adjust the patch to match the target LLVM's actual code:
- Fix line numbers and context lines
- If the OP/func being patched was removed, remove that hunk
- If the API changed, adapt the patch code
5. Write the fixed patch to `{ascend_patch_file}`

Reference: {reference_dir}/05-ir-patch-generation-guide.md

── ir_supplement_patch mode ────────────────────────────────────────────

Trigger: {mode} is "ir_supplement_patch" (add missing OPs to existing patch).

Tests revealed IR compatibility issues that the current patch does NOT
cover. The current patch at `{ascend_patch_file}` already handles some
OPs. You must SUPPLEMENT it — keep all existing content and ADD
adaptations for the missing OPs identified in the diagnosis.

1. Read the current patch to understand what's already covered
2. Read `{step_dir}/ir_diagnosis.json` for the IR issues found
3. For each missing OP, check its definition at the target LLVM:
git -C {llvm_project_path} show {target_llvm_hash}:<path>
4. ADD the new OP adaptations to the patch file (do NOT remove
existing content)
5. Apply the same patch patterns (per the guide) to the new OPs
6. Write the supplemented patch to `{ascend_patch_file}`

Reference: {reference_dir}/05-ir-patch-generation-guide.md
{reference_dir}/04-ir-compatibility-and-backend-adaptation.md

── For ir_diagnose mode ──
Output ONLY `{step_dir}/ir_diagnosis.json` — the structured JSON specified
in the ir_diagnose section above. Do NOT write analysis.md, step_summary.md,
Expand Down
Loading