Feat/GitHub account per owner #17516
ClosedNoext(GitHub profile, opens in a new tab)wants to merge 8 commits into
main fromrefs/pull/17516/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
Noext(GitHub profile, opens in a new tab) closed this
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- @@ -0,0 +258,21 @@258+ phaseTitle: agent.phase ?? null,259+ agentIndex: index,260+ runId: run.runId,261+ },262+ startedAt: parseIso(agent.startedAt),263+ completedAt: finished ? parseIso(agent.endedAt) : null,264+ updatedAt: parseIso(agent.endedAt ?? agent.startedAt) ?? context.emittedAt,265+ };266+};267+268+const memberProgress = (269+ run: PiWorkflowRunSnapshot,270+ mappedPhases: OrchestrationV2SubagentWorkflow["phases"],271+ members: Map<string, string>,272+ context: PiWorkflowProjectionContext,273+ force: boolean,274+): ReadonlyArray<OrchestrationV2Subagent> => {275+ const subagents: Array<OrchestrationV2Subagent> = [];276+ run.agents.forEach((agent, index) => {277+ const taskId = memberNativeId(run.runId, agent.id);278+ const fingerprint = memberFingerprint(agent);@@ -2834,0 +2993,21 @@2993+ // tracker, rather than reporting its runs as ended.2994+ const [snapshotListing, feedListing] = yield* Effect.all(2995+ [2996+ workflowStores.snapshot.listRunsForSession({ cwd, sessionIds: [sessionId] }),2997+ workflowStores.feed.listRunsForSession({2998+ sessionIds: [sessionId],2999+ ...(workflowSessionFile === null ? {} : { sessionFile: workflowSessionFile }),3000+ }),3001+ ],3002+ { concurrency: 2 },3003+ );3004+ const emittedAt = yield* DateTime.now;3005+ const reconciled = reconcilePiWorkflowRuns({3006+ runs: [...snapshotListing.runs, ...feedListing.runs],3007+ unresolvedRunIds: [3008+ ...snapshotListing.unresolvedRunIds,3009+ ...feedListing.unresolvedRunIds,3010+ ],3011+ tracker,3012+ context: {3013+ threadId: input.threadId,@@ -0,0 +504,21 @@504+ // A file that shrank or was replaced is not the file this reader folded.505+ const state =506+ previous !== undefined && previous.ino === info.ino && previous.offset <= info.size507+ ? previous508+ : { offset: 0, ino: info.ino, view: emptyFold() };509+ const remaining = info.size - state.offset;510+ if (remaining <= 0) return state.view;511+512+ const budget = Math.min(remaining, MAX_FEED_BYTES_PER_SWEEP);513+ const bytes = yield* Effect.scoped(514+ Effect.gen(function* () {515+ const file = yield* fileSystem.open(filePath, { flag: "r" });516+ // `seek` takes a bigint offset; the folded state tracks JS numbers.517+ yield* file.seek(BigInt(state.offset), "start");518+ return yield* readUpTo(file, budget);519+ }),520+ );521+ // 0x0a is a whole byte in UTF-8, so the boundary can be found before522+ // decoding and a record split across two writes is never half-parsed.523+ const lastNewline = bytes.lastIndexOf(0x0a);524+ if (lastNewline < 0) {@@ -0,0 +321,21 @@321+ // The writer's index, never its `agentId`: that id only appears on the322+ // agent's terminal record, and a member row that changed its task id323+ // mid-flight would show up twice.324+ id: String(index),325+ label: agent.label ?? `agent ${index}`,326+ phase: agent.phase,327+ status: agent.status ?? "queued",328+ model: agent.model,329+ tokens: agent.tokens,330+ startedAt: isoOrUndefined(agent.startedAtMs),331+ endedAt: isoOrUndefined(agent.endedAtMs),332+ }));333+334+/**335+ * The phase the card reports as current: the one the newest agent ran in. The feed336+ * carries no other honest signal — every declared phase is written up front, so337+ * the newest `workflow_phase` record is always the last one declared — and it only338+ * moves forward as agents start.339+ */340+const currentPhaseOf = (view: FoldedFeed): string | undefined => {341+ const newest = [...view.agents.entries()].sort(([a], [b]) => b - a)[0];@@ -0,0 +349,21 @@349+ // the first to see the last agents at all. The coordinator's terminal row350+ // still settles the run; these rows only describe what it settled.351+ subagents.push(...memberProgress(run, mapPhases(run.phases), members, input.context, false));352+ subagents.push(buildCoordinator(run, input.context, previous.subagent.parentNodeId));353+ coordinator.delete(run.runId);354+ dropMemberFingerprints(members, run.runId);355+ continue;356+ }357+358+ if (run.status === "paused") {359+ const built = buildCoordinator(run, input.context, previous.subagent.parentNodeId);360+ if (previous.status !== "paused") subagents.push(built);361+ // Store the *paused* fingerprint, not the pre-pause one: a resume whose362+ // other fields are unchanged must still emit, or the coordinator row keeps363+ // reading idle while the run is running again.364+ coordinator.set(run.runId, {365+ status: run.status,366+ fingerprint: coordinatorFingerprint(run),367+ subagent: built,368+ });369+ continue;@@ -1022,3 +1025,5 @@10221025 host,10231026 operation: "createRepository",10241027 method: "POST",1028+ // An organization's repository is created by a login that may belong to another account.1029+ account: owner ?? "",@@ -1100,0 +1111,21 @@1111+ /**1112+ * The environment a git process needs to reach its remote as the account that owns it. Resolved1113+ * before the command takes a process slot, because the `gh` probe it may need is itself a child1114+ * process and must not queue behind the command it is preparing.1115+ */1116+ const remoteAccountEnvironment = (input: {1117+ readonly cwd: string;1118+ readonly args: ReadonlyArray<string>;1119+ }): Effect.Effect<NodeJS.ProcessEnv> => {1120+ if (Option.isNone(gitHubAccounts)) return Effect.succeed<NodeJS.ProcessEnv>({});1121+ const credentials = gitHubAccounts.value;1122+ return gitRemoteAccountEnv({1123+ args: input.args,1124+ // `remote -v` is a local read, so this lookup resolves no account of its own.1125+ readRemoteUrls: () =>1126+ executeGit(1127+ "GitVcsDriver.remoteAccountEnvironment.remoteUrls",1128+ input.cwd,1129+ ["remote", "-v"],1130+ { allowNonZeroExit: true, timeoutMs: 10_000, maxOutputBytes: 32_000 },1131+ ).pipe(@@ -0,0 +377,21 @@377+ const readCachedRun = (filePath: string, info: PiWorkflowRunFileInfo) =>378+ Effect.gen(function* () {379+ if (info.size > MAX_RUN_BYTES) {380+ yield* Effect.logDebug("Pi workflow run file exceeds the size cap; skipping it.", {381+ filePath,382+ size: info.size,383+ });384+ cache.delete(filePath);385+ return null;386+ }387+ const cached = cache.get(filePath);388+ if (389+ cached &&390+ cached.mtimeMs === info.mtimeMs &&391+ cached.size === info.size &&392+ cached.ino === info.ino393+ ) {394+ return cached.run;395+ }396+ const run = yield* readRunFile(filePath);397+ cache.set(filePath, { mtimeMs: info.mtimeMs, size: info.size, ino: info.ino, run });
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed