Skip to content

feat(tasks): add status health and maintenance command#57423

Merged
vincentkoc merged 3 commits intomainfrom
feat/task-health-status-maintenance
Mar 30, 2026
Merged

feat(tasks): add status health and maintenance command#57423
vincentkoc merged 3 commits intomainfrom
feat/task-health-status-maintenance

Conversation

@vincentkoc
Copy link
Copy Markdown
Member

Summary

  • Problem: the new SQLite-backed task ledger can be audited, but operators still have to remember a separate command and there is no shared repair path for obviously broken rows.
  • Why it matters: task health stays out of the main status surface, and cleanup drift on restored terminal rows remains visible but not fixable from the CLI.
  • What changed: added task audit health to openclaw status, added openclaw tasks maintenance with preview/apply modes, and taught maintenance to stamp missing cleanup retention on terminal rows before pruning.
  • What did NOT change (scope boundary): no new task metadata model, no executor/retry semantics, no Redis/Temporal work.

Change Type (select all)

  • Feature
  • Refactor required for the fix

Scope (select all touched areas)

  • Gateway / orchestration
  • Memory / storage
  • UI / DX

Linked Issue/PR

Root Cause / Regression History (if applicable)

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
  • Target test or file: src/commands/status.summary.test.ts, src/commands/tasks.test.ts, src/cli/program/register.status-health-sessions.test.ts, src/tasks/task-registry.test.ts
  • Scenario the test should lock in: status includes task audit health, the new maintenance command is wired correctly, and maintenance can preview/apply cleanup stamping for legacy terminal rows.
  • Why this is the smallest reliable guardrail: these flows are pure command/registry seams without needing broader end-to-end coverage.
  • Existing test that already covers this (if any): existing task registry tests already covered reconcile/prune behavior.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

  • openclaw status now surfaces task audit health counts alongside task-run counts.
  • openclaw tasks maintenance previews or applies task-ledger reconciliation, cleanup stamping, and pruning.

Diagram (if applicable)

Before:
[operator] -> [openclaw status] -> [task counts only]
[operator] -> [openclaw tasks audit] -> [health details]

After:
[operator] -> [openclaw status] -> [task counts + audit health]
[operator] -> [openclaw tasks maintenance] -> [preview/apply repair + prune summary]

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) Yes
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation: added one local maintenance CLI command over the existing task ledger only; behavior is explicit and gated by --apply, with preview as the default.

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 22 / pnpm workspace
  • Model/provider: N/A
  • Integration/channel (if any): N/A
  • Relevant config (redacted): default local state dir

Steps

  1. Create task rows with stale/lost/missing-cleanup conditions.
  2. Run openclaw status and openclaw tasks maintenance.
  3. Re-run maintenance with --apply.

Expected

  • Status surfaces task audit health.
  • Maintenance previews changes by default, then applies reconciliation/cleanup/pruning with --apply.

Actual

  • Matches expected in scoped tests.

Evidence

  • Failing test/log before + passing after

Human Verification (required)

  • Verified scenarios: scoped status summary, maintenance command wiring, maintenance preview/apply behavior, task audit summary surfacing.
  • Edge cases checked: restored terminal rows missing cleanupAfter, empty audit summaries, JSON scan fallback shape.
  • What you did not verify: full pnpm test suite; interactive manual CLI session against a live task db.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: maintenance could over-report or over-apply task cleanup in edge cases.
    • Mitigation: preview is the default, apply path is separately tested, and the write scope stays limited to task-ledger reconciliation/cleanup fields.
  • Risk: pnpm check is currently red on latest main due to an unrelated existing type error in src/agents/skills.test-helpers.ts.
    • Mitigation: scoped task/status tests, plus pnpm build, are green for this PR.

AI Assistance

  • AI-assisted: yes
  • Testing: scoped tests + pnpm build; pnpm check blocked by unrelated existing main failure noted above.
  • codex review --base origin/main: attempted, but it failed with a local transport error to 127.0.0.1, so there was no usable review output.

@vincentkoc vincentkoc self-assigned this Mar 30, 2026
@openclaw-barnacle openclaw-barnacle bot added cli CLI command changes commands Command implementations size: M maintainer Maintainer-authored PR labels Mar 30, 2026
@vincentkoc vincentkoc marked this pull request as ready for review March 30, 2026 03:00
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 30, 2026

Greptile Summary

This PR surfaces task audit health inside openclaw status and adds a new openclaw tasks maintenance subcommand with preview/apply modes. Changes build cleanly on top of the existing SQLite task ledger and audit infrastructure from #57361, with no schema or executor changes.

Key changes:

  • task-registry.maintenance.ts gains previewTaskRegistryMaintenance, runTaskRegistryMaintenance, and getInspectableTaskAuditSummary; sweepTaskRegistry now delegates to the new runTaskRegistryMaintenance, returning the richer cleanupStamped field.
  • tasksMaintenanceCommand in tasks.ts calls maintenance (preview or apply), then samples the audit/registry summary; in apply mode the summary reflects the post-maintenance state, which is subtly different from what the user may expect.
  • status.command.ts shows the audit block (errors/warnings) inline with the existing tasks line, always using warn() styling even when errors === 0.
  • Tests cover preview counts, apply-mode mutations, and audit summary shape. The cleanupAfter assertion in task-registry.test.ts is loosely bounded (toBeGreaterThan(200)).

All findings are P2 (style/suggestion-level) and do not block merge.

Confidence Score: 5/5

Safe to merge; all findings are minor style and UX suggestions with no correctness or data-integrity risk.

The core logic (preview/apply symmetry, audit summary derivation, CLI wiring) is correct and well-tested. Remaining comments are P2: a cosmetic warn() styling inconsistency in status output, a post-maintenance audit ordering observation in apply mode, and a weak test assertion. None affect runtime behavior.

src/commands/tasks.ts (post-maintenance audit ordering) and src/tasks/task-registry.test.ts (weak cleanupAfter assertion) are worth a second look before merging.

Important Files Changed

Filename Overview
src/tasks/task-registry.maintenance.ts Adds previewTaskRegistryMaintenance, runTaskRegistryMaintenance, getInspectableTaskAuditSummary, and helpers for stamping missing cleanupAfter. Logic is sound: prune/stamp/mark-lost paths are mutually exclusive and consistently ordered between preview and apply.
src/commands/tasks.ts Adds tasksMaintenanceCommand with preview/apply modes; audit and health summaries are computed after maintenance runs (post-state), which may be surprising in apply mode.
src/commands/status.command.ts Adds task audit health to the tasks display block. Uses warn() styling for any audit finding including warnings-only, which is a minor UX inconsistency. Overall wiring is correct.
src/tasks/task-registry.test.ts Good new integration tests for preview/apply maintenance and audit summary; cleanupAfter assertion is weaker than ideal (toBeGreaterThan(200)).
src/commands/tasks.test.ts Comprehensive mock setup and new test for preview mode; covers the key behavioral paths for the maintenance command.
src/cli/program/register.status-health-sessions.ts Correctly wires maintenance subcommand with --json and --apply options, inheriting the parent JSON flag via command.parent?.opts().
src/tasks/task-registry.audit.ts Only change is exporting createEmptyTaskAuditSummary; no logic changes.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/commands/status.command.ts
Line: 397-401

Comment:
**`warn()` style when `errors === 0`**

When `taskAudit.total > 0` but `taskAudit.errors === 0` (only warnings present), the status line renders as `"audit 0 errors · N warn"` using `warn()` styling (typically yellow/amber). The "0 errors" copy accurately reflects severity, but the styling still signals something urgent. Consider branching on `taskAudit.errors > 0` vs. warnings-only so operators can distinguish the two at a glance:

```suggestion
          summary.taskAudit.errors > 0
            ? warn(
                `audit ${summary.taskAudit.errors} error${summary.taskAudit.errors === 1 ? "" : "s"} · ${summary.taskAudit.warnings} warn`,
              )
            : summary.taskAudit.warnings > 0
              ? muted(`audit ${summary.taskAudit.warnings} warn`)
              : muted("audit clean"),
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/commands/tasks.ts
Line: 390-392

Comment:
**Audit summary reflects post-maintenance state in `--apply` mode**

In apply mode, `runTaskRegistryMaintenance()` is called first, which deletes pruned tasks and marks active tasks as lost. The subsequent calls to `getInspectableTaskRegistrySummary()` and `getInspectableTaskAuditSummary()` then operate on the updated in-memory registry. This means the "Task health" line shown to the operator reflects the **after-maintenance** state rather than the pre-maintenance picture that motivated the run.

For example, if maintenance pruned 5 old `missing_cleanup` tasks, the audit will report 0 `missing_cleanup` findings even though those tasks were the reason maintenance was needed. This is arguably useful (shows current state), but it can be surprising.

Consider capturing the audit summary **before** maintenance runs, or at minimum add a note to the human-readable output that the health figures reflect the post-maintenance snapshot:

```ts
const auditBefore = getInspectableTaskAuditSummary();
const maintenance = opts.apply ? runTaskRegistryMaintenance() : previewTaskRegistryMaintenance();
const summary = getInspectableTaskRegistrySummary();
const audit = opts.apply ? getInspectableTaskAuditSummary() : auditBefore;
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/tasks/task-registry.test.ts
Line: 890

Comment:
**Weak `cleanupAfter` assertion**

`toBeGreaterThan(200)` essentially just verifies the field is a positive number, since any real epoch timestamp (or `terminalAt + TASK_RETENTION_MS`) will be many orders of magnitude larger than 200. The test would pass even if `cleanupAfter` were set to `1`, which would be wrong.

A more meaningful bound would anchor to the actual expected value or at least verify it is in the future relative to `now`:

```suggestion
      expect(getTaskById("task-missing-cleanup")?.cleanupAfter).toBeGreaterThan(now);
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Merge branch 'main' into feat/task-healt..." | Re-trigger Greptile

@vincentkoc vincentkoc merged commit c52fac8 into main Mar 30, 2026
9 checks passed
@vincentkoc vincentkoc deleted the feat/task-health-status-maintenance branch March 30, 2026 03:10
alexjiang1 pushed a commit to alexjiang1/openclaw that referenced this pull request Mar 31, 2026
* feat(tasks): add status health and maintenance command

* fix(tasks): address status and maintenance review feedback
pgondhi987 pushed a commit to pgondhi987/openclaw that referenced this pull request Mar 31, 2026
* feat(tasks): add status health and maintenance command

* fix(tasks): address status and maintenance review feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant