Skip to content

feat(backends): add beforeExecute/afterExecute lifecycle hooks to AgentEngine interface#836

Merged
aaight merged 1 commit intodevfrom
feature/engine-lifecycle-hooks
Mar 14, 2026
Merged

feat(backends): add beforeExecute/afterExecute lifecycle hooks to AgentEngine interface#836
aaight merged 1 commit intodevfrom
feature/engine-lifecycle-hooks

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Mar 14, 2026

See PR description

🕵️ claude-code · claude-sonnet-4-6 · run details

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

LGTM — well-designed lifecycle hooks that cleanly separate engine-specific setup/cleanup from the adapter orchestration layer. The interface extension is backward-compatible (optional methods), all engines are updated consistently, and all 571 backend tests pass.

Architecture & Design

The pattern is sound: beforeExecute/afterExecute in the AgentEngine interface give each engine a clean injection point for pre/post work, while the adapter's nested try/finally ensures afterExecute always runs even on failure. The backward compatibility story for direct execute() callers (e.g., tests) is well handled — ClaudeCode removes internal cleanup entirely, Codex uses _adapterLifecycleActive to avoid double-cleanup, and LLMist simply doesn't implement the hooks.

Should Fix

  • src/backends/opencode/index.ts:812 (afterExecute) — Unlike ClaudeCode (which fully moved cleanup to afterExecute) and Codex (which uses _adapterLifecycleActive to skip internal cleanup when the adapter lifecycle is active), OpenCode's execute() still calls cleanupContextFiles in its finally block (line 883-885 of the full file) and afterExecute calls it again unconditionally. This results in duplicate cleanup when called through the adapter. While cleanupContextFiles is idempotent and this won't cause failures, it's an inconsistency with the other engines. Consider either (a) removing the if (hasOffloadedContext) block from execute()'s finally, or (b) adding the _adapterLifecycleActive guard pattern from Codex.

🕵️ claude-code · claude-opus-4-6 · run details

@aaight aaight merged commit 4aee4c7 into dev Mar 14, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants