fix(core): Rework Instance ai settings (no-changelog)#28495
Conversation
Bundle ReportChanges will increase total bundle size by 6.32kB (0.01%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: editor-ui-esmAssets Changed:
Files in
Files in
Files in
Files in
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Performance ComparisonComparing current → latest master → 14-day baseline docker-stats
Memory consumption baseline with starter plan resources
Idle baseline with Instance AI module loaded
How to read this table
|
…tting for all users
…ce AI during execution
… & refactor zod usage
|
So we don't forget it: when Instance AI or Computer Use are disabled globally (admin changes the setting from enabled to disabled) - all clients should be disconnected immediately. An example of the existing call is here |
… (like it was before rebase)
fea95d5 to
7a5cfc5
Compare
| if (!this.enabled) return true; | ||
| if (this.config.localGatewayDisabled) return true; | ||
| const prefs = this.userPreferences.get(userId); | ||
| const prefs = await this.loadUserPreferences(userId); |
There was a problem hiding this comment.
Since the setting is for disabling the local gw before when this wasn't async and actually checking db it would return undefined -> "not disabled" on first reads after instance startup
…r the local GW globally
Addressed in 9b97410 |
There was a problem hiding this comment.
2 issues found across 17 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/frontend/editor-ui/src/features/ai/instanceAi/components/settings/LocalGatewaySection.vue">
<violation number="1" location="packages/frontend/editor-ui/src/features/ai/instanceAi/components/settings/LocalGatewaySection.vue:23">
P3: `fetchSetupCommand()` is triggered from both the toggle handler and the new watcher, which can cause duplicate network requests when enabling local gateway.</violation>
</file>
<file name="packages/frontend/editor-ui/src/features/ai/instanceAi/__tests__/LocalGatewaySection.test.ts">
<violation number="1" location="packages/frontend/editor-ui/src/features/ai/instanceAi/__tests__/LocalGatewaySection.test.ts:42">
P2: Mock the gateway API in this test file so mounting the component doesn't hit the real create-link endpoint.</violation>
</file>
Architecture diagram
sequenceDiagram
participant UI as Frontend (Pinia Store)
participant API as InstanceAiController
participant SetSvc as InstanceAiSettingsService
participant AISvc as InstanceAiService
participant Reg as LocalGatewayRegistry
participant Push as PushService (WebSockets)
Note over UI,Push: Admin Update: Disable Local Gateway
UI->>API: POST /admin/settings (localGatewayDisabled: true)
API->>SetSvc: updateAdminSettings(payload)
alt NEW: Cloud Managed or Proxy Active
SetSvc->>SetSvc: Validate managed fields
Note right of SetSvc: Throws UnprocessableError if updating<br/>platform-locked fields (e.g., model on Cloud)
end
SetSvc-->>API: Settings Updated
opt NEW: If enabled=false OR localGatewayDisabled=true
API->>AISvc: disconnectAllGateways()
AISvc->>Reg: disconnectAll()
Reg-->>AISvc: List of disconnected User IDs
AISvc-->>API: disconnectedUserIds
API->>Push: NEW: sendToUsers(instanceAiGatewayStateChanged, {connected: false})
end
API-->>UI: 200 OK
Note over UI,Push: Local Gateway Lifecycle (Computer Use)
UI->>API: POST /gateway/create-link
API->>SetSvc: NEW: isLocalGatewayDisabledForUser(userId)
Note right of SetSvc: Checks Global Admin Toggle + User Preference
SetSvc-->>API: boolean
alt If Disabled
API-->>UI: 403 Forbidden (Local gateway is disabled)
else If Enabled
API-->>UI: 200 OK (Returns npx setup command)
end
Note over UI,Push: Gateway Agent Initialization
rect rgb(240, 240, 240)
Note right of API: External Gateway -> n8n
API->>API: CHANGED: @Body Validation (InstanceAiGatewayCapabilitiesDto)
API->>SetSvc: isLocalGatewayDisabledForUser(userId)
SetSvc-->>API: boolean
alt Authorized
API->>AISvc: initGateway(userId, payload)
AISvc->>Reg: registerGateway(userId, state)
API->>Push: NEW: sendToUsers(instanceAiGatewayStateChanged, {connected: true})
Push-->>UI: Update UI Status (Connected)
API-->>UI: 200 OK
else Forbidden
API-->>UI: 403 Forbidden
end
end
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
|
|
||
| @Post('/gateway/init', { skipAuth: true }) | ||
| gatewayInit(req: Request) { | ||
| async gatewayInit(req: Request, _res: Response, @Body payload: InstanceAiGatewayCapabilitiesDto) { |
There was a problem hiding this comment.
Found the issue - same one as I've done a few times in the past, but looks like claude hasn't learned it yet - we can't export the DTO's as types. Should be fixed in f30b65b
|
there's some schema/DTO duplication in
I would derive one from the other (e.g. have the DTO class wrap the existing schema), or delete the old Zod schemas if they are no longer used... or they might drift? |
Good catch, definitely just claude being silly here and this isn't how we've been doing these schemas elsewhere. Addressed in c8dff7c |
Summary
@Bodydecorators instead of doing it manuallyRelated Linear tickets, Github issues, and Community forum posts
Review / Merge checklist
Backport to Beta,Backport to Stable, orBackport to v1(if the PR is an urgent fix that needs to be backported)