Skip to content

fix(core): Rework Instance ai settings (no-changelog)#28495

Merged
Cadiac merged 25 commits intomasterfrom
instance-ai-prevent-settings-on-cloud
Apr 17, 2026
Merged

fix(core): Rework Instance ai settings (no-changelog)#28495
Cadiac merged 25 commits intomasterfrom
instance-ai-prevent-settings-on-cloud

Conversation

@Cadiac
Copy link
Copy Markdown
Contributor

@Cadiac Cadiac commented Apr 14, 2026

Summary

  • If proxy is enabled hide & prevent setting sandbox / model on settings
  • Respect the local gateway settings correctly
    • Proper working global toggle for admins to disable local gateway for everyone
    • User level toggle for enabling / disabling local gateway personally for everyone
    • Enforce these settings on the backend
    • Don't request the gw's /events endpoint if local gateway is disabled
  • Make settings work for members (only allowing the personal toggle & model picker on self hosted)
  • Style fixes at the UI
  • Validate request bodies on local gw endpoints using our preferred @Body decorators instead of doing it manually

Related Linear tickets, Github issues, and Community forum posts

Review / Merge checklist

  • I have seen this code, I have run this code, and I take responsibility for this code.
  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with Backport to Beta, Backport to Stable, or Backport to v1 (if the PR is an urgent fix that needs to be backported)

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Bundle Report

Changes will increase total bundle size by 6.32kB (0.01%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
editor-ui-esm 45.76MB 6.32kB (0.01%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: editor-ui-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/constants-*.js -358 bytes 3.14MB -0.01%
assets/users.store-*.js 5.34kB 1.06MB 0.51%
assets/core-*.js 42 bytes 627.99kB 0.01%
assets/src-*.css 267 bytes 495.73kB 0.05%
assets/InstanceAiView-*.js 3.72kB 349.3kB 1.08%
assets/InstanceAiView-*.css 3 bytes 166.79kB 0.0%
assets/WorkflowLayout-*.js 87 bytes 127.92kB 0.07%
assets/router-*.js -2 bytes 119.31kB -0.0%
assets/CreditWarningBanner-*.js -285 bytes 54.89kB -0.52%
assets/SettingsInstanceAiView-*.js 1.83kB 46.46kB 4.11%
assets/WorkflowLayout-*.css 94 bytes 46.24kB 0.2%
assets/InstanceAiOptinModal-*.js 18 bytes 24.75kB 0.07%
assets/SettingsInstanceAiView-*.css 155 bytes 23.88kB 0.65%
assets/useCustomAgent-*.js -36 bytes 20.76kB -0.17%
assets/instanceAiSettings.store-*.js 738 bytes 15.73kB 4.92%
assets/WorkflowPreview-*.js 40 bytes 7.96kB 0.5%
assets/dist-*.js (Deleted) -5.34kB 0 bytes -100.0% 🗑️

Files in assets/InstanceAiView-*.js:

  • ./src/features/ai/instanceAi/InstanceAiView.vue → Total Size: 335 bytes

Files in assets/SettingsInstanceAiView-*.js:

  • ./src/features/ai/instanceAi/components/settings/LocalGatewaySection.vue → Total Size: 379 bytes

  • ./src/features/ai/instanceAi/views/SettingsInstanceAiView.vue → Total Size: 373 bytes

Files in assets/InstanceAiOptinModal-*.js:

  • ./src/features/ai/instanceAi/components/InstanceAiOptinModal.vue → Total Size: 370 bytes

Files in assets/instanceAiSettings.store-*.js:

  • ./src/features/ai/instanceAi/instanceAiSettings.store.ts → Total Size: 11.09kB

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 14, 2026

Performance Comparison

Comparing currentlatest master14-day baseline

docker-stats

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
docker-image-size-n8n 1269.76 MB 1269.76 MB 1269.76 MB (σ 0.00) +0.0% +0.0%
docker-image-size-runners 386.00 MB 393.00 MB 391.78 MB (σ 10.35) -1.8% -1.5%

Memory consumption baseline with starter plan resources

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
memory-rss-baseline 346.96 MB 332.36 MB 289.78 MB (σ 45.79) +4.4% +19.7% ⚠️
memory-heap-used-baseline 114.57 MB 114.54 MB 114.13 MB (σ 0.52) +0.0% +0.4%

Idle baseline with Instance AI module loaded

Metric Current Latest Master Baseline (avg) vs Master vs Baseline Status
instance-ai-heap-used-baseline 186.30 MB 186.90 MB 186.41 MB (σ 0.28) -0.3% -0.1%
instance-ai-rss-baseline 342.96 MB 345.77 MB 365.35 MB (σ 23.65) -0.8% -6.1%
How to read this table
  • Current: This PR's value (or latest master if PR perf tests haven't run)
  • Latest Master: Most recent nightly master measurement
  • Baseline: Rolling 14-day average from master
  • vs Master: PR impact (current vs latest master)
  • vs Baseline: Drift from baseline (current vs rolling avg)
  • Status: ✅ within 1σ | ⚠️ 1-2σ | 🔴 >2σ regression

@dlavrenuek
Copy link
Copy Markdown
Contributor

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

@Cadiac Cadiac force-pushed the instance-ai-prevent-settings-on-cloud branch from fea95d5 to 7a5cfc5 Compare April 15, 2026 13:25
@Cadiac Cadiac changed the title feat(core): Rework Instance ai settings fix(core): Rework Instance ai settings (no-changelog) Apr 15, 2026
if (!this.enabled) return true;
if (this.config.localGatewayDisabled) return true;
const prefs = this.userPreferences.get(userId);
const prefs = await this.loadUserPreferences(userId);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@Cadiac
Copy link
Copy Markdown
Contributor Author

Cadiac commented Apr 15, 2026

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

Addressed in 9b97410

@Cadiac Cadiac marked this pull request as ready for review April 15, 2026 17:25
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

@Cadiac Cadiac requested review from aalises and dlavrenuek April 15, 2026 20:27

@Post('/gateway/init', { skipAuth: true })
gatewayInit(req: Request) {
async gatewayInit(req: Request, _res: Response, @Body payload: InstanceAiGatewayCapabilitiesDto) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cadiac this does not seem to work properly

@Body payload: InstanceAiGatewayCapabilitiesDto

payload is null when I run the code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@aalises
Copy link
Copy Markdown
Contributor

aalises commented Apr 17, 2026

there's some schema/DTO duplication in instance-ai.schema.ts

InstanceAiGatewayCapabilitiesDto and InstanceAiFilesystemResponseDto seem copied duplicates of instanceAiGatewayCapabilitiesSchema / instanceAiFilesystemResponseSchema (same field list, separate declarations).

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?

@Cadiac
Copy link
Copy Markdown
Contributor Author

Cadiac commented Apr 17, 2026

there's some schema/DTO duplication in instance-ai.schema.ts

InstanceAiGatewayCapabilitiesDto and InstanceAiFilesystemResponseDto seem copied duplicates of instanceAiGatewayCapabilitiesSchema / instanceAiFilesystemResponseSchema (same field list, separate declarations).

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

@Cadiac Cadiac added this pull request to the merge queue Apr 17, 2026
Merged via the queue into master with commit 5c9a732 Apr 17, 2026
55 checks passed
@Cadiac Cadiac deleted the instance-ai-prevent-settings-on-cloud branch April 17, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants