Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Merge batch 11-05 i2410: #3161 (#3203)

0xken15b899e88565f4
diff --git a/backend/integration/superTabTeam.test.ts b/backend/integration/superTabTeam.test.ts
index 435a0570d..26951d07b 100644
--- a/backend/integration/superTabTeam.test.ts
+++ b/backend/integration/superTabTeam.test.ts
@@ -244,6 +244,42 @@ describe('a task a Team agent worked on', () => {
})
})
+// Huy's groupme, 2026-11-05 (task #3266): a Team account start for a repository the Harness GitHub App is not on failed
+// twice on its machine and suspended Claude there. The store reads the project's GitHub access first and refuses it at once.
+describe('a start whose account cannot reach the project repository', () => {
+ const withRepository = async (tab: string) => {
+ const state = await storedState(tab)
+ state.projects!.find(p => p.id === 'lead')!.repository = { machineId: 'owner-host', cwd: '/repo', repositoryUrl: 'https://github.com/acme/app' }
+ await saveState(tab, state)
+ }
+ const startOn = (asked: SuperTabStore, tab: string, conversationId: string) => asked.execute(owner, tab, { operationId: randomUUID(), command: { type: 'agent.start',
+ request: { conversationId, machineId: 'team-mac', engine: 'codex', name: 'Reviewer', cwd: '/team', worktree: false, requirements } } })
+ const starts = async (tab: string) => (await storedState(tab)).starts?.length ?? 0
+
+ it('is refused through the store before anything is queued, from the access it reads for that project', async () => {
+ const { tab, teamGroup } = await fixture()
+ await withRepository(tab)
+ const reach = vi.fn(async () => ({ state: 'not-installed' as const, repository: 'acme/app', installUrl: 'https://github.com/apps/harness/installations/new' }))
+ const asked = new SuperTabStore(db, Date.now, undefined, { repositoryReach: reach })
+ const before = await starts(tab)
+ await expect(startOn(asked, tab, teamGroup)).rejects.toMatchObject({ code: 'REPOSITORY_UNREACHABLE', status: 409,
+ message: expect.stringContaining('An owner of acme installs it (https://github.com/apps/harness/installations/new)') })
+ expect(reach).toHaveBeenCalledWith('prod', tab, 'lead', 'https://github.com/acme/app')
+ expect(await starts(tab)).toBe(before)
+ })
+
+ it('starts as before when the read fails, and reads nothing for a project with no GitHub repository', async () => {
+ const { tab, teamGroup } = await fixture()
+ const reach = vi.fn(async () => { throw new Error('GitHub did not answer') })
+ const asked = new SuperTabStore(db, Date.now, undefined, { repositoryReach: reach })
+ await expect(startOn(asked, tab, teamGroup)).resolves.toBeTruthy()
+ expect(reach).not.toHaveBeenCalled()
+ await withRepository(tab)
+ await expect(startOn(asked, tab, teamGroup)).resolves.toBeTruthy()
+ expect(reach).toHaveBeenCalledTimes(1)
+ })
+})
+
describe('a team session speaking in a Swarm', () => {
it('reads and posts as an agent on its own machine', async () => {
const f = await fixture()
diff --git a/backend/src/routes/superTabs.ts b/backend/src/routes/superTabs.ts
index ae2c06ef5..b3c0e4d5b 100644
--- a/backend/src/routes/superTabs.ts
+++ b/backend/src/routes/superTabs.ts
@@ -17,7 +17,8 @@ import { redisAutoJoinMemory } from '../superTabs/autoJoin.js'
import { redisReportMemory } from '../superTabs/machineReports.js'
import { routingPolicySaveSchema } from '../superTabs/routingPolicy.js'
import { nativeEventSchema, openNativeSchema } from '../superTabs/native.js'
-import { machineObservationSchema } from '../superTabs/machines.js'
+import { machineObservationSchema, teamAccountRequired } from '../superTabs/machines.js'
+import { repositoryReachOf } from '../superTabs/repositoryReach.js'
import { joinSwarmSchema, previewJoinSchema, saveSharingSchema } from '../superTabs/sharing.js'
import { holdReason } from '../superTabs/holdReason.js'
import { GitHubAppError } from '../github/app.js'
@@ -246,7 +247,7 @@ export const HOT_BODY_LIMIT = 128 * 1024
const updateRequired = (_req: unknown, reply: FastifyReply) => sendError(reply, UPDATE_REQUIRED.message, UPDATE_REQUIRED.code, UPDATE_REQUIRED.status)
/** The store this server runs on. Loaded only here: importing the bus opens its Redis connections. */
-async function productionStore(github: GitHubTokens | null): Promise<SuperTabStore> {
+async function productionStore(github: GitHubTokens | null, approvals: Approvals): Promise<SuperTabStore> {
const [bus, { announceSwarmDeliveries, announceSwarmTerminal }, { announceSwarmHostChanges }, { announceSwarmChanges }, { tellSessionViewers },
{ VoiceQuotaExceededError, voiceQuotaService }, { pickWavLang, transcribeWavWithDeepgram }] = await Promise.all([
import('../lib/bus.js'), import('../lib/swarmDeliveryPushes.js'), import('../lib/swarmHostPushes.js'), import('../lib/swarmClientPushes.js'),
@@ -263,6 +264,11 @@ async function productionStore(github: GitHubTokens | null): Promise<SuperTabSto
// A team account has no git login of its own: without the app it takes no teammates' work.
teamAccountsIdle: !github,
...(github ? { pushOrigin: projectPushOrigin(github.app), branchPushOrigin: projectBranchOrigin(github.app) } : {}),
+ // A start or assignment its account cannot reach the repository from is refused at once, by the read Project details
+ // shows (task #3266): the token endpoint below would refuse it on the machine, after the start was queued.
+ ...(github ? { repositoryReach: async (autonomousEnv: string, tabId: string, projectId: string, repositoryUrl: string) =>
+ repositoryReachOf(await projectGitHubAccess(github.app, repositoryUrl, { canApprove: false,
+ approved: async repository => !teamAccountRequired() || approvals.approved(autonomousEnv, tabId, projectId, repository) })) } : {}),
// Every server answers the quiet delivery poll from any server's full one, and tells the agent's machine of new work
// through whichever server holds its daemon socket (stability roadmap 2.4). Both only ever drop, never fail, on Redis.
polls: redisPollMemory(bus.pub),
@@ -311,7 +317,7 @@ export async function superTabRoutes(app: FastifyInstance, options: { store?: Su
throw new SuperTabError('GITHUB_REPOSITORY_NOT_APPROVED', `Nobody who can push to ${repository.fullName} has approved it for this project yet, `
+ 'so teammates\' agents get no access to it. Someone who can push to it approves it in Harness: Project details, GitHub access.', 403)
}
- const store = options.store ?? await productionStore(github)
+ const store = options.store ?? await productionStore(github, approvals)
// A rename in Machines reaches the Swarms the machine is in at once (MachineService.rename).
onMachineRenamed(rename => store.machineRenamed(rename))
// Another account's sign-in on a computer moves the computer's Swarm entries to it (computerMoves.ts).
diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.ts
index f686fee83..d43bc84c4 100644
--- a/backend/src/superTabs/commands.ts
+++ b/backend/src/superTabs/commands.ts
@@ -1,5 +1,6 @@
import { applyPushOrigin, failPushUnknown, failTeamWritten, hasStep, mainAccountMembers, markTeamWritten, mayName, requireNameable, requireTeamWrittenAccount, requireTeamWrittenMachine, TEAM_WRITTEN_REASON, TEAM_WRITTEN_STOP, teamWrittenTask } from './teamWritten.js'
import type { PushOrigin } from '../github/pushOrigin.js'
+import { requireRepositoryReach, unknownPushReason, type RepositoryReach } from './repositoryReach.js'
import { admitByRoom, admitMachineStart, noRepositoryStart, failOwnAccountTeamEntry, ownAccountTeamEntry, defaultProfileId, storedProfileId, BUDDY_WINDOWS_REFUSAL, refusesWindowsBuddy, buddyHomeFolder, buddyProjectsOn, SWARM_BUDDY_CAPABILITY, cleanupOverdue, dropIdleBuddyMachines, machineLimitReached, MACHINE_LIMIT_MESSAGE, NOT_SWARM_MACHINE, downSince, expireRemoval, expireRemovals, failTeamWork, machineContribution, machineOffline, machineSlots, contributedEngines, ownedMachine, productManagerOn, projectFolder, projectsOnMachine, requireTeamWork, teamMachineFor, teamAccountPool, teamPoolsOf, teamStartRequest, teamWorkCheck, movedToTeamAccount, type ContributedMachine } from './machines.js'
import { movableEntry } from './computerMoves.js'
import { agentDisplayName, assignAgentDisplayNames } from './agentNames.js'
@@ -591,6 +592,8 @@ export interface CommandContext {
machineVersions?: Record<string, string>
/** Who pushed the pull requests of a work.assign's or a Ready for review's task, read before the command (store.ts pushOriginFor). */
pushOrigin?: PushOrigin
+ /** Whether the Harness GitHub App reaches the project's repository, read before an agent.start or work.assign (store.ts repositoryReachFor). */
+ repositoryReach?: RepositoryReach
/** The person's role in the Swarm's Workspace, read by the store for invitations (workspaces.ts); absent outside a Workspace. */
workspaceRole?: WorkspaceRole
/** invite.create: the Workspace removed the account of the invited email, and the inviter's role cannot invite to the
@@ -1041,7 +1044,7 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
const pushedRefusal = (group: Conversation, worker: Agent) => {
marking(group, () => applyPushOrigin(state, group, context.pushOrigin))
if (onTeamAccount(state, worker) || ledProject(state, worker.id)?.id === groupProject(state, group).id) return
- if (context.pushOrigin === 'unknown') failPushUnknown()
+ if (context.pushOrigin === 'unknown') failPushUnknown(unknownPushReason(context.repositoryReach))
if (context.pushOrigin === 'team') failTeamWritten({ pushed: true })
}
/** A session already in the Swarm that a person's agent.add names joins [group] as conversation.agent adds one (security
@@ -2578,9 +2581,11 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
}
if (written) requireTeamWrittenMachine(state, startGroup, moved.machineId)
// A branch GitHub cannot place stays out of the main account too, unmarked, as it may yet read clean.
- else if (context.pushOrigin === 'unknown' && !teamAccountPool(state.machines?.find(m => m.machineId === moved.machineId))) failPushUnknown()
+ else if (context.pushOrigin === 'unknown' && !teamAccountPool(state.machines?.find(m => m.machineId === moved.machineId))) failPushUnknown(unknownPushReason(context.repositoryReach))
const request: AgentStartRequest = noRepositoryStart(state.machines?.find(m => m.machineId === moved.machineId), home,
written ? { ...moved, projectSettings: 'off' } : moved)
+ // Before it is queued: a machine that cannot get the app's token for it would fail it, and count that against its engine.
+ requireRepositoryReach(state, teamAccountPool(state.machines?.find(m => m.machineId === request.machineId)), grant.machineOwnerId, home, context.repositoryReach)
const pool = admitMachineStart(state, request, context.now, undefined, context.teamMachines, context.otherWorkspaceMachines)
// Off the Machines list, a teammate's project never runs: nothing there shows a privacy check (machines.ts).
if (!pool) requireTeamWork(state, request.machineId, grant.contributorId, home, context.now, context.teamMachines, context.otherWorkspaceMachines)
@@ -3649,6 +3654,7 @@ function applyCommandOnce(original: SuperTabState, actor: Actor, input: Command,
// And what the task needs to reach, where it runs (machineAccess.ts): an assignment is held to it as a start is.
const unreached = accessRefusal(state, worker.machineId, home, taskAccess(group))
if (unreached) failTeamWork(unreached)
+ requireRepositoryReach(state, onTeamAccount(state, worker), worker.machineOwnerId, home, context.repositoryReach)
// Team-written code runs only in a Team account, and a Team agent's work marks the task (teamWritten.ts, audit H2).
pushedRefusal(group, worker)
requireTeamWrittenAccount(state, group, worker)
diff --git a/backend/src/superTabs/engineHealth.test.ts b/backend/src/superTabs/engineHealth.test.ts
index 187ec1ec5..bf4327156 100644
--- a/backend/src/superTabs/engineHealth.test.ts
+++ b/backend/src/superTabs/engineHealth.test.ts
@@ -88,6 +88,22 @@ describe('an engine whose starts fail on a machine', () => {
expect(noteStartFailed(state, start(), NOW)).not.toBeNull()
})
+ // 11-05, Huy's groupme: two Team account starts could not get a token for a repository the app is not installed on, and
+ // Claude was suspended there for hours (task #3266).
+ it('is never suspended, Claude or Codex, by starts refused for want of access to the project repository', () => {
+ const reasons = ["This machine could not get a Harness GitHub App token for this project, so it was not prepared with its owner's own GitHub login either: The Harness GitHub App is not installed on ngochuy13/groupme. Ask an owner of ngochuy13 to install it.",
+ "This machine could not get a Harness GitHub App token for this project, so it was not prepared with its owner's own GitHub login either: Nobody who can push to ngochuy13/groupme has approved it for this project yet.",
+ 'This Harness server has no GitHub App, and a Harness Team account has no git login of its own, so it cannot fetch the project. Ask the server\'s administrator to set up the Harness GitHub App (docs/swarm-github-app.md).',
+ "Share a GitHub repository for this project before starting agents on another machine. Its lead can share its checkout's GitHub origin with the project.repository command, then start again."]
+ for (const engine of ['claude', 'codex']) {
+ const pool = machine(), state = stateWith(pool)
+ for (const error of reasons) for (let i = 0; i < 3; i++) expect(noteStartFailed(state, start({ engine }, error), NOW)).toBeNull()
+ expect(pool.engineFailures).toBeUndefined()
+ expect(suspendedEngines(pool, NOW)).toEqual({})
+ expect(engineUnusable(pool, engine, NOW)).toBeNull()
+ }
+ })
+
it('says so once per suspension, never on a later failed start or report', () => {
const pool = machine(), state = stateWith(pool)
noteStartFailed(state, start(), NOW)
diff --git a/backend/src/superTabs/repositoryReach.test.ts b/backend/src/superTabs/repositoryReach.test.ts
new file mode 100644
index 000000000..418cb68c8
--- /dev/null
+++ b/backend/src/superTabs/repositoryReach.test.ts
@@ -0,0 +1,128 @@
+import { describe, expect, it } from 'vitest'
+import { applyCommand, type Command, type CommandContext } from './commands.js'
+import type { ContributedMachine } from './machines.js'
+import { createSuperTab, SuperTabError, type Actor, type AgentConfiguration, type SuperTabState } from './model.js'
+import { REPOSITORY_UNREACHABLE, repositoryReachOf, type RepositoryReach } from './repositoryReach.js'
+import { TEAM_WRITTEN_WORK } from './teamWritten.js'
+
+// 11-05, Huy's groupme (task #3266): the Harness GitHub App was not on ngochuy13/groupme, so a Reviewer in the Mac's Team
+// account, which reaches GitHub only through the app, failed to start twice and Claude was suspended there. Such a start
+// is refused at once, naming what the owner must install or approve.
+const NOW = 50_000_000
+const owner: Extract<Actor, { kind: 'person' }> = { kind: 'person', userId: 'owner', email: '[email protected]' }
+const config: AgentConfiguration = { engine: 'claude', model: 'fixture-model', effort: 'high', contextWindow: 200000, engineVersion: 'fixture' }
+const requirements = { memoryBytes: 0, diskBytes: 0, maxCpuPercent: 100, tools: [], devices: [], quotaRequired: false }
+const resources = { cpuPercent: 1, memoryTotalBytes: 8, memoryUsedBytes: 1, diskFreeBytes: 8, diskTotalBytes: 8, projectDiskFreeBytes: 8,
+ deviceType: null, chip: null, os: null, gpuPercent: null }
+const reading = (sessionKind: 'team' | 'computer') => ({ generation: 'g1', receivedAt: NOW, sessionKind, resources, tools: {}, quotas: [], runningHarnessIds: [], stoppedHarnessIds: [],
+ ...(sessionKind === 'team' ? { privacy: { mode: 'account' as const, passed: true as const, checkedAt: NOW - 1000, seenAt: NOW - 1000 } } : {}) })
+const INSTALL = 'https://github.com/apps/harness-for-autonomous/installations/new'
+const notInstalled: RepositoryReach = { state: 'not-installed', repository: 'ngochuy13/groupme', installUrl: INSTALL }
+const notApproved: RepositoryReach = { state: 'not-approved', repository: 'ngochuy13/groupme' }
+
+function swarm() {
+ let state: SuperTabState = createSuperTab('tab', 'Pilot', { id: 'owner', email: owner.email }, 'prod')
+ let sequence = 0
+ const generation = state.people.find(p => p.id === 'owner')!.generation
+ const pool = (machineId: string, sessionKind: 'team' | 'computer', extra: Partial<ContributedMachine> = {}): ContributedMachine => ({ machineId, name: machineId, contributorId: 'owner',
+ membershipGeneration: generation, generation: 'g1', cwd: '/swarm', scope: 'swarm', engines: ['claude'], maxAgents: 4, paused: false, observation: reading(sessionKind), ...extra })
+ state.machines = [pool('mac', 'computer'), pool('mac-team', 'team', { hostMachineId: 'mac' })]
+ state.projects!.find(p => p.id === 'lead')!.repository = { machineId: 'owner-host', cwd: '/repo', repositoryUrl: 'https://github.com/ngochuy13/groupme' }
+ const run = (command: Command, context: Partial<CommandContext> = {}) => {
+ const effects = applyCommand(state, owner, command, { now: NOW, operationId: `op-${++sequence}`, teamMachines: ['mac-team'],
+ contribution: { machineOwnerId: 'owner', contributorId: 'owner', hostGrant: null }, ...context })
+ state = effects.state
+ return effects
+ }
+ const member = (id: string, machineId: string, machineOwnerId = 'owner') => {
+ state.agents.push({ id, machineId, harnessId: `harness-${id}`, projectId: 'lead', machineOwnerId, contributorId: 'owner',
+ membershipGeneration: generation, hostGrant: null, name: id, configuration: config })
+ return id
+ }
+ const group = (extra: Partial<Extract<Command, { type: 'conversation.create' }>> = {}) => String(run({ type: 'conversation.create', projectId: 'lead', title: 'Work', brief: 'Build it.',
+ checks: [], ...extra }).result.conversationId)
+ const start = (conversationId: string, machineId: string, context: Partial<CommandContext> = {}) => run({ type: 'agent.start',
+ request: { conversationId, machineId, engine: 'claude', name: 'Reviewer', cwd: '/swarm/lead', worktree: true, requirements } }, context)
+ return { run, group, member, start, get state() { return state } }
+}
+const refused = (body: () => unknown): SuperTabError | null => {
+ try { body(); return null } catch (error) { if (error instanceof SuperTabError) return error; throw error }
+}
+
+describe('a start whose account cannot reach the project repository', () => {
+ it('is refused at once in a Team account where the app is not installed, naming the repository and the install, and nothing is queued', () => {
+ const f = swarm(), review = f.group({ reviewOf: f.group(), step: 'Review' })
+ const error = refused(() => f.start(review, 'mac-team', { repositoryReach: notInstalled }))
+ expect(error?.code).toBe(REPOSITORY_UNREACHABLE)
+ expect(error?.status).toBe(409)
+ expect(error?.message).toBe('An agent in this account reaches ngochuy13/groupme only through the Harness GitHub App, which is not installed on it. '
+ + `An owner of ngochuy13 installs it (${INSTALL}), then start or assign it again.`)
+ expect(f.state.starts ?? []).toEqual([])
+ })
+
+ it('says to approve it when the app is installed but nobody approved the repository for this project', () => {
+ const f = swarm(), review = f.group({ reviewOf: f.group(), step: 'Review' })
+ const error = refused(() => f.start(review, 'mac-team', { repositoryReach: notApproved }))
+ expect(error?.code).toBe(REPOSITORY_UNREACHABLE)
+ expect(error?.message).toBe('An agent in this account reaches ngochuy13/groupme only through the Harness GitHub App, and nobody who can push to it '
+ + 'has approved it for this project. Someone who can push to it approves it in Harness (Project details, GitHub access), then start or assign it again.')
+ })
+
+ it('is refused where a start on the Mac moves into its Team account', () => {
+ const f = swarm(), task = f.group()
+ f.run({ type: 'work.assign', conversationId: task, agentId: f.member('team-builder', 'mac-team') })
+ const review = f.group({ reviewOf: task, step: 'Review' })
+ expect(refused(() => f.start(review, 'mac', { repositoryReach: notInstalled }))?.code).toBe(REPOSITORY_UNREACHABLE)
+ })
+
+ it('starts as before when the app covers it, when the read could not say, or with no read', () => {
+ for (const repositoryReach of [{ state: 'covered', repository: 'ngochuy13/groupme' }, { state: 'unknown', repository: 'ngochuy13/groupme' }, undefined] as const) {
+ const f = swarm(), review = f.group({ reviewOf: f.group(), step: 'Review' })
+ f.start(review, 'mac-team', repositoryReach ? { repositoryReach } : {})
+ expect(f.state.starts!.at(-1)!.request.machineId).toBe('mac-team')
+ }
+ })
+
+ it('starts the owner\'s own work in their own account, which uses their own GitHub login', () => {
+ const f = swarm()
+ f.start(f.group(), 'mac', { repositoryReach: notInstalled, pushOrigin: 'clean' })
+ expect(f.state.starts!.at(-1)!.request.machineId).toBe('mac')
+ })
+
+ it('names the install when it holds an own-account start for want of knowing who pushed', () => {
+ const f = swarm(), review = f.group({ reviewOf: f.group(), step: 'Review' })
+ const error = refused(() => f.start(review, 'mac', { repositoryReach: notInstalled, pushOrigin: 'unknown' }))
+ expect(error?.code).toBe(TEAM_WRITTEN_WORK)
+ expect(error?.message).toBe('GitHub cannot show who pushed this task\'s code because the Harness GitHub App is not installed on ngochuy13/groupme, '
+ + 'so it may run only in a Team account, and a Team account reaches the repository only through that app. '
+ + `An owner of ngochuy13 installs it (${INSTALL}); then it runs in your own account.`)
+ })
+})
+
+describe('an assignment whose agent cannot reach the project repository', () => {
+ it('is refused for a Team agent, and taken by the owner\'s agent in their own account', () => {
+ const f = swarm(), task = f.group()
+ expect(refused(() => f.run({ type: 'work.assign', conversationId: task, agentId: f.member('team-builder', 'mac-team') }, { repositoryReach: notInstalled }))?.code)
+ .toBe(REPOSITORY_UNREACHABLE)
+ expect(f.state.conversations.find(c => c.id === task)!.assignment).toBeNull()
+ f.run({ type: 'work.assign', conversationId: task, agentId: f.member('own-builder', 'mac') }, { repositoryReach: notInstalled })
+ expect(f.state.conversations.find(c => c.id === task)!.assignment?.agentId).toBe('own-builder')
+ })
+
+ it('is refused for a teammate\'s agent in the teammate\'s own account, which gets the app\'s token for another person\'s project', () => {
+ const f = swarm(), task = f.group()
+ expect(refused(() => f.run({ type: 'work.assign', conversationId: task, agentId: f.member('teammate-builder', 'mac', 'teammate') }, { repositoryReach: notApproved }))?.code)
+ .toBe(REPOSITORY_UNREACHABLE)
+ })
+})
+
+describe('the access Project details reads, as a start reads it', () => {
+ it('keeps what says whether the app reaches the repository, and reads nothing it cannot be asked of', () => {
+ expect(repositoryReachOf({ state: 'not-installed', repository: 'ngochuy13/groupme', installUrl: INSTALL, canApprove: true })).toEqual(notInstalled)
+ expect(repositoryReachOf({ state: 'not-approved', repository: 'ngochuy13/groupme', canApprove: false, approvedFor: ['Other'] })).toEqual(notApproved)
+ expect(repositoryReachOf({ state: 'covered', repository: 'ngochuy13/groupme' })).toEqual({ state: 'covered', repository: 'ngochuy13/groupme' })
+ for (const access of [{ state: 'unavailable' }, { state: 'no-repository' }, { state: 'not-github', repositoryUrl: 'https://gitlab.com/a/b' }] as const) {
+ expect(repositoryReachOf(access)).toBeUndefined()
+ }
+ })
+})
diff --git a/backend/src/superTabs/repositoryReach.ts b/backend/src/superTabs/repositoryReach.ts
new file mode 100644
index 000000000..c53234c3d
--- /dev/null
+++ b/backend/src/superTabs/repositoryReach.ts
@@ -0,0 +1,49 @@
+/**
+ * Whether the account an agent would run in can reach its project's repository (task #3266): an agent in a Harness Team
+ * account, or on a machine whose owner does not own the project, reaches GitHub only through the Harness GitHub App's token
+ * (routes/superTabs.ts `github-token`, cli superTabs/projectFolder.ts startGitHub). Such a start was failed by its machine
+ * instead, twice, which suspended Claude there (Huy's groupme, 2026-11-05). The token endpoint still decides access: this
+ * only refuses earlier, and a read that could not say refuses nothing.
+ */
+import type { ProjectGitHubAccess } from '../github/projectAccess.js'
+import { fail, type SuperTabState } from './model.js'
+import { ownsProject, type SwarmProject } from './projects.js'
+
+/** What the store read of the project's GitHub access before the command (store.ts repositoryReachFor). */
+export type RepositoryReach = Extract<ProjectGitHubAccess, { state: 'covered' | 'unknown' }> | { state: 'not-installed'; repository: string; installUrl: string | null }
+ | { state: 'not-approved'; repository: string }
+
+export const REPOSITORY_UNREACHABLE = 'REPOSITORY_UNREACHABLE'
+
+const ownerOf = (repository: string) => repository.split('/')[0]
+const install = (reach: Extract<RepositoryReach, { state: 'not-installed' }>) =>
+ `An owner of ${ownerOf(reach.repository)} installs it${reach.installUrl ? ` (${reach.installUrl})` : ''}`
+
+/** Refuses an agent in a Team account ([team]), or of a machine owner who does not own [project], when the app does not reach its repository. */
+export function requireRepositoryReach(state: SuperTabState, team: boolean, machineOwnerId: string, project: SwarmProject, reach: RepositoryReach | undefined): void {
+ if (!reach || (reach.state !== 'not-installed' && reach.state !== 'not-approved')) return
+ if (!team && ownsProject(state, machineOwnerId, project)) return
+ const through = `An agent in this account reaches ${reach.repository} only through the Harness GitHub App`
+ fail(REPOSITORY_UNREACHABLE, reach.state === 'not-installed'
+ ? `${through}, which is not installed on it. ${install(reach)}, then start or assign it again.`
+ : `${through}, and nobody who can push to it has approved it for this project. Someone who can push to it approves it in Harness `
+ + '(Project details, GitHub access), then start or assign it again.', 409)
+}
+
+/** Why GitHub cannot show who pushed, when it is that the app is not installed: a Team account cannot reach it either. */
+export function unknownPushReason(reach: RepositoryReach | undefined): string | null {
+ return reach?.state === 'not-installed'
+ ? `GitHub cannot show who pushed this task's code because the Harness GitHub App is not installed on ${reach.repository}, so it may run only in a `
+ + `Team account, and a Team account reaches the repository only through that app. ${install(reach)}; then it runs in your own account.`
+ : null
+}
+
+/** What a start needs of [access]: the states that say whether the app reaches the repository; none for a project it cannot be asked of. */
+export function repositoryReachOf(access: ProjectGitHubAccess): RepositoryReach | undefined {
+ switch (access.state) {
+ case 'covered': case 'unknown': return access
+ case 'not-installed': return { state: access.state, repository: access.repository, installUrl: access.installUrl }
+ case 'not-approved': return { state: access.state, repository: access.repository }
+ default: return undefined
+ }
+}
diff --git a/backend/src/superTabs/store.ts b/backend/src/superTabs/store.ts
index dfec79ceb..328304144 100644
--- a/backend/src/superTabs/store.ts
+++ b/backend/src/superTabs/store.ts
@@ -16,6 +16,7 @@ import { wavDurationMs } from '../lib/wav.js'
import { agentText, MAX_VOICE_BYTES, MAX_VOICE_MS, VOICE_CLAIM_MS, VOICE_TYPES, voiceFacts, voiceTranscript, voiceWaveform, type StoredVoice, type VoiceFacts } from './voiceMessages.js'
import { machineAlive } from '../lib/prisma.js'
import { pullRequestsIn, type PushOrigin } from '../github/pushOrigin.js'
+import type { RepositoryReach } from './repositoryReach.js'
import { githubRepository } from '../github/repository.js'
import { isTeamSession, teamMachine, TEAM_SESSION_LIMITED, TEAM_SESSION_MESSAGE } from '../lib/teamSession.js'
import { machineShareGrant, sharedVia } from '../lib/machineSharePolicy.js'
@@ -368,6 +369,9 @@ export interface SuperTabStoreHooks {
pushOrigin?: (repositoryUrl: string | null, pullRequestUrls: string[]) => Promise<PushOrigin>
/** The same for a branch a start names: its open pull request's answer, clean for the default branch, unknown with no pull request. */
branchPushOrigin?: (repositoryUrl: string | null, branch: string) => Promise<PushOrigin>
+ /** Whether the Harness GitHub App reaches a project's GitHub repository for this Swarm (github/projectAccess.ts), read before
+ * an agent.start or work.assign (repositoryReach.ts). Absent with no GitHub App. */
+ repositoryReach?: (autonomousEnv: string, tabId: string, projectId: string, repositoryUrl: string) => Promise<RepositoryReach | undefined>
/** No Harness GitHub App on this server: a Mac's Harness Team account joins no Swarm and takes no teammates' work, since
* it has no git login to fetch or push with (commands.ts `teamAccountsIdle`). */
teamAccountsIdle?: boolean
@@ -1526,12 +1530,37 @@ export class SuperTabStore {
}
}
+ /**
+ * Whether the app reaches the repository of the project an agent.start or work.assign is for (repositoryReach.ts, task
+ * #3266), read outside the command's transaction as GitHub may take seconds. It can only refuse earlier than the machine
+ * would: undefined, refusing nothing, when there is nothing to read or the read fails.
+ */
+ private async repositoryReachFor(user: AuthUser, tabId: string, command: unknown): Promise<RepositoryReach | undefined> {
+ const hook = this.hooks.repositoryReach
+ const asked = command as { type?: unknown; conversationId?: unknown; request?: { conversationId?: unknown } } | null
+ const conversationId = asked?.type === 'agent.start' ? asked.request?.conversationId : asked?.type === 'work.assign' ? asked.conversationId : undefined
+ if (!hook || typeof conversationId !== 'string') return undefined
+ try {
+ const project = await transaction(this.db, async tx => {
+ const { state } = await this.load(tx, user, tabId, namedFor(command as Command))
+ const group = state.conversations.find(c => c.id === conversationId)
+ return group ? groupProject(state, group) : undefined
+ })
+ const repositoryUrl = project?.repository?.repositoryUrl
+ if (!project || !repositoryUrl || !githubRepository(repositoryUrl)) return undefined
+ return await hook(user.autonomousEnv, tabId, project.id, repositoryUrl)
+ } catch (error) {
+ if (!(error instanceof SuperTabError)) logger.warn('[super-tab] repository access not read', { tabId, error: error instanceof Error ? error.message : String(error) })
+ return undefined
+ }
+ }
+
/** [only]: what the store alone may give a command: `overdue` for decision.answer (leaveOverdueDecisions), `movedTo` for
* machine.moved (computerSignedIn). */
private async executeOnce(user: AuthUser, tabId: string, input: { operationId: string; command: Command }, asAgentId?: string, hostMachineId?: string,
workspaceLeave = false, only: { overdue?: boolean; movedTo?: { machineId: string; ownerId: string } } = {}) {
const { operationId, command } = operationSchema.parse(input)
- const pushOrigin = await this.pushOriginFor(user, tabId, command)
+ const [pushOrigin, repositoryReach] = await Promise.all([this.pushOriginFor(user, tabId, command), this.repositoryReachFor(user, tabId, command)])
let ended: WorkHold[] = [], started: WorkHold[] = []
const done = await transaction(this.db, async tx => {
// A retried attempt starts again: only the attempt that commits says which tasks ended or started.
@@ -1817,6 +1846,7 @@ export class SuperTabStore {
if (this.hooks.teamAccountsIdle) context.teamAccountsIdle = true
}
if (pushOrigin) context.pushOrigin = pushOrigin
+ if (repositoryReach) context.repositoryReach = repositoryReach
if (command.type === 'agent.screen' || command.type === 'agent.input') {
// A machine that is gone or no longer shared refuses at once instead of leaving the request to time out.
await this.agentGrant(tx, original, agent(original, command.agentId))
diff --git a/backend/src/superTabs/teamWritten.ts b/backend/src/superTabs/teamWritten.ts
index 7c232404c..585a09b21 100644
--- a/backend/src/superTabs/teamWritten.ts
+++ b/backend/src/superTabs/teamWritten.ts
@@ -95,6 +95,7 @@ export function applyPushOrigin(state: SuperTabState, group: Conversation, origi
group.teamWritten = true
}
-export function failPushUnknown(): never {
- return fail(TEAM_WRITTEN_WORK, 'GitHub could not show who pushed this task\'s code, so it runs only in a Team account for now. Choose an agent in a Team account, or try again in a minute.', 403)
+/** [reason]: why GitHub cannot show it, when that is known (repositoryReach.ts unknownPushReason). */
+export function failPushUnknown(reason?: string | null): never {
+ return fail(TEAM_WRITTEN_WORK, reason ?? 'GitHub could not show who pushed this task\'s code, so it runs only in a Team account for now. Choose an agent in a Team account, or try again in a minute.', 403)
}
diff --git a/docs/plans/2026-11-05-repository-reach-plan.md b/docs/plans/2026-11-05-repository-reach-plan.md
new file mode 100644
index 000000000..ca767808d
--- /dev/null
+++ b/docs/plans/2026-11-05-repository-reach-plan.md
@@ -0,0 +1,103 @@
+# Repository reach before a start: implementation plan
+
+> Written by the Engineer and implemented by the same Engineer, task by task, test first
+> (superpowers writing-plans and test-driven-development, as the project's instructions set out).
+
+**Goal:** A start or assignment whose agent would reach GitHub only through the Harness GitHub App, for a repository the
+app does not cover, is refused at once with one plain sentence naming what the owner must install or approve. A start
+that failed for want of repository access never suspends Claude or Codex on its machine. Task #3266 (Huy's groupme:
+a Reviewer held to the Team account by an unknown push origin, two failed Team starts, Claude suspended).
+
+**Architecture:** The store reads the project's GitHub access before the command's transaction, as it reads who pushed
+(store.ts `pushOriginFor`), through a new hook built on `projectGitHubAccess` (github/projectAccess.ts, the read the app
+already shows in Project details). The answer goes into `CommandContext.repositoryReach`. `agent.start` and `work.assign`
+refuse with `REPOSITORY_UNREACHABLE` when the account the agent runs in needs the app's token (a Harness Team account,
+or a machine whose owner does not own the project: the cases `github-token` serves) and the read says `not-installed`
+or `not-approved`. An unknown or absent read refuses nothing: the token endpoint still enforces access, so this is only
+the early, plain answer. The push-origin refusal for an uncovered repository names the install instead of "try again
+in a minute". engineHealth.ts excuses failed starts whose reason is a repository-access refusal, as it excuses clone
+failures.
+
+**Tech Stack:** TypeScript, the backend's Swarm command model, vitest.
+
+**Spec:** the task brief of #3266; the cause posted in its conversation.
+
+## Design
+
+- growth: N/A because nothing is stored; the read is cached by the GitHub App client (installation 10 minutes,
+ not-installed 1 minute).
+- concurrency: N/A because the read happens outside the transaction and can only refuse.
+- read cost: one state load and one cached GitHub/approval read per `agent.start` and `work.assign` that names a GitHub
+ project; never on delivery or other hot paths.
+- scale: 10x starts are 10x cached reads; the installation lookup's GitHub rate is the first metric to warn.
+- compatibility: old clients see a new refusal code with a sentence, as any refusal; old CLIs' failure reasons are
+ matched by the backend, so no CLI release is needed for the suspension fix.
+- migration + rollback: none; reverting the change restores today's behaviour.
+- audience: the server decides; the sentence names only the repository and the install link, both already shown in
+ Project details.
+- identity: the access read uses the app and the Swarm's approvals, never the machine owner's login.
+- failure: a read that fails refuses nothing and is logged by the caller as today; the start then fails as before, now
+ without suspending the engine.
+- platforms: backend only; every client shows the refusal sentence.
+
+## Global Constraints
+
+- The Team-written rule (audit H2) is unchanged: unknown push origin still keeps work out of the main account.
+- Swarm code stays out of cli/src/core. Owned: backend/src/superTabs/ (plus the one-line hook wiring in
+ backend/src/routes/superTabs.ts).
+- PR body starts with "Requested by phamngochuy.1989 through Harness."
+
+## Review Focus
+
+- The refusal never loosens access: it only refuses earlier; the token endpoint is still the gate.
+- Which account needs the app's token matches `github-token` (routes/superTabs.ts) and the CLI's `startGitHub`.
+- The excused failure reasons are repository access only, never an engine problem.
+
+## Tasks
+
+### Task 1: a repository-access failure never suspends the engine
+
+**Files:** backend/src/superTabs/engineHealth.ts, backend/src/superTabs/engineHealth.test.ts
+
+**Interfaces:** `notTheEngine(error)` gains a `REPOSITORY_ACCESS` pattern: the CLI's "could not get a Harness GitHub App
+token for this project" (any refusal the backend decided), its no-app-on-Team-account sentence, and "Share a GitHub
+repository for this project".
+
+- [ ] Write the failing test: two starts failing with each reason leave no failure count and no suspension, for Claude
+ and Codex; a real failure in between still counts.
+- [ ] Run it and watch it fail.
+- [ ] Add the pattern.
+- [ ] Run engineHealth.test.ts green; commit.
+
+### Task 2: a start or assignment the account cannot reach is refused at once
+
+**Files:** backend/src/superTabs/repositoryReach.ts (new), backend/src/superTabs/repositoryReach.test.ts (new),
+backend/src/superTabs/commands.ts, backend/src/superTabs/teamWritten.ts
+
+**Interfaces:**
+- `type RepositoryReach = { state: 'covered' | 'not-installed' | 'not-approved' | 'unknown'; repository: string; installUrl?: string | null }`
+- `CommandContext.repositoryReach?: RepositoryReach`
+- `requireRepositoryReach(state, machineId, machineOwnerId, project, reach)`: throws `REPOSITORY_UNREACHABLE` (409)
+ with the sentence when the account needs the app's token and the reach is `not-installed` or `not-approved`.
+- `failPushUnknown(reach?)`: names the install when the repository is not covered.
+
+- [ ] Write the failing tests: a review step's start on the Mac moved to its Team account, for a repository the app is
+ not installed on, is refused with the sentence naming the repository and the install link, and no start is queued;
+ the same for not approved; an assignment of a Team agent is refused the same way; the owner's own project in their
+ own account starts (own login); a covered or unknown read refuses nothing; an own-account start held by an unknown
+ push origin on an uncovered repository names the install.
+- [ ] Run them and watch them fail.
+- [ ] Implement repositoryReach.ts and the calls in `agent.start` and `work.assign`.
+- [ ] Run repositoryReach.test.ts, teamWritten.test.ts and commands.test.ts green; commit.
+
+### Task 3: the store reads the access before the command
+
+**Files:** backend/src/superTabs/store.ts, backend/src/routes/superTabs.ts, a store test beside the push-origin one
+
+**Interfaces:** `SuperTabStoreHooks.repositoryReach?: (autonomousEnv, tabId, projectId, repositoryUrl) => Promise<RepositoryReach>`
+
+- [ ] Write the failing test: with the hook answering `not-installed`, an `agent.start` through the store is refused
+ with `REPOSITORY_UNREACHABLE`; a hook that throws refuses nothing.
+- [ ] Run it and watch it fail.
+- [ ] Read it in the store for `agent.start` and `work.assign`, and wire the hook from `projectGitHubAccess` in routes.
+- [ ] Run the store test green; commit.