Skip to content

feat(lifecycle): ResourceLifecycleRegistry — unified disposal + tool circuit breaker + memory breaker + retention cleanup - #1

Open
hernandez42 wants to merge 1 commit into
mainfrom
xuanji/resource-lifecycle-registry
Open

feat(lifecycle): ResourceLifecycleRegistry — unified disposal + tool circuit breaker + memory breaker + retention cleanup#1
hernandez42 wants to merge 1 commit into
mainfrom
xuanji/resource-lifecycle-registry

Conversation

@hernandez42

Copy link
Copy Markdown
Owner

Resource Lifecycle / 资源泄露修复方案

PilotDeck has no unified resource lifecycle management. This PR adds the core primitives:

Files added

src/lifecycle/disposable/ResourceLifecycleRegistry.ts  — singleton agentRegistry
src/lifecycle/disposable/index.ts
src/lifecycle/retention/RetentionPolicy.ts              — TTL cleanup
src/lifecycle/retention/index.ts
src/tool/protocol/circuitBreaker.ts                    — tool loop breaker
src/memory/health/CircuitBreakerHealthCheck.ts        — APEX-MEM breaker
src/memory/health/index.ts

Key APIs

  • ResourceLifecycleRegistry: register(), disposeAll(), getOpenHandles() smoke test
  • ToolCallCircuitBreaker: 3x same (toolName+validationError) → exponential backoff (60s→480s)
  • MemoryCircuitBreaker: 3 failures/30s → open, half-open probe, read-only health check
  • RetentionPolicy: TTL cleanup for .pilotdeck-always-on/ (7d), .agi-output/ (30d), .cci-output/ (30d)

Next steps

  1. Integrate agentRegistry into AgentSession + GatewayBrowserClient + McpRuntime
  2. Add --detect-open-handles CI flag
  3. Call RetentionPolicy.runRetentionCleanup() on session startup

ΔG improvement estimate: +330

…emoryCircuitBreaker, RetentionPolicy

Phase 1-5 of resource lifecycle management:

- ResourceLifecycleRegistry: unified disposable interface with priority-ordered
  disposeAll, getOpenHandles() smoke test, 3s per-resource timeout
- ToolCallCircuitBreaker: after 3x same (toolName+validationError) failures,
  breaker opens with exponential backoff (60s→480s capped)
- MemoryCircuitBreaker: APEX-MEM circuit breaker with half-open probe,
  read-only health check (SQLite integrity, memories/FTS count alignment,
  BM25 max_doc alignment)
- RetentionPolicy: TTL-based cleanup for .pilotdeck-always-on/ (7d),
  .agi-output/ (30d), .cci-output/ (30d); count-based for always-on dirs

Files:
  src/lifecycle/disposable/ResourceLifecycleRegistry.ts
  src/lifecycle/disposable/index.ts
  src/lifecycle/retention/RetentionPolicy.ts
  src/lifecycle/retention/index.ts
  src/tool/protocol/circuitBreaker.ts
  src/memory/health/CircuitBreakerHealthCheck.ts
  src/memory/health/index.ts

Fixes: P0 resource orphans (Playwright/MCP/background tasks), P1 tool loop
spinning, P2 directory accumulation
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