fix(relay): make Telegram broker pairing and reconnects resilient#59
Merged
Conversation
e8f93de to
b0d6563
Compare
There was a problem hiding this comment.
Pull request overview
This PR improves the resilience of the Telegram relay broker/client interaction by making pairing links retryable during transient Pi connectivity issues, rehydrating route bindings from persisted state after reconnects, and adding broker socket reconnect + route resync behavior so Telegram commands keep routing correctly across broker restarts.
Changes:
- Prevents consuming Telegram pending pairings until after successful local approval and client availability checks, allowing users to retry valid links.
- Hydrates broker-registered routes with persisted Telegram binding metadata when the client route registration is stale/missing binding details.
- Adds broker socket reconnect/backoff and route resync logic, plus clears stale local status warnings after recovery.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/relay/telegram-route-binding.test.ts | Adds unit coverage for persisted Telegram binding hydration behavior. |
| tests/broker-process.test.ts | Adds regression test ensuring broker hydrates stale route registrations from persisted bindings. |
| tests/broker-namespace.test.ts | Adds reconnect/resync test coverage for broker socket recreation scenarios. |
| extensions/relay/runtime/extension-runtime.ts | Adds clearLocalStatus wiring and clears lifecycle warnings after successful recovery. |
| extensions/relay/core/types.ts | Extends SessionRouteActions with optional clearLocalStatus. |
| extensions/relay/broker/tunnel-runtime.ts | Implements reconnect scheduling/backoff and resyncs registered routes after reconnect. |
| extensions/relay/broker/telegram-route-binding.ts | Introduces helper to hydrate routes with persisted Telegram binding metadata. |
| extensions/relay/broker/process.js | Makes Telegram pairing retryable and hydrates incoming route registrations with persisted bindings. |
| extensions/relay/adapters/telegram/runtime.ts | Clears binding-authority local status when state is healthy again. |
| extensions/relay/adapters/slack/runtime.ts | Clears binding-authority local status when delivery is authorized again. |
| extensions/relay/adapters/discord/runtime.ts | Clears binding-authority local status when delivery is authorized again. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
extensions/relay/adapters/slack/runtime.ts:182
relay-binding-authoritylocal status is only cleared when an active binding is returned. If the previous call set a state-unavailable warning, then later outcomes likerevoked/moved/missingwill leave that stale warning visible even though the state is now readable. Consider clearingrelay-binding-authorityfor any outcome whereoutcome.kind !== "state-unavailable"(e.g., before therevoked/moved/...cleanup or as a finalelsebranch).
if (authorityOutcomeAllowsDelivery(outcome) && "status" in outcome.binding) {
route.actions.clearLocalStatus?.("relay-binding-authority");
return outcome.binding;
}
if (outcome.kind === "state-unavailable") route.actions.setLocalStatus?.("relay-binding-authority", bindingAuthorityDiagnostic(outcome) ?? "Relay state is unavailable; protected messenger delivery was suppressed.");
if (outcome.kind === "revoked" || outcome.kind === "moved" || outcome.kind === "state-unavailable") {
this.ownedBindingSessionKeys.delete(route.sessionKey);
this.recentBindingBySessionKey.delete(route.sessionKey);
}
return undefined;
extensions/relay/adapters/discord/runtime.ts:144
relay-binding-authoritylocal status is cleared only when an active binding is returned. If a prior call set the state-unavailable warning, subsequent non-state-unavailableoutcomes (e.g.revoked,moved,missing) will keep the stale warning even though the state has recovered. Consider clearingrelay-binding-authoritywheneveroutcome.kind !== "state-unavailable"(before returning/cleanup).
if (authorityOutcomeAllowsDelivery(outcome) && "status" in outcome.binding) {
route.actions.clearLocalStatus?.("relay-binding-authority");
return outcome.binding;
}
if (outcome.kind === "state-unavailable") route.actions.setLocalStatus?.("relay-binding-authority", bindingAuthorityDiagnostic(outcome) ?? "Relay state is unavailable; protected messenger delivery was suppressed.");
if (outcome.kind === "revoked" || outcome.kind === "moved" || outcome.kind === "state-unavailable") this.recentBindingBySessionKey.delete(route.sessionKey);
return undefined;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/progress quietkeep working after broker/client reconnects.Validation
npm run typechecknpm test -- tests/broker-namespace.test.ts tests/broker-process.test.ts tests/relay/telegram-route-binding.test.ts tests/integration.test.tsnpx vitest run --testTimeout=15000Live verification