Skip to content

Sync Granola notes from opted-in personal folders - #30808

Closed
ehconitin wants to merge 3 commits into
mainfrom
ehco/granola-personal-live-sync
Closed

ehconitin wants to merge 3 commits into
mainfrom
ehco/granola-personal-live-sync

Conversation

@ehconitin

@ehconitin ehconitin commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Superseded by smaller PRs starting with #30814. The remaining recording ownership, folder eligibility, and webhook lifecycle changes will follow from main, one PR at a time.

Context

This follows #30803 and #30806. Members who connect Granola need to opt individual folders into sharing future meeting notes as Twenty Call Recordings. The existing workspace connection can keep syncing meetings in parallel.

Changes

  • Reconcile one folder-filtered Granola webhook per opted-in personal connection. Route deliveries through the existing workspace claim, verify the signature, and use the current member key.
  • Verify the note was created after opt-in and is still in a selected folder or subtree. Recheck the member connection and selection before writing. Disconnect, clearing the selection, and uninstall retire routing claims and remove the remote endpoint when its key still has access.
  • Use the existing deterministic Call Recording ID. Add one nullable, read-only app field to track the source revision of personal imports. A conditional update rejects stale personal writes, and a workspace write clears the revision so later personal deliveries leave the workspace copy alone. Existing Granola recordings have a null revision and retain workspace ownership.

Build and rollout

This PR is the live delivery path. Scheduled catch-up and the Folders tab will land together in the release PR after this merges. The current app version has no member-facing folder picker. The first scheduled run will reconcile every saved personal selection, including choices made during development or through the settings API before the release, so those members do not have to save again. There is no app version bump here. The new field is additive and needs no data backfill. The current workspace webhook URL, registration keys, and scope-selection behavior are preserved.

Verification

  • Granola lint, typecheck, unit tests, and Twenty CLI app build
  • Deploy and run the suite against an isolated local Twenty server. Coverage includes matching nested folder scope, opt-in timestamps, disconnect during a delivery, stale keys after reconnect, and competing workspace and personal writes.

@twenty-ci-bot-public

twenty-ci-bot-public Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🚀 Preview Environment Ready!

Your preview environment is available at: https://regions-comics-kilometers-cabinet.trycloudflare.com

This environment will automatically shut down after 5 hours.

@twenty-ci-bot-public

twenty-ci-bot-public Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🤖 PR Review

Check Result
🔍 Build safety ⏭️ skipped — external-only
🧭 Triage ⏭️ skipped — external-only
📐 Quality ✅ passed — 4 nit(s)
🛡️ Security ✅ passed
🚦 Auto-approve 👀 needs review — Complexity is medium
🔐 Permissions ⏭️ skipped: no endpoint permission change

🛡️ Security Review

✅ No high-severity vulnerabilities detected.


🚦 Auto-approve

🙋 Manual review recommended for the following reason(s):

  • Complexity is medium

  • 🧠 Complexity: medium

  • 📏 Size: +1334 / -55 lines across 39 file(s)


View details

Automated pre-review — human approval still required.

@twenty-ci-bot-public

twenty-ci-bot-public Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🟡 Quality review · 4 findings

Safe to merge — no new high-level issues

High-level — Personal Granola webhook sync stays inside the app and reuses its existing seams: connection hooks, kv, the shared resolver, signature parsing and the upsert path. The author has answered both earlier high-level findings (the duplicated eligibility check and the rollout gap), and the latest commit adds nothing new at the architecture or rollout level.
Low-level — 4 rule violations found — 1524 rule questions over 44 piece(s) of 39 file(s), 2 kept from the previous run

💬 4 inline comments on the diff.


Reviewed against the pr-review standard — high-level then low-level. Advisory; human review still required. Run details.


return undefined;
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · High-level · one source of truth

The check for whether a personal Granola connection is usable now exists in three places that already disagree

granola-personal-reconcile.ts:51-58 and load-granola-personal-sync.util.ts:28-33 both check workspaceMemberId, but the existing load-granola-personal-folder-settings.util.ts:22-27 does not, so the settings screen and the sync path can disagree about the same connection. Move this check into one shared util next to listGranolaPersonalConnections and use it from all three files; the reconcile handler can then rely on loadGranolaPersonalSync and drop its own copy.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Centralized connection eligibility in one lookup. Folder settings, webhook setup, and note imports now require the same active membership and usable personal key.

return { success: true, skipped: true };
}

const connection = isDefined(userWorkspaceId)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · Return early

The ternary on lines 40-50 has a multi-line promise-catch branch with a nested if, making it a big ternary that should be an early-return or separate helper.

Also on lines 41–50.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Replaced the nested ternary with an explicit branch in the shared connection lookup.

throw new Error('A personal Granola webhook requires selected folders.');
}

const scopesForKey: (GranolaWebhookScope[] | undefined)[] =

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · Return early

The multi-line ternary selecting between two scope-array lists is a big ternary that should be an early return or a simpler construct.

Also on lines 36–42.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Named the two scope candidate lists so the selection is a single expression.

GRANOLA_PERSONAL_KEY_SCOPES,
]
if (isPersonalConnection && !isNonEmptyArray(folderIds)) {
throw new Error('A personal Granola webhook requires selected folders.');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · Throw CustomException, never a generic Error``

The new validation throws a generic Error instead of a CustomException.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The missing folder filter now raises a GranolaWebhookConfigurationError.

receivedAt,
signingSecret,
}: {
routePayload: RoutePayload<unknown>;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · Narrow object parameters to the fields read

The routePayload parameter is typed as the whole RoutePayload<unknown> interface, but the function only reads rawBody and headers; it should be narrowed with Pick<>.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Narrowed the signature verifier input to rawBody and headers.

apiKeyFingerprint,
folderIds,
}: {
scope: GranolaPersonalSyncScope;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · Narrow object parameters to the fields read

The scope parameter is typed as the whole GranolaPersonalSyncScope even though the function only reads scope.connectionId, so it should be narrowed with Pick<>.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Both IDs are required. The helper stores userWorkspaceId with the registration and uses it to recheck the connection. I destructured both fields to make that explicit.

const apiUrl = process.env.TWENTY_API_URL;

if (!isNonEmptyString(apiUrl)) {
throw new Error(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · Throw CustomException, never a generic Error``

The added code throws a generic Error when TWENTY_API_URL is missing instead of a CustomException.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Missing TWENTY_API_URL now raises a GranolaWebhookConfigurationError without retrying the job.

throw error;
}

await deleteStaleGranolaWebhookEndpointOrThrow({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · No silent failures or permissive fallbacks

When the personal sync is missing, the code silently deletes the just-created webhook and returns successfully instead of surfacing the inconsistent state with an error.

Also on lines 119–121.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

A disconnect or opt-out during setup can legitimately clear the selection. The new endpoint is rolled back and the handler now returns skipped: true.


try {
if (!isDefined(client)) {
throw new Error('The Granola API key is unavailable.');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · Throw CustomException, never a generic Error``

The added line throws a generic new Error(...) instead of the module's CustomException.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Missing credentials now log the provider cleanup step and return after revoking the local registration.

},
});

return (result.updateCallRecordings ?? []).length > 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · Use isDefined over manual checks

The emptiness check (result.updateCallRecordings ?? []).length > 0 is a manual nullish-and-length check where isNonEmptyArray would express it directly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Replaced the nullish fallback and length check with isNonEmptyArray.

})),
);

await enqueueGranolaPersonalReconcileOrThrow({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · High-level · deploy strategy

Personal folder selections saved before this deploy never get a webhook, because reconcile only runs on connect or when a selection is saved

Members who already picked folders will see them as selected in settings, but none of their notes get imported until they save again or reconnect, and nothing tells them to do either. Run a one-time reconcile for every existing personal connection, for example from the daily catch-up or on app upgrade, or point the rollout note at this gap.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Clarified the rollout in the PR body. The Folders tab ships with scheduled reconciliation of every saved personal selection, including any choices already saved through the API.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This implementation is being split. The first replacement is #30814 and only extracts webhook verification. Saved selections will be reconciled in the release PR that enables personal sync.

await enqueueGranolaPersonalReconcileOrThrow({
connectionId: request.data.connectionId,
userWorkspaceId,
}).catch((error: unknown) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · No silent failures or permissive fallbacks

The .catch swallows the reconciliation error, only logs it to console, and the handler still returns success: true, so a failed sync start is silently ignored.

Also on lines 81–84.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The route now returns HTTP 503 if it cannot schedule setup. The saved selection remains available for retry.

connections.map(async (connection) => {
try {
await disconnectGranolaPersonalConnection({
connection,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · Consolidate duplicate concepts

The disconnect call passes both connection and connection.id, so the same identity is supplied twice and the util could take just the connection.

Also on line 54.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Simplified cleanup to accept just the connection ID and the API key.

`[granola] Could not list personal connections during uninstall. ${toErrorMessage(error)}`,
);

return [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · No silent failures or permissive fallbacks

The .catch on listGranolaPersonalConnections logs the error and returns an empty list, so uninstall proceeds as if there were no connections and leaves them uncleaned without failing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Keeping uninstall cleanup best effort. A failed connection lookup is logged, and uninstall still proceeds. Granola delivery cannot import once the app is removed.

@@ -0,0 +1,6 @@
export class GranolaWebhookConfigurationError extends Error {
constructor(message: string) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · Exceptions take a single object parameter

The exception constructor takes a bare message: string instead of a single object parameter.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changed the error constructor to accept a single options object.

}) => {
const scopeCandidates = [
if (isPersonalConnection && !isNonEmptyArray(folderIds)) {
throw new GranolaWebhookConfigurationError(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · Exceptions take a single object parameter

The new GranolaWebhookConfigurationError is constructed with a bare positional string instead of a single object parameter.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The error now takes a message options object at this call site.

const scopeCandidates = [
if (isPersonalConnection && !isNonEmptyArray(folderIds)) {
throw new GranolaWebhookConfigurationError(
'A personal Granola webhook requires selected folders.',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · Translate user-facing strings

The thrown configuration error message is a user-facing string not wrapped in t`` or msg, so it won't be translated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is an operator diagnostic from background webhook setup. The member-facing settings error is handled separately in the UI.

const connection = await getRequestedConnectionOrThrow().catch(
(error: unknown) => {
if (error instanceof AppConnectionAuthFailedError) {
return undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · No silent failures or permissive fallbacks

The function is named ...OrThrow yet swallows AppConnectionAuthFailedError and returns undefined for missing, mismatched, or auth-failed connections, so callers get no error signal.

Also on line 45.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Renamed the helper to findGranolaPersonalConnection. An unavailable credential is a normal stop condition after disconnect or auth failure. Unexpected lookup errors still propagate.

export const getGranolaPersonalWebhookKey = (connectionId: string): string =>
`granola:personal-webhook:${connectionId}`;

export const GRANOLA_PERSONAL_REGISTRATION_PREFIX = 'personal-';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · One util per file

The file bundles an unrelated registration-prefix constant (GRANOLA_PERSONAL_REGISTRATION_PREFIX) alongside the webhook key util, so it is not one util per file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Moved the prefix to the personal connection constants file.

userWorkspaceId,
});

if (!isDefined(connection)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · Don't guard what the types rule out

The connection comes from findGranolaPersonalConnectionOrThrow, which by its name never returns nullish, so the isDefined(connection) early return guards a case the types already rule out.

Also on lines 29–30.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The lookup can return undefined for a removed or unusable credential. I renamed it to make that contract explicit and kept the guard.

apiKeyFingerprint,
});

if (isDefined(current)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · Return early

The added if (isDefined(current)) is nested inside the 401 if block rather than being flattened with an early return or guard.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Flattened the 401 path with an early return when the connection has already changed.

});
} catch (error) {
if (error instanceof GranolaApiError && error.status === 401) {
const current = await loadGranolaPersonalSync({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Nit · Low-level · Reuse or extract instead of reimplementing

The 4-line loadGranolaPersonalSync({ ...scope, apiKeyFingerprint }) re-load block is duplicated verbatim from lines 50-53 instead of being extracted into a shared helper.

Also on lines 68–70.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Both paths already use the shared sync lookup. The write path rechecks consent before saving, and the 401 path separately checks the same key is still current before marking it for reconnect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant