Commit Graph

1299 Commits

Author SHA1 Message Date
Timothy Jaeryang Baek
b87c755574 refac 2026-04-24 15:29:36 +09:00
Timothy Jaeryang Baek
6ecba19447 refac 2026-04-24 15:21:52 +09:00
Timothy Jaeryang Baek
90584ab6f3 refac 2026-04-24 15:21:37 +09:00
Timothy Jaeryang Baek
4dc5c1eb4f refac 2026-04-24 15:00:47 +09:00
tcx4c70
f6bd08c852 fix(utils): Switch throttle decorator to async (#23979)
After migration to async db operations, the throttle decorator also
needs to support async. Since the decorator is only used for async funcs
now, we can just switch it to async instead of supporting sync and async
at the same time.

Signed-off-by: Adam Tao <tcx4c70@gmail.com>
2026-04-24 14:39:45 +09:00
Timothy Jaeryang Baek
116eb7fc55 refac 2026-04-21 16:05:26 +09:00
Timothy Jaeryang Baek
6cc799b1bb chore: format 2026-04-21 15:52:00 +09:00
Timothy Jaeryang Baek
a27916d1db refac 2026-04-21 14:31:04 +09:00
Timothy Jaeryang Baek
65834432a3 refac 2026-04-21 13:51:39 +09:00
Timothy Jaeryang Baek
46d73c9dcd refac 2026-04-21 13:46:39 +09:00
Timothy Jaeryang Baek
a2875f13c6 refac 2026-04-21 13:33:33 +09:00
Timothy Jaeryang Baek
e88e565ab4 refac 2026-04-21 13:18:54 +09:00
Timothy Jaeryang Baek
5127354b3e refac 2026-04-20 09:21:30 +09:00
Timothy Jaeryang Baek
f246a66810 refac 2026-04-20 09:10:48 +09:00
Timothy Jaeryang Baek
d5e69f182c refac 2026-04-20 08:53:06 +09:00
Timothy Jaeryang Baek
fd25152076 refac 2026-04-20 08:34:15 +09:00
Timothy Jaeryang Baek
e5b5a17426 refac 2026-04-19 23:38:58 +09:00
Timothy Jaeryang Baek
37eba1c5a6 chore: format 2026-04-19 22:45:54 +09:00
Timothy Jaeryang Baek
5afc258c5b refac 2026-04-19 22:37:10 +09:00
Timothy Jaeryang Baek
42694c7c0c refac 2026-04-19 22:33:32 +09:00
Timothy Jaeryang Baek
f45d0f130e refac 2026-04-19 22:22:15 +09:00
Timothy Jaeryang Baek
98627e42b4 refac 2026-04-19 22:13:47 +09:00
Timothy Jaeryang Baek
8d739e2aba feat: calendar 2026-04-19 19:15:05 +09:00
Timothy Jaeryang Baek
7cfb260b8a refac 2026-04-17 15:01:42 +09:00
Timothy Jaeryang Baek
49430de42d refac 2026-04-17 15:00:17 +09:00
Timothy Jaeryang Baek
55bfc7cbc2 refac 2026-04-17 14:35:13 +09:00
Timothy Jaeryang Baek
4113b15a60 chore: format 2026-04-17 14:28:18 +09:00
Timothy Jaeryang Baek
8acce144f9 refac 2026-04-17 14:15:36 +09:00
Timothy Jaeryang Baek
2c7acb9285 refac 2026-04-17 13:58:32 +09:00
Timothy Jaeryang Baek
50363ba66b refac 2026-04-17 13:52:11 +09:00
Timothy Jaeryang Baek
e695d854f2 refac 2026-04-17 13:10:06 +09:00
Timothy Jaeryang Baek
e709d6812f refac 2026-04-17 12:55:56 +09:00
Timothy Jaeryang Baek
3dd8255816 refac 2026-04-17 12:37:44 +09:00
Timothy Jaeryang Baek
349ea4ea9e refac 2026-04-17 12:25:43 +09:00
Timothy Jaeryang Baek
128cf41fce refac 2026-04-17 11:12:42 +09:00
Timothy Jaeryang Baek
398718d505 refac 2026-04-17 10:44:29 +09:00
Timothy Jaeryang Baek
2e52ad8ff2 refac: shared chat 2026-04-17 10:16:32 +09:00
Timothy Jaeryang Baek
70a6a24f14 refac 2026-04-15 10:37:59 -07:00
Timothy Jaeryang Baek
5944eda0ff refac 2026-04-15 10:17:40 -07:00
Timothy Jaeryang Baek
5dae600ce7 chore: format 2026-04-14 17:27:31 -05:00
Timothy Jaeryang Baek
8bd23b9145 refac 2026-04-14 16:47:43 -05:00
Timothy Jaeryang Baek
4866bec0f2 refac 2026-04-14 10:55:11 -05:00
Classic298
ee28032fb9 fix(middleware): replace BaseHTTPMiddleware HTTP middlewares with pure ASGI implementations (#23709)
* fix(middleware): replace BaseHTTPMiddleware HTTP middlewares with pure ASGI implementations

Starlette's BaseHTTPMiddleware (and the @app.middleware('http')
decorator that uses it) wraps the downstream app in an anyio task
group whose cancel scope tears down the inner task on every exit —
client disconnect, response complete, or any outer middleware bailing.
That CancelledError gets injected into whatever the inner task was
awaiting, so DB queries, embedding calls, and other long awaits get
killed mid-flight. Under aiosqlite the cleanup path then logs a
multi-page `terminate_force_close() not implemented` traceback at
ERROR for every cancelled DB call.

Open WebUI had four such middlewares stacked
(`commit_session_after_request`, `check_url`, `inspect_websocket`,
`RedirectMiddleware`) so a single cancellation would compound through
all four.

Move the four middlewares to a new `open_webui.utils.asgi_middleware`
module as plain ASGI classes (`__call__(scope, receive, send)`):

  * `CommitSessionMiddleware`   — was `commit_session_after_request`;
                                  now also rolls back if commit fails
                                  before releasing the connection.
  * `AuthTokenMiddleware`       — was `check_url`; sets request.state
                                  token + enable_api_keys + stamps
                                  X-Process-Time via a wrapped send.
  * `WebsocketUpgradeGuardMiddleware`
                                — was `inspect_websocket`; rejects
                                  /ws/socket.io HTTP requests that
                                  claim transport=websocket without a
                                  proper Upgrade/Connection header.
  * `RedirectMiddleware`        — was the BaseHTTPMiddleware subclass;
                                  same /watch + share-target rewrites.

Pure ASGI does not introduce a cancel scope around the downstream app,
so client disconnects propagate via `receive()` (the way ASGI was
designed) instead of being injected as CancelledError. Middleware
ordering is preserved.

https://claude.ai/code/session_01JSr4NZSskEUQvoJnavVXh8

* fix(middleware): CommitSessionMiddleware — rollback on downstream error, never commit failed requests

The first cut put commit() in a finally block, which meant that even
when a downstream handler raised, the middleware would still commit
whatever partial sync writes that handler had made before the
failure. That regressed the previous BaseHTTPMiddleware semantics
where commit only ran on the success path.

Restructure the failure handling:

* Downstream raised → rollback any pending sync work, release the
  connection, re-raise so the outer error middleware turns it into
  an error response. We never commit a request that did not complete.
* Downstream returned → commit. On commit failure, log loudly,
  rollback, and re-raise. ScopedSession.remove() always runs in
  finally so the connection cannot leak.

Document the inherent pure-ASGI limitation explicitly: by the time
`await self.app(...)` returns the response messages have already
been emitted, so a commit failure can no longer change what the
client sees on the wire. Buffering the response to gate it on commit
success would break streaming responses (chat completions, SSE) which
are core to Open WebUI; the trade-off is intentional. Routes that
need commit-before-send must manage the sync session explicitly.

Also drop unused `typing` imports flagged by review.

https://claude.ai/code/session_01JSr4NZSskEUQvoJnavVXh8

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-14 10:47:48 -05:00
Timothy Jaeryang Baek
37658fd541 refac 2026-04-14 01:17:39 -05:00
Timothy Jaeryang Baek
45e49d33e5 refac 2026-04-13 21:52:19 -05:00
Timothy Jaeryang Baek
cf4218e688 refac 2026-04-13 21:29:03 -05:00
Algorithm5838
33a4d1b412 fix: image url to base64 conversion (#23685) 2026-04-13 19:15:22 -05:00
Timothy Jaeryang Baek
c767bcaa73 refac 2026-04-13 18:20:46 -05:00
Timothy Jaeryang Baek
31406caa79 refac 2026-04-13 15:13:14 -05:00
Timothy Jaeryang Baek
40f5b3d135 refac 2026-04-13 14:51:09 -05:00