All Agent Engineering

Add human approval to a Codex App Server client

A client flow that matches server approval requests, returns decisions, and records decline and cancel separately.

AINavWritten / Updated
On this page

At a glance

When a custom client connects to Codex app-server, command execution, file changes and extra permissions may need human approval. The server sends a JSON-RPC request with an id, and the client must find the thread, turn and item it belongs to, give a decision and confirm the server handled it. This guide turns that into a checkable client flow, focused on request correlation, decision mapping and keeping decline and cancel apart in the record; permission requests have a different response shape from command and file approvals and are covered separately, with pinned official types supplying the response fields. Every observation below is a hypothetical expectation and was not run against a real server.

Runtime and applicability

Article type
Engineering practice
Verified
Applies to
  • Codex Add human approval to a Codex App Server client

Execution locations and responsibilities

  • Codex host and calling client Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Engineering workflow order
Engineering workflow order1. Handshake and keep a read loop → 2. Build a pending-approval table → 3. Render the prompt by request type → 4. Return the decision and fix a decline/cancel convention → 5. Verify resolved state and the final record → 6. Handle overload, interruption and shutdown. Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.1. Handshake and keep a read loop2. Build a pending-approval table3. Render the prompt by request type4. Return the decision and fix a decline/cancelconvention5. Verify resolved state and the final record6. Handle overload, interruption and shutdown

Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.

When to use

  • Each connection sends initialize and then initialized before any other request. Approval requests carry threadId and turnId, which the client uses to keep UI state scoped to the active conversation.

When not to use

  • This guide covers command, file and permission approvals. tool/requestUserInput and MCP elicitation requests have different response shapes and need their own design.
  • thread/shellCommand runs outside the sandbox with full access and does not inherit the thread sandbox policy; the docs say to expose it only for explicit user-initiated commands, so it does not belong in an automatic approval path.
  • additionalPermissions is experimental and appears only when experimentalApi is enabled in initialize; without it, do not design UI for the field.
  • optOutNotificationMethods suppresses notifications but not requests; still, muting notifications such as item/started removes correlation data, so confirm the pending table can still be built.
  • This client workflow handles ordinary commandExecution approval, fileChange and permission requests. The humanCommand kind is outside this implementation: detect it and stop this workflow for a dedicated UI. It requires requiredHumanApproval, does not itself start a commandExecution item and permits only accept/decline/cancel.

Prerequisites and input

  • The ability to generate a schema matching your Codex version (the docs say the output of codex app-server generate-json-schema --out matches the running version exactly); field details follow that schema, while this guide relies only on the documentation text.
  • A chosen transport. stdio is the default; WebSocket is marked experimental and unsupported in the docs, and a non-local connection needs authentication first.
  • Knowledge of the thread's approvalPolicy and sandbox settings: the docs say only that approvals depend on the user's Codex settings, so you must arrange for some action to trigger an approval before there is anything to check.

Engineering checks

Connection and scope — Each connection sends initialize and then initialized before any other request. Approval requests carry threadId and turnId, which the client uses to keep UI state scoped to the active conversation.

Request correlation and display — Earlier-item correlation applies only to ordinary command and file approvals. Check command kind first and route humanCommand outside this workflow. Ordinary command/file itemId matches an earlier item/started; render networkApprovalContext as host/protocol information. Permission requests separately record environmentId and cwd.

Decision and outcome — Command and file approval payloads have a decision field whose value is a string or a supported amendment object. Wrap the payload in a JSON-RPC response with the request id and result. Permission payloads instead use permissions and scope. A resolved notification means a pending request was answered or cleared; it alone does not establish tool success. This guide also reads pinned official protocol types; match them against the schema generated by your running version.

1. Handshake and keep a read loop

Where: the client's transport reader. Input: the chosen transport connection. Action: send initialize, then initialized, and keep reading server messages; treat messages with both method and id as server-initiated requests and messages with only method as notifications. Done when: initialization is answered and later requests no longer return Not initialized. Stop when: the handshake fails or Already initialized appears, which means connection state handling is wrong; fix it before starting any task.

2. Build a pending-approval table

Where: the pending approval table. Input: server requests and existing items. Identify approval kind first. Record humanCommand and stop automatic processing for a dedicated workflow, without requiring an earlier commandExecution. Ordinary command/file requests use request id to retain threadId, turnId and itemId and correlate item/started; permission requests retain environmentId and cwd. Completion: correlation matches each actual kind and unsupported branches have an owner. Stop automatic approval for missing ordinary-item correlation or unknown kind.

3. Render the prompt by request type

Where: the approval UI. Input: one record from the pending table. Action: for command approvals show command, cwd and reason; when networkApprovalContext is present switch to a network prompt showing the target host and protocol; for file approvals take changes from the fileChange item and the optional reason and grantRoot from the approval request; for permission requests list each requested network or filesystem permission with cwd and the optional reason, so the user can choose item by item. When availableDecisions is present offer only those options. Done when: each request type has its own prompt and no network approval appears as an ordinary command. Stop when: an unrecognized server request method arrives; do not guess its shape, record it and hand it to a person.

4. Return the decision and fix a decline/cancel convention

Where: the response sender. Input: the original request id, request type and human decision. First validate the payload against a schema generated by the running version. Command and file responses put the choice in result.decision, for example {"id":8,"result":{"decision":"decline"}}; 8 is illustrative and must be replaced with the actual request id. Base choices are accept, acceptForSession, decline and cancel. Command approval also supports an acceptWithExecpolicyAmendment object whose execpolicy_amendment holds the reviewed rule sequence; do not replace an object by its name as a string. The pinned command type also defines a network-policy amendment branch: map buttons and payloads through the request availableDecisions and current schema instead of assuming a permanent closed enum. For commands, the pinned definition says decline denies the action and continues the turn, while cancel also interrupts the turn; these are not merely dialog-close labels. Permission responses return only the granted subset. Both network and fileSystem are optional in the pinned grant type, so granting none can use {"id":8,"result":{"permissions":{},"scope":"turn"}}, checked again against the local schema. A session grant persists into later turns in that session; default to turn scope. An empty new grant does not mean revoking previous access. Done when the serialized response matches the version schema, echoes the id and matches the choice. Stop on a schema mismatch; after sending, retain pending confirmation without answering again simply because resolved has not arrived.

5. Verify resolved state and the final record

Where: the event handler and the audit record. Input: serverRequest/resolved and item/completed. Action: for each request record the request id, the decision sent (for permission requests, the subset and scope actually granted), whether resolved arrived and the final status of the related item. The docs do not state which final status follows cancel, nor which item reports completion after a permission request, so record those values as observed and do not presume them. Done when: every record has both a decision column and an observed-result column. Stop when: a turn ends with turn/completed while some record is still unresolved; mark it abnormal and stop sending new tasks to that thread until someone inspects it.

6. Handle overload, interruption and shutdown

Where: the request sender. Input: errors from the server or your own turn/interrupt. Action: in WebSocket mode, on error code -32001 (Server overloaded; retry later.) retry with exponentially increasing delay and jitter; on -32600 with data.reason set to serverShuttingDown, stop submitting new work. To interrupt, call turn/interrupt; the turn should end with status interrupted. Done when: a retried request is accepted, or pending approval records were saved at shutdown. Stop when: the server begins shutting down; stop submitting instead of retrying in a loop.

Task example

Fictional walkthrough: a task in demo-notes needs to run existing checks. Save the actual command item and approval request id, then serialize the response using the runtime schema. The accept case sends result.decision=accept; expect resolved, then record completed or failed for the item, since approval is not a passing check. The decline case denies execution and continues the turn. The cancel case interrupts the turn according to the pinned command definition; record the actual item status separately. An extra-permission case grants only one requested scope; a grant-none case uses the version-supported empty permissions with turn scope. This is a response-design walkthrough, with no real server execution or observed results.

Completion checks

  • Distinguish kind first; humanCommand does not inherit ordinary correlation or decision enums. Ordinary command/file requests retain id/threadId/turnId/itemId and correlate earlier item/started.
  • Network approvals and ordinary command approvals look different, and the former shows host and protocol; file approvals take changes from the item and reason and grantRoot from the request.
  • The audit record treats decline and cancel as two separate decisions, each with its own observed final status; permission requests record the granted subset and scope.
  • No decision was resent and no item was treated as finished before serverRequest/resolved arrived.

Verification scope

This guide reads official app-server documentation and pinned official protocol types. No installation, sign-in, server call, approval UI or real output was verified. Pinned code may differ from your runtime: generate its schema and compare. Example ids and expected states are not real receipts. Permission and decision payloads describe this fixed source snapshot, without promising compatibility with other versions.

Sources

All links are official pages; verification dates are listed per source, and links point to the version checked.

  1. Codex · Codex documentation: codex-app-server
  2. Codex · Codex documentation: codex-approval-types
    c0cc9fc
  3. Codex · Codex documentation: codex-item-types
    c0cc9fc

Found an error? Tell us →