Skip to content

feat(dotAI): Caffeine cache migration and free-text image size input#35844

Open
ihoffmann-dot wants to merge 5 commits into
mainfrom
dot-ai-langchain-minor-fixes
Open

feat(dotAI): Caffeine cache migration and free-text image size input#35844
ihoffmann-dot wants to merge 5 commits into
mainfrom
dot-ai-langchain-minor-fixes

Conversation

@ihoffmann-dot
Copy link
Copy Markdown
Member

Summary

Two minor improvements to the LangChain4J AI integration.

Caffeine cache migration

  • Replace Guava CacheBuilder / Cache with Caffeine equivalents in LangChain4jAIClient
  • Separate init-failure and execution-failure catch paths in executeWithFallback — each is now caught, logged, and handled independently (init failure uses continue, execution failure falls through to next model)
  • Remove ExecutionException, UncheckedExecutionException imports — no longer needed since Caffeine propagates loader exceptions directly

Free-text image size input

  • Replace p-select orientation dropdown in AiImagePromptFormComponent with a pInputText field, defaulting to 1024x1024
  • Replace hidden size field in the dotAI portlet Image Playground JSP with a visible text input
  • Change AIImagePrompt.size type from DotAIImageOrientation to string
  • Add block-editor.extension.ai-image.size=Size to Language.properties

Notes

  • DotAIImageOrientation enum is retained — still used in gallery component and stores as named string constants. Only removed from the form component.
  • The gallery placeholder CSS classes (s1024x1024, s1792x1024, s1024x1792) still work for the three common sizes. Custom sizes will fall back to the generic placeholder style.
  • Cache invalidation on app config save is unaffected — AIAppListener still calls flushCachesForHost via AppSecretSavedEvent.

Related Issue

This PR fixes #35843
EPIC: dotAI Multi-Provider Support #33970

@github-actions github-actions Bot added Area : Backend PR changes Java/Maven backend code Area : Frontend PR changes Angular/TypeScript frontend code labels May 26, 2026
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 26, 2026

Claude finished @ihoffmann-dot's task in 2m 56s —— View job


PR Review

Two minor concerns and a few things worth a second look — nothing blocking.

Caffeine migration (LangChain4jAIClient.java)

  • Null-from-loader semantics change. Guava's Cache.get(key, Callable) throws InvalidCacheLoadException if the callable returns null; Caffeine's Cache.get(key, Function) quietly returns null and records no mapping (Caffeine docs). If a modelBuilder ever returns null, the new code falls through and NPEs at executor.apply(model), which is then logged as an execution failure rather than an init failure — different log message, slightly misleading. Today's factories presumably never return null, but worth a guard:
    if (model == null) {
        lastException = new IllegalArgumentException("Model builder returned null for '" + modelName + "'");
        continue;
    }
  • catch (RuntimeException) is broader than the old ExecutionException | UncheckedExecutionException. Caffeine propagates loader exceptions unwrapped, which is what you want — but the catch will also swallow runtime exceptions thrown from inside modelCache.get(...) itself (cache machinery, weird states), classifying them as init failures. Almost certainly fine, just noting the widened net.
  • ImmutableProviderConfig.copyOf(...).withModel(...) was moved out of the try block in executeWithFallback (good — clear separation). One subtle consequence: if that ever throws (e.g. validation in the immutable builder), it now aborts the whole fallback loop instead of being treated as an init failure. Probably the right call, but a behavior change worth flagging.

Free-text size input (frontend / JSP)

  • No visible validation error on the form. The control has Validators.pattern(/^\d+x\d+$/) but the template has no <small class="p-invalid"> for it (ai-image-prompt-form.component.html:41-46). A user who types 1024X1024 (capital X), 1024 x 1024, or anything else mistakenly only sees the submit button greyed out — no feedback as to why. UX regression compared to the dropdown.
  • No upper bound / provider-validity check. 99999999x99999999 passes the regex. The provider will reject at request time, but worth at least capping (e.g. (\d{2,4})x(\d{2,4})) to fail fast.
  • Default size changed from horizontal to square. Stores + form now default to '1024x1024' (was DotAIImageOrientation.HORIZONTAL = '1792x1024'). Intentional? If so, fine — just a behavior shift that callers using the old default may notice.
  • Inconsistent default in dot-ai.service.ts:83 — still has size: string = DotAIImageOrientation.HORIZONTAL. The form always provides a value so it doesn't matter in practice, but it's now out of step with the form / store / JSP defaults.
  • Stale i18n keys. block-editor.extension.ai-image.orientation, …orientation.horizontal/square/vertical are still in Language.properties (lines 5929, 5944-5946) but no longer referenced. Either remove them or leave with intent — your call, but they're dead weight now.
  • DotAIImageOrientation enum is still exported and used in specs / mocks / dot-ai.service.ts. Per PR description it's retained intentionally — but with AIImagePrompt.size now typed string, the enum's only practical role is as a set of named constants for the three "blessed" sizes. Worth a comment on the enum saying so, or a follow-up to migrate the remaining usages.
  • Gallery orientation input typing is loose. Now string defaulting '1024x1024'. The template builds a CSS class via 's' + orientation, so any non-validated input produces a class name that just won't match any rule (degraded placeholder). Documented in the PR description; fine.
  • JSP pattern="^\d+x\d+$" — HTML5 pattern is auto-anchored; the ^…$ is redundant (not a bug). Same regex shape as the Angular validator — keep them in sync if either ever changes.

Tests

  • LangChain4jAIClientTest.freshCache() migration is a 1:1 swap — fine. No new tests cover the split init-vs-exec catch behavior; if you want to lock in the new semantics, a test that throws from the builder vs. from the executor would be cheap to add.

Summary

Caffeine swap is mechanically correct but worth a null guard. Free-text size input ships without a user-facing validation message — that's the biggest UX nit. Everything else is housekeeping (stale i18n, default mismatch in service).
· Branch

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

Labels

AI: Safe To Rollback Area : Backend PR changes Java/Maven backend code Area : Frontend PR changes Angular/TypeScript frontend code

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[IMPROVEMENT] dotAI: Caffeine cache migration and free-text image size input

1 participant