[GH-ISSUE #50] Feature: Manual account activate without daemon/container restart #45

Closed
opened 2026-02-27 15:38:06 +03:00 by kerem · 3 comments
Owner

Originally created by @DarKWinGTM on GitHub (Feb 22, 2026).
Original GitHub issue: https://github.com/NikkeTryHard/zerogravity/issues/50

Summary

Manual account switch currently needs daemon/container restart to take effect, while auto-rotation can switch account via internal runtime pipeline (LS recycle) without killing the zerogravity process.

Request: add a manual activation path that applies immediately at runtime (similar to auto-rotation behavior), without requiring zg restart / docker restart.


Current behavior (verified)

Manual path (zg accounts set)

  • zg accounts set updates active account in store:
    • src/bin/zg/accounts.rs:549
  • CLI explicitly says restart is required:
    • src/bin/zg/accounts.rs:552
  • zg restart is stop+start daemon:
    • src/bin/zg/commands.rs:140

Auto-rotation path

  • Rotation trigger policy is quota exhaustion path only:
    • docs/account-rotation.md:104
    • docs/account-rotation.md:151
  • Runtime LS recycle path (inside daemon):
    • kill LS: src/rotation.rs:99
    • spawn LS: src/rotation.rs:125
    • backend reconfigure: src/rotation.rs:155
  • Trigger sources:
    • rate limiter trigger: src/api/rate_limiter.rs:161
    • quota trigger: src/quota.rs:179, src/quota.rs:233

API gap

  • Existing routes expose add/list/remove accounts + token set:
    • src/api/mod.rs:82
    • src/api/mod.rs:83
    • src/api/mod.rs:84
    • src/api/mod.rs:85
  • No public route for "set active account + apply runtime switch".
  • Internal method exists but is not exposed:
    • src/account_rotator.rs:206 (set_active_by_email)

Why this matters

Operational/manual account switching is currently heavier and less smooth than auto-rotation:

  • manual requires restart path
  • auto path does LS recycle internally and keeps daemon process alive

Providing a runtime-apply manual switch would reduce downtime and align user/admin UX with existing rotation internals.


Flow Diagram

Current manual flow
User command
zg accounts set <email>
→ write active in accounts store
→ restart-required message
zg restart (required)
→ switch takes effect

Current auto-rotation flow
429/quota trigger
→ rate_limiter/quota sends rotation signal
→ rotation orchestrator
account_rotator.rotate()
→ kill old LS
→ spawn new LS
→ backend reconfigure + warmup
→ switch takes effect (daemon remains alive)

Expected manual flow
Manual activate command/API
→ set active account
→ refresh target account token
→ update runtime token handles/backend
→ trigger LS recycle/apply pipeline
→ switch takes effect immediately
→ no daemon/container restart required


Proposal

Either approach would work:

  1. New API endpoint (preferred)
  • POST /v1/accounts/activate with { \"email\": \"...\" }
  • Internally:
    • validate account
    • set active
    • refresh token
    • propagate runtime token/backend
    • run LS recycle/apply pipeline
  • Return clear status/result payload.
  1. CLI enhancement
  • zg accounts set <email> --apply-runtime
  • Call same runtime-apply path as endpoint above.

Backward-compatible option:

  • Keep existing default behavior but provide explicit immediate-apply mode.

Acceptance criteria

  • Manual activate works without daemon/container restart.
  • zerogravity process remains alive.
  • Switch is effective in runtime in bounded time.
  • API/CLI returns deterministic apply result and errors.
  • Existing auto-rotation behavior remains unchanged.

Reference version

Inspected against repository state:

  • commit: 5f4cc6ed5413fa2c7902254cef10289ddedef4b8
Originally created by @DarKWinGTM on GitHub (Feb 22, 2026). Original GitHub issue: https://github.com/NikkeTryHard/zerogravity/issues/50 ## Summary Manual account switch currently needs daemon/container restart to take effect, while auto-rotation can switch account via internal runtime pipeline (LS recycle) without killing the `zerogravity` process. Request: add a **manual activation path** that applies immediately at runtime (similar to auto-rotation behavior), without requiring `zg restart` / `docker restart`. --- ## Current behavior (verified) ### Manual path (`zg accounts set`) - `zg accounts set` updates active account in store: - `src/bin/zg/accounts.rs:549` - CLI explicitly says restart is required: - `src/bin/zg/accounts.rs:552` - `zg restart` is stop+start daemon: - `src/bin/zg/commands.rs:140` ### Auto-rotation path - Rotation trigger policy is quota exhaustion path only: - `docs/account-rotation.md:104` - `docs/account-rotation.md:151` - Runtime LS recycle path (inside daemon): - kill LS: `src/rotation.rs:99` - spawn LS: `src/rotation.rs:125` - backend reconfigure: `src/rotation.rs:155` - Trigger sources: - rate limiter trigger: `src/api/rate_limiter.rs:161` - quota trigger: `src/quota.rs:179`, `src/quota.rs:233` ### API gap - Existing routes expose add/list/remove accounts + token set: - `src/api/mod.rs:82` - `src/api/mod.rs:83` - `src/api/mod.rs:84` - `src/api/mod.rs:85` - No public route for "set active account + apply runtime switch". - Internal method exists but is not exposed: - `src/account_rotator.rs:206` (`set_active_by_email`) --- ## Why this matters Operational/manual account switching is currently heavier and less smooth than auto-rotation: - manual requires restart path - auto path does LS recycle internally and keeps daemon process alive Providing a runtime-apply manual switch would reduce downtime and align user/admin UX with existing rotation internals. --- ## Flow Diagram Current manual flow User command → `zg accounts set <email>` → write `active` in accounts store → restart-required message → `zg restart` (required) → switch takes effect Current auto-rotation flow 429/quota trigger → rate_limiter/quota sends rotation signal → rotation orchestrator → `account_rotator.rotate()` → kill old LS → spawn new LS → backend reconfigure + warmup → switch takes effect (daemon remains alive) Expected manual flow Manual activate command/API → set active account → refresh target account token → update runtime token handles/backend → trigger LS recycle/apply pipeline → switch takes effect immediately → no daemon/container restart required --- ## Proposal Either approach would work: 1) New API endpoint (preferred) - `POST /v1/accounts/activate` with `{ \"email\": \"...\" }` - Internally: - validate account - set active - refresh token - propagate runtime token/backend - run LS recycle/apply pipeline - Return clear status/result payload. 2) CLI enhancement - `zg accounts set <email> --apply-runtime` - Call same runtime-apply path as endpoint above. Backward-compatible option: - Keep existing default behavior but provide explicit immediate-apply mode. --- ## Acceptance criteria - Manual activate works without daemon/container restart. - `zerogravity` process remains alive. - Switch is effective in runtime in bounded time. - API/CLI returns deterministic apply result and errors. - Existing auto-rotation behavior remains unchanged. --- ## Reference version Inspected against repository state: - commit: `5f4cc6ed5413fa2c7902254cef10289ddedef4b8`
kerem closed this issue 2026-02-27 15:38:06 +03:00
Author
Owner

@jlwebs commented on GitHub (Feb 23, 2026):

agree, the incompleteness after the switch is currently confusing users.

<!-- gh-comment-id:3944972620 --> @jlwebs commented on GitHub (Feb 23, 2026): agree, the incompleteness after the switch is currently confusing users.
Author
Owner

@NikkeTryHard commented on GitHub (Feb 23, 2026):

Implemented and validated.\n\nWhat changed:\n- Added runtime account activation path via (set active account, refresh token, propagate runtime token, reset limiter, clear cached project, request LS respawn).\n- Updated to try runtime apply when daemon is reachable; if runtime apply is unavailable/fails, it falls back to explicit restart guidance.\n- This keeps Docker container uptime stable (no container restart on account switch) while still recycling LS when needed.\n\nVerification:\n- Integration tests for new endpoint behavior pass.\n- Full test suite and clippy pass.\n\nIf you need it immediately, build from after this push. Otherwise wait for the next release tag.

<!-- gh-comment-id:3947680088 --> @NikkeTryHard commented on GitHub (Feb 23, 2026): Implemented and validated.\n\nWhat changed:\n- Added runtime account activation path via (set active account, refresh token, propagate runtime token, reset limiter, clear cached project, request LS respawn).\n- Updated to try runtime apply when daemon is reachable; if runtime apply is unavailable/fails, it falls back to explicit restart guidance.\n- This keeps Docker container uptime stable (no container restart on account switch) while still recycling LS when needed.\n\nVerification:\n- Integration tests for new endpoint behavior pass.\n- Full test suite and clippy pass.\n\nIf you need it immediately, build from after this push. Otherwise wait for the next release tag.
Author
Owner

@NikkeTryHard commented on GitHub (Feb 23, 2026):

Follow-up with clean formatting:\n\nFixed and validated.\n\nWhat changed:\n- Added runtime account activation endpoint: POST /v1/accounts/set_active.\n- Endpoint flow: set active account, refresh token, propagate runtime token, reset limiter, clear cached project, request LS respawn.\n- Updated zg accounts set to attempt runtime apply when daemon is reachable; fallback remains explicit restart guidance if runtime apply is unavailable.\n- Docker container is not restarted for account switch; LS recycle is used instead.\n\nVerification:\n- New integration tests for set_active endpoint behavior pass.\n- Full cargo test and cargo clippy --all-targets pass.\n\nAvailability:\n- Need it now: build from main after push.\n- Prefer stable binaries: wait for next release tag.

<!-- gh-comment-id:3947683204 --> @NikkeTryHard commented on GitHub (Feb 23, 2026): Follow-up with clean formatting:\n\nFixed and validated.\n\nWhat changed:\n- Added runtime account activation endpoint: POST /v1/accounts/set_active.\n- Endpoint flow: set active account, refresh token, propagate runtime token, reset limiter, clear cached project, request LS respawn.\n- Updated zg accounts set <email> to attempt runtime apply when daemon is reachable; fallback remains explicit restart guidance if runtime apply is unavailable.\n- Docker container is not restarted for account switch; LS recycle is used instead.\n\nVerification:\n- New integration tests for set_active endpoint behavior pass.\n- Full cargo test and cargo clippy --all-targets pass.\n\nAvailability:\n- Need it now: build from main after push.\n- Prefer stable binaries: wait for next release tag.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/zerogravity#45
No description provided.