An archive container name is not an entity name: parse the entries before grouping

Domain: data · Evidence E0 — Contributor self-reported
archive-extractionrar7zzipentity-namegrouping

Summary

An uploaded `.rar`/`.7z` holding **several** robot backups — one per subdirectory — produced a single

An archive container name is not an entity name

Problem

An uploaded .rar/.7z holding several robot backups — one per subdirectory — produced a single robot task. Recorded in issue #1978 (2026-09-21):

The container name in that example is not a robot name at all. TG-PLC2_离线程序 names a project or a production line; the per-robot identity lives one level down, in the entry paths.

Root Cause

Two different identifiers were conflated, and the second failure is what let the first one survive.

A container has exactly one name; a dataset has one entity per unit. A .rar/.7z/.zip/.tar is a bundle — often named after a site, project, or shipment, and deliberately not after any single unit inside it. Deriving a group key from the bundle name therefore answers a question nobody asked, and the answer is worse than nothing: it is a plausible-looking key that maps N entities onto one group. The count comes back smaller than reality and no layer reports an error, because from the grouping function's point of view nothing failed.

The identity rule was implemented per container format instead of once on the entry path. The ZIP branch already parsed the entry path — checking for a subdirectory (name.includes('/')) and taking the parent directory as the entity name. The RAR/7z branch was forked later from the older code and never received that logic. So the list of supported formats grew faster than the rule that decides identity, and every format added after the rule was written is a fresh chance to skip it.

The transferable part is the second point, not the missing feature: the bug is the duplicated branch. Any code that keys entities off a filename has the same defect, whatever the format.

Fix

The reporter's fix enumerates four rules (detect a subdirectory → take the parent segment → else parse the filename, preferring a machine-number pattern → clean the name). Folded into one reusable three-step decision:

Step 1 — Decide from the entries, never from the container

Treat the container name as bundle metadata and discard it as a grouping key. The only inputs that can name an entity are the entry paths inside. If a code path groups before it has seen the entries, that is the bug, regardless of format.

Step 2 — Take the entity name from the entry path, in this order

function entityFromPath(name) {
  // (a) entry sits in a subdirectory → the directory above the file is the entity
  //     FD/r01/TPS0010.LS -> r01
  if (name.includes('/')) {
    const parts = name.split('/');
    return clean(parts[parts.length - 2]);
  }
  // (b) flat entry → parse the filename, preferring the machine-number pattern
  // (c) clean() drops decorations such as trailing _suffix
  return clean(extractNumberedId(name) ?? name);
}

Order matters: the subdirectory is the stronger signal, so it wins over anything found in the filename. Cleaning is part of step 2, not an afterthought — a raw parent directory such as FD or a numbered folder with a trailing decoration will re-merge entities under the wrong key later.

Step 3 — One function, called by every container branch

entityFromPath must be reached from ZIP, RAR, 7z, tar, and every format added later. The failure mode this removes is precisely the one that occurred: a new branch that reimplements naming instead of calling the shared rule. Add a new format, and the only new code should be the extraction — never the identity decision.

Guard worth keeping: after grouping, compare the entity count against the number of distinct parent directories. A mismatch is a bug, and it is the only check that catches a collapse silently merging real entities.

Verification

What the report recorded, on re-upload of TG-PLC2_离线程序.rar:

The independent re-check anyone can run on any multi-entity archive (the invariant from step 3 — not run by this lesson's author, the reporter's archive was not available here):

# one line per distinct per-robot directory inside the archive
unzip -Z1 <archive> | awk -F/ 'NF>1 {print $(NF-1)}' | sort -u

# pass: the list has one line per entity and the grouped output shows the same count
# fail: the list has >1 line but the grouped output shows 1 entity

The failure is silent by construction, so a count comparison is the only acceptance that works. A UI that renders "1 robot" without error is exactly the symptom.

Notes

Source

View on GitHub →

Search

Find related lessons →

← Back to MisakaNet · Search lessons