Skip to content

feat(agents): cap on stop hook retries#2546

Merged
jordan-umusu merged 2 commits intomainfrom
feat/agent-stop-hook-guardrails
Apr 21, 2026
Merged

feat(agents): cap on stop hook retries#2546
jordan-umusu merged 2 commits intomainfrom
feat/agent-stop-hook-guardrails

Conversation

@jordan-umusu
Copy link
Copy Markdown
Collaborator

@jordan-umusu jordan-umusu commented Apr 21, 2026

Summary by cubic

Add a retry cap to the Claude agent Stop hook to prevent structured-output death loops. Allows up to 3 active retries; on the next retry, the runtime stops the turn and logs a warning.

  • New Features
    • Implemented _stop_hook with MAX_STOP_HOOK_RETRIES=3; natural stops don’t count. Exceeding the cap stops the turn and logs a warning.
    • Registered the Stop hook, typed input as StopHookInput from claude_agent_sdk, and added tests for natural pass-through, cap-bound retries, and cap-exceeded termination.

Written for commit 240906b. Summary will update on new commits.

@jordan-umusu jordan-umusu marked this pull request as ready for review April 21, 2026 13:37
@jordan-umusu jordan-umusu temporarily deployed to internal-registry-ci April 21, 2026 13:37 — with GitHub Actions Inactive
@jordan-umusu jordan-umusu added enhancement New feature or request agents LLM agents labels Apr 21, 2026
@jordan-umusu jordan-umusu temporarily deployed to internal-registry-ci April 21, 2026 13:37 — with GitHub Actions Inactive
@zeropath-ai
Copy link
Copy Markdown

zeropath-ai Bot commented Apr 21, 2026

No security or compliance issues detected. Reviewed everything up to 240906b.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► tests/unit/test_agent_runtime.py
    Add tests for the Stop hook
    Implement Stop hook tests to cover retry logic and cap exceeding
► tracecat/agent/runtime/claude_code/runtime.py
    Implement Stop hook to prevent structured-output death loops
    Add MAX_STOP_HOOK_RETRIES constant
    Initialize _stop_hook_retries counter
    Register Stop hook in the runtime hooks

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

@blacksmith-sh

This comment has been minimized.

@jordan-umusu jordan-umusu requested a review from daryllimyt April 21, 2026 16:00
@jordan-umusu jordan-umusu force-pushed the feat/agent-stop-hook-guardrails branch from 3b4ec3a to 0e94baa Compare April 21, 2026 16:08
@jordan-umusu jordan-umusu temporarily deployed to internal-registry-ci April 21, 2026 16:08 — with GitHub Actions Inactive
@jordan-umusu jordan-umusu temporarily deployed to internal-registry-ci April 21, 2026 16:08 — with GitHub Actions Inactive
Copy link
Copy Markdown
Contributor

@daryllimyt daryllimyt left a comment

Choose a reason for hiding this comment

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

lgtm, just some small nits

Comment thread tracecat/agent/runtime/claude_code/runtime.py Outdated
Comment thread tracecat/agent/runtime/claude_code/runtime.py Outdated
Comment thread tests/unit/test_agent_runtime.py Outdated
Comment thread tests/unit/test_agent_runtime.py Outdated
@jordan-umusu jordan-umusu temporarily deployed to internal-registry-ci April 21, 2026 16:47 — with GitHub Actions Inactive
@jordan-umusu jordan-umusu temporarily deployed to internal-registry-ci April 21, 2026 16:47 — with GitHub Actions Inactive
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 240906b7b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tracecat/agent/runtime/claude_code/runtime.py
@jordan-umusu jordan-umusu merged commit 9475272 into main Apr 21, 2026
17 checks passed
@jordan-umusu jordan-umusu deleted the feat/agent-stop-hook-guardrails branch April 21, 2026 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents LLM agents enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants