Add dark theme, richer Markdown and readable plugin results. Improve Android input evidence, response integrity and diagnostics. Unify lifecycle, guidance receipts and evidence sources across clients. Keep direct action dispatch without an added AI quota approval layer. Align version metadata at 2.2.0 and bundle Helper 1.2.2. Validation: 3063 backend tests before the version bump; 44 after. Frontend: 317 tests and production build passed.
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
"""Allowlisted cancellation causes carried by asyncio's cancellation message.
|
|
|
|
Only the owner of an interruption assigns a cause. A bare CancelledError, an
|
|
HTTP status or arbitrary message cannot prove who cancelled the operation.
|
|
"""
|
|
|
|
import asyncio
|
|
from enum import StrEnum
|
|
|
|
|
|
class CancellationReason(StrEnum):
|
|
USER_STOP = "user_stop"
|
|
GUIDANCE_REPLACED = "guidance_replaced"
|
|
TASK_PAUSED = "task_paused"
|
|
TASK_REPLACED = "task_replaced"
|
|
SUPERSEDED = "superseded"
|
|
OUTER_TIMEOUT = "outer_timeout"
|
|
UNKNOWN = "unknown"
|
|
|
|
|
|
def cancellation_reason(error: BaseException | None) -> CancellationReason:
|
|
if isinstance(error, KeyboardInterrupt):
|
|
return CancellationReason.USER_STOP
|
|
if isinstance(error, asyncio.CancelledError) and error.args:
|
|
reason = error.args[0]
|
|
if isinstance(reason, CancellationReason):
|
|
return reason
|
|
return CancellationReason.UNKNOWN
|
|
|
|
|
|
def reason_from_code(value: object) -> CancellationReason:
|
|
"""Decode only our marker field, never a free-form user instruction."""
|
|
if isinstance(value, str):
|
|
try:
|
|
return CancellationReason(value)
|
|
except ValueError:
|
|
pass
|
|
return CancellationReason.UNKNOWN
|