Skip to content

chore: real token usage, Retry-After, mypy in CI, ruff 0.16 - #37

Merged
KazKozDev merged 1 commit into
masterfrom
claude/audit-minor
Sep 24, 2026
Merged

KazKozDev merged 1 commit into
masterfrom
claude/audit-minor

Conversation

@KazKozDev

Copy link
Copy Markdown
Owner

The four smaller items from the external audit.

Summary

  • Real token usage. llm_client reads what the provider reports — Ollama prompt_eval_count/eval_count, OpenAI-compatible usage.prompt_tokens/completion_tokens — per call. New ProcessingMetrics fields: llm_input_tokens, llm_output_tokens, llm_unreported_calls (calls with no counts, not in the sums), llm_models. BatchMetrics sums the token fields. The chars/4 estimate is kept.
  • Retry-After. 429/5xx retries wait the provider's Retry-After (seconds or HTTP date, capped at 60 s); without it, exponential backoff with jitter (2 s × 2^attempt × U(0.5, 1.5)).
  • mypy in CI. [tool.mypy] over src/docket; the lint job installs .[dev,review] and runs mypy. 115 errors fixed — annotations, narrowing, and loop-variable reuse; none turned out to be a runtime bug (the _turn(*c, ...) and duplicate by_row findings were false positives, now written so mypy can see it).
  • ruff 0.16.8. Pinned with mypy in the dev extra. 201 findings: 160 auto-fixed (import order, unused noqa, quoted annotations, …), the rest by hand. Config ignores C408 (kwargs-style dict() in factories) and DTZ (document dates are calendar dates), and allows FastAPI's File/Form/Depends/Header defaults. Intentional broad excepts carry a noqa with the reason.
  • Snapshot/OpenAPI updated for the new metrics fields and Union[...] → X | Y spelling.

Test plan

  • pytest: 1079 passed
  • ruff 0.16.8: clean
  • mypy: no issues in 67 files

🤖 Generated with Claude Code

- llm_client records provider-reported input/output tokens and models per
  document; ProcessingMetrics and BatchMetrics expose them.
- Retries honour Retry-After (capped at 60 s) or back off exponentially
  with jitter.
- mypy over src/docket runs in the CI lint job; 115 errors fixed.
- ruff 0.16.8 (pinned in the dev extra); 201 findings fixed, C408 and DTZ
  ignored and FastAPI's File/Form defaults allowed, with reasons in config.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KazKozDev
KazKozDev merged commit 8445530 into master Sep 24, 2026
6 checks passed
@KazKozDev
KazKozDev deleted the claude/audit-minor branch September 24, 2026 12:30

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

Copy link
Copy Markdown

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: 71d2889292

ℹ️ 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 src/docket/llm_client.py
seconds = None
if seconds is not None:
return min(max(seconds, 0.0), _MAX_RETRY_AFTER_S)
return _BACKOFF_S * (2 ** attempt) * random.uniform(0.5, 1.5)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Cap the exponential fallback delay

When DOCKET_LLM_RETRIES is set near its supported maximum of 10 and the provider omits Retry-After, this uncapped expression can sleep for as much as 1,536 seconds before the final retry and roughly 51 minutes cumulatively. That defeats the surrounding goal of avoiding workers being held for minutes and is a major regression from the previous linear schedule; apply a per-delay cap to the fallback path as well.

Useful? React with 👍 / 👎.

KazKozDev added a commit that referenced this pull request Sep 29, 2026
chore: real token usage, Retry-After, mypy in CI, ruff 0.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