Open a unit for a change
Code Mode: praxis.devops.projects.units.create
HTTP: POST /devops/v1/projects/{project}/units
Open the machine a change is developed on: one machine, one unit. Most callers never need this — opening a change opens its unit by itself — so call it to retry an automatic open that failed, or to open a unit for a change that has none yet. The unit is created from the project’s development workspace settings, starts from that stage’s ready prebuild when one exists and otherwise builds the stage template, and checks out the change’s branch. The change must exist in this project and must not be abandoned; a project holds at most one live unit per change, so a second call for the same change answers 409 UNIT_EXISTS_FOR_CHANGE instead of opening another (send requestId to make a retry of this same open answer the unit the first call made). The call answers at once with the unit in phase provisioning — no machine has been placed yet — and the sandbox’s answer is folded into the same unit afterwards; read the unit to watch it reach available. A refusal never leaves a unit behind.
签名
praxis.devops.projects.units.create(args:{path:{/** e.g. "dvp_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ project:string};body:{/** The change to open the unit for, named by its branch id such as feat/run-page-v2; it must exist in this project, must not be abandoned, and must not already hav e.g. "feat/run-page-v2" */ change:string;/** Client-chosen id that makes a retry answer the unit the first call made instead of failing on the change's one-unit rule; send the same value when retrying and e.g. "open-unit-feat-run-page-v2" */ requestId?:string}}):Promise<{/** The unit identifier, used by every other unit operation and never reused once the unit is deleted. e.g. "wsu_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ id:string;/** The resource type of this answer, always unit. */ object:"unit";/** RFC 3339 UTC time the unit was opened; the unit list is ordered by it, newest first. e.g. "2026-11-11T10:00:00Z" */ createTime:string;/** RFC 3339 UTC time the unit's own fields last changed. e.g. "2026-11-11T10:05:00Z" */ updateTime:string;/** Canonical Console link for this unit; use it in a message so a person can open the same machine. e.g. "https://console.deepraxis.com/devops/dvp_01m6j8swzteapw2j5sh4/units/wsu_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ viewerUrl:string;/** The project this unit belongs to, from the project list. e.g. "dvp_01m6j8swzteapw2j5sh4" */ project:string;/** The workspace configuration this unit was created from, from the project's workspace list. e.g. "wks_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ workspace:string;stage:"development"|"integration"|"release";/** What sort of work the unit carries, which is the subject's kind with the run kinds spelled out. e.g. "change" */ kind:"change"|"environment_run"|"test_run"|"prebuild_build";subject:{/** Which kind of subject this unit serves. e.g. "change" */ kind:"change"|"environment"|"test"|"prebuild";/** The change this unit develops, present when kind is change; the id is the change's branch name, such as feat/run-page-v2. e.g. "feat/run-page-v2" */ change?:string|null;/** The environment the run belongs to, present when kind is environment; from the project's environment list. e.g. "dve_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ environment?:string|null;/** The promotion that opened the run, present when kind is environment. e.g. "prm_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ promotion?:string|null;/** The test run this unit serves, present when kind is test. e.g. "trn_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ run?:string|null;/** The commit being prebuilt, present when kind is prebuild; a full 40-character commit. e.g. "4f2a9c1d8e7b6a5c4d3e2f1a0b9c8d7e6f5a4b3c" */ commit?:string|null};spec:{/** The state the unit was last asked to be in; it does not change when the machine fails, so a failed unit can still read running here. e.g. "running" */ desired:"running"|"stopped"|"deleted";/** How many times the unit's spec has been written; it rises with each verb, so an observation can be matched against the spec it saw. e.g. 2 */ specVersion:number;size:"small"|"medium"|"large"|"xlarge";source:{/** Which source the unit's machine was created from. e.g. "template" */ kind:"template"|"prebuild";/** The template the machine was built from, present when kind is template. e.g. "base" */ template?:string|null;/** The prebuild the machine started from, present when kind is prebuild. e.g. "pbd_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ prebuild?:string|null;/** The commit the prebuild was built at, present when kind is prebuild. e.g. "4f2a9c1d8e7b6a5c4d3e2f1a0b9c8d7e6f5a4b3c" */ commit?:string|null}};status:{phase:"queued"|"provisioning"|"available"|"shutting_down"|"shutdown"|"starting"|"failed"|"deleted";/** RFC 3339 UTC time the phase was last observed, or null before the first observation; a phase older than expected means the machine has not been read recently. e.g. "2026-11-11T10:05:00Z" */ observedAt:string|null;/** Why the unit stopped, or null while it is not stopped. */ stopReason:null|"user"|"idle"|"max_running"|"change_closed"|"lost"|"completed";/** The sandbox's own words for why the machine ended, quoted verbatim and never rewritten; null while the unit has not ended. e.g. "The instance was terminated by the provider." */ terminationReason:string|null;/** The sandbox handle for this unit's machine, or null before the sandbox has placed one and after it is gone; it never carries a vendor name. */ sandbox:null|{/** The sandbox's id for this machine; treat it as opaque and never parse it. e.g. "sbx_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ instance:string;/** Opaque route to the running machine, used by the platform to reach it; never build one from an instance id. e.g. "rt-a1b2c3d4e5f6" */ route:string}};/** What the unit's checkout last showed, or null before any observation has been recorded. */ git:null|{/** The branch checked out on the machine, which is the change's branch name. e.g. "feat/run-page-v2" */ branch:string;/** The commit the branch was last observed at, or null before any observation. e.g. "4f2a9c1d8e7b6a5c4d3e2f1a0b9c8d7e6f5a4b3c" */ head:string|null;/** How many commits the branch is ahead of the base the checkout was compared with; 0 before any observation. e.g. 0 */ ahead:number;/** How many commits the branch is behind that base; 0 before any observation. e.g. 0 */ behind:number;/** Whether the checkout has changes that were not committed; a unit with this true is refused by delete unless force is sent. e.g. false */ uncommitted:boolean;/** Whether the branch has commits that were not pushed; a unit with this true is refused by delete unless force is sent. e.g. false */ unpushed:boolean;/** The ref holding the unit's work in progress, or null when none was recorded. e.g. null */ wipRef:string|null;/** The branch's head on the remote as of the last fetch: the value units push wants as expectedHead. e.g. "4f2a9c1d8e7b6a5c4d3e2f1a0b9c8d7e6f5a4b3c" */ remoteHead?:string;/** RFC 3339 UTC time these facts were observed, or null before the first observation. e.g. "2026-11-11T10:04:00Z" */ observedAt:string|null};/** Whether the unit started from a prebuild that is no longer the current one, so it should be opened again to pick up the latest; false for template units. e.g. false */ stale:boolean;/** RFC 3339 UTC time after which a stopped unit is destroyed, or null while it is running or has no retention. e.g. "2026-11-18T10:05:00Z" */ retainUntil:string|null;/** RFC 3339 UTC time the unit was last seen doing something, used to decide idleness, or null before any activity was observed. e.g. "2026-11-11T10:05:00Z" */ lastActiveTime:string|null;/** The unit's most recent transition records, present only when the retrieve asked for expand=transitions. */ transitions?:Array<{/** Position in the unit's record, starting at 1 and rising by one; read the records in this order. e.g. 1 */ seq:number;/** The unit this record belongs to. e.g. "wsu_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ unit:string;/** The verb this record is about. e.g. "create" */ transition:"create"|"start"|"stop"|"delete"|"fetch"|"push"|"wip"|"observe"|"exec";/** What moved the unit: a caller, or something the platform noticed. e.g. "user" */ reason:"user"|"agent"|"idle"|"change_merged"|"change_abandoned"|"retention"|"lost"|"system";/** Who asked, written as human:<user id>, agent:<agent id> or system, so the record reads the way it did when it was written. e.g. "human:usr_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ actor:string;/** The unit spec version this verb was applied to, matching the specVersion on the unit at that time. e.g. 1 */ specVersion:number;/** RFC 3339 UTC time the verb was accepted. e.g. "2026-11-11T10:00:00Z" */ startedAt:string;/** RFC 3339 UTC time the verb finished, or null while it is still pending. e.g. "2026-11-11T10:00:20Z" */ finishedAt:string|null;/** How the verb ended: pending while it is in flight, then succeeded or failed. e.g. "succeeded" */ outcome:"pending"|"succeeded"|"failed";/** Why the verb failed, or null when it did not. */ error:null|{/** The refusal's code, the sandbox's own when it came from there; treat it as text to show, not as a platform error code to branch on. e.g. "instance_creation_failed" */ code:string;/** The refusal's message, the sandbox's own words when it came from there. e.g. "no instance available in the requested region" */ message:string}}>}>;参数
| 名称 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
| project | path | string | 是 | Identifies the project whose data you are reading, from the project list or create answer. |
请求体
| 必填 | 内容类型 | 说明 |
|---|---|---|
| 是 | application/json |
响应
| 状态码 | 内容类型 | 说明 |
|---|---|---|
| 200 | application/json | The unit, already in phase provisioning, before the sandbox has placed its machine. |
| 400 | application/json | INVALID_ARGUMENT means the change is abandoned, so no unit may be opened for it, or a submitted field is malformed; correct the named input and send it again. Nothing was created. |
| 401 | application/json | The API key is missing or invalid; send a valid Praxis API key in the Authorization header before retrying. |
| 403 | application/json | The credential carries no organization, or that organization cannot reach this project; use a key belonging to the project’s organization. No cross-organization read is possible. |
| 404 | application/json | PROJECT_NOT_FOUND means no project with that id is visible to this organization. CHANGE_NOT_FOUND means the project exists but has no change with that id; the id is the change’s branch name, so send it exactly as the change list or create answer gives it. Nothing was created. |
| 409 | application/json | UNIT_EXISTS_FOR_CHANGE means this change already has a unit in the project; a change has at most one live unit, so read that unit instead of opening another, or delete it first. Nothing was created. |
| 500 | application/json | INTERNAL means the service could not complete the request; retry once, and if it repeats report the request id. A read is safe to repeat; a write that failed this way should be re-read before it is sent again. |