Repository navigation
refactor(daemon): move live watch into polylogued - #680
Conversation
Problem: the standalone live source watcher was still exposed as a root polylogue command, mixing long-running service mode into the query-first archive CLI while the UX direction calls for daemon-owned live ingestion.\n\nWhat changed: add the polylogued console script and daemon Click entrypoint, move the live watcher command behind polylogued watch, remove the root polylogue watch registration, and refresh generated CLI/proof/topology/showcase surfaces. The pipeline run --watch mode remains unchanged.\n\nVerification: ruff format polylogue tests devtools; ruff check polylogue tests devtools --fix; pytest -q tests/unit/daemon/test_cli.py tests/unit/cli/test_click_app.py tests/unit/cli/test_terminal_snapshots.py tests/unit/proof/test_witnesses.py tests/unit/showcase/test_exercise_catalog.py; devtools render-all --check; devtools verify-topology; devtools verify-layering; devtools verify-test-ownership; mypy polylogue/; devtools verify --quick; devtools build-package; .local/result/bin/polylogued --help; .local/result/bin/polylogued watch --help.\n\nRef #635\nRef #593
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR relocates the ChangesWatch Command CLI Restructure
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 0/1 reviews remaining, refill in 45 minutes and 32 seconds.Comment |
Polylogue Proof PackRefs: Affected Domains
Required Gates
Known Gaps
Oracle / Cost
|
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
polylogue/daemon/cli.py (1)
22-25:⚠️ Potential issue | 🟠 MajorEnsure shutdown cleanup runs on the real Ctrl-C path.
Line 24 catches
KeyboardInterruptinside the coroutine, but withasyncio.run(...), SIGINT is delivered as task cancellation (CancelledError), notKeyboardInterrupt, so Line 25 never runs. Movewatcher.stop()intofinallyto guarantee cleanup on interruption.💡 Suggested fix
async def run_live_watcher( *, sources: tuple[WatchSource, ...], debounce_s: float, ) -> None: async with Polylogue() as polylogue: watcher = LiveWatcher(polylogue, sources, debounce_s=debounce_s) - try: - await watcher.run() - except KeyboardInterrupt: - watcher.stop() + try: + await watcher.run() + finally: + watcher.stop()🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@polylogue/daemon/cli.py` around lines 22 - 25, The cleanup call watcher.stop() is placed in an except KeyboardInterrupt block but asyncio.run delivers SIGINT as task cancellation, so watcher.stop() may never run; move the watcher.stop() invocation into a finally block that always runs after awaiting watcher.run() (or surrounding the await watcher.run() with try/finally) so that regardless of CancelledError or normal completion watcher.stop() is executed; update the code around watcher.run() and watcher.stop() (the async context where asyncio.run is used) to use try/finally instead of except KeyboardInterrupt.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/verification-catalog.md`:
- Around line 11-14: The daemon/CLI proof coverage lost bindings when `polylogue
watch` was renamed/moved; update the verification catalog to add the
daemon-scoped subjects and claim bindings for the new daemon command surface
(e.g., the `polylogued watch` command) so the proof envelope matches the current
`cli.command.*` surface—specifically add subject entries for the daemon commands
and corresponding claim entries (matching the prior `polylogue watch` bindings
such as `help`, `no_traceback`, `plain_mode`) or create an equivalent
daemon-scoped proof pack that includes those obligations; ensure the new entries
mirror the previous proof obligations count and binding names referenced in the
review (addresses around the 43-43 and 297-300 changes) so verification coverage
is preserved.
In `@tests/unit/daemon/test_cli.py`:
- Around line 40-60: The test currently only asserts the source count message
which can pass if defaults are used; update
test_polylogued_watch_builds_sources_from_roots to also verify the forwarded
roots rather than defaults by extracting the coroutine passed to asyncio.run
(variable coroutine from run.call_args) and inspecting its frame locals to
assert the roots argument contains the two provided paths (e.g., check
coroutine.cr_frame.f_locals["roots"] or the appropriate local name used by
main/watcher equals [str(root_a), str(root_b)]), then close the coroutine as
before and keep the existing exit_code and stderr message assertions.
---
Outside diff comments:
In `@polylogue/daemon/cli.py`:
- Around line 22-25: The cleanup call watcher.stop() is placed in an except
KeyboardInterrupt block but asyncio.run delivers SIGINT as task cancellation, so
watcher.stop() may never run; move the watcher.stop() invocation into a finally
block that always runs after awaiting watcher.run() (or surrounding the await
watcher.run() with try/finally) so that regardless of CancelledError or normal
completion watcher.stop() is executed; update the code around watcher.run() and
watcher.stop() (the async context where asyncio.run is used) to use try/finally
instead of except KeyboardInterrupt.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: c365bb2c-3ea2-4bad-8625-70210974b873
📒 Files selected for processing (17)
CHANGELOG.mdREADME.mddocs/cli-reference.mddocs/plans/topology-target.yamldocs/test-quality-workflows.mddocs/topology-status.mddocs/verification-catalog.mdpolylogue/cli/click_command_registration.pypolylogue/daemon/__init__.pypolylogue/daemon/cli.pypyproject.tomltests/baselines/showcase/help-main.txttests/baselines/showcase/help-watch.txttests/data/witnesses/cli-command-surface.jsontests/unit/cli/__snapshots__/test_terminal_snapshots.ambrtests/unit/cli/test_click_app.pytests/unit/daemon/test_cli.py
💤 Files with no reviewable changes (5)
- tests/baselines/showcase/help-watch.txt
- polylogue/cli/click_command_registration.py
- tests/unit/cli/snapshots/test_terminal_snapshots.ambr
- tests/baselines/showcase/help-main.txt
- docs/cli-reference.md
| - subjects: `503` | ||
| - claims: `44` | ||
| - runner bindings: `44` | ||
| - proof obligations: `576` | ||
| - proof obligations: `573` |
There was a problem hiding this comment.
Daemon CLI appears outside proof-obligation coverage.
These count reductions indicate polylogue watch was removed from cli.command.* claims, but there is no corresponding addition for polylogued watch. That leaves a new public command surface outside help/no_traceback/plain_mode proof contracts.
Please add daemon command subjects + claim bindings (or an equivalent daemon-scoped proof pack) so the verification envelope is preserved after the move.
Also applies to: 43-43, 297-300
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/verification-catalog.md` around lines 11 - 14, The daemon/CLI proof
coverage lost bindings when `polylogue watch` was renamed/moved; update the
verification catalog to add the daemon-scoped subjects and claim bindings for
the new daemon command surface (e.g., the `polylogued watch` command) so the
proof envelope matches the current `cli.command.*` surface—specifically add
subject entries for the daemon commands and corresponding claim entries
(matching the prior `polylogue watch` bindings such as `help`, `no_traceback`,
`plain_mode`) or create an equivalent daemon-scoped proof pack that includes
those obligations; ensure the new entries mirror the previous proof obligations
count and binding names referenced in the review (addresses around the 43-43 and
297-300 changes) so verification coverage is preserved.
| def test_polylogued_watch_builds_sources_from_roots(tmp_path: Path) -> None: | ||
| root_a = tmp_path / "claude-code" | ||
| root_b = tmp_path / "codex" | ||
|
|
||
| with patch("polylogue.daemon.cli.asyncio.run") as run: | ||
| result = CliRunner().invoke( | ||
| main, | ||
| [ | ||
| "watch", | ||
| "--root", | ||
| str(root_a), | ||
| "--root", | ||
| str(root_b), | ||
| ], | ||
| ) | ||
|
|
||
| assert result.exit_code == 0 | ||
| coroutine = run.call_args.kwargs.get("main") or run.call_args.args[0] | ||
| assert inspect.iscoroutine(coroutine) | ||
| coroutine.close() | ||
| assert "Watching 2 source(s); debounce=2.0s" in result.stderr |
There was a problem hiding this comment.
watch --root test can pass even if roots are ignored.
Right now it only checks source count/message. If code accidentally falls back to defaults with the same count, this still passes. Assert forwarded roots (and non-use of defaults) to prevent false greens.
Suggested test hardening
-from unittest.mock import patch
+from unittest.mock import AsyncMock, patch
@@
def test_polylogued_watch_builds_sources_from_roots(tmp_path: Path) -> None:
@@
- with patch("polylogue.daemon.cli.asyncio.run") as run:
+ with (
+ patch("polylogue.daemon.cli.default_sources") as default_sources,
+ patch("polylogue.daemon.cli.run_live_watcher", new_callable=AsyncMock) as run_live_watcher,
+ patch("polylogue.daemon.cli.asyncio.run") as run,
+ ):
result = CliRunner().invoke(
main,
[
@@
assert result.exit_code == 0
+ default_sources.assert_not_called()
+ run_live_watcher.assert_called_once()
+ forwarded_sources = run_live_watcher.call_args.kwargs["sources"]
+ assert tuple(source.root for source in forwarded_sources) == (root_a, root_b)
coroutine = run.call_args.kwargs.get("main") or run.call_args.args[0]
assert inspect.iscoroutine(coroutine)
coroutine.close()🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@tests/unit/daemon/test_cli.py` around lines 40 - 60, The test currently only
asserts the source count message which can pass if defaults are used; update
test_polylogued_watch_builds_sources_from_roots to also verify the forwarded
roots rather than defaults by extracting the coroutine passed to asyncio.run
(variable coroutine from run.call_args) and inspecting its frame locals to
assert the roots argument contains the two provided paths (e.g., check
coroutine.cr_frame.f_locals["roots"] or the appropriate local name used by
main/watcher equals [str(root_a), str(root_b)]), then close the coroutine as
before and keep the existing exit_code and stderr message assertions.
There was a problem hiding this comment.
Pull request overview
This pull request moves the standalone live source watcher off the query-first polylogue CLI and into a dedicated daemon/service executable, polylogued, aligning long-running ingestion with a service-oriented surface.
Changes:
- Added the
polyloguedconsole script andpolylogue.daemon.cliClick entrypoint withpolylogued watch. - Removed
polylogue watchfrom root command registration and updated CLI surface tests/snapshots accordingly. - Refreshed generated docs/baselines/topology/proof catalog outputs to reflect the new command surface.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
pyproject.toml |
Adds the polylogued console script entrypoint. |
polylogue/daemon/cli.py |
Introduces the daemon Click group and moves the live watcher command implementation here. |
polylogue/daemon/__init__.py |
Exposes the daemon entrypoint at the package level. |
polylogue/cli/click_command_registration.py |
Removes watch from the root polylogue CLI command registration. |
tests/unit/daemon/test_cli.py |
Adds unit tests for polylogued --help and polylogued watch behavior. |
tests/unit/cli/test_click_app.py |
Updates CLI registration expectations to ensure watch is no longer on polylogue. |
tests/unit/cli/__snapshots__/test_terminal_snapshots.ambr |
Updates polylogue --help snapshots to remove watch. |
tests/data/witnesses/cli-command-surface.json |
Updates required console scripts and removes watch from required root commands. |
tests/baselines/showcase/help-watch.txt |
Removes the old polylogue watch help baseline. |
tests/baselines/showcase/help-main.txt |
Updates root help baseline to remove watch. |
docs/cli-reference.md |
Removes watch from the documented polylogue command list. |
docs/verification-catalog.md |
Regenerates proof catalog counts and removes the polylogue watch subject entry. |
docs/test-quality-workflows.md |
Updates generated scenario projection counts and removes the help-watch exercise row. |
docs/topology-status.md |
Updates generated topology status counts. |
docs/plans/topology-target.yaml |
Removes the old watch command file entry and adds daemon files to the topology target. |
README.md |
Updates usage examples to show polylogued watch. |
CHANGELOG.md |
Documents the new daemon executable and the migration from polylogue watch to polylogued watch. |
Comments suppressed due to low confidence (3)
polylogue/daemon/cli.py:26
run_live_watcher()catchesKeyboardInterrupt, but when running underasyncio.run()a Ctrl-C typically cancels the running task (raisingasyncio.CancelledErrorinside the coroutine) and re-raisesKeyboardInterruptoutside the coroutine. As a result, this handler often won’t run andwatcher.stop()may never be called. Consider using atry/finallyto always callwatcher.stop()and/or explicitly handlingasyncio.CancelledError(re-raising it after cleanup), and optionally catchingKeyboardInterruptaround theasyncio.run(...)call inwatch_commandfor a clean exit.
polylogue/daemon/cli.py:33- This entrypoint doesn’t set
context_settings={"help_option_names": ["-h", "--help"]}like the mainpolylogueCLI andpolylogue-mcpdo. That makes-hstop working forpolyloguedand its subcommands, which is an observable CLI regression. Suggest adding the samehelp_option_namescontext setting to@click.group(...)(and/or@main.command(...)) here for consistency.
polylogue/daemon/cli.py:55 polyloguednever callsconfigure_logging(...), butLiveWatcher/pipeline code usesstructlog(get_logger) for warnings like parse failures and missing roots. Without configuring structlog in this entrypoint, operator-visible logs may be dropped or use unexpected defaults. Consider configuring logging early (e.g., inmain()before running subcommands), and optionally adding a--verboseflag to control log level the same way the primary CLI does.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def test_run_live_watcher_stops_on_keyboard_interrupt() -> None: | ||
| from polylogue.daemon import cli as daemon_cli | ||
|
|
||
| class FakePolylogue: | ||
| async def __aenter__(self) -> object: | ||
| return object() | ||
|
|
||
| async def __aexit__(self, *exc: object) -> None: | ||
| return None | ||
|
|
||
| stopped: list[bool] = [] | ||
|
|
||
| class FakeWatcher: | ||
| stopped = False | ||
|
|
||
| def __init__(self, *_args: object, **_kwargs: object) -> None: | ||
| pass | ||
|
|
||
| async def run(self) -> None: | ||
| raise KeyboardInterrupt | ||
|
|
||
| def stop(self) -> None: | ||
| self.stopped = True | ||
| stopped.append(self.stopped) | ||
|
|
||
| sources = (WatchSource(name="codex", root=Path("/tmp/codex")),) | ||
|
|
||
| with ( | ||
| patch.object(daemon_cli, "Polylogue", FakePolylogue), | ||
| patch.object(daemon_cli, "LiveWatcher", FakeWatcher), | ||
| ): | ||
| asyncio.run(daemon_cli.run_live_watcher(sources=sources, debounce_s=1.0)) | ||
|
|
||
| assert stopped == [True] |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bb0e8cec4e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
|
|
||
| @click.command("watch", help="Watch source directories and ingest new sessions live.") | ||
| @click.group(help="Run long-lived Polylogue local services.") |
There was a problem hiding this comment.
Preserve
-h help alias on daemon commands
The new polylogued group is declared without context_settings={"help_option_names": ["-h", "--help"]}, so polylogued -h and polylogued watch -h will now fail with an unknown option while the previous polylogue watch surface (and other repo CLIs) accepted -h. This is a user-visible CLI regression for existing shell habits/scripts that rely on the short help flag; adding the same context setting used by polylogue/polylogue-mcp keeps behavior consistent.
Useful? React with 👍 / 👎.
Problem: full pytest collection treats same-basename test modules as import-colliding when tests are collected without package imports; CI hit this between daemon/test_cli.py and mcp/test_cli.py.\n\nWhat changed: rename the daemon CLI test module to test_daemon_cli.py.\n\nVerification: ruff format tests/unit/daemon/test_daemon_cli.py; ruff check tests/unit/daemon/test_daemon_cli.py; pytest -q tests/unit/daemon/test_daemon_cli.py tests/unit/mcp/test_cli.py; pytest -q tests/unit/daemon/test_daemon_cli.py tests/unit/cli/test_click_app.py tests/unit/cli/test_terminal_snapshots.py tests/unit/proof/test_witnesses.py tests/unit/showcase/test_exercise_catalog.py.\n\nRef #635
## Summary Moves the standalone live source watcher out of the query-first `polylogue` CLI and into a new daemon executable, `polylogued watch`. ## Problem The UX direction keeps `polylogue` focused on archive querying and one-shot operations while long-running live ingestion belongs to a daemon/service surface. The old root `polylogue watch` command mixed those concerns and kept service mode beside query verbs. ## Solution - Added the `polylogued` console script and `polylogue.daemon.cli` entrypoint. - Moved the live watcher command to `polylogued watch` while preserving its source/default-root/debounce behavior. - Removed the root `polylogue watch` registration and refreshed CLI help baselines, proof catalog, topology, and scenario projections. - Kept `polylogue run --watch` unchanged because it is the continuous pipeline-run mode, not the standalone source tailer. ## Verification - `ruff format polylogue tests devtools` - `ruff check polylogue tests devtools --fix` - `pytest -q tests/unit/daemon/test_cli.py tests/unit/cli/test_click_app.py tests/unit/cli/test_terminal_snapshots.py tests/unit/proof/test_witnesses.py tests/unit/showcase/test_exercise_catalog.py` → `94 passed` - `devtools render-all --check` - `devtools verify-topology` - `devtools verify-layering` - `devtools verify-test-ownership` - `mypy polylogue/` - `devtools verify --quick` - `devtools build-package` - `.local/result/bin/polylogued --help` - `.local/result/bin/polylogued watch --help` - push hook reran `devtools verify --quick` successfully Ref #635 Ref #593 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Introduced `polylogued` daemon executable for managing live source watching via `polylogued watch`. * **Changed** * Live source watching moved from root CLI to daemon subcommand. * `polylogue run --watch` remains available for continuous pipeline execution. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
Moves the standalone live source watcher out of the query-first
polylogueCLI and into a new daemon executable,polylogued watch.Problem
The UX direction keeps
polyloguefocused on archive querying and one-shot operations while long-running live ingestion belongs to a daemon/service surface. The old rootpolylogue watchcommand mixed those concerns and kept service mode beside query verbs.Solution
polyloguedconsole script andpolylogue.daemon.clientrypoint.polylogued watchwhile preserving its source/default-root/debounce behavior.polylogue watchregistration and refreshed CLI help baselines, proof catalog, topology, and scenario projections.polylogue run --watchunchanged because it is the continuous pipeline-run mode, not the standalone source tailer.Verification
ruff format polylogue tests devtoolsruff check polylogue tests devtools --fixpytest -q tests/unit/daemon/test_cli.py tests/unit/cli/test_click_app.py tests/unit/cli/test_terminal_snapshots.py tests/unit/proof/test_witnesses.py tests/unit/showcase/test_exercise_catalog.py→94 passeddevtools render-all --checkdevtools verify-topologydevtools verify-layeringdevtools verify-test-ownershipmypy polylogue/devtools verify --quickdevtools build-package.local/result/bin/polylogued --help.local/result/bin/polylogued watch --helpdevtools verify --quicksuccessfullyRef #635
Ref #593
Summary by CodeRabbit
New Features
polylogueddaemon executable for managing live source watching viapolylogued watch.Changed
polylogue run --watchremains available for continuous pipeline execution.