Skip to content

Daemon: park retry backoffs, classify in-stream overloads, keep statements prepared - #257

Merged
lydakis merged 2 commits into
mainfrom
claude/project-thread-adwocq
Oct 28, 2026
Merged

lydakis merged 2 commits into
mainfrom
claude/project-thread-adwocq

Conversation

@lydakis

@lydakis lydakis commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

George asked that the daemon stay fast and light as features land: bots never block each other, model bots park properly on provider errors, and the pacer learns from every pacing fact. This PR fixes what a re-measurement against September and a review of the error paths found.

Changes

  • SQLite statement cache. rusqlite keeps 16 prepared statements per connection, and the store has 144 prepare_cached sites. A callgrind profile of bench.admission_burst showed Database::begin parsing its statements again on every admission, which was the +47% lone-submit CPU regression between Oct 11 and 0.4.1. Each connection now keeps 256.
  • Backoffs park. A transient-error retry (5xx, connection refused, stall) whose backoff is 1 s or more now parks the turn durably. Before, it slept in its task with the active slot held, up to 30 s per try. The backoff still counts toward the call's retry budget.
  • Pacer reads retry-after-ms before retry-after, as both providers send it and both SDKs prefer it. A socket overload event now closes the pool, as a rate limit does.
  • Responses in-stream codes. server_is_overloaded maps to provider_overloaded (paced), slow_down to provider_rate_limited, and server_error to provider_server_error (retried), as Codex classifies them (openai/codex e8e6a92, sse/responses_error.rs). Before, all three became provider_incomplete and failed the turn.
  • bot_busy after turn_finished. The CI thread found that delete could answer bot_busy right after a client saw turn_finished, because the event publishes at commit while the slot frees on reap. The task now sets an ending flag just before it submits its finish. From then on, delete and configure ask the store instead of the in-memory slot.
  • AGENTS.md gains "Keep the daemon fast and light": eight principles a daemon PR says it keeps.
  • bench/footprint.py is new. It reports idle RSS, RSS per idle bot (1000 bots), RSS after a turn each, and CPU, store jobs and commits per turn.
  • docs/DAEMON_MEASUREMENTS.md records the September re-measurement and this PR's screen.

How it keeps the principles

Nothing new runs on the runtime thread. The backoff park makes a waiting bot hold nothing live. The ending flag is one atomic store per turn. The statement cache adds no store jobs and costs about 0.5 MiB at the 32-bot screen's peak.

Measurements

Linux x86_64 container, synthetic provider, c16210c against this branch, two alternating rounds:

Measure main branch
32 lone submits, daemon CPU ms 72.6 49.0
32 lone submits, reply p50 ms 2.28 1.73
32-bot socket echo, CPU s 1.44 1.265
32-bot socket echo, peak RSS MiB 23.3 23.8
32-bot socket echo, turn p95 ms 604 596
Completion burst p99 ms 19.7 18.9
CPU per text turn (footprint), ms 1.68 1.49
Idle RSS (footprint), MiB 17.7 17.9

Store jobs per turn are unchanged (7.5). macOS is not measured.

Tests

  • New unit tests: header delays, in-stream codes, paced/retryable classes, and the ending flag (a bot whose turn committed its end can be deleted before reap).
  • New runtime test test_a_provider_outage_parks_its_retries_and_leaves_the_slot_to_others: with one active slot, a healthy bot finishes in under 0.9 s while another bot's turn sits in a 4-try outage, and the outage turn completes.
  • An existing test that slept 34 s through connection-refused backoffs now parks at the third try.
  • cargo test, clippy and fmt pass, and so does the full runtime suite (tests/run.py, AGENT_TEST_RUNTIME=1). One run had a single failure that a rerun did not reproduce, matching the flakes the CI thread reported on main.

No visible change, so no screenshots.

…ments prepared

- A retry backoff of a second or more parks the turn durably instead of
  sleeping in its task with an active slot held.
- The pacer reads retry-after-ms before retry-after; a socket overload
  closes the pool; Responses in-stream server_is_overloaded, slow_down and
  server_error are classified as Codex does instead of failing the turn.
- delete and configure stop answering bot_busy once a turn's task has
  submitted its finish, so a client that saw turn_finished is not refused.
- Each SQLite connection keeps 256 prepared statements instead of 16, so
  an admission no longer re-parses its statements.
- AGENTS.md: keep the daemon fast and light. bench/footprint.py measures
  idle, per-bot and after-turn memory with CPU and store work per turn.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGGx6KWd2rVq3RoYuXt
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T01:49:02.509959Z f63a8f8 PR opened
🔒 Security Review ✅ Completed 2026-10-28T01:50:20.304451Z f63a8f8 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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