MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / connectionCheckHealth

Function connectionCheckHealth

packages/core/sdk/src/executor.ts:5160–5336  ·  view source on GitHub ↗
(
      ref: ConnectionRef,
      options?: {
        /** Skip the probe and return the persisted verdict when it is younger
         *  than this. The server owns the freshness decision so N open tabs
         *  revalidating on load cannot stampede an upstream. Omit = always
         *  probe (the manual "Check now"). */
        readonly ifStaleMs?: number;
      },
    )

Source from the content-addressed store, hash-verified

5158 );
5159
5160 const connectionCheckHealth = (
5161 ref: ConnectionRef,
5162 options?: {
5163 /** Skip the probe and return the persisted verdict when it is younger
5164 * than this. The server owns the freshness decision so N open tabs
5165 * revalidating on load cannot stampede an upstream. Omit = always
5166 * probe (the manual "Check now"). */
5167 readonly ifStaleMs?: number;
5168 },
5169 ): Effect.Effect<
5170 HealthCheckResult,
5171 ConnectionNotFoundError | IntegrationNotFoundError | StorageFailure
5172 > =>
5173 Effect.gen(function* () {
5174 const connectionRow = yield* findConnectionRow(ref);
5175 if (!connectionRow) {
5176 return yield* new ConnectionNotFoundError({
5177 owner: ref.owner,
5178 integration: ref.integration,
5179 name: ref.name,
5180 });
5181 }
5182 // A recorded invalid_grant is the AS's standing verdict on this grant
5183 // (the refresh path's gate, applied to probing): a probe can still
5184 // pass on the access token's remaining lifetime, and persisting that
5185 // "healthy" would hide the required reconnect until the token finally
5186 // lapses — with read-time revalidation then trusting the lie forever.
5187 // Serve the dead-grant verdict and probe nothing; this covers the
5188 // manual "Check now" too. Only the reconnect mint, which rewrites
5189 // `provider_state` wholesale, re-opens probing. Nothing is written:
5190 // a buried `expired` verdict (e.g. a failing tool sync landing after
5191 // the recorder) is already re-derived on every read through
5192 // `presentedLastHealth`, so plain row reads agree with what this
5193 // serves — and a repair write here could observe a pre-reconnect
5194 // dead grant, pass the verdict CAS inside one SQLite `updated_at`
5195 // second, and stamp the OLD grant's expired verdict onto the freshly
5196 // reconnected row.
5197 // The verdict this check replaces, for the flip attributes on the
5198 // span (`previous_status` / `changed`). Read once, before any path
5199 // can write, so every exit annotates against the same baseline.
5200 const previous = presentedLastHealth(connectionRow);
5201 const reauthState = oauthReauthRequiredFromProviderState(connectionRow.provider_state);
5202 if (reauthState !== null) {
5203 const result = deadGrantVerdict(reauthState, connectionRow);
5204 yield* annotateHealthVerdict("dead_grant", result, previous);
5205 return result;
5206 }
5207 if (options?.ifStaleMs !== undefined) {
5208 const cached = Option.getOrNull(decodeLastHealth(connectionRow.last_health));
5209 if (cached && Date.now() - cached.checkedAt < options.ifStaleMs) {
5210 yield* annotateHealthVerdict("cache", cached, previous);
5211 return cached;
5212 }
5213 }
5214 const integrationRow = yield* findIntegrationRow(ref.integration);
5215 if (!integrationRow) {
5216 return yield* new IntegrationNotFoundError({ slug: ref.integration });
5217 }

Callers 1

createExecutorFunction · 0.85

Calls 15

isToolSyncHealthFunction · 0.90
findConnectionRowFunction · 0.85
presentedLastHealthFunction · 0.85
deadGrantVerdictFunction · 0.85
annotateHealthVerdictFunction · 0.85
findIntegrationRowFunction · 0.85
unknownHealthFunction · 0.85
healthProbeGateKeyFunction · 0.85
persistProbeHealthResultFunction · 0.85

Tested by

no test coverage detected