Skip to content

Commit 5441ff7

Browse files
committed
Fail open on ambiguous fork fingerprints
1 parent 1816116 commit 5441ff7

8 files changed

Lines changed: 75 additions & 688 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Generated by Scripts/regenerate-codex-parser-hash.sh. Do not edit by hand.
22

33
enum CodexParserHash {
4-
static let value = "b01ee8bf8af5ff3e"
4+
static let value = "9bed47837ac6591c"
55
}

Sources/CodexBarCore/Vendored/CostUsage/CostUsageCache.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ struct CostUsageFileUsage: Codable {
141141
var lastCodexTurnID: String?
142142
var sessionId: String?
143143
var forkedFromId: String?
144-
var forkTimestamp: String?
145-
/// Versioned identity of the billing suppressions applied while producing this file's rows.
146-
var codexBillingSuppressionKey: String?
147144
var projectPath: String?
148145
var canonicalProjectPath: String?
149146
var codexCostCacheComplete: Bool?

Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+CacheHelpers.swift

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,6 @@ extension CostUsageScanner {
285285
lastCodexTurnID: String? = nil,
286286
sessionId: String? = nil,
287287
forkedFromId: String? = nil,
288-
forkTimestamp: String? = nil,
289-
codexBillingSuppressionKey: String? = nil,
290288
projectPath: String? = nil,
291289
canonicalProjectPath: String? = nil,
292290
codexCostCacheComplete: Bool? = true,
@@ -316,8 +314,6 @@ extension CostUsageScanner {
316314
lastCodexTurnID: lastCodexTurnID,
317315
sessionId: sessionId,
318316
forkedFromId: forkedFromId,
319-
forkTimestamp: forkTimestamp,
320-
codexBillingSuppressionKey: codexBillingSuppressionKey,
321317
projectPath: projectPath,
322318
canonicalProjectPath: canonicalProjectPath,
323319
codexCostCacheComplete: codexCostCacheComplete,
@@ -709,8 +705,6 @@ extension CostUsageScanner {
709705
lastCodexTurnID: usage.lastCodexTurnID,
710706
sessionId: usage.sessionId,
711707
forkedFromId: usage.forkedFromId,
712-
forkTimestamp: usage.forkTimestamp,
713-
codexBillingSuppressionKey: usage.codexBillingSuppressionKey,
714708
projectPath: usage.projectPath,
715709
canonicalProjectPath: usage.canonicalProjectPath,
716710
codexCostNanos: Self.mergeCostMaps(
@@ -892,9 +886,6 @@ extension CostUsageScanner {
892886
state: inout CodexScanState) -> Bool
893887
{
894888
guard let cached = input.cached else { return false }
895-
// Reconcile both family growth and shrinkage. A cached file is reusable only when it was
896-
// produced with exactly the suppression plan that applies now.
897-
guard !Self.codexBillingSuppressionChanged(input: input, context: context) else { return false }
898889
let needsSessionId = cached.sessionId == nil
899890
guard cached.mtimeUnixMs == input.metadata.mtimeUnixMs,
900891
cached.size == input.metadata.size,
@@ -959,41 +950,6 @@ extension CostUsageScanner {
959950
return !(Set(cached.codexTurnIDs ?? []).isDisjoint(with: context.changedPriorityTurnIDs))
960951
}
961952

962-
static func codexBillingSuppressionKey(
963-
input: CodexFileScanInput,
964-
context: CodexFileScanContext) -> String?
965-
{
966-
self.codexBillingSuppressionKey(
967-
context.resources.billingSuppressedTokenOrdinalsByFilePath[input.fileURL.path] ?? [])
968-
}
969-
970-
static func codexBillingSuppressionKey(_ ordinals: Set<Int>) -> String? {
971-
let sorted = ordinals.sorted()
972-
guard let first = sorted.first else { return nil }
973-
974-
var encodedRanges: [String] = []
975-
var rangeStart = first
976-
var rangeEnd = first
977-
for ordinal in sorted.dropFirst() {
978-
if ordinal == rangeEnd + 1 {
979-
rangeEnd = ordinal
980-
continue
981-
}
982-
encodedRanges.append(rangeStart == rangeEnd ? "\(rangeStart)" : "\(rangeStart)-\(rangeEnd)")
983-
rangeStart = ordinal
984-
rangeEnd = ordinal
985-
}
986-
encodedRanges.append(rangeStart == rangeEnd ? "\(rangeStart)" : "\(rangeStart)-\(rangeEnd)")
987-
return "v2:" + encodedRanges.joined(separator: ",")
988-
}
989-
990-
static func codexBillingSuppressionChanged(
991-
input: CodexFileScanInput,
992-
context: CodexFileScanContext) -> Bool
993-
{
994-
input.cached?.codexBillingSuppressionKey != self.codexBillingSuppressionKey(input: input, context: context)
995-
}
996-
997953
static func appendCodexFileIncrementIfPossible(
998954
input: CodexFileScanInput,
999955
context: CodexFileScanContext,
@@ -1002,7 +958,6 @@ extension CostUsageScanner {
1002958
{
1003959
try context.checkCancellation?()
1004960
guard let cached = input.cached, cached.sessionId != nil, !context.forceFullScan else { return false }
1005-
guard !Self.codexBillingSuppressionChanged(input: input, context: context) else { return false }
1006961
guard !Self.cachedCodexFileNeedsPriorityRescan(cached, context: context) else { return false }
1007962
if Self.cachedCodexRowsNeedIdentityRescan(cached) {
1008963
return false
@@ -1111,8 +1066,6 @@ extension CostUsageScanner {
11111066
lastCodexTurnID: delta.lastCodexTurnID,
11121067
sessionId: sessionId,
11131068
forkedFromId: delta.forkedFromId ?? migratedCached.forkedFromId,
1114-
forkTimestamp: delta.forkTimestamp ?? migratedCached.forkTimestamp,
1115-
codexBillingSuppressionKey: Self.codexBillingSuppressionKey(input: input, context: context),
11161069
projectPath: projectPath,
11171070
canonicalProjectPath: canonicalProjectPath,
11181071
codexCostNanos: Self.codexMergedCostMap(
@@ -1165,8 +1118,6 @@ extension CostUsageScanner {
11651118
fileURL: input.fileURL,
11661119
range: context.range,
11671120
inheritedTotalsResolver: context.resources.inheritedResolver.inheritedTotals(for:atOrBefore:),
1168-
billingSuppressedTokenOrdinals: context.resources
1169-
.billingSuppressedTokenOrdinalsByFilePath[input.fileURL.path] ?? [],
11701121
checkCancellation: context.checkCancellation)
11711122
let sessionId = parsed.sessionId ?? input.cached?.sessionId
11721123
let projectPath = parsed.projectPath ?? input.cached?.projectPath
@@ -1212,8 +1163,6 @@ extension CostUsageScanner {
12121163
lastCodexTurnID: parsed.lastCodexTurnID,
12131164
sessionId: sessionId,
12141165
forkedFromId: parsed.forkedFromId,
1215-
forkTimestamp: parsed.forkTimestamp,
1216-
codexBillingSuppressionKey: Self.codexBillingSuppressionKey(input: input, context: context),
12171166
projectPath: projectPath,
12181167
canonicalProjectPath: canonicalProjectPath,
12191168
codexCostNanos: Self.mergeCostMaps(
@@ -1338,10 +1287,6 @@ extension CostUsageScanner {
13381287
guard isForceRescan else { return }
13391288
for key in cache.files.keys {
13401289
guard let old = cache.files[key] else { continue }
1341-
// A fully state-only sibling has no report days, but its empty contribution and
1342-
// applied suppression key are still a valid cache result. Retain it so unchanged
1343-
// families do not reparse that file on every refresh.
1344-
guard old.codexBillingSuppressionKey == nil else { continue }
13451290
guard !old.touchesCodexScanWindow(sinceKey: range.scanSinceKey, untilKey: range.scanUntilKey)
13461291
else { continue }
13471292
Self.applyFileDays(cache: &cache, fileDays: old.days, sign: -1)

0 commit comments

Comments
 (0)