@@ -24,7 +24,8 @@ use tracedecay_code_index::production::{
2424 VerifiedSealedLexicalSourceReceiptV1 , VerifiedSealedLexicalSymbolDisplayV1 ,
2525} ;
2626use tracedecay_domain:: {
27- CodeSearchChunkAnchorV1 , CodeSearchChunkV1 , ExactTechnicalTermV1 , ManifestDigest ,
27+ CodeSearchChunkAnchorV1 , CodeSearchChunkV1 , ExactTechnicalTermV1 , FileOccurrenceId ,
28+ ManifestDigest ,
2829} ;
2930use tracedecay_private_fs:: framed_log:: { DirectorySyncPolicy , sync_parent_directory} ;
3031use tracedecay_private_fs:: { create_private_file_retained, open_private_file} ;
@@ -2455,8 +2456,7 @@ fn validated_fixed_ledger_charge(
24552456 let serialized_bytes = metadata_serialized_upper_bound ( metadata) ;
24562457 let fixed = ARTIFACT_SQLITE_CACHE_BYTES
24572458 . checked_add (
2458- metadata
2459- . retained_owned_bytes ( )
2459+ metadata_retained_bytes ( metadata)
24602460 . checked_mul ( 2 )
24612461 . ok_or_else ( || {
24622462 CodeLexicalArtifactErrorV1 :: Contract (
@@ -2490,13 +2490,50 @@ fn metadata_serialized_upper_bound(metadata: &CodeLexicalProjectionMetadataV1) -
24902490 . saturating_add ( path. len ( ) )
24912491 . saturating_add ( 32 )
24922492 } ) ;
2493- metadata
2494- . retained_owned_bytes ( )
2493+ metadata_retained_bytes ( metadata)
24952494 . saturating_add ( path_bytes)
24962495 . saturating_mul ( 6 )
24972496 . saturating_add ( 512 )
24982497}
24992498
2499+ /// Owned bytes one projection metadata structure retains: logical paths at
2500+ /// capacity with per-entry b-tree node overhead, and every scalar identity
2501+ /// string charged as its `String` header plus payload length.
2502+ fn metadata_retained_bytes ( metadata : & CodeLexicalProjectionMetadataV1 ) -> usize {
2503+ let path_bytes = metadata. logical_paths . iter ( ) . fold (
2504+ metadata. logical_paths . len ( ) . saturating_mul (
2505+ std:: mem:: size_of :: < ( FileOccurrenceId , String ) > ( )
2506+ . saturating_add ( BTREE_MAP_ENTRY_OVERHEAD_BYTES ) ,
2507+ ) ,
2508+ |bytes, ( file, path) | {
2509+ bytes
2510+ . saturating_add ( file. as_str ( ) . len ( ) )
2511+ . saturating_add ( path. capacity ( ) )
2512+ } ,
2513+ ) ;
2514+ let scalar_identities = [
2515+ Some ( metadata. generation . as_str ( ) ) ,
2516+ metadata
2517+ . repository_id
2518+ . as_ref ( )
2519+ . map ( |repository| repository. as_str ( ) ) ,
2520+ Some ( metadata. freshness . source_namespace . as_str ( ) ) ,
2521+ Some ( metadata. freshness . source_instance . as_str ( ) ) ,
2522+ Some ( metadata. freshness . policy_revision . as_str ( ) ) ,
2523+ Some ( metadata. exact_retriever_revision . as_str ( ) ) ,
2524+ Some ( metadata. lexical_retriever_revision . as_str ( ) ) ,
2525+ Some ( metadata. exact_score_domain . as_str ( ) ) ,
2526+ ] ;
2527+ scalar_identities
2528+ . into_iter ( )
2529+ . flatten ( )
2530+ . fold ( path_bytes, |bytes, identity| {
2531+ bytes
2532+ . saturating_add ( std:: mem:: size_of :: < String > ( ) )
2533+ . saturating_add ( identity. len ( ) )
2534+ } )
2535+ }
2536+
25002537fn page_batch_ledger_charge_bytes (
25012538 metadata : & CodeLexicalProjectionMetadataV1 ,
25022539 pages : & [ VerifiedSealedLexicalPageV1 ] ,
@@ -3802,7 +3839,6 @@ fn verify_clone_payload_digests<'body>(
38023839 Ok ( ( ) )
38033840}
38043841
3805- /// CI retrigger marker (no behavior).
38063842fn append_prepared_clone_bodies (
38073843 transaction : & Transaction < ' _ > ,
38083844 pages : & [ PreparedCodeLexicalArtifactPageV1 ] ,
0 commit comments