feat: add panic recovery with crash log & finish -> agent_exit#21
Conversation
…tter truncation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… cognitive reflection scope Co-Authored-By: Claude Code <noreply@anthropic.com>
…meter Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Reviewer's GuideIntroduces a centralized panic recovery with crash logging, renames and re-wires the core flow-control tool from Sequence diagram for panic recovery crash loggingsequenceDiagram
actor User
participant main
participant util_RecoverPanic as util.RecoverPanic
participant util_buildCrashReport as buildCrashReport
participant OS_FileSystem as OS_FileSystem
User->>main: start_application()
activate main
main->>main: defer util.RecoverPanic()
main->>main: execute_application_logic()
main-->>main: panic(recovered_value)
deactivate main
activate util_RecoverPanic
util_RecoverPanic->>util_RecoverPanic: r = recover()
alt r is nil
util_RecoverPanic-->>User: return (no crash)
else r is not nil
util_RecoverPanic->>util_buildCrashReport: buildCrashReport(r)
activate util_buildCrashReport
util_buildCrashReport-->>util_RecoverPanic: crash_report_string
deactivate util_buildCrashReport
util_RecoverPanic->>OS_FileSystem: crashLogDir() (resolve ~/.codeactor/logs/crash)
alt dir resolution fails
util_RecoverPanic->>User: write report to stderr
util_RecoverPanic-->>main: re_panic(r)
else dir ok
OS_FileSystem-->>util_RecoverPanic: crash_dir_path
util_RecoverPanic->>OS_FileSystem: MkdirAll(crash_dir_path)
alt MkdirAll fails
util_RecoverPanic->>User: write report to stderr
util_RecoverPanic-->>main: re_panic(r)
else MkdirAll ok
util_RecoverPanic->>OS_FileSystem: OpenFile(crash-YYYY-MM-DD.log, append)
alt OpenFile fails
util_RecoverPanic->>User: write report to stderr
util_RecoverPanic-->>main: re_panic(r)
else OpenFile ok
OS_FileSystem-->>util_RecoverPanic: file_handle
util_RecoverPanic->>OS_FileSystem: WriteString(report)
OS_FileSystem-->>util_RecoverPanic: write_result
util_RecoverPanic->>User: also print report to stderr
util_RecoverPanic-->>main: re_panic(r)
end
end
end
end
Updated class diagram for flow control, thinking tool, and agentsclassDiagram
class FlowControlTool {
+string WorkingDir
+ExecuteAgentExit(ctx context.Context, params map_string_interface) (interface_type, error)
}
class ThinkingTool {
+Name() string
+Call(ctx context.Context, input string) (string, error)
-buildCrashReport(recovered interface_type) string
}
class GlobalCtx {
+FlowOps *FlowOps
+ThinkingTool *ThinkingTool
}
class FlowOps {
+ExecuteAgentExit(ctx context.Context, params map_string_interface) (interface_type, error)
+ExecuteAskUserForHelp(ctx context.Context, params map_string_interface) (interface_type, error)
}
class ConductorAgent {
+GlobalCtx *GlobalCtx
+toolDefMap map[string]ToolDefinition
+getToolFunc(name string) tools.ToolFunc
+registerCustomAgent(ca *CustomAgent)
+Run(ctx context.Context, input string, mem *memory.Conversation) (string, error)
}
class CodingAgent {
+GlobalCtx *GlobalCtx
+NewCodingAgent(globalCtx *GlobalCtx, llm llms.LLM, maxSteps int) *CodingAgent
}
class ExecutorConfig {
+bool StopOnFinish
}
class RunAgentLoopFn {
+RunAgentLoop(ctx context.Context, cfg ExecutorConfig) (string, error)
}
%% Relationships
GlobalCtx --> FlowOps : has
GlobalCtx --> ThinkingTool : has
FlowOps --> FlowControlTool : uses
ConductorAgent --> GlobalCtx : has
CodingAgent --> GlobalCtx : has
ConductorAgent --> FlowOps : uses ExecuteAgentExit
CodingAgent --> FlowOps : uses ExecuteAgentExit
ConductorAgent --> ThinkingTool : uses Call
CodingAgent --> ThinkingTool : uses Call
ExecutorConfig --> RunAgentLoopFn : config_for
RunAgentLoopFn --> FlowOps : calls ExecuteAgentExit
class ToolDefinition {
+string Description
+map_string_interface Parameters
}
ConductorAgent --> ToolDefinition : stores_in_toolDefMap
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
FlowControlTool.ExecuteAgentExit, the error wrap context string is still"executeFinish", which is confusing now that the function and tool have been renamed; consider updating it to something like"executeAgentExit"for accurate diagnostics. - In
ThinkingTool.Call, the JSON field was renamed fromerror_messagetoproblem_descriptionbut the formatted output still labels it asError:; consider updating the label to match the new semantics to avoid confusion in logs.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `FlowControlTool.ExecuteAgentExit`, the error wrap context string is still `"executeFinish"`, which is confusing now that the function and tool have been renamed; consider updating it to something like `"executeAgentExit"` for accurate diagnostics.
- In `ThinkingTool.Call`, the JSON field was renamed from `error_message` to `problem_description` but the formatted output still labels it as `Error:`; consider updating the label to match the new semantics to avoid confusion in logs.
## Individual Comments
### Comment 1
<location path="internal/agents/conductor.go" line_range="686" />
<code_context>
},
},
})
- if tc.FunctionCall.Name == "finish" {
+ if tc.FunctionCall.Name == "agent_exit" {
return "Task completed successfully", nil
}
</code_context>
<issue_to_address>
**issue (bug_risk):** The fixed "Task completed successfully" message no longer matches the broader semantics of agent_exit.
agent_exit can represent success, failure, clarification, or forced termination, but the returned string always says “Task completed successfully”. This risks misleading callers and any UI using this value. Consider deriving a status from the tool output (e.g., including the reason) or using a neutral message that doesn’t imply success.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| }, | ||
| }, | ||
| }) | ||
| if tc.FunctionCall.Name == "finish" { |
There was a problem hiding this comment.
issue (bug_risk): The fixed "Task completed successfully" message no longer matches the broader semantics of agent_exit.
agent_exit can represent success, failure, clarification, or forced termination, but the returned string always says “Task completed successfully”. This risks misleading callers and any UI using this value. Consider deriving a status from the tool output (e.g., including the reason) or using a neutral message that doesn’t imply success.
Summary by Sourcery
Introduce robust crash logging and align agent flow-control tooling and TUI history presentation with the new exit semantics and more compact task titles.
New Features:
Enhancements:
finishtoagent_exitacross agents, executors, prompts, and tests to better represent agent termination semantics.problem_descriptionfield instead oferror_messagefor clearer logging semantics.Tests:
agent_exittool name and expectations instead offinish.