Skip to content

Add bounded agent-step recovery retries - #1123

Closed
viniciusdebruin wants to merge 8806 commits into
CodebuffAI:mainfrom
viniciusdebruin:contrib/engine-recovery
Closed

Add bounded agent-step recovery retries#1123
viniciusdebruin wants to merge 8806 commits into
CodebuffAI:mainfrom
viniciusdebruin:contrib/engine-recovery

Conversation

@viniciusdebruin

Copy link
Copy Markdown

Summary

  • add a bounded outer recovery retry for transient agent-step failures
  • cover network errors, idle timeouts, rate limits, and server 5xx responses
  • preserve the same run/history while emitting recovery metadata and a recovery message
  • skip retries for aborts, authentication failures, and client 4xx errors

Validation

  • 156 focused runtime tests passing
  • typecheck reaches unrelated pre-existing missing researcher imports in read-docs-tool.test.ts and web-search-tool.test.ts

Source: CodebuffAI/freebuff-private@6a6c2560a0d89ff9d4fb3b3b3dcf459e718aa015
Source: CodebuffAI/freebuff-private@6bbe32b95effc6c81479ffe1be3854bbf2b6a175
Source: CodebuffAI/freebuff-private@9c49375348733a5bdc7b13b5e5c71b6aac3c150c
Source: CodebuffAI/freebuff-private@18d9e898bfc0e44ac24017f980f81033123c2f83
Source: CodebuffAI/freebuff-private@67af829808816a20e117fd57c654b471e6857eae
Source: CodebuffAI/freebuff-private@3285b31b770fd5b07e854d993ac8e87e5e679f8b
Source: CodebuffAI/freebuff-private@79bfc42ece2b9e4cc4a88140e23479e5809da816
Source: CodebuffAI/freebuff-private@65df59b85e220b8f962fe01cdbe7d4e18824e320
Source: CodebuffAI/freebuff-private@e6b914d9b664add769727e29d0984c69e8717e74
Source: CodebuffAI/freebuff-private@1781f579a7d28f6609f75540529b58bd5ee8208f
Source: CodebuffAI/freebuff-private@d266b9ad26aa4d539a01097c6be544afada6b7e6
Source: CodebuffAI/freebuff-private@a518571bda930dd9f6d3c513f405f879d9474585
Source: CodebuffAI/freebuff-private@ff3322e5cc03fc4f33796f8f49fce51744b6ecb0
Source: CodebuffAI/freebuff-private@b96808549f5ba06fbac82369b419fef88bc6c6ae
Source: CodebuffAI/freebuff-private@2cf94fb38519b4fdc2caa80ce073ec2e423b2ddd
Source: CodebuffAI/freebuff-private@a3a71b3b96bd25ce2f4258704267af6ff646f9ec
Source: CodebuffAI/freebuff-private@0693087e2e254602d44514d9c44099410dda8323
Source: CodebuffAI/freebuff-private@efdf10960936cf0f87f8141191fb76b55706ed85
Source: CodebuffAI/freebuff-private@ad6bc9adfa02f0b967424df70a6b1202bcec285d
Source: CodebuffAI/freebuff-private@c71eca2672511e34e48c6e36344b060af95f0ee6
Source: CodebuffAI/freebuff-private@edac5d5b4121e342607f803b277b2a20eed859a0
Source: CodebuffAI/freebuff-private@05417f841e0359ece3e80876fe19ba5f25044f51
Source: CodebuffAI/freebuff-private@7f756a3d3d5ae9237b007a038334de6f143daff1
Source: CodebuffAI/freebuff-private@665569ba8321ae5a453633dd0693029e3414bf93
Source: CodebuffAI/freebuff-private@050b9f6fd4658f2589d2b4498e99298e49ccbb81
Source: CodebuffAI/freebuff-private@a5771d769f7ec7dac6c97fdc4bf9c5aa6201895a
Source: CodebuffAI/freebuff-private@5720ef36ed9e8ed03feac155a528d4e210778f99
Source: CodebuffAI/freebuff-private@21d1b8dbfdc437b857f751cb71d33aefd5a9b586
Source: CodebuffAI/freebuff-private@f496b0de4478d19ce64daa3b25d063a38f6b7cfb
Source: CodebuffAI/freebuff-private@5c09ea46e6370730b3a6a441bdc199fd189eb375
codebuff public sync bot and others added 22 commits August 24, 2026 22:48
Source: CodebuffAI/freebuff-private@cfc7760af31f29f1acc7153a7e9fcb48d35f730b
Source: CodebuffAI/freebuff-private@6965ea40dbf54a44c932ca4df63b0dd6377bfec5
Source: CodebuffAI/freebuff-private@ecf4fa2e98fcefcec1a96cbd596b5b16bccd97e3
Source: CodebuffAI/freebuff-private@ce96ca2455d9c6a027d6e41048e8f2520f78754f
Source: CodebuffAI/freebuff-private@890653e2610c57c22298d532cae0129efb26f862
Source: CodebuffAI/freebuff-private@d60d93125f90cdca18e1fc97819b91997081a97f
Source: CodebuffAI/freebuff-private@70ba2a57ab1e48c9f799107675dfb6029dc6d54f
Source: CodebuffAI/freebuff-private@9c2be6595fa98153b9ec0474caed5ec3a58ec116
Source: CodebuffAI/freebuff-private@c1db5271ba86e1c89c3c9fc0c6e6a2a857d3b5dd
Source: CodebuffAI/freebuff-private@2846f67777f75ee23da1e3a3047176d66953d906
Source: CodebuffAI/freebuff-private@f5329a11c8431d6f5c98581c2bfc67fb2d1829ba
Source: CodebuffAI/freebuff-private@e319a9e3de31d8c4cd1d0a9285dfd5360eebb7a1
Source: CodebuffAI/freebuff-private@9cbbba39efda2071b8325bf2779b39170e35348c
Source: CodebuffAI/freebuff-private@8470da01520ea7c273efb6eca943fd37fb265189
Source: CodebuffAI/freebuff-private@884e8a41dd02bb5c0be09d8da8e465c994a6c6a4
Source: CodebuffAI/freebuff-private@b550c712e828f5211de07c5699a643fe0fa8f22e
Source: CodebuffAI/freebuff-private@ddfa6c89a27176e4e1afef0bd597077698e3d9e3
Source: CodebuffAI/freebuff-private@9b8fb92689a45c3d52b65f6d4177bb8b0e4a29db
Source: CodebuffAI/freebuff-private@e20dcb5811c89bc349a283c8fb8b474f03857eaa
Source: CodebuffAI/freebuff-private@1a9bb08ef45331c94cfa616a7e5f91dbc3375e7b
Source: CodebuffAI/freebuff-private@2204d7f013215d4a9746f87ccadb88422bdbf0ce
@codebuff-team

ghost commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Good targeted addition. classifyAgentRecovery in agent-recovery.ts cleanly separates retryable transient failures (network, idle-timeout, 429/5xx) from aborts/auth/4xx, and the unit tests in agent-recovery.test.ts cover the boundary cases well (401/403 vs 400, explicit isRetryable signal, abort). The integration test in loop-agent-steps.test.ts demonstrates the retry actually recovers mid-loop and tags the injected message with AGENT_RECOVERY, which is the right level of test for this kind of change.

A few things worth double-checking before this lands in the private tree:

  1. Cost/credit accounting. creditsBefore/childrenBefore are captured once before the retry loop in run-agent-step.ts, but if the failed first attempt already streamed partial tokens/tool calls before throwing, it's unclear whether that usage is reflected in currentAgentState by the time the retry succeeds. Worth confirming the diff computed after the loop doesn't silently drop or double-count the failed attempt's partial cost.
  2. MAX_AGENT_STEP_RECOVERY_ATTEMPTS = 1 vs. the exponential backoff design. getAgentRecoveryDelayMs supports many attempts (tested up to 20), but with the cap at 1 it will only ever be called with attempt=1 in production, so the backoff curve is currently dead code. Either bump the cap slightly or simplify the delay function to match actual usage — as written it reads like it's designed for more retries than the code allows.
  3. Worth confirming that partial/successful side effects on currentAgentState from a failed runAgentStep call (if any exist internally) are not carried into the retry, since the loop reuses the same currentAgentState reference across attempts.

None of these are blocking correctness issues from what's visible in the diff, just things the maintainer porting this by hand should verify against the private tree's actual runAgentStep internals, which aren't shown here.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree labels Aug 25, 2026
@viniciusdebruin

ghost commented Aug 26, 2026

Copy link
Copy Markdown
Author

Thanks for the review. I addressed the three points in c488f2e:

  • Each recovery attempt now snapshots and restores the message history, partial output, and context before retrying, so failed-attempt side effects are not carried into the successful attempt.
  • Credits and child run IDs are preserved from the failed attempt and merged without double-counting usage.
  • MAX_AGENT_STEP_RECOVERY_ATTEMPTS is now 2, so the existing exponential backoff is exercised for two additional bounded attempts.

Validation:

  • Focused recovery and integration tests: 42 passed, 0 failed.
  • Typecheck reaches only the same two pre-existing missing agents-graveyard/researcher imports; there are no errors in the changed files.

This keeps aborts, authentication failures, and client 4xx responses non-retryable.

@victorxheng

ghost commented Aug 31, 2026

Copy link
Copy Markdown

Apologies — this PR was auto-closed by GitHub when we force-pushed a history rewrite of this repository (repository maintenance; every commit SHA changed). That was not a judgment on this PR, and GitHub does not allow us to reopen it because the commits it was based on no longer exist in the new history.

If you'd like to continue with this change: rebase your branch onto the new main (or recreate it from a fresh clone) and open a new PR — feel free to link back to this one for context, and we'll pick up the review there.

Sorry for the churn, and thanks for contributing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants