{"record":{"id":"f8ecdde01de24cc4","repo":"ZhuLinsen/daily_stock_analysis","slug":"cancelled","errorCode":"cancelled","errorMessage":"App Server request was cancelled","messagePattern":"App Server request was cancelled","errorType":"error_code","errorClass":"CodexAppServerError","httpStatus":null,"severity":"info","filePath":"src/agent/codex_app_server_transport.py","lineNumber":352,"sourceCode":"            self._pending[request_id] = response_queue\n        try:\n            self._write_message(\n                {\"id\": request_id, \"method\": method, \"params\": params},\n                deadline=deadline,\n                respect_cancellation=respect_cancellation,\n            )\n        except CodexAppServerError as exc:\n            with self._state_lock:\n                self._pending.pop(request_id, None)\n            if exc.code in {\"cancelled\", \"timeout\"}:\n                self._terminate_process()\n            if exc.code == \"timeout\":\n                raise CodexAppServerError(\n                    \"timeout\",\n                    f\"App Server request timed out: {method}\",\n                ) from exc\n            if exc.code == \"cancelled\":\n                raise CodexAppServerError(\n                    \"cancelled\",\n                    \"App Server request was cancelled\",\n                ) from exc\n            raise\n        while True:\n            self._raise_if_fatal()\n            if (\n                respect_cancellation\n                and self.cancel_event is not None\n                and self.cancel_event.is_set()\n            ):\n                with self._state_lock:\n                    self._pending.pop(request_id, None)\n                self._terminate_process()\n                raise CodexAppServerError(\"cancelled\", \"App Server request was cancelled\")\n            remaining = deadline - time.monotonic()\n            if remaining <= 0:\n                with self._state_lock:","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/src/agent/codex_app_server_transport.py#L334-L370","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nresult = client.request(\"history/inject\", params)  # may raise 'cancelled'\n\n# after\nif cancel_event is not None and cancel_event.is_set():\n    return CancelledResult()\ntry:\n    result = client.request(\"history/inject\", params)\nexcept CodexAppServerError as exc:\n    if exc.code == \"cancelled\":\n        return CancelledResult()\n    raise","handlingStrategy":"try-catch","validationCode":"if cancel_event is not None and cancel_event.is_set():\n    return CancelledResult()  # skip the RPC entirely","typeGuard":null,"tryCatchPattern":"try:\n    client.request(method, params)\nexcept CodexAppServerError as exc:\n    if exc.code == \"cancelled\":\n        return CancelledResult()\n    raise","preventionTips":["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"],"tags":["codex","cancellation","jsonrpc"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}