[Connections] Changing a piece's auth type silently breaks existing connections
Summary
When a piece changes its declared authentication method — most commonly moving from a single PieceAuth.X() to an array of methods — connections created under the old shape keep their original value.type in the database. Nothing in the platform notices the mismatch:
- the connection is not migrated,
- the type is not validated against the piece's current auth methods at read time,
- the status stays
ACTIVEand the UI keeps showing the connection as connected, - the piece receives a value shape it no longer expects and fails at runtime in a way that points the user at the wrong thing.
The user sees a green, "working" connection whose every API call fails. There is no signal anywhere that reconnecting is what's needed.
Reproduction
SavvyCal, with a connection created before #12233 (merged 2026-05-06).
That PR changed the piece's auth from:
export const savvyCalAuth = PieceAuth.SecretText({ ... })to:
export const savvyCalAuth = [PieceAuth.OAuth2({ ... }), PieceAuth.CustomAuth({ props: { token } })]The pre-existing connection is stored as { type: 'SECRET_TEXT', secret_text: 'pt_secret_…' }. The piece's token accessor is:
export function getToken(auth: SavvyCalAuthValue): string {
if (auth.type === AppConnectionType.CUSTOM_AUTH) {
return auth.props.token;
}
return auth.access_token;
}SECRET_TEXT matches neither branch's intent, falls through to auth.access_token, and returns undefined. Every request goes out as Authorization: Bearer undefined and comes back 401 Unauthenticated — including /v1/me, the endpoint the piece's own validate uses.
Observed behaviour:
- The connection shows Active on the Connections page and Connected in the flow builder.
- Every action fails with
401, which reads as "your token expired" — the token was in fact valid the whole time. - Dynamic dropdowns that catch their own errors show generic "failed to load" placeholders, hiding the 401 entirely.
- The only fix is to delete and recreate the connection. Editing it in place does not help, because the stored
typeis what's wrong.
Diagnosing this took several hours and required reading the piece's git history. Nothing in the product pointed at the cause.
Root cause
Three things compound:
1. No type compatibility check at read time. getConnectionValue in packages/server/engine/src/lib/piece-context/connection-resolver.ts passes connection.value straight through to the piece. There is no comparison against the auth methods the piece currently declares.
2. No migration path. There is no migration code anywhere under packages/server/api/src/app/app-connection/. validateConnectionValue in app-connection-service.ts switches on the incoming value's type at creation time and never cross-checks it against the piece's declared auth. Once stored, a value's type is never revisited.
3. The status can never flip. needRefresh (app-connection.handler.ts:267) only handles the OAuth2 variants and CUSTOM_AUTH. SECRET_TEXT falls through to the default and never refreshes, so it never reaches the catch block that would set AppConnectionStatus.ERROR. A static-token connection stays ACTIVE permanently regardless of whether it works. The only live check in the product is the manual Revalidate button, which exists solely on the Connections page — not in the flow builder, where users actually hit the problem.
Worth noting: connections already store pieceVersion, so the information needed to detect a stale value shape is present today.
Scope
The bug is one piece today, but nothing prevents the next one.
28 pieces currently declare multi-method auth. 18 of them migrated from a single PieceAuth.X() to an array after connections could already exist. 17 of those 18 kept their original method and added others alongside it (OAuth2 → [OAuth2, …], CustomAuth → [CustomAuth, …]), so existing connections still match a declared type and keep working.
SavvyCal is the only one that dropped its original type: SecretText → [OAuth2, CustomAuth]. That is the breaking shape, and it went unnoticed for three months because the platform reports the broken connection as ACTIVE.
fathom and mistral-ai made the same SecretText-to-array move but still declare SecretText, so they are unaffected — which is luck, not a guard rail. Nothing in review, CI, or runtime distinguishes their case from SavvyCal's.
Suggested direction
Roughly in order of value:
- Detect and surface the mismatch. When resolving a connection, compare
connection.value.typeagainst the piece's currently declared auth methods. On mismatch, set the connection toERRORwith an explicit message — "this connection was created with an authentication method this piece no longer supports, please reconnect" — instead of handing the piece a shape it can't read. - Make the builder's status reflect reality, rather than a stored value that some connection types can never update.
- Optionally, an auth migration hook so piece authors can map an old stored shape onto a new one instead of forcing every user to reconnect.
- Optionally, a CI check that flags when a piece version removes an auth type that a previous version declared — this is a breaking change for existing connections and currently passes review unnoticed.
Even just (1) would have turned this from a multi-hour investigation into a one-line message.
Environment
- Activepieces Cloud (
cloud.activepieces.com) - Piece:
@activepieces/piece-savvycalv0.1.6 - Connection created before 2026-05-06
Source: activepieces/activepieces