…ing deletes match
- A streaming body refused a concurrency permit returned without calling
bridge.stream(), so the stateless conversation prepare() had started was
never ended. New OpenAiConversationBridge.abandon(turn) ends a stateless
turn's conversation; the refused body calls it.
- Every mapping delete in the bridge now uses
deleteUserConversationIfMatches with the conversation the request read, so
concurrent requests for a chat whose conversation ended (Open WebUI's
completion and title request) converge on one new conversation instead of
the slower one deleting the faster one's fresh mapping.
- AgentModelResolver asks ResourceAccessGuard.hasAccess(id, USE) instead of
catching requireAgentUseAccess (a WARN and an exception per hidden agent on
every polled GET /v1/models), and no longer caches the empty catalogue a
failed agent listing produced for model-cache-seconds.
Three small defects in the OpenAI-compatible
/v1adapter, found in the whole-codebase review (MOD-16, NEW-channels-2, NEW-gap-modules-integrations-5).A stateless stream refused a permit left its conversation open
chatCompletionscallsbridge.prepare, which for a stateless model (…:statelessor"stateless": true) starts the throwaway conversation immediately, and then releases its permit. The SSE body re-acquires a permit when it runs. If that fails, it writes the in-band429error event and returns without callingbridge.stream— andstream()'sfinallywas the only place a streamed stateless conversation was ended.Failure scenario:
max-concurrent-requests=64, a burst of 100 Open WebUI title requests pointed at a:statelessmodel withstream: true. Every body that loses the permit race answers "Too many concurrent requests" and leaves one READY conversation behind, which nothing ever ends. The sync path was fine (say()ends it infinally).Fix: a new
OpenAiConversationBridge.abandon(PreparedTurn)ends a stateless turn's conversation and does nothing for a stateful one (that conversation belongs to the chat). The refused body calls it before writing the error. Thestream()Javadoc now says every exit ends a stateless turn and that a never-streamed turn goes toabandon.Unconditional mapping deletes split a chat across two conversations
When a chat's mapped conversation has ended (idle sweep, rollover), the bridge deletes the mapping and starts a new conversation. Open WebUI sends a chat's completion and its title request together, with the same chat id — the bridge's own comment calls this routine. Both read the ended mapping. A deletes it, starts
a, writes the mapping. B, which read the old mapping earlier, then runsdeleteUserConversation(intent, userId)— unconditional — removing A's fresh mapping, startsband writes that. Conversationastays open and orphaned, and the chat continues inbwithout A's turn.Fix: every mapping delete in the bridge (stale mapping, new-chat supersede, ended legacy mapping, legacy re-key, mid-turn self-heal) goes through
IUserConversationStore.deleteUserConversationIfMatcheswith the conversation id the request read. That primitive exists for exactly this race and Slack and the webhook handler already use it. B's delete now matches nothing, its create collides with A's mapping, and the existing insert-conflict re-read adoptsaand ends B's own fresh conversation.Model resolution probed access by exception, and cached a failed catalogue
AgentModelResolver.mayUsecalledrequireAgentUseAccessand caught the exception. For every agent the caller may not use, that logsWARN Use check failed…and builds aForbiddenException.GET /v1/modelsruns it per catalogue entry and Open WebUI polls it, so a deployment with 150 private agents wrote 150 WARN lines per listing (andresolve()did the same). It now asksResourceAccessGuard.hasAccess(agentId, AccessLevel.USE), which is documented to be true exactly whenrequireUseAccesswould pass, including the legacy fallback for a missing descriptor.Separately, when
getAllLatestAgentsthrew,buildCataloguereturned an empty catalogue that Caffeine cached formodel-cache-seconds(30 s), so a one-off store error made every model "unknown" for 30 s. The loader now returnsnullon failure (Caffeine does not store it) and that one call gets an empty view.Decisions
bridge.abandon(turn)endConversationfrom the adaptersay/streamend it infinally); the adapter should not need to know which turns own a throwaway conversation.X-EDDI-Conversation-Idheaderabandon.nullon failurenullkeeps the failure log in one place and avoids an exception round-trip throughcache.get.What this changes for users and operators
/v1request and response shapes, REST paths, config keys and defaults are unchanged.429fromConversationCoordinatorif both hit it at the same instant; clients retry).GET /v1/modelsno longer logs a WARN per hidden agent.docs/open-webui-integration.md: themodel-cache-secondsrow and the "two requests in one chat" row say so.Where to look hardest
Scope, checked against every streaming entry point: this PR covers one way a
/v1stream body gives up beforestream(), a body that runs but is refused a permit. A body the server never invokes still leaves a stateless conversation open until the idle sweep; that gap has no owner yet, and fix(openai): cancel a /v1 stream's turn when its client leaves or times out #1404 does not close it because its checks sit insidestream(). No other streaming entry point creates something before a deferred body: native and group SSE do their work in the resource method, the A2A body only drains a queue whose turn settles on its own, and the ratings export creates nothing before its body.The "body never runs" case, which this PR does not cover. In RESTEasy Reactive 3.40.1 a closed connection sets
connectionClosed, andResteasyReactiveRequestContext.isHandlerCanceledthen skips every remaining cancellable handler.ResponseWriterHandler, which invokes theStreamingOutput, keeps the defaultisCancellable() == true. So a client that disconnects afterprepare()has started a stateless conversation, but before the response is written, leaves that conversation open until the idle sweep (maximumLifeTimeOfIdleConversationsInDays, 90 days by default) ends it. This was read from the library source, not reproduced against a live server. It is the same window the adapter's existing permit comment guards against. The window is much narrower than the permit-refused case fixed here, and is listed as a follow-up.OpenAiConversationBridge.getOrCreateConversation, thenewChatbranch: the supersede delete is now conditional too. Two requests that open a history-keyed chat with the same words at the same instant now converge on one conversation instead of B silently deleting A's mapping. Since history-keyed chats share the intent from their second turn on anyway, this matches what happens one turn later.AgentModelResolver.mayUse:hasAccessanswersfalsefor a blank id whererequireUseAccessreturned (passed). Catalogue entries always carry the deployed agent's id, so this does not change who sees what.Verification
./mvnw -o -q -DskipUi=true compile— exit 0.Red run before the fix (
abandonas an empty stub, everything else unchanged),./mvnw -o -DskipUi=true test -Dtest='RestOpenAiAdapterTest,OpenAiConversationBridgeTest,OpenAiBridgeSessionAndErrorTest,AgentModelResolverTest': 137 tests, 15 failures and 1 error, each for the item's reason: the adapter test "Wanted but not invoked: abandon(conv-2)"; the race test "expected …03 but was …01" (the chat split); the cache test "expected 2 but was 0";useGate_asksWithoutThrowinglisted the private agent; the conditional-delete verifies were not met.Green run, same command: 137 tests, 0 failures.
Final run with the guard classes:
./mvnw -o -DskipUi=true test -Dtest='RestOpenAiAdapterTest,OpenAiConversationBridgeTest,OpenAiBridgeSessionAndErrorTest,AgentModelResolverTest,ImportStyleTest,BuildQualityGatesTest,ChangelogRotationTest,ChangelogFragmentTest,DocumentationLinksTest,DocumentationAccuracyTest,DocumentedRestPathsTest,DeploymentManifestsTest'— BUILD SUCCESS, 325 tests, 0 failures, 1 skipped (a pre-existing skip inDeploymentManifestsTest); a surefire report exists for all 12 named classes.Mutation check: the red run above is the pre-fix code for every key line (no
abandoncall, an emptyabandon, unconditional deletes, the catchingmayUse, the cached empty catalogue), and each new or changed test failed against it.Independent review mutation check: three mutants together (the plain delete back in
deleteMappingIfMatches, noabandoncall in the adapter, and a cached empty catalogue on a listing failure).-Dtest='RestOpenAiAdapterTest,OpenAiConversationBridgeTest,AgentModelResolverTest'gave 107 tests and 8 failures, each for its own item. After restoring them, the 12-class run above was repeated: 325 tests, 0 failures, 1 pre-existing skip, and 12/12 reports.Not run locally: the full unit suite, integration tests (
*IT) and the UI suites, left to CI.Follow-ups
Summary by CodeRabbit