Skip to content

Fix pcf-compact corrupting PFS-MS files; add PFS-aware compaction#23

Merged
kduma merged 2 commits into
masterfrom
claude/pcf-compact-pfs-session-chain-gM5hG
Jun 8, 2026
Merged

Fix pcf-compact corrupting PFS-MS files; add PFS-aware compaction#23
kduma merged 2 commits into
masterfrom
claude/pcf-compact-pfs-session-chain-gM5hG

Conversation

@kduma

@kduma kduma commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Generic PCF compaction (Container::compacted_image) repacks entries into
shared table blocks and rewrites every table_hash. On a PFS-MS file this
destroys the one-PFS_SESSION-per-HEAD invariant and the inter-session
commitments (member_blocks_digest, prev_session_hash), so the result no
longer scans or verifies as PFS-MS:

pfs: broken session chain: HEAD block must hold exactly one PFS_SESSION

Generic content-preserving compaction therefore cannot keep a multi-session
PFS-MS file valid. Two changes address this:

  1. PFS-aware compaction (pfs-ms crate): new compact / compact_archive
    resolve the live tree at the head and re-emit it as a single fresh
    session (seq=1, prev_session_hash=0), discarding history per spec
    Section 15 -- deleted nodes are dropped and delta chains collapse to the
    newest full DIRECT content. Exposed as pfs compact <file> [<out>].
    Reuses FsReader/FsWriter/commit_changes; the synthesized root means a
    single commit_changes on a fresh create() yields one valid session.

  2. Guard in pcf-compact: refuses an input carrying a PFS_SESSION partition
    (type 0xAAAA0002) and points the user to pfs compact. --allow-pfs
    forces a plain-PCF compaction that intentionally discards PFS structure.

Specs (PFS-MS Section 15, PCF Section 11.5) and READMEs updated to document
that generic PCF compaction MUST NOT be applied to profile-structured files.
Adds tests: single-session round-trip, deleted/delta flattening, metadata
and hash-algo preservation, empty tree, idempotence, corrupt-source
rejection, in-place/separate-output archives, and the pcf-compact guard.

https://claude.ai/code/session_016Xc2k2U7vWCQQUjTPNSRjK

claude added 2 commits June 7, 2026 23:44
Generic PCF compaction (Container::compacted_image) repacks entries into
shared table blocks and rewrites every table_hash. On a PFS-MS file this
destroys the one-PFS_SESSION-per-HEAD invariant and the inter-session
commitments (member_blocks_digest, prev_session_hash), so the result no
longer scans or verifies as PFS-MS:

    pfs: broken session chain: HEAD block must hold exactly one PFS_SESSION

Generic content-preserving compaction therefore cannot keep a multi-session
PFS-MS file valid. Two changes address this:

1. PFS-aware compaction (pfs-ms crate): new `compact` / `compact_archive`
   resolve the live tree at the head and re-emit it as a single fresh
   session (seq=1, prev_session_hash=0), discarding history per spec
   Section 15 -- deleted nodes are dropped and delta chains collapse to the
   newest full DIRECT content. Exposed as `pfs compact <file> [<out>]`.
   Reuses FsReader/FsWriter/commit_changes; the synthesized root means a
   single commit_changes on a fresh create() yields one valid session.

2. Guard in pcf-compact: refuses an input carrying a PFS_SESSION partition
   (type 0xAAAA0002) and points the user to `pfs compact`. `--allow-pfs`
   forces a plain-PCF compaction that intentionally discards PFS structure.

Specs (PFS-MS Section 15, PCF Section 11.5) and READMEs updated to document
that generic PCF compaction MUST NOT be applied to profile-structured files.
Adds tests: single-session round-trip, deleted/delta flattening, metadata
and hash-algo preservation, empty tree, idempotence, corrupt-source
rejection, in-place/separate-output archives, and the pcf-compact guard.

https://claude.ai/code/session_016Xc2k2U7vWCQQUjTPNSRjK
…pfs-session-chain-gM5hG

# Conflicts:
#	reference/PFS-MS-v1.0/src/bin/pfs.rs
@kduma kduma merged commit 4ffee36 into master Jun 8, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants