Skip to content

Commit dc5a90a

Browse files
roberttwangclaude
andcommitted
fix: name the gate policy in early loop hand-offs; show "checking" while the branch-naming CLI list loads
- agentLoopHumanMessage now distinguishes an executor failure from a gate (or submit_gate_result) failure whose policy is not "loop", matching agentLoopSkipMessage, instead of calling both "执行失败". - The repository drawer repaints the AI branch-naming CLI picker as soon as the executor catalog request starts, so a saved configured CLI shows "(检查配置中)" rather than "(未配置)", and a prefix repo switched to AI shows "检查配置中…" rather than "无可用 CLI" until the catalog returns. Co-Authored-By: Claude Code <noreply@anthropic.com>
1 parent d8f6bd4 commit dc5a90a

4 files changed

Lines changed: 66 additions & 8 deletions

File tree

‎internal/engine/core_cases_test.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,13 @@ func TestAgentLoopMessagesDescribeExecutorFailures(t *testing.T) {
519519
if got := agentLoopSkipMessage("human"); got != "门禁失败策略为 human,跳过自修正" {
520520
t.Fatalf("gate policy skip message = %q", got)
521521
}
522-
if got := agentLoopHumanMessage(1, 3); strings.Contains(got, "耗尽") || !strings.Contains(got, "第 1 轮") {
522+
if got := agentLoopHumanMessage(1, 3, ""); strings.Contains(got, "耗尽") || !strings.Contains(got, "第 1 轮执行失败") {
523523
t.Fatalf("early hand-off message = %q", got)
524524
}
525-
if got := agentLoopHumanMessage(3, 3); got != "Agent 自修正次数已耗尽,转人工判断:" {
525+
if got := agentLoopHumanMessage(1, 3, "fail"); strings.Contains(got, "执行失败") || !strings.Contains(got, "第 1 轮门禁未通过(失败策略为 fail)") {
526+
t.Fatalf("early gate hand-off message = %q", got)
527+
}
528+
if got := agentLoopHumanMessage(3, 3, "loop"); got != "Agent 自修正次数已耗尽,转人工判断:" {
526529
t.Fatalf("exhausted message = %q", got)
527530
}
528531
}

‎internal/engine/node_execute.go‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ func (e *Engine) executeNode(ctx context.Context, runID string, wf domain.Workfl
11831183
return
11841184
}
11851185
nr.Output, nr.Error, nr.Status, nr.FinishedAt = output, err.Error(), "waiting_approval", time.Now().UTC()
1186-
e.event(r, node.ID, "agent.loop.exhausted", agentLoopHumanMessage(lastIteration, maxIterations)+err.Error())
1186+
e.event(r, node.ID, "agent.loop.exhausted", agentLoopHumanMessage(lastIteration, maxIterations, failedAction)+err.Error())
11871187
})
11881188
return
11891189
}
@@ -1414,10 +1414,14 @@ func agentLoopSkipMessage(failedAction string) string {
14141414

14151415
// agentLoopHumanMessage prefixes the hand-off to a person when a looping role
14161416
// stops. It claims the self-correction budget is spent only when every
1417-
// iteration actually ran.
1418-
func agentLoopHumanMessage(iterations, maxIterations int) string {
1419-
if iterations < maxIterations {
1417+
// iteration actually ran, and names the gate policy when a gate (rather than
1418+
// the executor) ended the loop early, matching agentLoopSkipMessage.
1419+
func agentLoopHumanMessage(iterations, maxIterations int, failedAction string) string {
1420+
if iterations >= maxIterations {
1421+
return "Agent 自修正次数已耗尽,转人工判断:"
1422+
}
1423+
if failedAction == "" {
14201424
return fmt.Sprintf("Agent 第 %d 轮执行失败,未进入自修正,转人工判断:", iterations)
14211425
}
1422-
return "Agent 自修正次数已耗尽,转人工判断:"
1426+
return fmt.Sprintf("Agent 第 %d 轮门禁未通过(失败策略为 %s),未进入自修正,转人工判断:", iterations, failedAction)
14231427
}

‎web/app/repo_drawer.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ function syncRepoBranchNaming(form){
8585
form.querySelector('[data-work-branch-custom-prefix]').hidden=form.elements.workBranchPrefix.value!=='custom';
8686
if(isAI){
8787
const user=state.currentUser?.id;
88-
loadExecutorModelCatalogs().then(()=>{
88+
const loading=loadExecutorModelCatalogs();
89+
// Repaint while the catalog loads so the picker says "checking" instead
90+
// of reporting configured CLIs as missing until the request returns.
91+
fillRepoBranchExecutors(form,form.elements.workBranchExecutorId.value);
92+
loading.then(()=>{
8993
if(repoDrawerOpen()&&state.currentUser?.id===user&&form.elements.workBranchNamingMode.value==='ai'){
9094
const manual=form.elements.workBranchModelChoice.value===AGENT_CUSTOM_MODEL;
9195
const model=repoBranchModel(form);

‎webtest/tests/projects-repos.test.mjs‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,53 @@ test('AI branch naming offers only CLIs configured for the user', async (t) => {
272272
assert.deepEqual(updates().at(-1).body.workBranchNaming, { mode: 'ai', executorId: 'codex', model: 'gpt-5.6-sol', prompt: '' });
273273
});
274274

275+
test('AI branch naming says the CLI list is loading instead of not configured', async (t) => {
276+
const app = await loadApp();
277+
t.after(app.close);
278+
let release;
279+
app.router.get('/api/executor-models', () => new Promise(resolve => {
280+
release = () => resolve({ codebuddy: { configured: true, models: [{ id: 'hy4std', name: 'Hy4' }] } });
281+
}));
282+
app.evaluate(`
283+
state.projectAdminDetailId='project-1';
284+
state.projectDraftFor='project-1';
285+
state.data.executors=[{id:'codebuddy',kind:'codebuddy',name:'CodeBuddy'},{id:'codex',kind:'codex',name:'Codex'}];
286+
state.data.repositories=[{
287+
id:'saved-ai', projectId:'project-1', provider:'github',
288+
name:'payments', cloneUrl:'https://github.com/acme/payments.git', defaultBranch:'main',
289+
workBranchNaming:{mode:'ai',executorId:'codebuddy',model:'hy4std',prompt:''}
290+
},{
291+
id:'prefix-repo', projectId:'project-1', provider:'github',
292+
name:'ledger', cloneUrl:'https://github.com/acme/ledger.git', defaultBranch:'main',
293+
workBranchNaming:{mode:'prefix',prefix:'feature/'}
294+
}];
295+
state.projectDraft=projectDraftFrom(state.data.projects[0]);
296+
state.projectDraftBase=clone(state.projectDraft);
297+
openRepoDrawer('saved-ai');
298+
`);
299+
const fields = app.document.querySelector('#repoDrawerForm').elements;
300+
const options = () => Array.from(fields.workBranchExecutorId.options, option => [option.value, option.text, option.disabled]);
301+
await settle(2);
302+
assert.deepEqual(options(), [['', '选择 CLI', false], ['codebuddy', 'CodeBuddy(检查配置中)', true]],
303+
'a saved CLI is not reported as unconfigured before the catalog answers');
304+
assert.equal(fields.workBranchExecutorId.value, 'codebuddy');
305+
release();
306+
await settle(6);
307+
assert.deepEqual(options(), [['', '选择 CLI', false], ['codebuddy', 'CodeBuddy', false]]);
308+
assert.equal(fields.workBranchExecutorId.value, 'codebuddy');
309+
310+
// Switching a prefix repository to AI while the catalog reloads shows the
311+
// checking placeholder rather than "no configured CLI".
312+
app.evaluate(`closeRepoDrawer({restoreFocus:false});openRepoDrawer('prefix-repo');`);
313+
fields.workBranchNamingMode.value = 'ai';
314+
fields.workBranchNamingMode.dispatchEvent(new app.window.Event('change', { bubbles: true }));
315+
await settle(2);
316+
assert.deepEqual(options(), [['', '检查配置中…', false]]);
317+
release();
318+
await settle(6);
319+
assert.deepEqual(options(), [['', '选择 CLI', false], ['codebuddy', 'CodeBuddy', false]]);
320+
});
321+
275322
test('project owner deletes a project from its danger zone and the list moves on', async (t) => {
276323
const app = await loadApp();
277324
t.after(app.close);

0 commit comments

Comments
 (0)