Skip to content

fix(service): move startup side effects out of CiderAgentService.__init__ - #102

Merged
randileeharper merged 1 commit into
mainfrom
fix/init-side-effects
Jun 28, 2026
Merged

fix(service): move startup side effects out of CiderAgentService.__init__#102
randileeharper merged 1 commit into
mainfrom
fix/init-side-effects

Conversation

@randileeharper

Copy link
Copy Markdown
Owner

Summary

Fixes #86.

CiderAgentService.__init__ called self.reconcile_session_runtime(), which immediately hits SQLite for the active session and calls Cider RPC via playback_snapshot(). This meant constructing the service could fail if Cider was unreachable, and it made pure unit tests harder to write — construction had side effects that could wipe runtime state carefully set up by tests.

Changes

  • vesper/service.py: removed self.reconcile_session_runtime() from __init__. Construction is now cheap and deterministic.
  • vesper/app.py:
    • Application.worker_lifespan: calls reconcile_session_runtime() before start_background_session_worker(). This is the server/transport startup path.
    • service_context: calls reconcile_session_runtime() before yielding the service. This is the CLI one-shot path where session state needs to be restored.
  • tests/test_service.py:
    • Updated 5 restart tests that implicitly relied on reconcile during construction to call reconcile_session_runtime() explicitly.
    • Added test_construction_has_no_storage_or_rpc_side_effects: pre-seeds an active session, constructs a service, and asserts no playback RPC calls were made and session runtime is empty until reconcile_session_runtime() is called explicitly.

Test commands run

.venv/bin/python -m pytest -q
.venv/bin/python -m compileall vesper tests

All 256 tests pass; compileall clean.

CiderAgentService.__init__ called self.reconcile_session_runtime(), which
immediately hits SQLite for the active session and calls Cider RPC via
playback_snapshot(). This meant constructing the service could fail if Cider
was unreachable, and it made pure unit tests harder to write — construction
had side effects that could wipe runtime state carefully set up by tests.

Move the reconcile call to the explicit startup paths:
- Application.worker_lifespan: the server/transport startup path, called
  before the background session worker starts.
- service_context: the CLI one-shot path, where session state needs to be
  restored before the command runs.

Construction is now cheap and deterministic. Tests that relied on reconcile
running during construction (the restart tests) now call
reconcile_session_runtime() explicitly after constructing the service.

Add a regression test verifying construction makes no playback RPC calls
and leaves session runtime empty until reconcile is called explicitly.
@randileeharper
randileeharper force-pushed the fix/init-side-effects branch from 7949ea6 to 0d12cd8 Compare June 28, 2026 17:54
@randileeharper
randileeharper merged commit 126fd9f into main Jun 28, 2026
1 check passed
@randileeharper
randileeharper deleted the fix/init-side-effects branch June 28, 2026 17:57
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.

Move startup side effects out of CiderAgentService.__init__

1 participant