Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/sidebar/tabs/AssetsSidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ import MediaAssetContextMenu from '@/platform/assets/components/MediaAssetContex
import MediaAssetFilterBar from '@/platform/assets/components/MediaAssetFilterBar.vue'
import { getAssetType } from '@/platform/assets/composables/media/assetMappers'
import { useAssetsApi } from '@/platform/assets/composables/media/useAssetsApi'
import { useFlatOutputAssetsGrouped } from '@/platform/assets/composables/media/useFlatOutputAssetsGrouped'
import { useAssetSelection } from '@/platform/assets/composables/useAssetSelection'
import { useMediaAssetActions } from '@/platform/assets/composables/useMediaAssetActions'
import { useMediaAssetFiltering } from '@/platform/assets/composables/useMediaAssetFiltering'
Expand Down Expand Up @@ -311,7 +312,7 @@ const formattedExecutionTime = computed(() => {
const toast = useToast()

const inputAssets = useAssetsApi('input')
const outputAssets = useAssetsApi('output')
const outputAssets = useFlatOutputAssetsGrouped()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — This swaps the output provider from useAssetsApi('output') (backed by api.getHistory(), which works in OSS) to useFlatOutputAssetsGrouped(), which reads flatOutputAssets populated via assetService.getAssetsPageByTag(OUTPUT_TAG, ...) — a path the store explicitly comments as 'cloud-only'. In OSS/non-cloud runs the generated-outputs tab may stop loading and render empty; gate this on isCloud (falling back to the history provider) or confirm /api/assets?include_tags=output is served in OSS. Raised by 1 of 8 reviewers (gpt-5.3-codex-xhigh edge-case).


// Asset selection
const {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { describe, expect, it, vi } from 'vitest'
import { ref } from 'vue'
import type { Ref } from 'vue'

import type { AssetItem } from '@/platform/assets/schemas/assetSchema'

import { useFlatOutputAssetsGrouped } from './useFlatOutputAssetsGrouped'

const mediaRef: Ref<AssetItem[]> = ref([])

vi.mock('./useFlatOutputAssets', () => ({
useFlatOutputAssets: () => ({
media: mediaRef,
loading: ref(false),
error: ref(null),
hasMore: ref(false),
isLoadingMore: ref(false),
fetchMediaList: vi.fn(),
refresh: vi.fn(),
loadMore: vi.fn()
})
}))

function asset(overrides: Partial<AssetItem> = {}): AssetItem {
return {
id: 'asset-id',
name: 'output.png',
tags: ['output'],
...overrides
}
}

describe('useFlatOutputAssetsGrouped', () => {
it('collapses rows with the same job_id into a single representative', () => {
mediaRef.value = [
asset({ id: 'a', name: 'out1.png', job_id: 'job-1' }),
asset({ id: 'b', name: 'out2.png', job_id: 'job-1' }),
asset({ id: 'c', name: 'out3.png', job_id: 'job-1' }),
asset({ id: 'd', name: 'solo.png', job_id: 'job-2' })
]

const { media } = useFlatOutputAssetsGrouped()

expect(media.value.map((a) => a.id)).toEqual(['a', 'd'])
})

it('exposes the group size as user_metadata.outputCount', () => {
mediaRef.value = [
asset({ id: 'a', job_id: 'job-1' }),
asset({ id: 'b', job_id: 'job-1' }),
asset({ id: 'c', job_id: 'job-1' }),
asset({ id: 'd', job_id: 'job-2' })
]

const { media } = useFlatOutputAssetsGrouped()

expect(media.value[0].user_metadata?.outputCount).toBe(3)
expect(media.value[0].user_metadata?.jobId).toBe('job-1')
expect(media.value[1].user_metadata?.outputCount).toBe(1)
})

it('falls back to prompt_id when job_id is absent (legacy)', () => {
mediaRef.value = [
asset({ id: 'a', prompt_id: 'job-legacy' }),
asset({ id: 'b', prompt_id: 'job-legacy' })
]

const { media } = useFlatOutputAssetsGrouped()

expect(media.value).toHaveLength(1)
expect(media.value[0].user_metadata?.jobId).toBe('job-legacy')
expect(media.value[0].user_metadata?.outputCount).toBe(2)
})

it('passes through rows that have neither job_id nor prompt_id', () => {
mediaRef.value = [asset({ id: 'orphan-a' }), asset({ id: 'orphan-b' })]

const { media } = useFlatOutputAssetsGrouped()

expect(media.value.map((a) => a.id)).toEqual(['orphan-a', 'orphan-b'])
})

it('preserves the order of the first occurrence per job_id', () => {
mediaRef.value = [
asset({ id: 'a', job_id: 'job-A' }),
asset({ id: 'b', job_id: 'job-B' }),
asset({ id: 'c', job_id: 'job-A' }),
asset({ id: 'd', job_id: 'job-C' })
]

const { media } = useFlatOutputAssetsGrouped()

expect(media.value.map((a) => a.id)).toEqual(['a', 'b', 'd'])
})

it('does not mutate the underlying assets', () => {
const original = asset({ id: 'a', job_id: 'job-1' })
mediaRef.value = [original, asset({ id: 'b', job_id: 'job-1' })]

const { media } = useFlatOutputAssetsGrouped()
void media.value

expect(original.user_metadata).toBeUndefined()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { computed } from 'vue'

import type { AssetItem } from '@/platform/assets/schemas/assetSchema'

import type { IAssetsProvider } from './IAssetsProvider'
import { useFlatOutputAssets } from './useFlatOutputAssets'

/**
* Cloud `/api/assets?include_tags=output` returns one row per individual output
* file. The asset sidebar's stack UX expects one card per job with an
* `outputCount` badge, so collapse rows that share a `job_id` into a single
* representative (the first occurrence — assets are returned newest-first).
*
* The siblings remain reachable through the existing stack-expand path via
* `resolveOutputAssetItems(metadata)`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Expansion restores Asset-API-deleted outputs.

Full context for agent readers

Grouping retains only the surviving Asset API rows, but these rows have no allOutputs. Expanding calls resolveOutputAssetItems() and reloads stale job history, so a sibling deleted through /api/assets reappears. Please derive children from the surviving Asset API rows and add a regression test that deletes one sibling before expansion.

*/
export function useFlatOutputAssetsGrouped(): IAssetsProvider {
const inner = useFlatOutputAssets()

const media = computed(() => groupByJobId(inner.media.value))

return {
...inner,
media
}
}

function groupByJobId(assets: AssetItem[]): AssetItem[] {
const countsByJobId = new Map<string, number>()
for (const asset of assets) {
const jobId = asset.job_id ?? asset.prompt_id

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Low — asset.job_id ?? asset.prompt_id uses nullish coalescing, but job_id is typed z.string().nullish() and can be ''; an empty-string job_id is preserved instead of falling back to a valid prompt_id, then fails the if (!jobId) check and is treated as an orphan. Use a truthy check (or ||) so empty strings fall through to prompt_id. Raised by 1 of 8 reviewers (kimi-k2.5 edge-case).

if (!jobId) continue
countsByJobId.set(jobId, (countsByJobId.get(jobId) ?? 0) + 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Low — outputCount is tallied only over the currently-loaded page (inner.media.value), but /api/assets returns one row per output file, so a job whose outputs straddle a page boundary is undercounted until later pages load. When only one row of a multi-output job is present, shouldShowOutputCount (> 1) suppresses the stack affordance entirely. Raised by 2 of 8 reviewers (claude-opus-4-8-thinking-xhigh edge-case, claude-opus-4-8-thinking-xhigh adversarial).

}

const seenJobIds = new Set<string>()
const grouped: AssetItem[] = []
for (const asset of assets) {
const jobId = asset.job_id ?? asset.prompt_id ?? null
if (!jobId) {
grouped.push(asset)
continue
}
if (seenJobIds.has(jobId)) continue
seenJobIds.add(jobId)

const outputCount = countsByJobId.get(jobId) ?? 1
grouped.push({
...asset,
user_metadata: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — The grouped representative's user_metadata is rebuilt with only jobId/outputCount and never carries nodeId/subfolder (the flat /api/assets rows lack them). On expansion, useOutputStacks.resolveStackChildren builds excludeOutputKey via getOutputKey({nodeId, subfolder, filename}), which returns null when those fields are absent, so the representative output is not filtered out of the re-fetched job outputs and renders twice — once as the stack header and again as a child — for every multi-output job. Stamp the representative's nodeId/subfolder (or exclude by filename) so the header file is removed from its children. Raised by 4 of 8 reviewers (gpt-5.3-codex-xhigh edge-case, gpt-5.3-codex-xhigh adversarial, claude-opus-4-8-thinking-xhigh edge-case, claude-opus-4-8-thinking-xhigh adversarial).

...asset.user_metadata,
jobId,
outputCount
}
})
}
return grouped
}
2 changes: 1 addition & 1 deletion src/platform/assets/composables/useOutputStacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function useOutputStacks({ assets }: UseOutputStacksOptions) {

function getStackJobId(asset: AssetItem): string | null {
const metadata = getOutputAssetMetadata(asset.user_metadata)
return metadata?.jobId ?? null
return metadata?.jobId ?? asset.job_id ?? null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Low — getStackJobId falls back to asset.job_id but omits the prompt_id alias that groupByJobId uses (asset.job_id ?? asset.prompt_id). A legacy asset exposing only prompt_id (and no user_metadata.jobId) resolves to null here and cannot be expanded, inconsistent with how it was grouped; mirror the ?? asset.prompt_id fallback. Raised by 3 of 8 reviewers (gemini-3.1-pro edge-case, gpt-5.3-codex-xhigh adversarial, claude-opus-4-8-thinking-xhigh edge-case).

}

function isStackExpanded(asset: AssetItem): boolean {
Expand Down
17 changes: 6 additions & 11 deletions src/platform/assets/schemas/assetMetadataSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,26 @@ import type { ComfyWorkflowJSON } from '@/platform/workflow/validation/schemas/w
import type { ResultItemImpl } from '@/stores/queueStore'

/**
* Metadata for output assets from queue store
* Extends Record<string, unknown> for compatibility with AssetItem schema
* Metadata for output assets. Originates from the queue/history mapping but
* also surfaces on assets sourced directly from `/api/assets?include_tags=output`,
* which carry `jobId` only (no per-output `nodeId` / `subfolder`).
*/
export interface OutputAssetMetadata extends Record<string, unknown> {
jobId: string
nodeId: string | number
subfolder: string
nodeId?: string | number
subfolder?: string
executionTimeInSeconds?: number
format?: string
workflow?: ComfyWorkflowJSON
outputCount?: number
allOutputs?: ResultItemImpl[]
}

/**
* Type guard to check if metadata is OutputAssetMetadata
*/
function isOutputAssetMetadata(
metadata: Record<string, unknown> | undefined
): metadata is OutputAssetMetadata {
if (!metadata) return false
return (
typeof metadata.jobId === 'string' &&
(typeof metadata.nodeId === 'string' || typeof metadata.nodeId === 'number')
)
return typeof metadata.jobId === 'string'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium — isOutputAssetMetadata now returns true for any user_metadata containing a string jobId, dropping the previous nodeId check. Since user_metadata is arbitrary on every asset type, unrelated assets that happen to carry a jobId key are misclassified as output metadata and routed through output-only behavior (e.g. /jobs/{jobId} lookups), producing incorrect results — and an IDOR-style exposure if backend authorization on that lookup is incomplete. Validate a more output-specific shape, or restrict the guard to assets tagged output. Raised by 2 of 8 reviewers (gpt-5.3-codex-xhigh adversarial, gpt-5.3-codex-xhigh edge-case).

}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/platform/assets/schemas/assetSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ const zAsset = z.object({
is_immutable: z.boolean().optional(),
last_access_time: z.string().optional(),
metadata: z.record(z.unknown()).optional(), // API allows arbitrary key-value pairs
user_metadata: z.record(z.unknown()).optional() // API allows arbitrary key-value pairs
user_metadata: z.record(z.unknown()).optional(), // API allows arbitrary key-value pairs
job_id: z.string().nullish(),
// Deprecated alias of job_id. See ingest-types Asset schema; both backends emit this during the L6 transition.
prompt_id: z.string().nullish()
})

const zAssetResponse = zListAssetsResponse
Expand Down
Loading