ZhuLinsen/daily_stock_analysis · info · CodexAppServerError
cancelled
cancelled
Error message
App Server request was cancelled
What it means
Raised while writing a request frame to the app-server's stdin when the shared cancel_event is set (the write path respects cancellation). The pending request is removed and the process is terminated, then the error is re-raised with code 'cancelled'. This is the intentional cooperative-cancellation path for outbound writes.
Source
Thrown at src/agent/codex_app_server_transport.py:352
self._pending[request_id] = response_queue
try:
self._write_message(
{"id": request_id, "method": method, "params": params},
deadline=deadline,
respect_cancellation=respect_cancellation,
)
except CodexAppServerError as exc:
with self._state_lock:
self._pending.pop(request_id, None)
if exc.code in {"cancelled", "timeout"}:
self._terminate_process()
if exc.code == "timeout":
raise CodexAppServerError(
"timeout",
f"App Server request timed out: {method}",
) from exc
if exc.code == "cancelled":
raise CodexAppServerError(
"cancelled",
"App Server request was cancelled",
) from exc
raise
while True:
self._raise_if_fatal()
if (
respect_cancellation
and self.cancel_event is not None
and self.cancel_event.is_set()
):
with self._state_lock:
self._pending.pop(request_id, None)
self._terminate_process()
raise CodexAppServerError("cancelled", "App Server request was cancelled")
remaining = deadline - time.monotonic()
if remaining <= 0:
with self._state_lock:View on GitHub (pinned to 5159bd72e8)
Solutions
- Treat this as a normal cancellation outcome: catch CodexAppServerError with code=='cancelled' and return a clean 'cancelled' result to the caller instead of an error
- Avoid starting new RPCs after initiating cancellation; guard with 'if cancel_event.is_set(): return' before each request
- If cancellation was unexpected, trace who set cancel_event (request abort handler, deadline watchdog) and fix that trigger
- Do not reuse the transport afterwards; it is terminated and a new session must be created
Example fix
# before
result = client.request("history/inject", params) # may raise 'cancelled'
# after
if cancel_event is not None and cancel_event.is_set():
return CancelledResult()
try:
result = client.request("history/inject", params)
except CodexAppServerError as exc:
if exc.code == "cancelled":
return CancelledResult()
raise Defensive patterns
Strategy: try-catch
Validate before calling
if cancel_event is not None and cancel_event.is_set():
return CancelledResult() # skip the RPC entirely Try / catch
try:
client.request(method, params)
except CodexAppServerError as exc:
if exc.code == "cancelled":
return CancelledResult()
raise Prevention
- Check cancel_event before initiating any new RPC
- Map 'cancelled' to a first-class cancelled outcome in your API, not an error
- Give the cancel_event a single owner to avoid accidental sets
When it happens
Trigger: The user or orchestrator sets cancel_event (e.g. HTTP request aborted, user pressed stop) at the exact moment a new RPC frame is being written; a watchdog fires cancellation because the overall deadline is about to expire; _write_message with respect_cancellation=True is in progress when cancel happens.
Common situations: User cancels an interactive analysis in the Web UI mid-turn; an upstream timeout triggers the cancellation policy; tests race a cancel_event against an in-flight request.
Related errors
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/f8ecdde01de24cc4.
Report an issue: GitHub.