fix(agents): deny apply_patch for GPT models to prevent verification hangs (#2935)
GPT models (5.3-codex, 5.4, etc.) frequently hang when using apply_patch due to verification loops. This adds: 1. Tool restriction: apply_patch is denied for GPT variants of Hephaestus, Sisyphus-Junior, and Sisyphus agents 2. Prompt guidance: GPT-specific prompts now explicitly instruct using edit/write tools instead of apply_patch 3. Removed the 'Always use apply_patch' instruction from sisyphus-junior/gpt-5-4.ts that contradicted the fix The deny is model-conditional — Claude variants retain apply_patch access since it works reliably there.
This commit is contained in:
@@ -192,6 +192,8 @@ describe("createHephaestusAgent", () => {
|
||||
expect(config.prompt).toContain("You build context by examining");
|
||||
expect(config.prompt).toContain("Never chain together bash commands");
|
||||
expect(config.prompt).toContain("<tool_usage_rules>");
|
||||
expect(config.prompt).toContain("Do not use `apply_patch`");
|
||||
expect(config.prompt).toContain("`edit` and `write`");
|
||||
});
|
||||
|
||||
test("GPT 5.3-codex model includes GPT-5.3 specific prompt content", () => {
|
||||
@@ -205,6 +207,8 @@ describe("createHephaestusAgent", () => {
|
||||
expect(config.prompt).toContain("Senior Staff Engineer");
|
||||
expect(config.prompt).toContain("Hard Constraints");
|
||||
expect(config.prompt).toContain("<tool_usage_rules>");
|
||||
expect(config.prompt).toContain("Do not use `apply_patch`");
|
||||
expect(config.prompt).toContain("`edit` and `write`");
|
||||
});
|
||||
|
||||
test("includes Hephaestus identity in prompt", () => {
|
||||
@@ -219,6 +223,35 @@ describe("createHephaestusAgent", () => {
|
||||
expect(config.prompt).toContain("autonomous deep worker");
|
||||
});
|
||||
|
||||
test("generic GPT model includes apply_patch workaround guidance", () => {
|
||||
// given
|
||||
const model = "openai/gpt-4o";
|
||||
|
||||
// when
|
||||
const config = createHephaestusAgent(model);
|
||||
|
||||
// then
|
||||
expect(config.prompt).toContain("Do not use `apply_patch`");
|
||||
expect(config.prompt).toContain("`edit` and `write`");
|
||||
});
|
||||
|
||||
test("GPT models deny apply_patch while non-GPT models do not", () => {
|
||||
// given
|
||||
const gpt54Model = "openai/gpt-5.4";
|
||||
const gptGenericModel = "openai/gpt-4o";
|
||||
const claudeModel = "anthropic/claude-opus-4-6";
|
||||
|
||||
// when
|
||||
const gpt54Config = createHephaestusAgent(gpt54Model);
|
||||
const gptGenericConfig = createHephaestusAgent(gptGenericModel);
|
||||
const claudeConfig = createHephaestusAgent(claudeModel);
|
||||
|
||||
// then
|
||||
expect(gpt54Config.permission ?? {}).toHaveProperty("apply_patch", "deny");
|
||||
expect(gptGenericConfig.permission ?? {}).toHaveProperty("apply_patch", "deny");
|
||||
expect(claudeConfig.permission ?? {}).not.toHaveProperty("apply_patch");
|
||||
});
|
||||
|
||||
test("useTaskSystem=true produces Task Discipline prompt", () => {
|
||||
// given
|
||||
const model = "openai/gpt-5.4";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { AgentConfig } from "@opencode-ai/sdk";
|
||||
import type { AgentMode, AgentPromptMetadata } from "../types";
|
||||
import { isGpt5_4Model, isGpt5_3CodexModel } from "../types";
|
||||
import { isGptModel, isGpt5_4Model, isGpt5_3CodexModel } from "../types";
|
||||
import type {
|
||||
AvailableAgent,
|
||||
AvailableTool,
|
||||
@@ -120,6 +120,7 @@ export function createHephaestusAgent(
|
||||
permission: {
|
||||
question: "allow",
|
||||
call_omo_agent: "deny",
|
||||
...(isGptModel(model) ? { apply_patch: "deny" as const } : {}),
|
||||
} as AgentConfig["permission"],
|
||||
reasoningEffort: "medium",
|
||||
};
|
||||
|
||||
@@ -448,6 +448,7 @@ ${oracleSection}
|
||||
1. SEARCH existing codebase for similar patterns/styles
|
||||
2. Match naming, indentation, import styles, error handling conventions
|
||||
3. Default to ASCII. Add comments only for non-obvious blocks
|
||||
4. Use the \`edit\` and \`write\` tools for file changes. Do not use \`apply_patch\` on GPT models - it is unreliable here and can hang during verification.
|
||||
|
||||
### After Implementation (MANDATORY - DO NOT SKIP)
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@ ${antiPatterns}
|
||||
1. **Explore**: Fire 2-5 explore/librarian agents in parallel + direct tool reads. Goal: complete understanding, not just enough context.
|
||||
2. **Plan**: List files to modify, specific changes, dependencies, complexity estimate.
|
||||
3. **Decide**: Trivial (<10 lines, single file) -> self. Complex (multi-file, >100 lines) -> delegate.
|
||||
4. **Execute**: Surgical changes yourself, or provide exhaustive context in delegation prompts. Match existing patterns. Minimal diff. Search the codebase for similar patterns before writing code. Default to ASCII. Add comments only for non-obvious blocks.
|
||||
4. **Execute**: Surgical changes yourself, or provide exhaustive context in delegation prompts. Match existing patterns. Minimal diff. Search the codebase for similar patterns before writing code. Default to ASCII. Add comments only for non-obvious blocks. Use the \`edit\` and \`write\` tools for file changes. Do not use \`apply_patch\` on GPT models - it is unreliable here and can hang during verification.
|
||||
5. **Verify**: \`lsp_diagnostics\` on all modified files (zero errors) -> run related tests (\`foo.ts\` -> \`foo.test.ts\`) -> typecheck -> build if applicable (exit 0). Fix only issues your changes caused.
|
||||
|
||||
If verification fails, return to step 1 with a materially different approach. After three attempts: stop, revert to last working state, document what you tried, consult Oracle. If Oracle cannot resolve, ask the user.
|
||||
|
||||
@@ -311,6 +311,7 @@ ${oracleSection}
|
||||
1. SEARCH existing codebase for similar patterns/styles
|
||||
2. Match naming, indentation, import styles, error handling conventions
|
||||
3. Default to ASCII. Add comments only for non-obvious blocks
|
||||
4. Use the \`edit\` and \`write\` tools for file changes. Do not use \`apply_patch\` on GPT models - it is unreliable here and can hang during verification.
|
||||
|
||||
### After Implementation (MANDATORY - DO NOT SKIP)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user