feat(tasks): add status health and maintenance command#57423
feat(tasks): add status health and maintenance command#57423vincentkoc merged 3 commits intomainfrom
Conversation
Greptile SummaryThis PR surfaces task audit health inside Key changes:
All findings are P2 (style/suggestion-level) and do not block merge. Confidence Score: 5/5Safe 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.
|
| 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
* feat(tasks): add status health and maintenance command * fix(tasks): address status and maintenance review feedback
* feat(tasks): add status health and maintenance command * fix(tasks): address status and maintenance review feedback
Summary
openclaw status, addedopenclaw tasks maintenancewith preview/apply modes, and taught maintenance to stamp missing cleanup retention on terminal rows before pruning.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause / Regression History (if applicable)
git blame, prior PR, issue, or refactor if known): follow-up to the SQLite task ledger and audit work in feat(tasks): move task ledger to sqlite and add audit CLI #57361.Regression Test Plan (if applicable)
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.tsUser-visible / Behavior Changes
openclaw statusnow surfaces task audit health counts alongside task-run counts.openclaw tasks maintenancepreviews or applies task-ledger reconciliation, cleanup stamping, and pruning.Diagram (if applicable)
Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) YesYes/No) NoYes, 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
Steps
openclaw statusandopenclaw tasks maintenance.--apply.Expected
--apply.Actual
Evidence
Human Verification (required)
cleanupAfter, empty audit summaries, JSON scan fallback shape.pnpm testsuite; interactive manual CLI session against a live task db.Review Conversations
Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoRisks and Mitigations
pnpm checkis currently red on latestmaindue to an unrelated existing type error insrc/agents/skills.test-helpers.ts.pnpm build, are green for this PR.AI Assistance
pnpm build;pnpm checkblocked by unrelated existingmainfailure noted above.codex review --base origin/main: attempted, but it failed with a local transport error to127.0.0.1, so there was no usable review output.