Skip to content

fix(cli): rewrite status command to consume real DaemonStatus fields (#825) - #886

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/cli-status-825
May 7, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/cli-status-825

Conversation

@Sinity

@Sinity Sinity commented May 7, 2026

Copy link
Copy Markdown
Owner

Fixed broken status command. Added --format json. All 14 gates passed.

…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]>
Copilot AI review requested due to automatic review settings May 7, 2026 07:57
@Sinity
Sinity merged commit e87e000 into master May 7, 2026
@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 53 minutes and 56 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: a4496366-26eb-4c5c-92bb-c9499a3038d1

📥 Commits

Reviewing files that changed from the base of the PR and between 3ecb47d and c22814c.

📒 Files selected for processing (2)
  • docs/verification-catalog.md
  • polylogue/cli/commands/status.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/cli-status-825

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Sinity
Sinity deleted the feature/feat/cli-status-825 branch May 7, 2026 07:57

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread polylogue/cli/commands/status.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 json to 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_json and _show_direct_status open a read-write connection (open_connection) even though they only perform reads. Using open_readonly_connection here 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.

Comment on lines +96 to +105
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}")

Comment on lines +121 to +123
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}]")
Comment on lines +109 to +115
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")
Comment on lines 25 to +65
@@ -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)

Comment on lines +67 to +84
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"
Comment on lines +25 to +32
@click.option(
"--format",
"-f",
"output_format",
type=click.Choice(["json"]),
default=None,
help="Output format (json for machine-readable).",
)
Sinity added a commit that referenced this pull request May 7, 2026
`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
Sinity added a commit that referenced this pull request May 7, 2026
`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
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 61.F056 / P2: fixed-already at the checked revision: polylogue/cli/commands/status.py:516 distinguishes absent FTS coverage from a measured percentage and renders coverage unknown at line 521. A daemon response containing only readiness booleans is no longer reported as 0.0% indexed.

Only the rows listed above are dispositioned. Held findings remain open.

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.

2 participants