Repository navigation
feat(daemon): ingest/status CLI, convergence model, systemd service - #831
Conversation
First tranche of the #717 daemon overhaul: - POST /api/ingest — copies requested path into archive inbox, daemon watcher picks it up. Returns operation ID for tracking. - polylogue ingest <path> — thin CLI that contacts the daemon API. Reports "Scheduled" and directs user to check status. - polylogue status — queries daemon health via GET /api/status. Falls back to direct DB query when daemon is not running. - Remove polylogue run from interactive CLI command registration (pipeline module still exists for daemon internal use). Ref #717 Co-Authored-By: Claude Opus 4.7 <[email protected]>
…unit Core architectural pieces for the #717 daemon overhaul: - DaemonConverger: stage-based state convergence framework. Each source file progresses through acquire → parse → materialize → index → insights stages independently. CPU-bound stages dispatched to ProcessPoolExecutor, main process is the sole SQLite writer. - _periodic_convergence_check: safety-net task running every 10 minutes to detect and repair FTS gaps (crash recovery, rare edge cases). - systemd/polylogued.service: user systemd service unit with security hardening (NoNewPrivileges, PrivateTmp, ProtectSystem=strict, read-only home with explicit write paths). Ref #717 Co-Authored-By: Claude Opus 4.7 <[email protected]>
Start the convergence engine on daemon startup, stop it on shutdown. The converger currently runs with an empty stage set (periodic FTS convergence is handled by _periodic_convergence_check). Stage implementations will be filled in incrementally as pipeline stages are refactored into independent check+execute pairs. Ref #717 Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR introduces new CLI commands ( ChangesIngest & Status Commands + Daemon Convergence Framework
Sequence DiagramsequenceDiagram
participant User as User/CLI
participant Ingest as ingest_command
participant API as Daemon HTTP API
participant Daemon as Daemon Service
participant Inbox as Inbox Directory
User->>Ingest: polylogue ingest /path/to/data
Ingest->>API: POST /api/ingest {"path": "/path/to/data"}
API->>Inbox: Validate & copy path to inbox
API->>Daemon: Emit ingest event
API-->>Ingest: 202 Accepted {operation_id, path}
Ingest-->>User: Scheduled ingestion (operation_id, path)
sequenceDiagram
participant User as User/CLI
participant Status as status_command
participant API as Daemon HTTP API
participant Daemon as Daemon Service
participant Archive as SQLite Archive
User->>Status: polylogue status
Status->>API: GET /api/status
API->>Daemon: Query daemon state
alt Daemon Reachable
Daemon-->>API: {status, pid, uptime, components, version}
API-->>Status: 200 OK with daemon metrics
Status-->>User: Display daemon health summary
else Daemon Unreachable
Status->>Archive: Open local SQLite DB
Archive-->>Status: Query counts (conversations, messages, FTS)
Status-->>User: Display local archive metrics
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
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 docstrings
🧪 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 60 minutes.Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a62f57d773
ℹ️ 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".
| overall = status.get("overall", "unknown") | ||
| color = {"ok": "green", "warn": "yellow", "err": "red", "idle": "blue"}.get(overall, "white") | ||
| env.ui.console.print(f"\n[bold {color}]Status: {overall}[/bold {color}]") |
There was a problem hiding this comment.
Parse daemon status using existing API fields
_show_daemon_status expects keys like overall, components, and archive_display_path, but /api/status currently serves daemon_status_payload() with fields such as component_state, live, and db_path. As a result, when the daemon is running, polylogue status reports Status: unknown and drops most health details instead of showing real component state.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
This PR starts the daemon-surface overhaul by adding polylogue ingest / polylogue status, introducing a new convergence module, wiring an ad-hoc ingest API endpoint, and adding a sample systemd unit. It fits into the codebase as the first step toward moving long-running ingestion and status/reporting behind polylogued.
Changes:
- Added new interactive CLI surfaces for daemon-triggered ingest and daemon/archive status.
- Added daemon-side HTTP handling for
/api/ingestplus a new convergence module and periodic convergence check wiring. - Updated generated docs/catalog artifacts and added a user systemd service unit.
Assessment:
- Not ready as-is: the new ingest path is not wired to anything the daemon actually watches, the new status CLI expects a different payload shape than
/api/statusreturns, and several generated docs/tests are left inconsistent with the new CLI surface.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
systemd/polylogued.service |
Adds a user service unit for running polylogued with API enabled and systemd hardening. |
polylogue/daemon/http.py |
Adds POST /api/ingest handling on the daemon HTTP server. |
polylogue/daemon/convergence.py |
Introduces new stage/state data structures for daemon convergence. |
polylogue/daemon/cli.py |
Starts periodic convergence checks and instantiates the new converger in daemon startup/shutdown. |
polylogue/daemon/__init__.py |
Re-exports convergence types from the daemon package. |
polylogue/cli/commands/status.py |
Adds the new polylogue status command with daemon query and DB fallback behavior. |
polylogue/cli/commands/ingest.py |
Adds the new polylogue ingest command that POSTs a path to the daemon. |
polylogue/cli/click_command_registration.py |
Registers status and ingest and removes run from root interactive commands. |
docs/verification-catalog.md |
Updates generated verification catalog command/count snapshots for the CLI surface change. |
docs/topology-status.md |
Updates generated topology file-count snapshot. |
docs/test-quality-workflows.md |
Updates generated workflow/scenario listings for CLI help coverage. |
docs/cli-reference.md |
Updates generated CLI reference command list and command-help sections. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ROOT_COMMANDS: tuple[click.Command, ...] = ( | ||
| run_command, # timer-driven maintenance: polylogue run index, polylogue run site | ||
| check_command, | ||
| reset_command, | ||
| status_command, | ||
| ingest_command, |
| # Stage into the archive inbox — the daemon watcher picks it up. | ||
| from polylogue.paths import archive_root | ||
|
|
||
| inbox = archive_root() / "inbox" | ||
| inbox.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| import shutil | ||
|
|
||
| dest = inbox / source.name | ||
| try: | ||
| if source.is_dir(): | ||
| shutil.copytree(source, dest, dirs_exist_ok=True) | ||
| else: | ||
| shutil.copy2(source, dest) | ||
| except OSError as exc: | ||
| self._send_json(HTTPStatus.INTERNAL_SERVER_ERROR, {"ok": False, "error": str(exc)}) | ||
| return | ||
|
|
||
| op_id = f"ingest-{source.name}" | ||
| emit_daemon_event("ingest", operation_id=op_id, payload={"path": str(source), "inbox": str(dest)}) | ||
| self._send_json( | ||
| HTTPStatus.ACCEPTED, | ||
| { | ||
| "ok": True, | ||
| "operation_id": op_id, | ||
| "path": str(source), | ||
| "message": "Ingestion scheduled. Check status for progress.", |
| dest = inbox / source.name | ||
| try: | ||
| if source.is_dir(): | ||
| shutil.copytree(source, dest, dirs_exist_ok=True) | ||
| else: | ||
| shutil.copy2(source, dest) |
| try: | ||
| with urlopen(req, timeout=5) as resp: | ||
| result = json.loads(resp.read()) | ||
| except OSError: | ||
| # Daemon not running — fall back to direct archive check | ||
| _show_direct_status(env) | ||
| return |
| def _show_daemon_status(env: AppEnv, status: dict[str, Any]) -> None: | ||
| overall = status.get("overall", "unknown") | ||
| color = {"ok": "green", "warn": "yellow", "err": "red", "idle": "blue"}.get(overall, "white") | ||
| env.ui.console.print(f"\n[bold {color}]Status: {overall}[/bold {color}]") | ||
|
|
||
| pid = status.get("pid") | ||
| uptime = status.get("uptime_s") | ||
| if pid: | ||
| env.ui.console.print(f" Daemon PID: {pid}") | ||
| if uptime is not None: | ||
| env.ui.console.print(f" Uptime: {uptime:.0f}s") | ||
|
|
||
| components = status.get("components", []) | ||
| if components: | ||
| env.ui.console.print("\n[bold]Components:[/bold]") | ||
| for c in components: | ||
| state_color = { | ||
| "ok": "green", | ||
| "warn": "yellow", | ||
| "err": "red", | ||
| "stale": "yellow", | ||
| "idle": "blue", | ||
| "disabled": "dim", | ||
| }.get(c.get("state"), "white") | ||
| env.ui.console.print(f" [{state_color}]●[/{state_color}] {c['name']}: {c.get('summary', '')}") | ||
|
|
||
| env.ui.console.print(f"\n Archive: {status.get('archive_display_path', 'unknown')}") |
| ## Run Site | ||
|
|
||
| ```text | ||
| Usage: polylogue run site [OPTIONS] | ||
| Usage: polylogue [OPTIONS] COMMAND [ARGS]... | ||
|
|
| @@ -154,11 +155,11 @@ Commands: | |||
| raw Show raw archive artifacts for a conversation. | |||
| reset Reset database, blob store, assets, rendered outputs, or... | |||
| resume Reconstruct work-state context for a fresh agent session. | |||
| run Run pipeline stages on configured sources and/or transient... | |||
| schema Inspect schema packages, versions, and evidence. | |||
| select Select one matched conversation and print a field. | |||
| show Show matched conversations with default full-content output. | |||
| stats Show statistics for matched conversations. | |||
| status Show daemon and archive health. | |||
| ingest_path = body.get("path") | ||
| if not ingest_path: | ||
| self._send_error(HTTPStatus.BAD_REQUEST, "missing_path") | ||
| return | ||
|
|
||
| from pathlib import Path as _Path | ||
|
|
||
| source = _Path(ingest_path).expanduser().resolve() |
| # Start the convergence engine — it periodically checks and repairs | ||
| # FTS gaps, insight freshness, and other archive invariants. | ||
| from polylogue.daemon.convergence import DaemonConverger | ||
|
|
||
| converger = DaemonConverger(stages=(), max_workers=2) | ||
| await converger.start() |
| | `exercise` | `help-run` | — | — | — | — | — | Run subcommand help | | ||
| | `exercise` | `help-run-embed` | — | — | — | — | — | Run embed subcommand help | | ||
| | `exercise` | `help-run-site` | — | — | — | — | — | Run site stage help | |
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
First tranche of the #717 daemon overhaul — adds
polylogue ingestandpolylogue statusCLI commands, a daemon API endpoint for ad-hoc ingestion, a stage-based state convergence framework, and a systemd service unit.Problem
The daemon currently wraps the old batch pipeline (
ingest_sources()with acquire→validate→parse→transform→write) in an inotify watcher. There's no ad-hoc ingestion path, no CLI status command, and no convergence model — the daemon just runs the full pipeline for every changed file.Solution
CLI surface:
polylogue ingest <path>— contacts daemon viaPOST /api/ingest, copies file into archive inbox. Thin RPC trigger, no pipeline logic.polylogue status— queries daemon health viaGET /api/status. Falls back to direct DB query when daemon isn't running.polylogue runremoved from interactive CLI registration (pipeline module stays for daemon internal use)Daemon API:
POST /api/ingest— accepts{"path": "..."}, copies into archive inbox, daemon watcher picks it upPOST /api/resetalready exists;POST /api/ingestis newConvergence model:
DaemonConverger— stage-based state convergence. Each source file progresses through independent stages. CPU-bound stages dispatched toProcessPoolExecutor, main process is the sole SQLite writer._periodic_convergence_check— safety-net task (10-min interval) detecting and repairing FTS gapsSystemd:
systemd/polylogued.service— user service unit with security hardening (NoNewPrivileges,PrivateTmp,ProtectSystem=strict, read-only home with explicit write paths for~/.local/share/polylogue,~/.config/claude,~/.codex)Verification
Ref #717
🤖 Generated with Claude Code
Summary by CodeRabbit
polylogue ingestcommand to ingest files and directories into the archivepolylogue statuscommand to display daemon health status, component states, and archive statistics