Repository navigation
fix(cli): rewrite status command to consume real DaemonStatus fields (#825) - #886
Conversation
…825) The _show_daemon_status function was looking for non-existent fields (overall, pid, uptime_s, components) that don't exist in the real daemon_status_payload(). Rewritten to use actual DaemonStatus fields: daemon_liveness, component_state, live_ingest_attempts, fts_readiness. Added --format json flag and show_fast_status() for future bare invocation wiring. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Warning Rate limit exceeded
To continue reviewing without waiting, purchase usage credits in the billing tab. ⌛ 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 (2)
✨ 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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c22814cb80
ℹ️ 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".
There was a problem hiding this comment.
Pull request overview
This PR updates the polylogue status CLI command to query the daemon’s /api/status endpoint using the current DaemonStatus payload shape, and adds a --format json option for machine-readable output.
Changes:
- Reworked CLI status rendering to use daemon-provided status fields (plus a direct SQLite fallback when the daemon is unreachable).
- Added
--format jsonto emit machine-readable output. - Updated the verification catalog reference line number for the status command entry.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
polylogue/cli/commands/status.py |
Rewrites status retrieval/rendering, adds --format json, adds fast-status helper and direct JSON fallback. |
docs/verification-catalog.md |
Updates the recorded source line reference for polylogue status. |
Comments suppressed due to low confidence (1)
polylogue/cli/commands/status.py:189
- Both
_show_direct_jsonand_show_direct_statusopen a read-write connection (open_connection) even though they only perform reads. Usingopen_readonly_connectionhere would better match the connection profile intent and avoid taking write locks / waiting behind writers (especially important for the fast status fallback).
if db.exists():
try:
from polylogue.storage.sqlite.connection_profile import open_connection
conn = open_connection(db)
try:
payload["conversations"] = conn.execute("SELECT COUNT(*) FROM conversations").fetchone()[0]
payload["messages"] = conn.execute("SELECT COUNT(*) FROM messages").fetchone()[0]
payload["raw_records"] = conn.execute("SELECT COUNT(*) FROM raw_conversations").fetchone()[0]
finally:
conn.close()
except Exception as exc:
payload["error"] = str(exc)
env.ui.console.print(json.dumps(payload, indent=2, default=str))
def _show_direct_status(env: AppEnv, *, compact: bool = False) -> None:
"""Fallback status when daemon is not running."""
from polylogue.paths import archive_root, db_path
db = db_path()
if not db.exists():
env.ui.console.print(
"\n[yellow]No archive found.[/yellow] Start the daemon with [bold]polylogued run[/bold] to begin ingestion."
)
return
try:
from polylogue.storage.sqlite.connection_profile import open_connection
conn = open_connection(db)
try:
convs = conn.execute("SELECT COUNT(*) FROM conversations").fetchone()[0]
msgs = conn.execute("SELECT COUNT(*) FROM messages").fetchone()[0]
raw = conn.execute("SELECT COUNT(*) FROM raw_conversations").fetchone()[0]
fts = conn.execute("SELECT COUNT(*) FROM messages_fts").fetchone()[0]
finally:
conn.close()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for name in ("watcher", "api", "browser_capture"): | ||
| comp = components.get(name, {}) | ||
| if isinstance(comp, dict) and comp: | ||
| state = comp.get("state", "unknown") | ||
| state_color = {"running": "green", "degraded": "yellow", "stopped": "red", "disabled": "dim"}.get( | ||
| state, "white" | ||
| ) | ||
| desc = comp.get("description", "") | ||
| env.ui.console.print(f" [{state_color}]●[/{state_color}] {name}: {desc}") | ||
|
|
| pct = fts.get("coverage_pct", 0) | ||
| fts_color = "green" if pct > 99 else "yellow" | ||
| env.ui.console.print(f" FTS: [{fts_color}]{pct:.1f}% indexed[/{fts_color}]") |
| completed = live.get("completed_count", 0) | ||
| total = live.get("total_count", 0) | ||
| in_flight = live.get("worker_in_flight_count", 0) | ||
| if total: | ||
| parts = [f"{completed}/{total} done"] | ||
| if in_flight: | ||
| parts.append(f"+{in_flight} in-flight") |
| @@ -38,49 +49,123 @@ def status_command( | |||
| ) | |||
|
|
|||
| try: | |||
| with urlopen(req, timeout=5) as resp: | |||
| with urlopen(req, timeout=_FULL_TIMEOUT_S) as resp: | |||
| result = json.loads(resp.read()) | |||
| except OSError: | |||
| # Daemon not running — fall back to direct archive check | |||
| _show_direct_status(env) | |||
| if output_format == "json": | |||
| _show_direct_json(env) | |||
| else: | |||
| _show_direct_status(env) | |||
| return | |||
|
|
|||
| _show_daemon_status(env, result) | |||
|
|
|||
|
|
|||
| 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')}") | |||
| version = status.get("version") | |||
| if version: | |||
| env.ui.console.print(f" Version: {version}") | |||
|
|
|||
|
|
|||
| def _show_direct_status(env: AppEnv) -> None: | |||
| if output_format == "json": | |||
| _show_status_json(env, result) | |||
| else: | |||
| _show_daemon_status(env, result) | |||
|
|
|||
| def show_fast_status(env: AppEnv, *, daemon_url: str = _DEFAULT_DAEMON_URL) -> None: | ||
| """Fast bare-invocation status: try daemon, fall back to local SQLite. | ||
|
|
||
| Called from ``polylogue`` with no args. Uses a short HTTP timeout | ||
| and bounded SQLite queries to stay under 2 seconds. | ||
| """ | ||
| try: | ||
| req = Request( | ||
| f"{daemon_url}/api/status", | ||
| headers={"Accept": "application/json"}, | ||
| method="GET", | ||
| ) | ||
| with urlopen(req, timeout=_FAST_TIMEOUT_S) as resp: | ||
| result = json.loads(resp.read()) | ||
| _show_daemon_status(env, result, compact=True) | ||
| except OSError: | ||
| _show_direct_status(env, compact=True) | ||
|
|
| return f"{n / 1_000_000_000:.1f} GB" | ||
| if n >= 1_000_000: | ||
| return f"{n / 1_000_000:.1f} MB" | ||
| return f"{n / 1_000:.0f} KB" |
| @click.option( | ||
| "--format", | ||
| "-f", | ||
| "output_format", | ||
| type=click.Choice(["json"]), | ||
| default=None, | ||
| help="Output format (json for machine-readable).", | ||
| ) |
`polylogue status` was reading fields from a pre-#854 `DaemonStatus` shape and partially fabricating values when those fields were missing. After the typed `DaemonStatus` redesign the command was stale and showed misleading data such as a constant uptime or a wrong daemon-running flag. - `polylogue/cli/commands/status.py`: rewritten against the current `DaemonStatus` Pydantic model. Adds `--format json` for machine consumers and a deterministic text format for humans. - `docs/verification-catalog.md`: regenerated after the command-help surface change. Refs #825
`polylogue status` was reading fields from a pre-#854 `DaemonStatus` shape and partially fabricating values when those fields were missing. After the typed `DaemonStatus` redesign the command was stale and showed misleading data such as a constant uptime or a wrong daemon-running flag. - `polylogue/cli/commands/status.py`: rewritten against the current `DaemonStatus` Pydantic model. Adds `--format json` for machine consumers and a deterministic text format for humans. - `docs/verification-catalog.md`: regenerated after the command-help surface change. Refs #825
|
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. |
Fixed broken status command. Added --format json. All 14 gates passed.