mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 19:05:18 +00:00
3.8 KiB
3.8 KiB
Task Creation Should Return After Actor Bootstrap
Read 00-end-to-end-async-realtime-plan.md first for the governing migration order, runtime constraints, and realtime client model this brief assumes.
Problem
Task creation currently waits for full provisioning: naming, repo checks, sandbox creation/resume, sandbox-agent install/start, sandbox-instance wiring, and session creation.
That makes a user-facing action depend on queue-backed and provider-backed work that can take minutes. The client only needs the task actor to exist so it can navigate to the task and observe progress.
Current Code Context
- Organization entry point:
foundry/packages/backend/src/actors/organization/actions.ts - Repository task creation path:
foundry/packages/backend/src/actors/repository/actions.ts - Task action surface:
foundry/packages/backend/src/actors/task/index.ts - Task workflow:
foundry/packages/backend/src/actors/task/workflow/index.ts - Task init/provision steps:
foundry/packages/backend/src/actors/task/workflow/init.ts - Provider-backed long steps currently happen inside the task provision workflow.
Target Contract
createTaskreturns once the task actor exists and initial task metadata is persisted.- The response includes the task identity the client needs for follow-up reads and subscriptions.
- Provisioning continues in the background through the task workflow.
- Progress and failure are surfaced through task state, history events, and workbench updates.
Proposed Fix
- Restore the async split between
initializeandprovision. - Keep
task.command.initializeresponsible for:- creating the task actor
- bootstrapping DB rows
- persisting any immediately-known metadata
- returning the current task record
- After initialize completes, enqueue
task.command.provisionwithwait: false. - Change
organization.createTaskto:- create or resolve the repository
- create the task actor
- call
task.initialize(...) - stop awaiting
task.provision(...) - broadcast a workbench/task update
- return the task record immediately
- Persist a clear queued/running state for provisioning so the frontend can distinguish:
init_enqueue_provisioninit_ensure_nameinit_create_sandboxinit_ensure_agentinit_create_sessionrunningerror
Files Likely To Change
foundry/packages/backend/src/actors/organization/actions.tsfoundry/packages/backend/src/actors/repository/actions.tsfoundry/packages/backend/src/actors/task/index.tsfoundry/packages/backend/src/actors/task/workflow/index.tsfoundry/packages/backend/src/actors/task/workflow/init.tsfoundry/packages/frontend/src/components/organization-dashboard.tsxfoundry/packages/client/src/remote/workbench-client.ts
Client Impact
- Task creation UI should navigate immediately to the task page.
- The page should render a provisioning state from task status instead of treating create as an all-or-nothing spinner.
- Any tab/session creation that depends on provisioning should observe task state and wait for readiness asynchronously.
Acceptance Criteria
- Creating a task never waits on sandbox creation or session creation.
- A timeout in provider setup does not make the original create request fail after several minutes.
- After a backend restart, the task workflow can resume provisioning from durable state without requiring the client to retry create.
Implementation Notes
- Preserve the existing task actor as the single writer for task runtime state.
- Do not introduce a second creator path for task actors; keep one create/bootstrap path and one background provision path.
- Fresh-agent check: verify that
createWorkbenchTaskand any dashboard create flow still have enough data to navigate immediately after this change.