fix(kc_format): eliminate duplicate silo/manifest.json in .kc files #311

Merged
forbes merged 1 commits from fix/kc-duplicate-manifest into main 2026-02-21 15:51:00 +00:00
Owner

Problem

Every save produces a Python warning:

/opt/kindred-create/lib/python3.11/zipfile.py:1567: UserWarning: Duplicate name: 'silo/manifest.json'

The .kc ZIP accumulates duplicate silo/manifest.json entries on each save, growing the file over time.

Root Cause

Two code paths in kc_format.py append silo/manifest.json without removing the previous entry:

  1. slotFinishSaveDocument() — re-injects the cached manifest from entries, then the modified_at update branch writes a second copy via writestr in append mode.

  2. update_manifest_fields() — opens the ZIP in append mode and writes an updated manifest without removing the old one.

Fix

slotFinishSaveDocument(): Prepare the final manifest (with updated modified_at) in the entries dict before writing to the ZIP, so only one copy is ever written.

update_manifest_fields(): Rewrite the ZIP atomically via a temp file, deduplicating any pre-existing duplicate entries in the process.

Testing

  1. Save any .kc document
  2. Verify no Duplicate name: 'silo/manifest.json' warning in the console
  3. Inspect the ZIP: python3 -c "import zipfile; print(zipfile.ZipFile('file.kc').namelist())" — should show silo/manifest.json exactly once
  4. Verify manifest content is correct (has modified_at, part_uuid, etc.)
## Problem Every save produces a Python warning: ``` /opt/kindred-create/lib/python3.11/zipfile.py:1567: UserWarning: Duplicate name: 'silo/manifest.json' ``` The `.kc` ZIP accumulates duplicate `silo/manifest.json` entries on each save, growing the file over time. ## Root Cause Two code paths in `kc_format.py` append `silo/manifest.json` without removing the previous entry: 1. **`slotFinishSaveDocument()`** — re-injects the cached manifest from `entries`, then the `modified_at` update branch writes a second copy via `writestr` in append mode. 2. **`update_manifest_fields()`** — opens the ZIP in append mode and writes an updated manifest without removing the old one. ## Fix **`slotFinishSaveDocument()`**: Prepare the final manifest (with updated `modified_at`) in the `entries` dict *before* writing to the ZIP, so only one copy is ever written. **`update_manifest_fields()`**: Rewrite the ZIP atomically via a temp file, deduplicating any pre-existing duplicate entries in the process. ## Testing 1. Save any `.kc` document 2. Verify no `Duplicate name: 'silo/manifest.json'` warning in the console 3. Inspect the ZIP: `python3 -c "import zipfile; print(zipfile.ZipFile('file.kc').namelist())" ` — should show `silo/manifest.json` exactly once 4. Verify manifest content is correct (has `modified_at`, `part_uuid`, etc.)
forbes added 1 commit 2026-02-21 15:49:53 +00:00
fix(kc_format): eliminate duplicate silo/manifest.json entries in .kc files
Some checks failed
Build and Test / build (pull_request) Has been cancelled
88efa2a6ae
Two code paths were appending silo/manifest.json to the ZIP without
removing the previous entry, causing Python's zipfile module to warn
about duplicate names:

1. slotFinishSaveDocument() re-injected the cached manifest from
   entries, then the modified_at update branch wrote a second copy.

2. update_manifest_fields() opened the ZIP in append mode and wrote
   an updated manifest without removing the old one.

Fix slotFinishSaveDocument() by preparing the final manifest (with
updated modified_at) in the entries dict before writing, so only one
copy is written to the ZIP.

Fix update_manifest_fields() by rewriting the ZIP atomically via a
temp file, deduplicating any pre-existing duplicate entries in the
process.
forbes merged commit a445275fd2 into main 2026-02-21 15:51:00 +00:00
forbes deleted branch fix/kc-duplicate-manifest 2026-02-21 15:51:00 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/create#311