fix(team): trust persisted permission state in renderer
This commit is contained in:
parent
34dd669d88
commit
d8f0d78358
2 changed files with 105 additions and 12 deletions
|
|
@ -32,20 +32,43 @@ interface FailedSpawnDetail {
|
||||||
reason: string | null;
|
reason: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function countPermissionBlockedMembers(memberSpawnStatuses: MemberSpawnStatusCollection): number {
|
function countPermissionBlockedMembers(params: {
|
||||||
if (!memberSpawnStatuses) {
|
memberSpawnStatuses: MemberSpawnStatusCollection;
|
||||||
return 0;
|
memberSpawnSnapshotStatuses?: MemberSpawnStatusesSnapshot['statuses'];
|
||||||
|
}): number {
|
||||||
|
const names = new Set<string>();
|
||||||
|
if (params.memberSpawnStatuses instanceof Map) {
|
||||||
|
for (const name of params.memberSpawnStatuses.keys()) {
|
||||||
|
names.add(name);
|
||||||
|
}
|
||||||
|
} else if (params.memberSpawnStatuses) {
|
||||||
|
for (const name of Object.keys(params.memberSpawnStatuses)) {
|
||||||
|
names.add(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const name of Object.keys(params.memberSpawnSnapshotStatuses ?? {})) {
|
||||||
|
names.add(name);
|
||||||
}
|
}
|
||||||
const entries =
|
|
||||||
memberSpawnStatuses instanceof Map
|
|
||||||
? [...memberSpawnStatuses.values()]
|
|
||||||
: Object.values(memberSpawnStatuses);
|
|
||||||
|
|
||||||
return entries.filter(
|
let count = 0;
|
||||||
(entry) =>
|
for (const name of names) {
|
||||||
|
const liveEntry =
|
||||||
|
params.memberSpawnStatuses instanceof Map
|
||||||
|
? params.memberSpawnStatuses.get(name)
|
||||||
|
: params.memberSpawnStatuses?.[name];
|
||||||
|
const snapshotEntry = params.memberSpawnSnapshotStatuses?.[name];
|
||||||
|
const entry = liveEntry ?? snapshotEntry;
|
||||||
|
if (!entry) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (
|
||||||
entry.launchState === 'runtime_pending_permission' ||
|
entry.launchState === 'runtime_pending_permission' ||
|
||||||
(entry.pendingPermissionRequestIds?.length ?? 0) > 0
|
(entry.pendingPermissionRequestIds?.length ?? 0) > 0
|
||||||
).length;
|
) {
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildAwaitingPermissionPhrase(count: number): string {
|
function buildAwaitingPermissionPhrase(count: number): string {
|
||||||
|
|
@ -185,7 +208,9 @@ export function buildTeamProvisioningPresentation({
|
||||||
progress: TeamProvisioningProgress | null | undefined;
|
progress: TeamProvisioningProgress | null | undefined;
|
||||||
members: readonly ProvisioningMemberLike[];
|
members: readonly ProvisioningMemberLike[];
|
||||||
memberSpawnStatuses?: MemberSpawnStatusCollection;
|
memberSpawnStatuses?: MemberSpawnStatusCollection;
|
||||||
memberSpawnSnapshot?: Pick<MemberSpawnStatusesSnapshot, 'expectedMembers' | 'summary'>;
|
memberSpawnSnapshot?: Pick<MemberSpawnStatusesSnapshot, 'expectedMembers' | 'summary'> & {
|
||||||
|
statuses?: MemberSpawnStatusesSnapshot['statuses'];
|
||||||
|
};
|
||||||
}): TeamProvisioningPresentation | null {
|
}): TeamProvisioningPresentation | null {
|
||||||
if (!progress) {
|
if (!progress) {
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -223,7 +248,10 @@ export function buildTeamProvisioningPresentation({
|
||||||
failedSpawnCount,
|
failedSpawnCount,
|
||||||
expectedTeammateCount
|
expectedTeammateCount
|
||||||
);
|
);
|
||||||
const permissionBlockedCount = countPermissionBlockedMembers(memberSpawnStatuses);
|
const permissionBlockedCount = countPermissionBlockedMembers({
|
||||||
|
memberSpawnStatuses,
|
||||||
|
memberSpawnSnapshotStatuses: memberSpawnSnapshot?.statuses,
|
||||||
|
});
|
||||||
|
|
||||||
const { allTeammatesConfirmedAlive, hasMembersStillJoining, remainingJoinCount } =
|
const { allTeammatesConfirmedAlive, hasMembersStillJoining, remainingJoinCount } =
|
||||||
getLaunchJoinState({
|
getLaunchJoinState({
|
||||||
|
|
|
||||||
|
|
@ -460,6 +460,71 @@ describe('buildTeamProvisioningPresentation', () => {
|
||||||
expect(presentation?.panelMessage).toBe('1 teammate awaiting permission approval');
|
expect(presentation?.panelMessage).toBe('1 teammate awaiting permission approval');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('trusts persisted snapshot permission state when live member spawn statuses are absent', () => {
|
||||||
|
const presentation = buildTeamProvisioningPresentation({
|
||||||
|
progress: {
|
||||||
|
runId: 'run-4f',
|
||||||
|
teamName: 'opencode-team',
|
||||||
|
state: 'ready',
|
||||||
|
startedAt: '2026-04-13T10:00:00.000Z',
|
||||||
|
updatedAt: '2026-04-13T10:00:08.000Z',
|
||||||
|
message: 'Launch completed',
|
||||||
|
messageSeverity: undefined,
|
||||||
|
pid: 4321,
|
||||||
|
cliLogsTail: '',
|
||||||
|
assistantOutput: '',
|
||||||
|
},
|
||||||
|
members: [
|
||||||
|
{
|
||||||
|
name: 'team-lead',
|
||||||
|
agentType: 'team-lead',
|
||||||
|
status: 'active',
|
||||||
|
currentTaskId: null,
|
||||||
|
taskCount: 0,
|
||||||
|
lastActiveAt: null,
|
||||||
|
messageCount: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'bob',
|
||||||
|
agentType: 'engineer',
|
||||||
|
status: 'unknown',
|
||||||
|
currentTaskId: null,
|
||||||
|
taskCount: 0,
|
||||||
|
lastActiveAt: null,
|
||||||
|
messageCount: 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
memberSpawnStatuses: {},
|
||||||
|
memberSpawnSnapshot: {
|
||||||
|
expectedMembers: ['bob'],
|
||||||
|
statuses: {
|
||||||
|
bob: {
|
||||||
|
status: 'online',
|
||||||
|
launchState: 'runtime_pending_bootstrap',
|
||||||
|
updatedAt: '2026-04-13T10:00:07.000Z',
|
||||||
|
runtimeAlive: true,
|
||||||
|
livenessSource: 'process',
|
||||||
|
bootstrapConfirmed: false,
|
||||||
|
hardFailure: false,
|
||||||
|
agentToolAccepted: true,
|
||||||
|
pendingPermissionRequestIds: ['perm_1'],
|
||||||
|
firstSpawnAcceptedAt: '2026-04-13T10:00:01.000Z',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
summary: {
|
||||||
|
confirmedCount: 0,
|
||||||
|
pendingCount: 1,
|
||||||
|
failedCount: 0,
|
||||||
|
runtimeAlivePendingCount: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(presentation?.compactTitle).toBe('Finishing launch');
|
||||||
|
expect(presentation?.compactDetail).toBe('1 teammate awaiting permission approval');
|
||||||
|
expect(presentation?.panelMessage).toBe('1 teammate awaiting permission approval');
|
||||||
|
});
|
||||||
|
|
||||||
it('keeps a generic failed teammate message while launch is still active if only persisted failure counts remain', () => {
|
it('keeps a generic failed teammate message while launch is still active if only persisted failure counts remain', () => {
|
||||||
const presentation = buildTeamProvisioningPresentation({
|
const presentation = buildTeamProvisioningPresentation({
|
||||||
progress: {
|
progress: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue