Skip to content

Commit 3d8a31d

Browse files
fix(agents): defer GitHub credential lookup until session open
1 parent a8bd4ce commit 3d8a31d

5 files changed

Lines changed: 41 additions & 13 deletions

File tree

‎apps/server/src/orchestration-v2/CheckpointRollbackService.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ export const layer: Layer.Layer<
241241
const resolvedRuntimePolicy = yield* runtimePolicy.resolve({
242242
thread: projection.thread,
243243
modelSelection,
244+
includeEnvironment: true,
244245
});
245246
const existingSession = projection.providerSessions.find(
246247
(candidate) => candidate.id === providerThread.providerSessionId,

‎apps/server/src/orchestration-v2/ProviderTurnStartService.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ export const layer: Layer.Layer<
516516
const resolvedRuntimePolicy = yield* runtimePolicy.resolve({
517517
thread: projection.thread,
518518
modelSelection: run.modelSelection,
519+
includeEnvironment: true,
519520
});
520521
const existingSessionProjection = projection.providerSessions.find(
521522
(candidate) => candidate.id === providerSessionId,

‎apps/server/src/orchestration-v2/RuntimePolicy.test.ts‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ it.layer(layerTest)("RuntimePolicyV2", (it) => {
157157
});
158158

159159
const tokenReads: Array<string | null | undefined> = [];
160+
const repositoryReads: Array<string> = [];
160161
const identityFor = (owner: string, host = "github.com") => ({
161162
canonicalKey: `${host}/${owner}/web`,
162163
locator: {
@@ -173,11 +174,12 @@ const layerWithAccounts = layerTest.pipe(
173174
Layer.mergeAll(
174175
Layer.mock(RepositoryIdentityResolver.RepositoryIdentityResolver)({
175176
resolve: (cwd) =>
176-
Effect.succeed(
177-
cwd === "/enterprise-worktree"
177+
Effect.sync(() => {
178+
repositoryReads.push(cwd);
179+
return cwd === "/enterprise-worktree"
178180
? identityFor("acme", "github.acme-corp.example")
179-
: identityFor(cwd === "/project-worktree" ? "acme" : "someone"),
180-
),
181+
: identityFor(cwd === "/project-worktree" ? "acme" : "someone");
182+
}),
181183
}),
182184
Layer.mock(GitHubCredentials.GitHubCredentials)({
183185
accountFor: (_host, repository) =>
@@ -199,22 +201,34 @@ const layerWithAccounts = layerTest.pipe(
199201
);
200202

201203
it.layer(layerWithAccounts)("RuntimePolicyV2 with GitHub accounts", (it) => {
202-
it.effect("hands the agent the token of the account its repository reads as", () =>
204+
it.effect("resolves repository credentials only when opening a provider session", () =>
203205
Effect.gen(function* () {
204206
const policy = yield* RuntimePolicy.RuntimePolicyV2;
205207
const now = yield* DateTime.now;
206-
const company = yield* policy.resolve({
208+
const input = {
207209
thread: makeThread({ now, worktreePath: "/project-worktree" }),
208210
modelSelection,
211+
};
212+
const dispatch = yield* policy.resolve(input);
213+
assert.equal(dispatch.cwd, "/project-worktree");
214+
assert.deepEqual(repositoryReads, []);
215+
assert.deepEqual(tokenReads, []);
216+
assert.isUndefined(dispatch.environment);
217+
218+
const company = yield* policy.resolve({
219+
...input,
220+
includeEnvironment: true,
209221
});
210222
assert.deepEqual(ProviderAdapter.runtimePolicyEnvironment(company), {
211223
GH_TOKEN: "work-token",
212224
});
213225
assert.notInclude(JSON.stringify(company), "work-token");
226+
assert.deepEqual(repositoryReads, ["/project-worktree"]);
214227

215228
const personal = yield* policy.resolve({
216229
thread: makeThread({ now, worktreePath: null }),
217230
modelSelection,
231+
includeEnvironment: true,
218232
});
219233
assert.isUndefined(personal.environment);
220234
assert.deepEqual(tokenReads, ["acme/web"]);
@@ -224,6 +238,7 @@ it.layer(layerWithAccounts)("RuntimePolicyV2 with GitHub accounts", (it) => {
224238
const enterprise = yield* policy.resolve({
225239
thread: makeThread({ now, worktreePath: "/enterprise-worktree" }),
226240
modelSelection,
241+
includeEnvironment: true,
227242
});
228243
assert.isUndefined(enterprise.environment);
229244
assert.deepEqual(tokenReads, ["acme/web"]);

‎apps/server/src/orchestration-v2/RuntimePolicy.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface RuntimePolicyV2Shape {
4646
readonly resolve: (input: {
4747
readonly thread: OrchestrationV2AppThread;
4848
readonly modelSelection: ModelSelection;
49+
readonly includeEnvironment?: boolean;
4950
}) => Effect.Effect<ProviderAdapter.ProviderAdapterV2RuntimePolicy, RuntimePolicyV2Error>;
5051
}
5152

@@ -129,7 +130,7 @@ export const layerFromProjectStore: Layer.Layer<
129130
}),
130131
),
131132
));
132-
const environment = yield* workspaceEnvironment(cwd);
133+
const environment = input.includeEnvironment ? yield* workspaceEnvironment(cwd) : {};
133134
return ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
134135
runtimeMode: providerRuntimeMode(input.thread.runtimeMode, supportedRuntimeModes),
135136
interactionMode: input.thread.interactionMode,

‎docs/user/source-control.md‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,23 @@ to remove the saved rule. **Mine** and **Reviewing** use the accounts selected f
3636
On mobile, host and owner choices are under **Settings → Source control → GitHub accounts**;
3737
select a project in Settings for its repository override.
3838

39+
These rules apply to T3 Code's GitHub API reads and writes. Git checkout, fetch, and push still
40+
use Git's configured credential helper or SSH credentials.
41+
42+
Update the server and every client connected to it before using owner or repository rules.
43+
Older clients can erase these rules when changing a host's account. Newer clients connected to
44+
older servers may display rules that the server ignores.
45+
3946
Agents using Codex, Claude, Grok, Antigravity, OpenCode 1.x, Pi, Muse, or a registry ACP agent receive
40-
the selected account's token as `GH_TOKEN` for github.com and GHE.com. Claude applies changes before
41-
the next user turn; if background work is still running, finish it or stop the thread first. Restart
42-
other agents' sessions after changing an account. Cursor, OpenCode 2.x, and externally hosted
43-
OpenCode servers keep their server process's credentials. On GitHub Enterprise Server, agents keep
44-
using `gh`'s host-specific login. A saved token or environment token takes precedence over account
45-
choices for T3 Code's GitHub requests; a host turned off stays off either way.
47+
the selected `gh` account's token as `GH_TOKEN` for github.com and GHE.com when no saved or
48+
environment token takes precedence. A token saved in Settings suppresses this override; agents
49+
retain their own inherited environment or `gh` credentials instead of receiving the saved token.
50+
Claude applies changes before the next user turn; if background work is still running, finish it
51+
or stop the thread first. Restart other agents' sessions after changing an account. Cursor,
52+
OpenCode 2.x, and externally hosted OpenCode servers keep their server process's credentials.
53+
On GitHub Enterprise Server, agents keep using `gh`'s host-specific login. A saved token or
54+
environment token takes precedence over account choices for T3 Code's GitHub requests; a host
55+
turned off stays off either way.
4656

4757
For GitHub Enterprise, sign in with `gh auth login --hostname YOUR_HOST`. T3 Code treats a
4858
custom server name as GitHub once it has a credential for that host.

0 commit comments

Comments
 (0)