Repository navigation
fix(licensing): try EVOLUTION_OPERATOR_EMAIL when the global API key is not a license - #2814
Conversation
…is not a license AUTHENTICATION_API_KEY always has a value (it falls back to a default), so the boot never reached the branch that tries the operator e-mail. When the global key is rejected by the licensing server, try the e-mail activation before falling back to the browser registration flow.
Reviewer's GuideImplementationAdd a shared fallback that tries operator-email activation when no stored license applies, including after the global API key receives a 401 or 403; preserve the existing behavior for other errors.
ConfigurationUpdate the example environment configuration for the licensing change.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/licensing/runtime.ts" line_range="182" />
<code_context>
- printRegistrationBanner();
- rc.setActive(false);
logger.debug(`Global API key not accepted by licensing server: ${readErrorMessage(err)}`);
+ await autoRegisterOrWait(rc);
}
} else {
</code_context>
<issue_to_address>
**Instance activates under the wrong license**
When the configured global key is valid but activation or saving its license data fails, and auto-registration succeeds with a key for a different account, `initializeRuntime` treats errors from `activateInstance` or `saveRuntimeData` as a rejected key and calls `autoRegisterOrWait`, which can replace the valid global key with the email-issued key; the instance then runs under the wrong account’s license.
Only fall back to auto-registration when the licensing server explicitly rejects the configured key, and handle activation or persistence errors separately.
</issue_to_address>
### Comment 2
<location path="src/licensing/runtime.ts" line_range="182" />
<code_context>
- printRegistrationBanner();
- rc.setActive(false);
logger.debug(`Global API key not accepted by licensing server: ${readErrorMessage(err)}`);
+ await autoRegisterOrWait(rc);
}
} else {
</code_context>
<issue_to_address>
**Licensing outage delays startup**
When the licensing server is unresponsive, a global API key is configured, and `EVOLUTION_OPERATOR_EMAIL` is set, `initializeRuntime` waits for the failed global-key activation request and then waits for auto-registration before returning; if both requests time out, startup can take about 20 seconds before `server.listen` runs, exceeding a deployment’s startup deadline and preventing the service from becoming ready.
Use a shared startup deadline or avoid making the second licensing request block server startup when the activation request has already timed out.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and when a global API key is rejected, the runtime now tries to activate a license using the operator email and may save that license and enable the instance. Reverting stops future attempts but does not necessarily remove a license already activated; that state is bounded and should be repairable through the licensing flow.
Blocking findings: src/licensing/runtime.ts:182, src/licensing/runtime.ts:182
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/licensing/runtime.ts" line_range="182" />
<code_context>
- printRegistrationBanner();
- rc.setActive(false);
logger.debug(`Global API key not accepted by licensing server: ${readErrorMessage(err)}`);
+ await autoRegisterOrWait(rc);
}
} else {
</code_context>
<issue_to_address>
**Valid license key gets replaced**
When the configured global key is valid, activation or saving it fails for a non-rejection reason, and email auto-registration succeeds, `initializeRuntime` treats errors from `activateInstance` or `saveRuntimeData` as a rejected key and calls `autoRegisterOrWait`, which saves the email-issued key in place of the configured key and can leave the instance using a different license or customer.
Only run email auto-registration after confirming the configured key was rejected, and do not replace it after transient activation or persistence failures.
</issue_to_address>
### Comment 2
<location path="src/licensing/runtime.ts" line_range="182" />
<code_context>
- printRegistrationBanner();
- rc.setActive(false);
logger.debug(`Global API key not accepted by licensing server: ${readErrorMessage(err)}`);
+ await autoRegisterOrWait(rc);
}
} else {
</code_context>
<issue_to_address>
**New license keeps old customer ID**
When a stale `customer_id` row exists and `/v1/register/auto` omits or returns a nonpositive customer ID, `tryAutoRegisterFromEnv` saves the new API key, but `saveRuntimeData` only updates `customer_id` when the response value is positive; the persisted license is therefore paired with the previous customer ID on the next load.
Clear the stored customer ID when saving a license whose customer ID is absent or nonpositive.
</issue_to_address>
### Comment 3
<location path="src/licensing/runtime.ts" line_range="182" />
<code_context>
- printRegistrationBanner();
- rc.setActive(false);
logger.debug(`Global API key not accepted by licensing server: ${readErrorMessage(err)}`);
+ await autoRegisterOrWait(rc);
}
} else {
</code_context>
<issue_to_address>
**Startup waits on a second request**
When a global API key is configured and the licensing server times out or is unreachable, `initializeRuntime` awaits `autoRegisterOrWait` after the activation request times out, causing a second request to consume another timeout before `server.listen` runs and leaving the API unavailable during that delay.
Do not start the email auto-registration request after an activation timeout or an unreachable licensing server.
</issue_to_address>
### Comment 4
<location path="src/licensing/runtime.ts" line_range="207-208" />
<code_context>
* tryAutoRegisterFromEnv attempts a silent license activation using only the
- * operator email from EVOLUTION_OPERATOR_EMAIL. The customer must have completed
- * at least one manual registration in the past.
+ * operator email from EVOLUTION_OPERATOR_EMAIL. Whether the email alone is enough
+ * to get a key is decided by the licensing server.
*
* Returns true on success. Returns false on any failure — the caller is expected
</code_context>
<issue_to_address>
**Setup guide implies prior registration**
When an operator configures `EVOLUTION_OPERATOR_EMAIL` using the checked-in `env.example` guidance, `env.example` tells operators to use an email from a first manual registration and says an unregistered email falls back to manual activation. That conflicts with the updated description that the server decides whether email alone is sufficient, so operators without a prior registration can wrongly conclude this automatic path is unavailable.
Update `env.example` to explain that the server determines whether the email can auto-activate, without requiring a prior manual registration.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 3 findings to address first, and when a configured global API key is rejected, the runtime now tries email-based activation and can save a license and enable the gated runtime if the licensing server accepts it. Reverting stops future attempts, but it does not necessarily revoke a license already issued or undo access already granted.
Blocking findings: src/licensing/runtime.ts:182, src/licensing/runtime.ts:182, src/licensing/runtime.ts:182
…lobal key is refused A licensing outage or a failed save while activating a valid global key also reached the e-mail activation, which could replace the operator's key with an e-mail issued one and doubled the startup wait on timeouts. Only a 401/403 from the licensing server now leads to the e-mail activation; other errors keep the previous behaviour.
📋 Description
EVOLUTION_OPERATOR_EMAILauto-activation never ran.initializeRuntimeonly tried it when there was no stored license and no global API key, butAUTHENTICATION_API_KEYalways has a value (it falls back to a default inenv.config.ts). When the global key is not a licensing key, the boot printed the registration banner and stopped there.Now, when the global key is rejected by the licensing server, the boot tries the operator e-mail before falling back to the browser registration flow. Both "no key" paths share
autoRegisterOrWait.🧪 Type of Change
🧪 Testing
Local licensing server + API bundle built with
LICENSE_ENDPOINT_*pointing to it, cleanRuntimeConfig,AUTHENTICATION_API_KEYthat is not a license andEVOLUTION_OPERATOR_EMAILset:developmain/v1/activate(401) is called,/v1/register/autoneverdevelop/register/auto/v1/register/autonever calledmain/v1/register/autocalled, 401 (route still admin-only there), falls back to the banner/register/autoLicense activated automatically via EVOLUTION_OPERATOR_EMAIL, business routes 200tsc --noEmit,eslint(pre-commit) andnpm run build+lint:check(pre-push)✅ Checklist
📝 Additional Notes
On the licensing server this path only succeeds once the self-hosted
/v1/register/autochange is deployed there; until then the behaviour is the same as today (banner + browser flow).Summary by Sourcery
Allow operator-email auto-activation to run when the configured global API key is not accepted as a license.
Bug Fixes:
Chores: