A refresh token with a 30-day idle limit, held by a job that runs once a quarter, is dead for two months of every three, and the job’s dashboard stays green the whole time.
When the token passes its idle limit, nothing happens. No job is running, so nothing errors and nobody gets paged. The error waits for the next scheduled run, which might be the morning payroll needs its file.
The nightly check that catches this compares days until the token expires with days until the job next runs. When the first is smaller, the job is already broken and hasn’t found out. That takes a registry of integrations in git, joined each night to the CRM’s token history.
Every token holder gets an entry in git
Anything that holds a CRM token goes in integrations.yml, and the file changes only by pull request. That includes event consumers like the ones in keeping CRM systems in sync with events.
# Invented. The loader overwrites last_success from the run log.
integrations:
- id: commission-export-payroll
owner_team: sales-systems
owner_person: payroll-export-owner
auth_flow: client_credentials
runs_as: int-commission-export
scopes: [opportunities.read, users.read]
schedule: "0 2 1 1,4,7,10 *"
idle_token_limit_days: null
last_success: 2026-10-01T02:04:00Z
runbook: https://wiki.example.com/runbooks/commission-export
- id: renewal-upload-billing
owner_team: billing-integrations
owner_person: billing-upload-owner
auth_flow: refresh_token
runs_as: int-renewal-upload
scopes: [contracts.write, accounts.read]
schedule: "0 3 15 * *"
idle_token_limit_days: 30
last_success: 2026-09-15T03:11:00Z
runbook: https://wiki.example.com/runbooks/renewal-upload
- id: marketing-automation-sync
owner_team: marketing-ops
owner_person: marketing-sync-owner
auth_flow: password
runs_as: [email protected]
scopes: [full]
schedule: "*/15 * * * *"
idle_token_limit_days: null
last_success: 2026-10-06T23:45:00Z
runbook: https://wiki.example.com/runbooks/marketing-sync
runs_as is what makes the nightly check possible. Each integration gets its own integration user, never a person’s account. If the commission export runs as a sales ops analyst, her login history mixes her Tuesday afternoons with the job’s four runs a year. With a dedicated user, every row belongs to the job.
Flows that send a password, and anything running as a person, get flagged as migration debt with an owner. Both work today, and both break on somebody else’s schedule.
Days until expiry, next to days until the next run
Each night a job loads the registry, expands each cron schedule into next_run_at, and joins the CRM’s token use, logins and user records. Days idle count from the later of the CRM’s last sighting of that user and the run log’s last success.
-- PostgreSQL. registry is integrations.yml as loaded, plus next_run_at.
WITH activity AS (
SELECT username, MAX(event_at) AS last_seen_at
FROM (
SELECT username, used_at AS event_at FROM crm_token_usage
UNION ALL
SELECT username, login_at FROM crm_login_history
) AS events
GROUP BY username
),
forecast AS (
SELECT
r.id, r.owner_team, r.auth_flow, r.runs_as, u.user_type, u.is_active,
CURRENT_DATE - GREATEST(a.last_seen_at, r.last_success)::date AS days_idle,
r.next_run_at::date - CURRENT_DATE AS days_until_next_run,
r.idle_token_limit_days
FROM registry AS r
LEFT JOIN activity AS a ON a.username = r.runs_as
LEFT JOIN crm_users AS u ON u.username = r.runs_as
),
flags AS (
SELECT
id, owner_team, runs_as, days_idle, days_until_next_run,
idle_token_limit_days - days_idle AS days_until_expiry,
idle_token_limit_days - days_idle <= days_until_next_run AS expires_first,
auth_flow = 'password' AS sends_password,
user_type IS DISTINCT FROM 'integration' AS runs_as_person,
is_active IS NOT TRUE AS identity_inactive
FROM forecast
)
SELECT * FROM flags
WHERE expires_first OR sends_password OR runs_as_person OR identity_inactive
ORDER BY days_until_expiry NULLS LAST, id;
A check that looks only at days idle sees 28 and moves on. Next to a run 63 days away, that token is already lost, and the report says so tonight.
A weekly keep-alive call would reset the idle clock. I’ll allow one as a bridge if it has its own registry entry and a deletion date. Otherwise it’s permanent, and it won’t survive the person who authorized the token leaving. Scheduled jobs belong on a server-to-server flow under a dedicated integration user, with no refresh token to go idle.
Granted scopes against called endpoints
Once a quarter, the job compares each integration’s granted scopes with the endpoints it called in the last 90 days, and owners trim the difference.
A stolen integration token is one of the cheapest ways into CRM data, and a full-access one is the kind worth stealing. Any third-party app with broad scopes and no owner in the registry gets disabled. If someone complains, they’ve just volunteered to own it. Coding agents got the same treatment in the blast-radius post. Integration tokens are older and usually broader, which makes them the bigger target.
Two days of token, 63 days to the next run
Say a company, fictional for this post, has 23 CRM integrations, and its quarterly commission export to payroll last ran at 2 a.m. on the quarter’s first day. With a 30-day idle limit, the token dies a month later, and the job would fail when the next quarter’s close begins.
They turn on the nightly forecast a few weeks into the quarter, and the export tops the first report: two days of token left, next run 63 days away. Someone now has two months to fix it in working hours.
The same run finds four integrations running as named people, one of whom has left. A marketing tool holds full-access scope and has called two read endpoints in 90 days. Two third-party apps have no owner and get disabled.
The export moves to a server-to-server flow and drops off the report. It’s the first entry in the file above.
A re-auth drill in the sandbox every quarter
You find out whether a runbook works when someone other than its author follows it. Each quarter, break the riskiest entries in a sandbox:
- Pick the entries flagged most often.
- Confirm each integration user exists in the sandbox with production’s permissions.
- Revoke their tokens.
- Trigger the job and confirm the alert reaches the owner team.
- Give the runbook to someone other than the
owner_person. - Note each step that needed admin rights or a second factor.
- Confirm the new token belongs to the integration user, not the person re-authorizing.
- Run the job end to end and diff its output against production’s.
- Compare granted scopes with the registry entry.
- Fix the runbook and the entry in one pull request.
Token history varies by CRM
Some CRMs record a last-used date for each app and user. Others offer bare login history. Endpoint-level API logs may cost extra or expire within days, so the scope review needs a daily copy in the warehouse.
Most of the work is in the join: usernames that differ between the registry and the CRM, and apps registered twice under different names. I’d start with run logs alone, which still catch the quarterly export, then add token history.
If the platform shortens its idle limit, change one number per entry, and the next night’s report lists the jobs that won’t make their next run.