Files
PaperClipAI/server
Mehmet Yağız MaktavandClaude Opus 5.5 513f9522dc fix(hermes-gateway): retry a create request refused during a gateway drain (#22311)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The `hermes_gateway` adapter starts a run with `POST /v1/runs` on a
running Hermes gateway
> - A Hermes gateway that drains for a restart refuses new runs with
HTTP 503 and the code `gateway_draining`. Hermes does not start a run
for that request
> - The adapter reported the refusal as a plain upstream error. It gave
no evidence that provider work did not start
> - So the retry scheduler found no proof of a safe retry. It did not
schedule the bounded transient retry and held the run as
`legacy_execution_requires_reconciliation`. The parent task then blocked
on children that never started
> - This pull request makes the adapter record `executionRecovery: {
kind: "bootstrap", providerWorkStarted: false }` only for that explicit
drain refusal of the create request
> - The benefit is that the existing bounded transient retry runs again
after the drain. Uncertain outcomes keep their reconciliation safeguard

## Linked Issues or Issue Description

Fixes: #15236

Related: #10422 and #10424 (`hermes_local` error classification, a
different path). #17235 was a closed, larger attempt to book Hermes
profile-capacity deferrals as waits. This PR does not touch that path.

## What Changed

- `packages/adapters/hermes/src/gateway/server/execute.ts`: `fetchJson`
marks an error as a drain admission refusal at the request boundary, in
a `WeakSet`. This is the same provenance pattern as
`requestConnectionFailures`. The mark needs all three conditions: status
503, a response that was not redirected, and `error.code ===
"gateway_draining"` in the body. `errorResult`, which only the
create-run path uses, then adds the bootstrap evidence. The error code,
error family, `retryNotBefore` and connection-failure marker do not
change.
- `packages/adapters/hermes/src/gateway/server/execute.test.ts`: tests
for the evidence on a drain refusal. Tests that the outcome stays
unknown for another 503 code, a top-level code, a drain code on 502 or
429, and a redirected response. A test that a drain 503 after an
accepted run gives no evidence. The forged-callback test also covers a
forged drain error.
- `server/src/__tests__/hermes-gateway-drain-admission.test.ts`: runs
the real adapter result through the server classifiers. A drain refusal
takes the transient retry contract and is not held for reconciliation on
the first and second failures. After two charged retries it is held
again. A plain 503 stays held.

## Verification

- `cd packages/adapters/hermes && npx vitest run src/gateway`: 116
passed.
- `cd server && npx vitest run
src/__tests__/hermes-gateway-drain-admission.test.ts`: 2 passed.
- Red check: with only `execute.ts` reverted, the new adapter test fails
(`executionRecovery` is undefined).
- `pnpm --filter @paperclipai/hermes-paperclip-adapter typecheck` and
`cd server && pnpm typecheck` pass.
- I did not run a live Hermes gateway drain. The 503 body and
`Retry-After: 1` header in the tests match Hermes
`gateway/platforms/api_server.py` (`_draining_response`) and its test
`tests/gateway/test_api_server_active_work_drain.py`.

## Risks

- Low risk. The change only affects a direct 503 `gateway_draining`
response to the create request. Every other failure keeps its current
classification.
- The retry budget does not change:
`BOUNDED_TRANSIENT_HEARTBEAT_RETRY_DELAYS_MS` (about 30 s, then 60 s,
with jitter). A drain that lasts longer than these retries still
exhausts them. After that the existing reconciliation hold applies, as
for other exhausted bootstrap failures. A drain-aware wait would need a
scheduler change, which this PR does not make.
- Hermes sends `Retry-After: 1` (seconds). The adapter forwards the raw
header value as before. That value is earlier than the base retry delay,
so the base schedule wins.

## Model Used

- AI-assisted with Claude Code (tool use and local code execution). The
commit carries the matching `Co-Authored-By` trailer.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [ ] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [ ] I have updated relevant documentation to reflect my changes (no
documentation change needed)
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 04:27:12 -08:00
..