Skip to content

feat(plugin): add session retry hook - #45999

Merged
rekram1-node merged 3 commits into
v2from
session-retry-hook
Aug 28, 2026
Merged

feat(plugin): add session retry hook#45999
rekram1-node merged 3 commits into
v2from
session-retry-hook

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add a public session.retry plugin hook as the final policy decision for provider failures, without exposing the runner's internal recovery mechanism.

await ctx.session.hook("retry", (event) => {
  if (event.error.status === 429) {
    event.decision = { retry: true, delay: 10_000 }
    return
  }
  if (event.error.type === "provider.invalid-request" && event.attempt === 2) {
    event.decision = { retry: true, delay: 0 }
    return
  }
  if (event.attempt >= 3) event.decision = { retry: false }
})

The hook receives stable Session context (sessionID, agent, model, projected Session error, and the physical attempt being proposed) plus a discriminated decision:

type SessionRetryDecision =
  | { retry: false }
  | { retry: true; delay: number }
  • Core initializes decision from its built-in retry classification and backoff. Plugins can veto a proposed retry or force a normally terminal provider failure to retry.
  • The hook runs before session.retry.scheduled; the final delay drives both the durable at deadline/UI countdown and actual sleep.
  • Hooks run sequentially, so later hooks see and may replace the current decision. Provider scoping uses the event's model reference.
  • The initial request is attempt 1 and the first retry is attempt 2, preserving existing durable event semantics.
  • The existing five-attempt ceiling is outside plugin control and remains a hard safety bound. Context-overflow compaction remains separate.
  • Invalid delays (negative or non-finite) fall back to Core's computed delay.
  • The hook does not expose replay/continuation mechanics, so its contract remains valid if recovery implementation changes.

Verification

  • Runner scenarios cover vetoing a transient retry, forcing a terminal failure to retry, sequential delay overrides, durable deadlines, and the existing retry ceiling.
  • Full isolated Core suite: 3789 pass / 39 skip / 0 fail.
  • Core and plugin typechecks pass; plugin tests: 5 pass / 0 fail.
  • Documentation Astro check reports 0 errors/warnings/hints; formatting and diff checks pass.

@rekram1-node
rekram1-node merged commit d837ffe into v2 Aug 28, 2026
12 checks passed
@rekram1-node
rekram1-node deleted the session-retry-hook branch August 28, 2026 21:16
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.

1 participant