Skip to content

feat(maintenance): unify credential renewal, liveness, quota refresh and check-in tasks - #661

Open
guyu233 wants to merge 2 commits into
caigee-cmd:mainfrom
guyu233:feat/maintenance-task-registry
Open

guyu233 wants to merge 2 commits into
caigee-cmd:mainfrom
guyu233:feat/maintenance-task-registry

Conversation

@guyu233

@guyu233 guyu233 commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Why

internal/runtime still split maintenance behavior across one-off tickers: check-in scheduling, WorkBuddy's daily pass, worker liveness, resource sampling, exhausted-quota probing, plus a hardcoded 10-minute "renew the credential" pass that only ran for a subset of providers. Credential renewal, liveness and credit refresh were provider-local (client.Refresh, client.Probe), so every provider had to re-implement its own cadence, backoff and failure accounting.

This PR moves all of it into one task registry and gives renewal / liveness / credits first-class, provider-driven implementations.

What changed

  • One task registry (runtime/manager_tasks.go): check-in, WorkBuddy daily, resource sampling, worker liveness, exhausted-quota probing, credential renewal, liveness, periodic credits. Cadence and semantics unchanged; the registry just owns start/stop, tick cancellation, and shutdown draining.
  • Credential renewal (runtime/maintenance_credential.go): five-minute sweep, renews five minutes before expires_at (configurable look-ahead), per-account backoff 1m / 5m / 30m / 2h, and only a definitive auth refusal (three consecutive) marks login_required. Generic network errors are failures, not logouts.
  • Liveness (ProviderMaintenance in providers/interfaces.go): providers that actually can read usage/catalog (kiro, codex, zhipu, command, opencode) implement Liveness; everyone else falls back to the existing probe. Default six hours, configurable, 0 disables.
  • Periodic credits: default 30 minutes with provider/account overrides, keeps the existing exhausted-account ladder.
  • Store: migration 036_request_outcome_facts.sql, 037_account_maintenance_state.sql, 038_checkin_record_source.sql — attempt outcome facts, per-account maintenance state, and check-in source.
  • Console: background-maintenance card in system settings, renewal/probe timestamps and failure badges on account cards, source chips in check-in history.

Tests

  • go build ./...
  • go test ./internal/store/ ./internal/accounts/ ./internal/control/ ./internal/providers/... ./internal/runtime/ — all pass
  • cd frontend && npm run sync

New tests: runtime/maintenance_credential_test.go (renewal look-ahead, backoff, login_required only after repeated auth refusal), store/maintenance_test.go, provider maintenance tests for each implementing package.

Notes

  • No shipped migration is modified; the three migrations are new numbered entries with their own checksums.
  • Cadence and semantics of existing jobs are unchanged, so this is not a behavior change for operators who leave settings at default.

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