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

Function connectionCheckHealth

packages/core/sdk/src/executor.ts:5042–5207  ·  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

5040 );
5041
5042 const connectionCheckHealth = (
5043 ref: ConnectionRef,
5044 options?: {
5045 /** Skip the probe and return the persisted verdict when it is younger
5046 * than this. The server owns the freshness decision so N open tabs
5047 * revalidating on load cannot stampede an upstream. Omit = always
5048 * probe (the manual "Check now"). */
5049 readonly ifStaleMs?: number;
5050 },
5051 ): Effect.Effect<
5052 HealthCheckResult,
5053 ConnectionNotFoundError | IntegrationNotFoundError | StorageFailure
5054 > =>
5055 Effect.gen(function* () {
5056 const connectionRow = yield* findConnectionRow(ref);
5057 if (!connectionRow) {
5058 return yield* new ConnectionNotFoundError({
5059 owner: ref.owner,
5060 integration: ref.integration,
5061 name: ref.name,
5062 });
5063 }
5064 // A recorded invalid_grant is the AS's standing verdict on this grant
5065 // (the refresh path's gate, applied to probing): a probe can still
5066 // pass on the access token's remaining lifetime, and persisting that
5067 // "healthy" would hide the required reconnect until the token finally
5068 // lapses — with read-time revalidation then trusting the lie forever.
5069 // Serve the dead-grant verdict and probe nothing; this covers the
5070 // manual "Check now" too. Only the reconnect mint, which rewrites
5071 // `provider_state` wholesale, re-opens probing. Nothing is written:
5072 // a buried `expired` verdict (e.g. a failing tool sync landing after
5073 // the recorder) is already re-derived on every read through
5074 // `presentedLastHealth`, so plain row reads agree with what this
5075 // serves — and a repair write here could observe a pre-reconnect
5076 // dead grant, pass the verdict CAS inside one SQLite `updated_at`
5077 // second, and stamp the OLD grant's expired verdict onto the freshly
5078 // reconnected row.
5079 // The verdict this check replaces, for the flip attributes on the
5080 // span (`previous_status` / `changed`). Read once, before any path
5081 // can write, so every exit annotates against the same baseline.
5082 const previous = presentedLastHealth(connectionRow);
5083 const reauthState = oauthReauthRequiredFromProviderState(connectionRow.provider_state);
5084 if (reauthState !== null) {
5085 const result = deadGrantVerdict(reauthState, connectionRow);
5086 yield* annotateHealthVerdict("dead_grant", result, previous);
5087 return result;
5088 }
5089 if (options?.ifStaleMs !== undefined) {
5090 const cached = Option.getOrNull(decodeLastHealth(connectionRow.last_health));
5091 if (cached && Date.now() - cached.checkedAt < options.ifStaleMs) {
5092 yield* annotateHealthVerdict("cache", cached, previous);
5093 return cached;
5094 }
5095 }
5096 const integrationRow = yield* findIntegrationRow(ref.integration);
5097 if (!integrationRow) {
5098 return yield* new IntegrationNotFoundError({ slug: ref.integration });
5099 }

Callers 1

createExecutorFunction · 0.85

Calls 15

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