Files
twenty/packages
martmull c4a79c50c3 Install pre-installed apps in a dedicated job after the workspace upgrade cursor is written (#23517)
## Problem

Application registrations flagged `isPreInstalled: true` were not
installed on newly created workspaces.

The call was wired in, but it ran too early. `activateWorkspace` invoked
`preInstalledAppsService.installOnWorkspace` from inside
`prefillCreatedWorkspaceRecords`, which runs **before**
`activateAndInitializeUpgradeState`.

The install path validates app/workspace version compatibility:

- `ApplicationInstallService.runInstall` reads `engines.twenty` from the
app's `package.json` and calls `validateWorkspaceCompatibility`
- `ApplicationVersionValidationService.validateWorkspaceCompatibility`
resolves the workspace version through
`UpgradeStatusService.getWorkspaceCompletedVersion`
- that reads the workspace's upgrade-migration cursor, which is only
written by `markAsWorkspaceInitial` inside
`activateAndInitializeUpgradeState`

During creation the workspace has no cursor row yet, so
`getWorkspaceCompletedVersion` returns `null`, the install throws
`INVALID_WORKSPACE_VERSION`, and the failure is swallowed twice over:
`PreInstalledAppsService` logs per-app failures without rethrowing, and
`activateWorkspace` wraps the whole call in non-critical error handling.
The workspace comes up silently missing its apps.

This affects most real apps, since they pin `engines.twenty`:
`fireflies`, `last-contact`, `people-data-labs`, `call-recorder`,
`postcard`, `self-hosting`, `twenty-partners` (`>=2.23.0`) and `exa`,
`real-estate` (`>=2.19.0`). Only apps with no `engines.twenty` installed
successfully. The same interaction is already documented in
`2-23-workspace-command-1784565137000-upgrade-people-data-labs-application.command.ts`,
which works around it with `skipWorkspaceCompatibilityCheck: true`.

## Changes

- Added `InstallPreInstalledAppsJob` on the workspace queue, mirroring
the existing `InstallOnboardingAppsJob`.
- `activateWorkspace` now enqueues that job instead of installing
synchronously, so workspace creation no longer blocks on package
fetching and manifest application.
- The enqueue happens after `activateAndInitializeUpgradeState` writes
the upgrade cursor, so the compatibility check has a workspace version
to resolve by the time the worker picks the job up.

## Notes

Workspaces created before this fix can be repaired with the existing
`install-pre-installed-apps` backfill command, which is idempotent.
2026-07-29 16:30:00 +00:00
..