Skip to content

[Task]: Add get_task_status(task_id) returning a typed lifecycle status #85

Description

@grantfox-oss

get_task(task_id) returns the full TaskInfo, and today every client (dashboard, indexer, orchestrator UI) re-derives a task's status from a mix of fields: completed, spent vs plan_cost, and — for staleness — created_at versus the current ledger time plus the configurable stale threshold. That inference is duplicated everywhere and easy to get subtly wrong. The riskiest part is the "is this task force-completable right now?" question, because it must exactly match the on-chain rule the contract enforces.

Goal

Expose a single authoritative view that computes status on-chain: get_task_status(env, task_id) -> Option<TaskStatus>, where TaskStatus is a #[contracttype] enum with at least Active, Stale, and Completed.

Requirements & constraints

  • The Active vs Stale boundary must be identical to force_complete_stale_task's eligibility rule at lib.rs:774 (currently elapsed > threshold, using get_stale_threshold). If the two ever disagree, a UI would offer a "force complete" button that the contract then rejects — so this equivalence is the crux of the issue, not an afterthought. Consider factoring the eligibility comparison into a shared internal helper that both force_complete_stale_task and get_task_status call, so they cannot drift.
  • Completed is returned for any finalized task (completed, cancelled, or force-completed) regardless of elapsed time.
  • Unknown task IDs return None.

Edge cases to consider

  • A task exactly at the threshold boundary (elapsed == threshold) — must land on the same side as the contract's force-complete check.
  • A task that is both past-threshold and already completed — Completed wins.
  • The stale threshold having been changed by the admin after the task was created.

Acceptance criteria

  • TaskStatus enum defined with #[contracttype]
  • get_task_status returns None for unknown IDs and the correct variant otherwise
  • The Active/Stale boundary provably matches force_complete_stale_task (ideally via a shared helper)
  • Tests advance ledger time (env.ledger()) to exercise the Active → Stale transition, including the exact boundary, plus the completed case and a post-change threshold
  • cargo test and cargo clippy --all-targets -- -D warnings pass

Notes for contributors

If you'd like to work on this, comment below so we can assign it to you.
Questions welcome — see CONTRIBUTING.md for setup
and workflow.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions