Skip to content

fix(sdk): state backend hardening — retry, circuit-breaker, startup verification - #907

Closed
diberry wants to merge 1 commit into
devfrom
squad/864-state-backend-hardening
Closed

fix(sdk): state backend hardening — retry, circuit-breaker, startup verification#907
diberry wants to merge 1 commit into
devfrom
squad/864-state-backend-hardening

Conversation

@diberry

@diberry diberry commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

What

Add retry with exponential backoff, circuit-breaker pattern, and startup verification to state backends.

Why

State backends silently swallow git errors (resolveStateBackend catches and ignores, external backend falls back silently). This causes silent data loss and makes debugging impossible.

How

  1. Retry transient git errors with exponential backoff (3 retries, 100ms base, 2s max)
  2. Circuit-breaker trips after 5 consecutive failures, fast-fails subsequent ops with 30s cooldown
  3. Startup health check — read-only verifyStateBackend() validates backend accessibility
  4. Error surfacing — all errors logged with context; explicit backend selection throws on failure instead of silent fallback
  5. execSync → execFileSync migration for write paths (eliminates shell injection surface)

Closes #864
Related: #895 (Phase 1, items #4, #5)

Copilot AI review requested due to automatic review settings April 7, 2026 23:09
@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

🟡 Impact Analysis — PR #907

Risk tier: 🟡 MEDIUM

📊 Summary

Metric Count
Files changed 4
Files added 1
Files modified 3
Files deleted 0
Modules touched 3
Critical files 1

🎯 Risk Factors

  • 4 files changed (≤5 → LOW)
  • 3 modules touched (2-4 → MEDIUM)
  • Critical files touched: packages/squad-sdk/src/index.ts

📦 Modules Affected

root (1 file)
  • .changeset/state-backend-hardening.md
squad-sdk (2 files)
  • packages/squad-sdk/src/index.ts
  • packages/squad-sdk/src/state-backend.ts
tests (1 file)
  • test/state-backend.test.ts

⚠️ Critical Files

  • packages/squad-sdk/src/index.ts

This report is generated automatically for every PR. See #733 for details.

@github-actions

github-actions Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

🏗️ Architectural Review

⚠️ Architectural review: 1 warning(s).

Severity Category Finding Files
🟡 warning export-surface Package entry point(s) modified with 4 new/changed export(s). New public API surface requires careful review for backward compatibility. packages/squad-sdk/src/index.ts

Automated architectural review — informational only.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the SDK’s git-based state backends by adding retry/backoff and a circuit-breaker, surfacing previously swallowed config/initialization errors, and introducing a read-only startup verification helper.

Changes:

  • Add retry helpers (exponential backoff) and a CircuitBreaker applied to git-backed backend operations.
  • Make resolveStateBackend() warn on config read failures and fail-fast for explicit backend selections that can’t initialize.
  • Export new APIs (CircuitBreaker, verifyStateBackend) and add/extend tests + changeset.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
packages/squad-sdk/src/state-backend.ts Implements retry/backoff, circuit breaker, config warning/fail-fast behavior, and verifyStateBackend(); migrates write paths to execFileSync.
packages/squad-sdk/src/index.ts Exports CircuitBreaker and verifyStateBackend from the SDK barrel.
test/state-backend.test.ts Adds tests for warnings, circuit breaker behavior, and backend verification.
.changeset/state-backend-hardening.md Adds a patch changeset documenting the hardening work.

Comment thread packages/squad-sdk/src/state-backend.ts Outdated
Comment thread packages/squad-sdk/src/state-backend.ts
Comment thread test/state-backend.test.ts Outdated
Comment thread packages/squad-sdk/src/state-backend.ts Outdated
Comment thread packages/squad-sdk/src/state-backend.ts Outdated
@diberry
diberry force-pushed the squad/864-state-backend-hardening branch 2 times, most recently from 17243f4 to ed2f163 Compare April 8, 2026 14:22
@diberry

diberry commented Apr 8, 2026

Copy link
Copy Markdown
Contributor Author

🔍 Squad Review — Kaylee (Engineering)

# Check Status Notes
1 Changelog entry .changeset/state-backend-hardening.md (SDK patch)
2 Squashed to 1 commit 1 commit
3 CI green All checks passed
4 Copilot comments resolved 5/5 threads resolved with fixes or acknowledgments
5 No .squad/ files Clean
6 No unrelated files 4 files — all scoped to state backend hardening
7 Tests for changes est/state-backend.test.ts updated
8 Not a duplicate/reversal Unique scope (closes #864); #916 is separate (shell injection)

Verdict: ✅ Ready to merge


Review by Squad AI team (Kaylee — Engineering) · requested by Dina Berry

@diberry diberry closed this Apr 10, 2026
@bradygaster
bradygaster deleted the squad/864-state-backend-hardening branch August 8, 2026 08:42
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.

arch: state backend silent error swallowing — add retry, circuit-breaker, startup verification

2 participants