Skip to content

Add bulkhead concurrency isolation and rate-limit header parsing#282

Merged
JE-Chen merged 2 commits into
devfrom
feat/bulkhead
Jun 21, 2026
Merged

Add bulkhead concurrency isolation and rate-limit header parsing#282
JE-Chen merged 2 commits into
devfrom
feat/bulkhead

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Jun 21, 2026

Copy link
Copy Markdown
Member

Summary

resilience recovers from failures and rate_limit paces calls, but nothing capped the number of simultaneous in-flight calls to one resource (a slow dependency could exhaust every worker), and the HTTP client read Retry-After/RateLimit-* headers but honored none of them. This adds both.

  • Bulkhead(max_concurrent, name=)try_enter/release, context manager, run(func); rejects with BulkheadFullError when full (load-shedding / fault isolation). Non-blocking permit counting → deterministic, no threads in tests.
  • parse_retry_after(headers) — delta-seconds or HTTP-date; parse_ratelimit(headers)RateLimit-Limit/Remaining/Reset; next_delay(response) — the wait a flow should observe after 429/503.

Pure stdlib (threading+email.utils).

Five-layer wiring

  • Headless core: je_auto_control/utils/bulkhead/
  • Facade: re-exported from __init__.py + __all__
  • Executor: AC_bulkhead_run (named bulkhead wraps an action list), AC_retry_after
  • MCP: ac_bulkhead_run, ac_retry_after
  • Script Builder: "Bulkhead (Bounded Concurrency)" / "Parse Retry-After / RateLimit" under Flow

Tests & docs

  • test/unit_test/headless/test_bulkhead_batch.py (9 tests: permit/reject, context manager, run, bad max, Retry-After delta/date/case, RateLimit parse, next_delay sources)
  • v74 feature docs (EN + Zh) + toctree
  • What's-new in all three READMEs

Lint clean: ruff / pylint / bandit / radon.

resilience recovers and rate_limit paces, but nothing capped simultaneous
in-flight calls (a slow dependency could exhaust every worker) and the
HTTP client ignored Retry-After/RateLimit-* headers. Add a bulkhead
(bounded-concurrency permit that sheds load when full) and parsers for the
server-advised delay (delta-seconds or HTTP-date). Non-blocking permit
counting is deterministic. Wired through the facade, AC_bulkhead_run/
AC_retry_after executor commands, MCP tools and the Script Builder.
@codacy-production

codacy-production Bot commented Jun 21, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 47 complexity · 0 duplication

Metric Results
Complexity 47
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@JE-Chen JE-Chen merged commit de8b4bf into dev Jun 21, 2026
2 checks passed
@JE-Chen JE-Chen deleted the feat/bulkhead branch June 21, 2026 13:10
@sonarqubecloud

Copy link
Copy Markdown

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