Skip to content

[Task]: Allow a user to run multiple concurrent tasks if balance is sufficient #40

Description

@grantfox-oss

create_task() asserts config.active_tasks_count == 0, meaning a user can only ever have one active task at a time. The active_tasks_count field already supports values greater than 1 — the restriction is a single assert, not a structural limit.

This is unnecessarily restrictive. An orchestrator serving a user with multiple parallel steps (already supported in executor.ts) must currently serialize all tasks sequentially at the contract level.

Change in create_task():

Remove:

assert!(config.active_tasks_count == 0, "User already has an active task");

Replace with a balance check only — if the user has sufficient available balance for the new task's plan_cost, the task should be allowed regardless of how many tasks are already active:

// `available` is already computed below; the assert on it is sufficient

The existing available >= plan_cost assert already prevents over-commitment. No other guard is needed.

Test updates:

  • test_create_task_already_active_fails should be renamed and updated to verify that a second task succeeds when balance is sufficient, and fails only when available balance is insufficient.
  • Add a test for two concurrent tasks completing independently.

Acceptance criteria

  • create_task() no longer panics when active_tasks_count > 0
  • Creating a second task with sufficient available balance succeeds
  • Creating a second task that would exceed available balance fails with an insufficient-balance error
  • active_tasks_count is correctly incremented/decremented through the full lifecycle of two concurrent tasks
  • cargo test and cargo clippy -- -D warnings pass

Relevant files

  • contracts/agent-vault/src/lib.rs (only the create_task function)
  • contracts/agent-vault/src/tests.rs

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