Skip to content
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9245047
Add shadow Codex lineage ledger
iam-brain Jul 13, 2026
c731bd1
Adapt rollout snapshots for lineage accounting
iam-brain Jul 13, 2026
41dc8aa
Preserve rollout event identity
iam-brain Jul 14, 2026
5cce73b
Refresh lineage parser fingerprint
iam-brain Jul 14, 2026
9280c36
Discover referenced Codex lineage parents
iam-brain Jul 13, 2026
c751e2f
Preserve lineage accounting dimensions
iam-brain Jul 13, 2026
71427b1
Run Codex lineage accounting in shadow
iam-brain Jul 13, 2026
36dca74
Resolve physical lineage parents
iam-brain Jul 14, 2026
b499c28
Keep lineage parser lint-clean
iam-brain Jul 14, 2026
1aa2182
Classify Codex lineage residuals
iam-brain Jul 13, 2026
aca6abc
Handle ambiguous Codex lineage evidence
iam-brain Jul 13, 2026
7ed3715
Bound Codex lineage reconciliation
iam-brain Jul 13, 2026
6863907
Stream Codex lineage families
iam-brain Jul 13, 2026
2f16a69
Define Codex lineage promotion gates
iam-brain Jul 13, 2026
ca001d1
Add Codex lineage accounting selector
iam-brain Jul 13, 2026
b3abe45
Gate lineage authority promotion
iam-brain Jul 14, 2026
0e3033f
Keep lineage promotion lint-clean
iam-brain Jul 14, 2026
7857e8b
Validate lineage accounting on local histories
iam-brain Jul 13, 2026
3ba071f
Instrument Codex reset epoch collisions
iam-brain Jul 13, 2026
e6fb8b6
Diagnose Codex branch frontier collisions
iam-brain Jul 13, 2026
2a25e7a
Profile and optimize lineage accounting
iam-brain Jul 13, 2026
ae3c19e
Stabilize lineage validation compilation
iam-brain Jul 14, 2026
d10f38b
Address lineage accounting review findings
iam-brain Jul 14, 2026
0b5a00e
Refresh lineage parser fingerprint
iam-brain Jul 14, 2026
5be1a78
Bound lineage performance tests
iam-brain Jul 14, 2026
b1cb89f
Avoid unused lineage observations
iam-brain Jul 14, 2026
c36f341
Propagate lineage accounting safeguards
iam-brain Jul 14, 2026
ab22936
Cover lineage cache window reconstruction
iam-brain Jul 14, 2026
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by Scripts/regenerate-codex-parser-hash.sh. Do not edit by hand.

enum CodexParserHash {
static let value = "cdef6eb9658a43e2"
static let value = "ecbcccef8abf2e9a"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import Foundation

enum CodexLineageAccountingMode: String, CaseIterable, Sendable {
case legacy
case shadow
case lineage

static let defaultMode: Self = .legacy
static let schemaVersion = 1

var producerKeySuffix: String {
"lineage-accounting:\(self.rawValue):v\(Self.schemaVersion)"
}
}

/// Selects one whole-scan authority while preserving a permanent family-scoped containment route.
enum CodexLineageAccountingSelector {
typealias PackedDays = [String: [String: [Int]]]

enum SelectionError: Error, Equatable {
case missingContainedFamilyEvidence
}

struct ContainedDocument: Equatable, Sendable {
/// Stable logical rollout identity. Physical active/archive copies share this value.
let identity: String
let days: PackedDays
}

struct ContainedFamily: Equatable, Sendable {
/// Legacy file contributions belonging only to this contained family.
let documents: [ContainedDocument]
}

struct Selection: Equatable, Sendable {
let days: PackedDays
let usedLineageAuthority: Bool
let containedFamilyCount: Int
}

static func select(
mode: CodexLineageAccountingMode,
authorization: CodexLineagePromotionEvaluator.Authorization? = nil,
legacyDays: PackedDays,
primaryRows: [CodexLineageLedger.DailyRow],
containedFamilies: [ContainedFamily]) -> Selection
{
guard mode == .lineage, authorization != nil else {
return Selection(days: legacyDays, usedLineageAuthority: false, containedFamilyCount: 0)
}
var days = Self.days(from: primaryRows)
for family in containedFamilies {
Self.add(Self.containedDays(family.documents), to: &days)
}
return Selection(
days: days,
usedLineageAuthority: true,
containedFamilyCount: containedFamilies.count)
}

/// A contained family contributes once. Physical copies of one logical rollout use an envelope;
/// distinct siblings remain additive so containment does not discard their independent work.
private static func containedDays(_ documents: [ContainedDocument]) -> PackedDays {
var documentsByIdentity: [String: [PackedDays]] = [:]
for document in documents {
documentsByIdentity[document.identity, default: []].append(document.days)
}
var result: PackedDays = [:]
for copies in documentsByIdentity.values {
var envelope: PackedDays = [:]
for copy in copies {
for (day, models) in copy {
for (model, packed) in models {
let existing = envelope[day]?[model] ?? [0, 0, 0]
envelope[day, default: [:]][model] = (0..<3).map { index in
max(existing[safe: index] ?? 0, packed[safe: index] ?? 0)
}
}
}
}
Self.add(envelope, to: &result)
}
return result
}

private static func days(from rows: [CodexLineageLedger.DailyRow]) -> PackedDays {
var days: PackedDays = [:]
for row in rows {
var packed = days[row.day]?[row.model] ?? [0, 0, 0]
packed[0] += row.totals.input
packed[1] += row.totals.cached
packed[2] += row.totals.output
days[row.day, default: [:]][row.model] = packed
}
return days
}

private static func add(_ source: PackedDays, to destination: inout PackedDays) {
for (day, models) in source {
for (model, packed) in models {
var value = destination[day]?[model] ?? [0, 0, 0]
for index in 0..<3 {
value[index] += packed[safe: index] ?? 0
}
destination[day, default: [:]][model] = value
}
}
}
}
Loading
Loading