Merge pull request #2583 from pikasTech/fix/agentrun-tree-order
Pipelines as Code CI / hwlab-nc01-v03-ci-poll- Success

固定 AgentRun 关系树实时刷新顺序
This commit is contained in:
Lyon
2026-07-17 00:18:45 +08:00
committed by GitHub
2 changed files with 18 additions and 2 deletions
@@ -27,9 +27,16 @@ test("Agent observer relation tree consumes the YAML node limit", () => {
assert.equal(window.rows.length, 3);
});
test("Agent observer relation tree keeps a stable order across live activity reordering", () => {
const first = buildRelationWindow([observerRun("run_2"), observerRun("run_1")], null, new Set(), new Set(), 10);
const second = buildRelationWindow([observerRun("run_1"), observerRun("run_2")], null, new Set(), new Set(), 10);
assert.deepEqual(first.rows.map((row) => row.id), second.rows.map((row) => row.id));
});
function observerRun(id: string): AgentObserverRun {
return {
id,
title: null,
taskId: null,
taskStatus: null,
commandId: null,
@@ -591,7 +591,8 @@ export function buildRelationWindow(
});
let omittedRunCount = 0;
for (const [runIndex, run] of runs.entries()) {
const stableRuns = [...runs].sort((left, right) => compareText(relationRunOrderKey(left), relationRunOrderKey(right)));
for (const [runIndex, run] of stableRuns.entries()) {
const hasCompleteContainment = Boolean((run.projectId || run.workspace) && run.sessionId && run.taskId);
const scopeId = hasCompleteContainment ? relationId("scope", `${run.projectId ?? ""}\u0000${run.workspace ?? ""}`) : unassociatedId;
const sessionId = hasCompleteContainment && run.sessionId ? relationId("session", `${scopeId}\u0000${run.sessionId}`) : null;
@@ -603,7 +604,7 @@ export function buildRelationWindow(
const commandId = run.commandId ? relationId("command", `${commandParentId}\u0000${run.commandId}`) : null;
const missingNodeCount = [scopeId, sessionId, taskId, runNodeId, attemptId, commandId].filter((id): id is string => typeof id === "string" && !nodes.has(id)).length;
if (nodes.size + missingNodeCount > nodeLimit) {
omittedRunCount = runs.length - runIndex;
omittedRunCount = stableRuns.length - runIndex;
break;
}
let parent = hasCompleteContainment
@@ -713,6 +714,14 @@ function relationId(kind: AgentObserverRelationKind, value: string): string {
return `${kind}:${encodeURIComponent(value)}`;
}
function relationRunOrderKey(run: AgentObserverRun): string {
return [run.projectId, run.workspace, run.sessionId, run.taskId, run.id].map((value) => value ?? "").join("\u0000");
}
function compareText(left: string, right: string): number {
return left < right ? -1 : left > right ? 1 : 0;
}
function latestTimestamp(previous: string | null, next: string | null): string | null {
if (!previous) return next;
if (!next) return previous;