fix(server): gh credential lookups no longer leak D-Bus daemons#23824

open2
main
fix/issue-23603
opened19d agobyJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 12h ago

Problem

On Linux hosts without a session bus, opening a project can make gh auth token and account discovery autolaunch a new D-Bus daemon for each keyring lookup. These daemons survive the command and accumulate until the host exhausts resources.

Change

Share a guard between GitHub credential retrieval and account discovery that disables gh's bus autolaunch when no configured or discoverable session bus exists. Preserve existing bus addresses and per-command environment overrides.

Preserves HelixNebula's fix from #23549, including author credit, with a linear trailing-newline scan.

Scope and approval

Fixes #23603

Triaged bug via the automated issue flow. Server-only process-environment change; no client, wire-contract, settings, or persisted-data changes.

Verification

  • Red first: the credential regression test in commit 9a1b6f67e5 failed on main with expected undefined to be 'disabled:'; it passes with the fix.
  • GitHub server package: 11 files, 241 tests passed.
  • Final vp run check:changed: exit 0; format, lint, knip, GraphQL generation, affected-package typechecks, and 45 focused tests passed.
  • Three rounds of independent Codex and Claude reviews found no concrete bugs. Credential-surface routing remains for the PR gates.

Runtime transcript: Ubuntu Linux/Xvfb, real gh 2.97.0, real development app. Baseline 22840ab943 and fixed 0dd6c9fdfe. In a mount/PID namespace with /run/user hidden and the bus address unset, added a local project with remote git@github-hn:owner/repo.git through the app.

Runtimegh operationsD-Bus daemon count
Main, missing busProject credential lookup2 → 4; both new daemons survived gh exit
Fixed, missing busRepeated token lookup and account discovery2 → 2
Fixed, configured busToken lookup and account discovery2 → 2

The fixed app's command log recorded:

text
1gh auth token --hostname github-hn | bus=disabled:
2gh auth token --hostname github.com | bus=disabled:
3gh --version | bus=disabled:
4gh auth status --json hosts | bus=disabled:

Repeated missing-bus calls retained disabled:. With a configured bus, all four operations retained unix:path=/run/user/1000/bus. Supplemental direct gh token lookup for github.com exited 0 with output suppressed; the alias lookup exited 1. No tokens were recorded. Stopping the baseline namespace removed its two leaked daemons.

The render fixture matrix is empty (0/0): this backend fix has no visible render paths. Actual Windows/WSL and Secret Service-only credential login remain unverified. Credentials reachable only through a Secret Service activated by an autolaunched bus can become unavailable; existing configured buses and gh's other credential sources remain available. Calls to gh made indirectly by git credential helpers are outside this change.

Written with Claude Opus 5.5 and GPT-6.1-Sol in T3 Code through the Codex harness.

Fixes pingdotgg/t3code#23603

Checks

22 successful · 8 skipped · 1 neutral
All checks passed
0dd6c9f

Added 2 commits

  • fix(github): gh no longer leaks a dbus-daemon per credential lookup0dd6c9f
  • test(github): reproduce #23603 gh autolaunching a D-Bus session bus9a1b6f6
Synced from GitHub

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — This is a focused server-side fix that prevents D-Bus daemon leaks during GitHub CLI credential and account discovery, while changing credential availability in no-session-bus environments. Because it directly affects authentication and keyring-backed credential retrieval, the change warrants human review.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ProviderMetricMain baselineThis PRImpactPR ceiling
CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
CodexLive turn messages220 (0.0%)8✅
ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
ClaudeLive turn messages220 (0.0%)8✅

Baseline: 22840ab · PR result: 0dd6c9f · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The PR adds a process service that checks D-Bus availability before running GitHub CLI commands. GitHub credential lookup and CLI discovery now use this service.

Changes: GitHub CLI D-Bus handling

Layer / File(s)Summary
D-Bus process environment handling
packages/source-control-github/src/server/gitHubCliProcess.ts, packages/source-control-github/src/server/gitHubCliProcess.test.ts
makeGhProcess checks the effective D-Bus address. When no usable bus is discoverable on a supported platform, it sets DBUS_SESSION_BUS_ADDRESS to disabled:. Tests cover host and spawn addresses, bus discovery, filesystem errors, and platform behavior.
Credential and discovery integration
packages/source-control-github/src/server/GitHubCredentials.ts, packages/source-control-github/src/server/GitHubSourceControlProvider.ts, packages/source-control-github/src/server/GitHubCredentials.test.ts, packages/source-control-github/src/server/GitHubRest.test.ts
Credential lookup and CLI discovery now use makeGhProcess. Credential tests verify the spawned environment, and the REST credential test setup provides a no-op filesystem layer.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

mermaid
1sequenceDiagram
2 participant GitHubCredentials
3 participant makeGhProcess
4 participant FileSystem
5 participant HostProcess
6 GitHubCredentials->>makeGhProcess: Request GitHub CLI process
7 makeGhProcess->>FileSystem: Check for a session bus
8 FileSystem-->>makeGhProcess: Return bus or session-file result
9 makeGhProcess->>HostProcess: Run gh with the selected environment
Merge Risk: External image Minimal · up to 0dd6c

The change is mergeable after normal checks. No actionable risk remains established for GitHub credential lookup or CLI discovery.

Pre-merge checks: Passed 4

Check nameStatusExplanation
Title checkPassedThe title clearly and concisely describes the main fix: preventing D-Bus daemon leaks during GitHub credential lookups.
Linked Issues checkPassedIssue #23603 requires background gh token lookups and account discovery to avoid D-Bus autolaunch when no session bus exists. makeGhProcess checks the effective address, the runtime bus socket, an…
Out of Scope Changes checkPassedThe changes stay within issue #23603. The new process service prevents D-Bus autolaunch for GitHub CLI calls. The credential and discovery integrations route the affected calls through that service. T…
Description checkPassedThe description covers the required Problem, Change, Scope and approval, and Verification sections. It explains the issue and expected behavior, describes the server-side fix and its scope, links the …
Full details: Linked Issues check

Explanation

Issue #23603 requires background gh token lookups and account discovery to avoid D-Bus autolaunch when no session bus exists. makeGhProcess checks the effective address, the runtime bus socket, and dbus-session, then sets DBUS_SESSION_BUS_ADDRESS to disabled: only when no bus is configured or discoverable. It preserves explicit and discoverable addresses. GitHubCredentials and GitHubSourceControlProvider use this process service. Tests cover missing, configured, discoverable, overridden, Darwin, and filesystem-error cases. The supplied validation reports the credential regression test and package checks passing.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #23603. The new process service prevents D-Bus autolaunch for GitHub CLI calls. The credential and discovery integrations route the affected calls through that service. The added tests and test-layer updates support this behavior. No unrelated client, wire-contract, settings, or persisted-data changes are evidenced.

Full details: Description check

Explanation

The description covers the required Problem, Change, Scope and approval, and Verification sections. It explains the issue and expected behavior, describes the server-side fix and its scope, links the tracked issue, and reports focused tests, runtime checks, and unverified cases.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
ℹ️ Recent review info

⚙️ Run configuration

📥 Commits

Reviewing files that changed from the base of the PR and between 22840ab943b8418744b48223411e46ba4fdcef1a and 0dd6c9fdfe5802104768fb96b48c64a89dbdcd8f.

📒 Files selected for processing: 6

  • packages/source-control-github/src/server/GitHubCredentials.test.ts
  • packages/source-control-github/src/server/GitHubCredentials.ts
  • packages/source-control-github/src/server/GitHubRest.test.ts
  • packages/source-control-github/src/server/GitHubSourceControlProvider.ts
  • packages/source-control-github/src/server/gitHubCliProcess.test.ts
  • packages/source-control-github/src/server/gitHubCliProcess.ts

Limit details: You’ve used all 10 included reviews currently available.