Skip to content

[Bug] Windows hooks corrupt UTF-8 prompts and crash validation error handling #1305

Description

@Alanxtl

Bug description

On Windows, the Codex/Claude Code prompt hook corrupts non-ASCII prompts before sending them to the PowerContext Server. Chinese prompts arrive as mojibake and contain lone surrogate characters such as \\udcaa.

The Server then rejects the request with a Pydantic string_unicode validation error. While constructing the 422 response, the validation handler includes the raw input value in error.errors(); Starlette's JSONResponse cannot UTF-8 encode the lone surrogate and raises a second exception.

fastapi.exceptions.RequestValidationError:
  type: string_unicode
  loc: ('body', 'query')
  msg: Input should be a valid string, unable to parse raw data as a unicode string

UnicodeEncodeError: 'utf-8' codec can't encode character '\\udcaa':
surrogates not allowed
detailed log

2026-08-21T15:10:03+0800 INFO uvicorn.error Started server process [11524]
2026-08-21T15:10:03+0800 INFO uvicorn.error Waiting for application startup.
2026-08-21T15:10:03+0800 INFO powercontext.server.factory PowerContext Server is starting
2026-08-21T15:10:03+0800 INFO powercontext.server.factory PowerContext Server is ready
2026-08-21T15:10:03+0800 INFO uvicorn.error Application startup complete.
2026-08-21T15:10:03+0800 INFO uvicorn.error Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
2026-08-21T15:11:49+0800 ERROR uvicorn.error Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 137, in app
response = await f(request)
^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 740, in app
raise validation_error
fastapi.exceptions.RequestValidationError: 1 validation error:
{'type': 'string_unicode', 'loc': ('body', 'query'), 'msg': 'Input should be a valid string, unable to parse raw data as a unicode string', 'input': '浣跨敤powercontext鐪嬬幇鍦ㄦ湁鍝\udcaa浜涜\udcae板繂銆\udc91'}

File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 1006, in prepare_context
POST /v1/context/prepare

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 416, in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
self.scope, self.receive, self.send
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 63, in call
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\applications.py", line 1163, in call
await super().call(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\applications.py", line 90, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\errors.py", line 186, in call
raise exc
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\errors.py", line 164, in call
await self.app(scope, receive, _send)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\tracing.py", line 279, in call
await self.app(scope, receive, send_with_status)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\access.py", line 64, in call
await self.app(scope, receive, send_with_access_log)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\metrics.py", line 150, in call
await self.app(scope, receive, send_with_metrics)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 193, in call
response = await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 597, in attach_request_id
response = await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 168, in call_next
raise app_exc from app_exc.cause or app_exc.context
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 144, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\exceptions.py", line 63, in call
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 53, in wrapped_app
raise exc
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in call
await self.app(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\routing.py", line 660, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 2685, in app
await route.handle(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 1267, in handle
await super().handle(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\routing.py", line 276, in handle
await self.app(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 151, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 59, in wrapped_app
response = await handler(conn, exc) # type: ignore[arg-type]
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 606, in invalid_request
return _error_response(
status.HTTP_422_UNPROCESSABLE_CONTENT,
...<2 lines>...
details={"errors": error.errors()},
)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 1465, in _error_response
return JSONResponse(status_code=response_status, content=error.model_dump(mode="json"))
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 192, in init
super().init(content, status_code, headers, media_type, background)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 45, in init
self.body = self.render(content)
~~~~~~~~~~~^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 201, in render
).encode("utf-8")
~~~~~~^^^^^^^^^
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcaa' in position 271: surrogates not allowed
2026-08-21T15:13:41+0800 INFO powercontext.server.access PowerContext transport request completed request_id=5dc6fdbe65f495fd trace_id=cdee98acf2ff53e73e09d6643b969871 span_id=5dc6fdbe65f495fd
2026-08-21T15:14:04+0800 INFO powercontext.server.access PowerContext transport request completed request_id=63ec0a98c150618d trace_id=c8bc26a115e9cbc217f1f640a0004dae span_id=63ec0a98c150618d
2026-08-21T15:15:05+0800 INFO powercontext.server.access PowerContext transport request completed request_id=cb3c4c9910c4fab0 trace_id=da9e93313fd16211259d47135de5f87b span_id=cb3c4c9910c4fab0
2026-08-21T15:15:05+0800 INFO powercontext.server.access PowerContext transport request completed request_id=ba3fe8573c23e9c4 trace_id=01a30b80190af0a41b55a41be143d1e1 span_id=ba3fe8573c23e9c4
2026-08-21T15:15:08+0800 ERROR uvicorn.error Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 137, in app
response = await f(request)
^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 740, in app
raise validation_error
fastapi.exceptions.RequestValidationError: 1 validation error:
{'type': 'string_unicode', 'loc': ('body', 'query'), 'msg': 'Input should be a valid string, unable to parse raw data as a unicode string', 'input': '鏌ョ湅褰撳墠鎵\udc80鏈夎\udcae板繂\n'}

File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 1006, in prepare_context
POST /v1/context/prepare

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 416, in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
self.scope, self.receive, self.send
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 63, in call
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\applications.py", line 1163, in call
await super().call(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\applications.py", line 90, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\errors.py", line 186, in call
raise exc
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\errors.py", line 164, in call
await self.app(scope, receive, _send)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\tracing.py", line 279, in call
await self.app(scope, receive, send_with_status)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\access.py", line 64, in call
await self.app(scope, receive, send_with_access_log)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\metrics.py", line 150, in call
await self.app(scope, receive, send_with_metrics)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 193, in call
response = await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 597, in attach_request_id
response = await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 168, in call_next
raise app_exc from app_exc.cause or app_exc.context
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 144, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\exceptions.py", line 63, in call
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 53, in wrapped_app
raise exc
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in call
await self.app(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\routing.py", line 660, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 2685, in app
await route.handle(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 1267, in handle
await super().handle(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\routing.py", line 276, in handle
await self.app(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 151, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 59, in wrapped_app
response = await handler(conn, exc) # type: ignore[arg-type]
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 606, in invalid_request
return _error_response(
status.HTTP_422_UNPROCESSABLE_CONTENT,
...<2 lines>...
details={"errors": error.errors()},
)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 1465, in _error_response
return JSONResponse(status_code=response_status, content=error.model_dump(mode="json"))
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 192, in init
super().init(content, status_code, headers, media_type, background)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 45, in init
self.body = self.render(content)
~~~~~~~~~~~^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 201, in render
).encode("utf-8")
~~~~~~^^^^^^^^^
UnicodeEncodeError: 'utf-8' codec can't encode character '\udc80' in position 256: surrogates not allowed
2026-08-21T15:16:17+0800 INFO powercontext.server.access PowerContext transport request completed request_id=4d20a6597f1957a3 trace_id=ce89741dbae4cd832596b55889eb0f40 span_id=4d20a6597f1957a3
2026-08-21T15:16:17+0800 INFO powercontext.server.access PowerContext transport request completed request_id=98a7e391c2e7838c trace_id=2dbd9703f08a9154d3fe2b9d005258e0 span_id=98a7e391c2e7838c
2026-08-21T15:16:17+0800 ERROR uvicorn.error Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 137, in app
response = await f(request)
^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 740, in app
raise validation_error
fastapi.exceptions.RequestValidationError: 1 validation error:
{'type': 'string_unicode', 'loc': ('body', 'query'), 'msg': 'Input should be a valid string, unable to parse raw data as a unicode string', 'input': '@PowerContext 浣犳湁鍝\udcaa浜涜\udcae板繂\n'}

File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 1006, in prepare_context
POST /v1/context/prepare

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 416, in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
self.scope, self.receive, self.send
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 63, in call
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\applications.py", line 1163, in call
await super().call(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\applications.py", line 90, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\errors.py", line 186, in call
raise exc
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\errors.py", line 164, in call
await self.app(scope, receive, _send)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\tracing.py", line 279, in call
await self.app(scope, receive, send_with_status)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\access.py", line 64, in call
await self.app(scope, receive, send_with_access_log)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\metrics.py", line 150, in call
await self.app(scope, receive, send_with_metrics)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 193, in call
response = await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 597, in attach_request_id
response = await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 168, in call_next
raise app_exc from app_exc.cause or app_exc.context
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 144, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\exceptions.py", line 63, in call
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 53, in wrapped_app
raise exc
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in call
await self.app(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\routing.py", line 660, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 2685, in app
await route.handle(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 1267, in handle
await super().handle(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\routing.py", line 276, in handle
await self.app(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 151, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 59, in wrapped_app
response = await handler(conn, exc) # type: ignore[arg-type]
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 606, in invalid_request
return _error_response(
status.HTTP_422_UNPROCESSABLE_CONTENT,
...<2 lines>...
details={"errors": error.errors()},
)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 1465, in _error_response
return JSONResponse(status_code=response_status, content=error.model_dump(mode="json"))
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 192, in init
super().init(content, status_code, headers, media_type, background)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 45, in init
self.body = self.render(content)
~~~~~~~~~~~^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 201, in render
).encode("utf-8")
~~~~~~^^^^^^^^^
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcaa' in position 305: surrogates not allowed
2026-08-21T15:16:52+0800 INFO powercontext.server.access PowerContext transport request completed request_id=14b576a2e2022c16 trace_id=3dd5029492f8bf814422b968b65b2e02 span_id=14b576a2e2022c16
2026-08-21T15:16:53+0800 INFO powercontext.server.access PowerContext transport request completed request_id=530cd90e55aa8906 trace_id=71c1426fdd095544592377ad0759c6a4 span_id=530cd90e55aa8906
2026-08-21T15:17:30+0800 INFO powercontext.server.access PowerContext transport request completed request_id=fcd2d868e704e5f6 trace_id=ecaafdedfc49d47620c831fe895f7612 span_id=fcd2d868e704e5f6
2026-08-21T15:17:38+0800 INFO powercontext.server.access PowerContext transport request completed request_id=c6e65f89495c9664 trace_id=468ac7d867b1e4ebc5f18388a45c6546 span_id=c6e65f89495c9664
2026-08-21T15:18:04+0800 INFO powercontext.server.access PowerContext transport request completed request_id=16e8e56ab51a1eae trace_id=743ce4cedcaf2b0af7fd5eb20d24ea87 span_id=16e8e56ab51a1eae
2026-08-21T15:18:04+0800 INFO powercontext.server.access PowerContext transport request completed request_id=5ed085e47491e1b3 trace_id=c58e9f22edbf5a31c5ff197daf11ea70 span_id=5ed085e47491e1b3
2026-08-21T15:18:15+0800 INFO powercontext.server.access PowerContext transport request completed request_id=dea2ab5de8c546fd trace_id=b497efd3c19cb90fbb78247f2d9f0aaf span_id=dea2ab5de8c546fd
2026-08-21T15:18:32+0800 INFO powercontext.server.access PowerContext transport request completed request_id=e4bd263ce54d6e02 trace_id=bfb08e20ed9a48a4516285255867d0bc span_id=e4bd263ce54d6e02
2026-08-21T15:18:32+0800 INFO powercontext.server.access PowerContext transport request completed request_id=922dc05b605093f2 trace_id=00602cad1a01b152631724c89d8965a3 span_id=922dc05b605093f2
2026-08-21T15:18:38+0800 ERROR uvicorn.error Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 137, in app
response = await f(request)
^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 740, in app
raise validation_error
fastapi.exceptions.RequestValidationError: 1 validation error:
{'type': 'string_unicode', 'loc': ('body', 'query'), 'msg': 'Input should be a valid string, unable to parse raw data as a unicode string', 'input': '浣犺\udcae颁竴涓\udc8b 鎴戜娇鐢ㄧ殑python绠$悊鍣ㄦ槸uv\n'}

File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 1006, in prepare_context
POST /v1/context/prepare

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 416, in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
self.scope, self.receive, self.send
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 63, in call
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\applications.py", line 1163, in call
await super().call(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\applications.py", line 90, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\errors.py", line 186, in call
raise exc
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\errors.py", line 164, in call
await self.app(scope, receive, _send)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\tracing.py", line 279, in call
await self.app(scope, receive, send_with_status)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\access.py", line 64, in call
await self.app(scope, receive, send_with_access_log)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\metrics.py", line 150, in call
await self.app(scope, receive, send_with_metrics)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 193, in call
response = await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 597, in attach_request_id
response = await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 168, in call_next
raise app_exc from app_exc.cause or app_exc.context
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 144, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\exceptions.py", line 63, in call
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 53, in wrapped_app
raise exc
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in call
await self.app(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\routing.py", line 660, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 2685, in app
await route.handle(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 1267, in handle
await super().handle(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\routing.py", line 276, in handle
await self.app(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 151, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 59, in wrapped_app
response = await handler(conn, exc) # type: ignore[arg-type]
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 606, in invalid_request
return _error_response(
status.HTTP_422_UNPROCESSABLE_CONTENT,
...<2 lines>...
details={"errors": error.errors()},
)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 1465, in _error_response
return JSONResponse(status_code=response_status, content=error.model_dump(mode="json"))
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 192, in init
super().init(content, status_code, headers, media_type, background)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 45, in init
self.body = self.render(content)
~~~~~~~~~~~^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 201, in render
).encode("utf-8")
~~~~~~^^^^^^^^^
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcae' in position 251: surrogates not allowed
2026-08-21T15:18:45+0800 INFO powercontext.server.access PowerContext transport request completed request_id=c240b20ba064ee92 trace_id=21f70d01e755a48309709b1d56c5e55e span_id=c240b20ba064ee92
2026-08-21T15:18:45+0800 INFO powercontext.server.access PowerContext transport request completed request_id=f80e356c8aa33025 trace_id=c330c401834ed2d3a9578e40bec91135 span_id=f80e356c8aa33025
2026-08-21T15:18:46+0800 INFO powercontext.server.access PowerContext transport request completed request_id=780fe461918cd435 trace_id=39e29f9e63c84dfcd83ecfc842d4bab1 span_id=780fe461918cd435
2026-08-21T15:19:04+0800 INFO powercontext.server.access PowerContext transport request completed request_id=3c9ddd48db1d4f33 trace_id=8b72e86dcb083b481d431766f36a6361 span_id=3c9ddd48db1d4f33
2026-08-21T15:19:04+0800 INFO powercontext.server.access PowerContext transport request completed request_id=7697a225680a40f3 trace_id=400c8366da584765c0d7eab71b0db6cb span_id=7697a225680a40f3
2026-08-21T15:19:06+0800 ERROR uvicorn.error Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 137, in app
response = await f(request)
^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 740, in app
raise validation_error
fastapi.exceptions.RequestValidationError: 1 validation error:
{'type': 'string_unicode', 'loc': ('body', 'query'), 'msg': 'Input should be a valid string, unable to parse raw data as a unicode string', 'input': '鎴戜娇鐢ㄧ殑榛樿\udcae\udca4python绠$悊鍣ㄦ槸浠\udc80涔圽n'}

File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 1006, in prepare_context
POST /v1/context/prepare

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 416, in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
self.scope, self.receive, self.send
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 63, in call
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\applications.py", line 1163, in call
await super().call(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\applications.py", line 90, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\errors.py", line 186, in call
raise exc
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\errors.py", line 164, in call
await self.app(scope, receive, _send)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\tracing.py", line 279, in call
await self.app(scope, receive, send_with_status)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\access.py", line 64, in call
await self.app(scope, receive, send_with_access_log)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\metrics.py", line 150, in call
await self.app(scope, receive, send_with_metrics)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 193, in call
response = await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 597, in attach_request_id
response = await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 168, in call_next
raise app_exc from app_exc.cause or app_exc.context
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 144, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\exceptions.py", line 63, in call
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 53, in wrapped_app
raise exc
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in call
await self.app(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\routing.py", line 660, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 2685, in app
await route.handle(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 1267, in handle
await super().handle(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\routing.py", line 276, in handle
await self.app(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 151, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 59, in wrapped_app
response = await handler(conn, exc) # type: ignore[arg-type]
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 606, in invalid_request
return _error_response(
status.HTTP_422_UNPROCESSABLE_CONTENT,
...<2 lines>...
details={"errors": error.errors()},
)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 1465, in _error_response
return JSONResponse(status_code=response_status, content=error.model_dump(mode="json"))
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 192, in init
super().init(content, status_code, headers, media_type, background)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 45, in init
self.body = self.render(content)
~~~~~~~~~~~^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 201, in render
).encode("utf-8")
~~~~~~^^^^^^^^^
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 257-258: surrogates not allowed
2026-08-21T15:19:10+0800 INFO powercontext.server.access PowerContext transport request completed request_id=bb18bc3b1ae8a133 trace_id=edfba538ec7dfc3ace7d779eb55c4776 span_id=bb18bc3b1ae8a133
2026-08-21T15:19:23+0800 INFO powercontext.server.access PowerContext transport request completed request_id=bf5cf4e0601be414 trace_id=eafcc3c2d65c26e8296cdedfc7d25bd0 span_id=bf5cf4e0601be414
2026-08-21T15:19:23+0800 INFO powercontext.server.access PowerContext transport request completed request_id=7e8b8b2d1ff838b9 trace_id=2bea4eb95225288998dcbb2e45aa9fc8 span_id=7e8b8b2d1ff838b9
2026-08-21T15:19:47+0800 ERROR uvicorn.error Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 137, in app
response = await f(request)
^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 740, in app
raise validation_error
fastapi.exceptions.RequestValidationError: 1 validation error:
{'type': 'string_unicode', 'loc': ('body', 'query'), 'msg': 'Input should be a valid string, unable to parse raw data as a unicode string', 'input': '浣犵殑鎬濊\udc80冭繃绋嬩娇鐢╬owercontext璁板繂浜嗗悧\n'}

File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 1006, in prepare_context
POST /v1/context/prepare

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 416, in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
self.scope, self.receive, self.send
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 63, in call
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\applications.py", line 1163, in call
await super().call(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\applications.py", line 90, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\errors.py", line 186, in call
raise exc
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\errors.py", line 164, in call
await self.app(scope, receive, _send)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\tracing.py", line 279, in call
await self.app(scope, receive, send_with_status)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\access.py", line 64, in call
await self.app(scope, receive, send_with_access_log)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\metrics.py", line 150, in call
await self.app(scope, receive, send_with_metrics)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 193, in call
response = await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 597, in attach_request_id
response = await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 168, in call_next
raise app_exc from app_exc.cause or app_exc.context
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 144, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\exceptions.py", line 63, in call
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 53, in wrapped_app
raise exc
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in call
await self.app(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\routing.py", line 660, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 2685, in app
await route.handle(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 1267, in handle
await super().handle(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\routing.py", line 276, in handle
await self.app(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 151, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 59, in wrapped_app
response = await handler(conn, exc) # type: ignore[arg-type]
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 606, in invalid_request
return _error_response(
status.HTTP_422_UNPROCESSABLE_CONTENT,
...<2 lines>...
details={"errors": error.errors()},
)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 1465, in _error_response
return JSONResponse(status_code=response_status, content=error.model_dump(mode="json"))
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 192, in init
super().init(content, status_code, headers, media_type, background)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 45, in init
self.body = self.render(content)
~~~~~~~~~~~^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 201, in render
).encode("utf-8")
~~~~~~^^^^^^^^^
UnicodeEncodeError: 'utf-8' codec can't encode character '\udc80' in position 254: surrogates not allowed
2026-08-21T15:19:53+0800 INFO powercontext.server.access PowerContext transport request completed request_id=59cf89b8f45fbf50 trace_id=c90268dc99c38e74105de3d7aceaff69 span_id=59cf89b8f45fbf50
2026-08-21T15:19:53+0800 INFO powercontext.server.access PowerContext transport request completed request_id=bc196514d1c7db00 trace_id=0c3b5bab0d30296bbcaa303dd1aed2a1 span_id=bc196514d1c7db00
2026-08-21T15:19:53+0800 INFO powercontext.server.access PowerContext transport request completed request_id=b3f693bea9ab6156 trace_id=0fcf2249ea2e1de359e11048887652e6 span_id=b3f693bea9ab6156
2026-08-21T15:20:09+0800 ERROR uvicorn.error Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 137, in app
response = await f(request)
^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 740, in app
raise validation_error
fastapi.exceptions.RequestValidationError: 1 validation error:
{'type': 'string_unicode', 'loc': ('body', 'query'), 'msg': 'Input should be a valid string, unable to parse raw data as a unicode string', 'input': '浣犺\udcaf诲彇 PowerContext 璁板繂 \n'}

File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 1006, in prepare_context
POST /v1/context/prepare

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 416, in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
self.scope, self.receive, self.send
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 63, in call
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\applications.py", line 1163, in call
await super().call(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\applications.py", line 90, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\errors.py", line 186, in call
raise exc
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\errors.py", line 164, in call
await self.app(scope, receive, _send)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\tracing.py", line 279, in call
await self.app(scope, receive, send_with_status)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\access.py", line 64, in call
await self.app(scope, receive, send_with_access_log)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\metrics.py", line 150, in call
await self.app(scope, receive, send_with_metrics)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 193, in call
response = await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 597, in attach_request_id
response = await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 168, in call_next
raise app_exc from app_exc.cause or app_exc.context
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\base.py", line 144, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\middleware\exceptions.py", line 63, in call
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 53, in wrapped_app
raise exc
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in call
await self.app(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\routing.py", line 660, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 2685, in app
await route.handle(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 1267, in handle
await super().handle(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\routing.py", line 276, in handle
await self.app(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\fastapi\routing.py", line 151, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette_exception_handler.py", line 59, in wrapped_app
response = await handler(conn, exc) # type: ignore[arg-type]
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 606, in invalid_request
return _error_response(
status.HTTP_422_UNPROCESSABLE_CONTENT,
...<2 lines>...
details={"errors": error.errors()},
)
File "C:\Users\m1346\Desktop\repos\powercontext\src\powercontext\server\app.py", line 1465, in _error_response
return JSONResponse(status_code=response_status, content=error.model_dump(mode="json"))
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 192, in init
super().init(content, status_code, headers, media_type, background)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 45, in init
self.body = self.render(content)
~~~~~~~~~~~^^^^^^^^^
File "C:\Users\m1346\Desktop\repos\powercontext.venv\Lib\site-packages\starlette\responses.py", line 201, in render
).encode("utf-8")
~~~~~~^^^^^^^^^
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcaf' in position 251: surrogates not allowed

Impact

  • Automatic context preparation fails for affected non-ASCII prompts.
  • The expected HTTP 422 response is replaced by an unhandled ASGI exception.
  • The hook fails open, so the normal agent turn may continue without PowerContext recall/capture.
  • The validation response may also expose the original query through the raw input field.

Likely cause

The hook reads JSON through json.load(sys.stdin) without explicitly enforcing UTF-8. On Windows, the subprocess standard input can use the system code page while Codex/Claude sends UTF-8 JSON.

Relevant code:

  • integrations/codex/plugins/powercontext/hooks/recall.py
  • integrations/claude-code/plugins/powercontext/hooks/user_prompt_submit.py
  • src/powercontext/server/app.py (RequestValidationError handler and _error_response)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions