caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

72 lines
1.9 KiB
Go

package doctor
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"time"
)
// CheckCircuitBreaker checks for stale circuit breaker state files that may
// block all bd operations. Returns a fixable DoctorCheck if stale files exist.
func CheckCircuitBreaker() DoctorCheck {
dir := "/tmp/beads-circuit"
pattern := filepath.Join(dir, "beads-dolt-circuit-*.json")
matches, err := filepath.Glob(pattern)
if err != nil || len(matches) == 0 {
return DoctorCheck{
Name: "Circuit Breaker",
Status: StatusOK,
Message: "No stale circuit breaker files",
Category: CategoryRuntime,
}
}
staleCount := 0
for _, path := range matches {
data, err := os.ReadFile(path) //nolint:gosec // G304: path is from filepath.Glob with controlled pattern
if err != nil {
continue
}
var state struct {
State string `json:"state"`
TrippedAt time.Time `json:"tripped_at,omitempty"`
LastFail time.Time `json:"last_failure,omitempty"`
}
if err := json.Unmarshal(data, &state); err != nil {
staleCount++ // corrupt file counts as stale
continue
}
if state.State == "open" || state.State == "half-open" {
// Only flag as stale if the breaker has been tripped for longer
// than the staleness TTL (5 minutes). A recently-tripped breaker
// during a real outage should not be cleared.
ref := state.TrippedAt
if ref.IsZero() {
ref = state.LastFail
}
if ref.IsZero() || time.Since(ref) > 5*time.Minute {
staleCount++
}
}
}
if staleCount == 0 {
return DoctorCheck{
Name: "Circuit Breaker",
Status: StatusOK,
Message: "No stale circuit breaker files",
Category: CategoryRuntime,
}
}
return DoctorCheck{
Name: "Circuit Breaker",
Status: StatusWarning,
Message: fmt.Sprintf("%d stale circuit breaker file(s) found in %s", staleCount, dir),
Fix: "Run 'bd doctor --fix' to clear stale circuit breaker files",
Category: CategoryRuntime,
}
}