Open or resume the session for a workspace
POST/sessions/open
Resolves a workspace directory to its session and returns it, creating the session the first time the directory is opened. This is the only REST operation that creates a workspace session, so a controller starts with none and a client must name the workspace it wants. POST /sessions/system creates the system session. It takes no X-Session-ID header; use the returned session.id as X-Session-ID on later REST calls and as metadata.sessionId on the WebSocket. The response also carries it in the X-Session-ID response header.
The path is resolved through its symbolic links, so opening the same directory again by any of its names resumes the same session. All entry points targeting that directory use its session.
Each workspace session has one agent space.
- For a workspace with no session yet,
agentSpacepicks the agent space. Leaving it out gives the deployment default (defaultinGET /agent-spaces). - For a workspace with a session, leaving
agentSpaceout or naming its current space reuses the session. Naming a different one returns 409AGENT_SPACE_CONFLICT, whose message names the workspace's current agent space. UsePOST /session/reconfigureto move the workspace on purpose.
Errors, none of which creates a session:
- 400
VALIDATION_FAILED: the body is missing or malformed,workspaceis empty, or the path is not a directory. - 403
AGENT_SPACE_NOT_ALLOWED:agentSpacenames an agent space the deployment does not offer. This is checked first, even when the workspace already has a session. - 403
WORKSPACE_NOT_ALLOWED: the path is outside every configured workspace root (before or after resolving symbolic links), or the workspace is, contains, or sits inside the controller's state directory, or is or contains its configuration directory. The message never names a root. - 404
WORKSPACE_NOT_FOUND: the path is beneath a configured root but the directory does not exist. - 409
AGENT_SPACE_CONFLICT: see above.
Request
Responses
- 200
- 400
- 401
- 403
- 404
- 406
- 409
- 500
The session, and whether this call created it.
Response Headers
The session this response belongs to. For session-scoped requests it echoes the X-Session-ID request header; for POST /sessions/open and POST /sessions/system it is the session that was opened or created.
The request's correlation ID. When the request carried an X-Request-ID header holding a UUID, Peen echoes it; otherwise Peen generates a new UUID. The controller log records the same value for this request.
The request is invalid. code is VALIDATION_FAILED for a bad parameter, body field, page bound, base64 value or file size, or a body that is not one JSON value or exceeds the body limit, and INVALID_SESSION_ID for a malformed X-Session-ID header.
PEEN_API_TOKEN is set and the request's bearer token is missing or wrong. code is UNAUTHORIZED. A deployment with no token never returns this.
The deployment does not allow what the request names. code is WORKSPACE_NOT_ALLOWED for a workspace outside every workspace root, a workspace file path that is not a clean relative path inside the workspace, or a file operation on the system session; AGENT_SPACE_NOT_ALLOWED for an agent space the deployment does not offer or a move of the system session; and SYSTEM_AGENT_OFF for a system session while PEEN_SYSTEM_AGENT is off.
The session, or the record the request names inside it, does not exist. code is SESSION_NOT_FOUND when no session has the X-Session-ID ID, on every operation. It is NOT_FOUND when the session exists but the record the request names inside it does not, and the message names what is missing, such as job not found. It is WORKSPACE_NOT_FOUND when an opened workspace directory no longer exists.
The request's Accept header allows neither application/json nor */*, and every response is JSON. code is BAD_REQUEST and message is unsupported response representation. Omit Accept or send application/json.
The request conflicts with the current state. code is SESSION_BUSY when the session has an active turn, AGENT_SPACE_CONFLICT when the request names an agent space other than the one the workspace's session runs in (the message names the current one), and CONFLICT when a workspace directory to delete is not empty or a reconfiguration names the agent space the workspace already runs in.
An unexpected server failure. code is INTERNAL_SERVER_ERROR and message is internal server error. The controller log has the details under the response's X-Request-ID.