Skip to content

fix(github): managed GitHub identity stays expired after a refresh fails during a network outage - #187495

Open
yutouchino wants to merge 3 commits into
openclaw:mainfrom
yutouchino:fix/github-oauth-refresh-network-outage
Open

yutouchino wants to merge 3 commits into
openclaw:mainfrom
yutouchino:fix/github-oauth-refresh-network-outage

Conversation

@yutouchino

Copy link
Copy Markdown

Closes #187494
Related: #181262, #184774

What Problem This Solves

Fixes: a managed GitHub OAuth identity stays expired until someone reconnects it when its scheduled refresh runs during a DNS or network outage.

User Impact

User impact: managed GitHub identities recover on their own after a network outage. When a refresh genuinely cannot be retried safely, Agent Settings shows "Expired — reconnect required" instead of "Refresh failed — retrying", and the Gateway log says to reconnect.

Why This Change Was Made

GitHub refresh tokens are single-use, so a refresh whose outcome is unknown must keep its claim and not be replayed. But the GitHub client marked every fetch() rejection as dispatched, including DNS lookup and TCP connect failures that never write the request. A single refresh during an outage therefore fenced a still-valid grant permanently.

  • The client now treats a rejection as not dispatched only when its cause chain proves the connection never opened: a DNS failure (getaddrinfo), a connect failure (connect), or undici's connect timeout, with every branch proven for multi-address attempts. The claim is released, and maintenance retries. Resets after writing, closed sockets, aborts, timeouts and coded wrappers stay fenced exactly as before.
  • Every failed refresh now logs either "will retry" or "reconnect GitHub".
  • A failure that keeps its claim is reported as expired (reconnect required). Each claimed attempt now starts without the previous failure, so "claim + failure" always means a stuck grant rather than an in-flight retry.
  • docs/gateway/config-tools/github-identity.md now says which refresh failures retry and which need reconnection.

The pre-connect predicate mirrors the private one in src/infra/delivery-recovery.shared.ts. I left delivery recovery untouched to keep this PR focused; happy to consolidate if maintainers prefer.

Evidence

  • Observed in production: see the linked issue. One refresh during a 4.7-hour outage left the System identity unusable for 12+ hours, with status reading "Refresh failed — retrying".
  • Focused tests on this branch (base 011a170): 12 files, 218 tests pass (github-oauth-client, github-oauth-records, github-tool-identity, github-identity-status-tool, github-oauth-lifecycle (+helpers, scheduling), github-personal-publication*, tools-github, delivery-recovery.shared).
  • New tests:
    • six pre-connect shapes (ENOTFOUND, EAI_AGAIN, ECONNREFUSED, ENETUNREACH, UND_ERR_CONNECT_TIMEOUT, all-address aggregate) become before-dispatch and recoverable;
    • six ambiguous shapes (reset after write, closed socket, timeout, refusal without a syscall, coded wrapper, mixed aggregate) stay unknown;
    • a lifecycle regression with the real client: DNS failure releases the claim, and the next refresh succeeds. A reset after write keeps the claim, warns to reconnect, and makes no further request;
    • status projection for released, in-flight and stuck records.
  • Negative controls: without the client change, all 7 new retry tests fail. Without the status change, both new status assertions fail.
  • Error shapes were checked against real Node 26.12.1 fetch (DNS, refused port, blackhole connect timeout at ~10.5 s, multi-address refusal, reset after write).
  • oxlint, oxfmt, format:docs:check, tsgo:core and tsgo:core:test are clean.
  • Gap: pnpm install could not run offline against this base's lockfile. Tests used the previous install, and the only lockfile delta is @noble/hashes in packages/gateway-client, which these tests do not load. Proxy setups were not exercised: connect failures to a proxy are also classified as pre-dispatch, while proxy CONNECT rejections (for example 503) still stay fenced.

This touches OAuth credential refresh, so it needs /allow-security-sensitive-change.

A GitHub refresh token is single-use, so a refresh whose outcome is unknown
keeps its claim and is never retried automatically. The client marked every
fetch rejection as dispatched, including DNS and TCP connect failures that
never write the request. One refresh during an internet outage therefore left
the managed identity stuck with an expired access token until a manual
reconnect, and nothing was logged.

- Classify fetch rejections whose cause chain proves a failed DNS lookup,
  connect or undici connect timeout (every address, for aggregates) as
  before-dispatch/not-attempted, so the claim is released and maintenance
  retries. Resets, closed sockets, aborts and coded wrappers stay unknown.
- Share the failed-refresh settlement and warn on every failure: "will retry"
  when the claim is released, "reconnect GitHub" when it is retained.
A refresh whose outcome is unknown keeps its claim and is never retried,
but the identity status still reported "failed", which the Control UI labels
"Refresh failed — retrying".

- Report a failed refresh that kept its claim as "expired" (labelled
  "Expired — reconnect required"); a released failure stays "failed".
- Start each claimed attempt without the previous failure, so a claim plus
  a failure always means a stuck grant rather than an in-flight retry.
- Document which refresh failures retry and which need reconnection.
@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Maintainer security review required

This external contributor PR changes sensitive security components. A maintainer must review these changes before merging.

Current SHA: 5521c2859df2b75a68cfe76a2ffe8112b7a1053e

These sensitive security changes were made:

  • src/agents/github-oauth-client.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/github-oauth-records.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/gateway/github-oauth-lifecycle-helpers.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/github-oauth-lifecycle.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

After reviewing the changes, post a new PR comment containing only approval commands, each on its own line:

/allow-security-sensitive-change

A later push requires a fresh approval comment.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head a0ff20535dc550834a538bb2048bbafb0f38fdad, but the PR head is now 5521c2859df2b75a68cfe76a2ffe8112b7a1053e. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (1 earlier review cycle)
  • reviewed 2026-10-29T08:35:25.137Z sha a0ff205 :: needs real behavior proof before merge. :: [P2] Share the existing pre-connect leaf classifier | [P2] Remove the new unchecked error-shape assertions | [P2] Prune the retired closed-mock baseline entry

Document the non-null object invariants for the two unknown-property reads. Prune the obsolete closed-mock exemption now that the identity test preserves real OAuth-record exports.
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Nov 1, 2026

This branch has not been deployed

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. security-review-required security-sensitive-changed size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Managed GitHub OAuth identity stays expired after a refresh fails during a network outage

1 participant