Skip to content

1.4b — Python SDK precheck() kwargs + configurable retry backoff#14

Open
Shaivpidadi wants to merge 1 commit intodevfrom
feat/1.4b-python-sdk-precheck
Open

1.4b — Python SDK precheck() kwargs + configurable retry backoff#14
Shaivpidadi wants to merge 1 commit intodevfrom
feat/1.4b-python-sdk-precheck

Conversation

@Shaivpidadi
Copy link
Copy Markdown
Member

Summary

  • precheck() / async_precheck() now accept **kwargs for per-call overrides (timeout, retry tuning, scope, user_id, corr_id, tags, payload) plus forward-compatible pass-through of unknown body fields.
  • Retry backoff is fully configurable via retry_initial_delay, retry_backoff_factor, retry_max_delay, and optional jitter; defaults preserve the existing 1s / ×2 behavior.
  • Extracted _is_retryable_status / _compute_retry_delay helpers; the async path no longer falls back to hard-coded 2**attempt.
  • 8 new tests: PrecheckResult field population (decision, redacted_content, reasons, latency_ms), kwargs → request-body, configurable backoff delays, per-call max_retries, 4xx non-retry, timeout override, async field population, async max-retries-exceeded.

GovernsAI Tracker issue

GOV-575 (4e8a9405-60fb-489e-99e3-d0f9df5f730d)

TASKS.md ref: §1.4b

Reviewers

Tagging Nexus (code quality) and Cipher (security/arch) — both approvals required.

Test plan

  • pytest tests/ — 44 passed, 2 integration skipped
  • black --check src/ tests/ on changed files — clean
  • mypy src/governs_ai/client.py --ignore-missing-imports — no new errors
  • Integration smoke: run local precheck, verify precheck(...) returns a real decision (reviewer to run with GOVERNS_LOCAL_PRECHECK_URL + -m integration)

… tests

Polishes the 1.4a scaffolding to match TASKS.md §1.4b acceptance criteria:

- `precheck()` / `async_precheck()` accept `**kwargs` — per-call override of
  `timeout`, `max_retries`, retry tuning, plus request-body fields
  (`scope`, `user_id`, `corr_id`, `tags`, `payload`). Unknown kwargs pass
  through into the request body for forward compat with server schema growth.
- Exponential backoff is now fully configurable via `retry_initial_delay`,
  `retry_backoff_factor`, `retry_max_delay`, and optional `jitter`. Defaults
  preserve the existing 1s / ×2 / no-jitter behavior.
- `_is_retryable_status` and `_compute_retry_delay` factored into module
  helpers; async path no longer falls back to hard-coded `2**attempt`.

Tests added:
- `test_precheck_result_fields_populated_from_response` — all 4 fields
  (decision, redacted_content, reasons, latency_ms) populated from JSON
- `test_precheck_forwards_kwargs_into_request_body` — body includes
  scope/user_id/corr_id/tags/payload and pass-through unknowns
- `test_precheck_uses_configurable_backoff` — observed sleeps match
  initial * factor^attempt without jitter
- `test_precheck_max_retries_override_via_kwargs` — per-call limit respected
- `test_precheck_does_not_retry_on_4xx` — 4xx surfaces immediately
- `test_precheck_timeout_override_via_kwargs`
- `test_async_precheck_result_fields_populated`,
  `test_async_precheck_max_retries_exceeded`

All 44 existing + new tests pass; existing retry/payload tests unchanged.

Refs: GOV-575
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant