oficina / docs Public

Hold missing metadata, deduplicate held markers and present durable pending state

Paul Campbell pushed by paul@keymail.dev c94e4671ad46c2213e7efddfe5e8cc9c106be2cb parent cafee6f
9 files changed, +85 −11
  • docs/testing/k3-evidence.md +10 −0
  • native/apple/Package.resolved +1 −1
  • native/apple/Package.swift +1 −1
  • native/apple/Sources/DocsKit/DocsModel.swift +3 −3
  • native/apple/Sources/DocsKit/DocsOfflineAccount.swift +10 −2
  • native/apple/Tests/DocsKitTests/OfflineDurabilityTests.swift +57 −1
  • native/ios/project.yml +1 −1
  • native/macos/project.yml +1 −1
  • native/smoke/document-window/Package.resolved +1 −1

CI passed — run details

diff --git a/docs/testing/k3-evidence.md b/docs/testing/k3-evidence.md
index b804796..2aa16a2 100644
--- a/docs/testing/k3-evidence.md
+++ b/docs/testing/k3-evidence.md
@@ -116,3 +116,13 @@ Disk is measured on /System/Volumes/Data, with a mandatory stop below 1.5 GiB.
Only outputs created by this session are removed. The kit's inherited .build is
moved aside for full gates, preserved, then restored; Docs targets, framework,
.build and DerivedData created here are removed between stages.
+
+
+## Fable review follow-up (2026-09-24)
+
+- Missing, malformed-JSON, and tampered sealed metadata now hold only that lane with `rejected("metadata")`; genuine unavailable I/O still throws. The new test failed all three hold assertions against the inherited implementation, then passed while another document drained.
+- Held metadata markers are deduplicated using `entries(lane:excludingInFlight:)`. The new repeated-flush test first found five markers instead of one; it now passes, as does the existing rename-after-title-POST/in-flight-successor regression.
+- A durable offline lane uses SyncStatus without setting the generic errorKey. The new test first observed `native.pending` rather than nil, and now observes nil plus `.offline(pending: 1)`.
+- All 24 durability tests passed. Logs: `/tmp/k3-docs-review-{red,green}.log` (ephemeral); the red run had five expected assertions across three tests. The existing key-loss test was adjusted to create a fresh sealed store on simulated process restart: reusing the old instance now intentionally retains its cached key.
+- Native pins (all five) advance to `0ff1de9d542ce96430e158708e62be04d87d65a4`; native final-head local `make ci` passed (119 Swift tests and remaining platform/Go/Python gates). Its hub runner still fails before tests on missing unzip / absent macOS infrastructure.
+- Deferred as directed: review finding 4 (WASM decode per writer tick) belongs to K4/K7; finding 6 (sessionRestored on existing-account/window access) belongs to K5. No new K3 spec departure.
diff --git a/native/apple/Package.resolved b/native/apple/Package.resolved
index 32cd5cd..8eb9342 100644
--- a/native/apple/Package.resolved
+++ b/native/apple/Package.resolved
@@ -6,7 +6,7 @@
"kind" : "remoteSourceControl",
"location" : "https://amadan.net/rastrillo/native",
"state" : {
- "revision" : "4d40c6f145bbfd6d82f4c87a6226e2833f63704e"
+ "revision" : "0ff1de9d542ce96430e158708e62be04d87d65a4"
}
},
{
diff --git a/native/apple/Package.swift b/native/apple/Package.swift
index 4303e5a..a34f02a 100644
--- a/native/apple/Package.swift
+++ b/native/apple/Package.swift
@@ -3,7 +3,7 @@ import PackageDescription
import Foundation
let sharedNative: Package.Dependency = ProcessInfo.processInfo.environment["OFICINA_NATIVE_PACKAGE_PATH"].map { .package(name: "native", path: $0) }
- ?? .package(url: "https://amadan.net/rastrillo/native", revision: "4d40c6f145bbfd6d82f4c87a6226e2833f63704e")
+ ?? .package(url: "https://amadan.net/rastrillo/native", revision: "0ff1de9d542ce96430e158708e62be04d87d65a4")
let package = Package(name: "DocsNative", defaultLocalization: "en", platforms: [.macOS(.v26), .iOS(.v26)],
products: [.library(name: "DocsKit", targets: ["DocsKit"]), .executable(name: "DocsMac", targets: ["DocsMac"])],
diff --git a/native/apple/Sources/DocsKit/DocsModel.swift b/native/apple/Sources/DocsKit/DocsModel.swift
index 7721307..44c5836 100644
--- a/native/apple/Sources/DocsKit/DocsModel.swift
+++ b/native/apple/Sources/DocsKit/DocsModel.swift
@@ -426,9 +426,9 @@ import RastrilloNative
guard documentEpoch == epoch else { return }
laneSummary = await offlineAccount.outbox.summary.only(persistence.lane)
reloadMetadata()
- if laneSummary.isEmpty {
- if errorKey == "native.pending" || errorKey == "docs.editor.status.retrying" { errorKey = nil }
- } else { errorKey = "native.pending" }
+ // SyncStatus presents a durable pending lane; it does not require
+ // keeping this document open. Preserve unrelated actionable errors.
+ if errorKey == "native.pending" || errorKey == "docs.editor.status.retrying" { errorKey = nil }
}
private func listen(_ sqid: String) async {
let epoch = documentEpoch
diff --git a/native/apple/Sources/DocsKit/DocsOfflineAccount.swift b/native/apple/Sources/DocsKit/DocsOfflineAccount.swift
index b6e2432..b8faef2 100644
--- a/native/apple/Sources/DocsKit/DocsOfflineAccount.swift
+++ b/native/apple/Sources/DocsKit/DocsOfflineAccount.swift
@@ -73,7 +73,7 @@ struct DocsOfflineMetadata: Codable {
func ensureMetadataEntry(_ key: String) async throws {
let generation = replicaCache.generation(key)
guard let metadata = try metadata(key), metadata.pendingTitle != nil || metadata.draftToken != nil else { return }
- let entries = await outbox.sendable(lane: "doc:" + key, maxBytes: nil)
+ let entries = await outbox.entries(lane: "doc:" + key, excludingInFlight: true)
guard replicaCache.generation(key) == generation, !entries.contains(where: { $0.kind == "metadata" }) else { return }
try await outbox.enqueue(lane: "doc:" + key, kind: "metadata", payload: Data())
}
@@ -91,7 +91,15 @@ struct DocsOfflineMetadata: Codable {
}
private func send(_ lane: String, entries: [OutboxEntry], transport: NativeTransport) async throws -> [UUID: OutboxDrainer.Disposition] {
let key = String(lane.dropFirst(4)), generation = replicaCache.generation(String(lane.dropFirst(4)))
- guard lane.hasPrefix("doc:"), var metadata = try metadata(key) else { throw BlobStoreError.unavailable }
+ let saved: DocsOfflineMetadata?
+ do { saved = try metadata(key) }
+ catch BlobStoreError.corrupt { saved = nil }
+ catch is DecodingError { saved = nil }
+ // A missing/corrupt destination cannot be retried into existence. Keep
+ // its lane for resolution, without mistaking a locked store for loss.
+ guard lane.hasPrefix("doc:"), var metadata = saved else {
+ return Dictionary(uniqueKeysWithValues: entries.map { ($0.id, .hold(Hold(.rejected("metadata")))) })
+ }
if let token = metadata.draftToken {
let reply = try await transport.responseDetails("/documents", method: "POST", body: Self.form(["title": metadata.detail.title, "creation_token": token]), contentType: "application/x-www-form-urlencoded")
try reply.requireSuccess()
diff --git a/native/apple/Tests/DocsKitTests/OfflineDurabilityTests.swift b/native/apple/Tests/DocsKitTests/OfflineDurabilityTests.swift
index 81f8d9b..d055b96 100644
--- a/native/apple/Tests/DocsKitTests/OfflineDurabilityTests.swift
+++ b/native/apple/Tests/DocsKitTests/OfflineDurabilityTests.swift
@@ -117,6 +117,59 @@ private struct OfflineRandom: RandomNumberGenerator {
let at = projection.children.map(\.plainText).joined().utf16.count
return try await replica.command(["op": .string("display_edit"), "at": .number(Double(at)), "length": .number(0), "text": .string(text)]).0
}
+ func testMissingOrCorruptMetadataHoldsOnlyItsLane() async throws {
+ for damage in 0..<3 {
+ let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
+ defer { try? FileManager.default.removeItem(at: root) }
+ let disk = NativeSealedStore(root: root, accountID: "a", keys: ScriptedKeyProvider())
+ let connectivity = NativeConnectivity(source: ScriptedPathSource(.satisfied))
+ while !connectivity.isPathSatisfied { await Task.yield() }
+ let transport = ScriptedTransport([])
+ let account = DocsOfflineAccount(store: disk, accountID: "a", connectivity: connectivity, transport: { transport })
+ if damage > 0 { try disk.write(Data("invalid metadata".utf8), to: "cache/docs/a/meta") }
+ if damage == 2 { try Data([0]).write(to: root.appendingPathComponent("cache/docs/a/meta")) }
+ try await account.outbox.enqueue(lane: "doc:a", kind: "metadata", payload: Data())
+ let detail = DocumentDetail(sqid: "b", title: "B", guid: "b", can_write: true, can_share: false)
+ try account.saveMetadata(DocsOfflineMetadata(detail: detail), key: "b")
+ try await account.outbox.enqueue(lane: "doc:b", kind: "metadata", payload: Data())
+ await account.drainer.drain()
+ let broken = await account.outbox.entries(lane: "doc:a")
+ let good = await account.outbox.entries(lane: "doc:b")
+ XCTAssertEqual(broken.first?.hold, Hold(.rejected("metadata")))
+ XCTAssertTrue(good.isEmpty, "Missing metadata must not block another document")
+ }
+ }
+
+ func testHeldMetadataMarkerDoesNotMultiplyOnFlush() async throws {
+ let account = DocsOfflineAccount(store: MemoryBlobStore(), accountID: "a", connectivity: NativeConnectivity(source: ScriptedPathSource(.unsatisfied)), transport: { ScriptedTransport([]) })
+ let detail = DocumentDetail(sqid: "doc", title: "Title", guid: "doc", can_write: true, can_share: false)
+ try account.saveMetadata(DocsOfflineMetadata(detail: detail, pendingTitle: "Rename"), key: "doc")
+ try await account.ensureMetadataEntry("doc")
+ let original = await account.outbox.entries(lane: "doc:doc")
+ try await account.outbox.hold(original.map(\.id), Hold(.accessLost))
+ for _ in 0..<4 { try await account.ensureMetadataEntry("doc") }
+ let entries = await account.outbox.entries(lane: "doc:doc")
+ XCTAssertEqual(entries.map(\.id), original.map(\.id))
+ }
+
+ func testDurableOfflineLaneUsesSyncStatusWithoutAnErrorMessage() async throws {
+ let server = IntegratingServer(); try await server.open(initial())
+ let path = ScriptedPathSource(.satisfied)
+ let connectivity = NativeConnectivity(source: path)
+ let account = DocsOfflineAccount(store: MemoryBlobStore(), accountID: "a", connectivity: connectivity, transport: { server })
+ let model = DocsModel(transport: { server }, connectivity: connectivity, offlineAccount: account)
+ await model.open("doc"); _ = await model.saveAll()
+ path.send(.unsatisfied)
+ while connectivity.isPathSatisfied { await Task.yield() }
+ model.didRender(model.projectionGeneration)
+ XCTAssertTrue(model.enqueue(["op": .string("display_edit"), "at": .number(0), "length": .number(0), "text": .string("Offline")]))
+ while model.hasPendingInput { await Task.yield() }
+ await model.flush()
+ XCTAssertNil(model.errorKey, "A durable pending lane does not require keeping this window open")
+ XCTAssertEqual(model.syncStatus, .offline(pending: 1))
+ await model.stop(); account.drainer.stop()
+ }
+
func testWriterBetweenCommandAndEnqueueCannotPersistTheCommand() async throws {
let disk = MemoryBlobStore(), initial = try await initial()
let replica = CRDTReplica(guid: "offline-property")
@@ -647,7 +700,10 @@ private struct OfflineRandom: RandomNumberGenerator {
try old.saveMetadata(DocsOfflineMetadata(detail: detail), key: "doc")
try await old.outbox.enqueue(lane: "doc:doc", kind: "update", payload: Data([0]))
_ = keys.deleteKey()
- let next = DocsOfflineAccount(store: disk, accountID: "a", connectivity: network, transport: { server })
+ // A process restart also drops NativeSealedStore's cached key/state.
+ // Reusing the old store would deliberately keep the still-usable key.
+ let reopened = NativeSealedStore(root: root, accountID: "a", keys: keys)
+ let next = DocsOfflineAccount(store: reopened, accountID: "a", connectivity: network, transport: { server })
let model = DocsModel(transport: { server }, connectivity: network, offlineAccount: next)
await model.open("doc")
try await Task.sleep(for: .milliseconds(50))
diff --git a/native/ios/project.yml b/native/ios/project.yml
index e0078d5..4305994 100644
--- a/native/ios/project.yml
+++ b/native/ios/project.yml
@@ -8,7 +8,7 @@ packages:
path: ../apple
RastrilloNative:
url: https://amadan.net/rastrillo/native
- revision: 4d40c6f145bbfd6d82f4c87a6226e2833f63704e
+ revision: 0ff1de9d542ce96430e158708e62be04d87d65a4
settings:
base:
SWIFT_VERSION: '6.0'
diff --git a/native/macos/project.yml b/native/macos/project.yml
index 9d16ff5..4b23a0b 100644
--- a/native/macos/project.yml
+++ b/native/macos/project.yml
@@ -7,7 +7,7 @@ packages:
path: ../apple
RastrilloNative:
url: https://amadan.net/rastrillo/native
- revision: 4d40c6f145bbfd6d82f4c87a6226e2833f63704e
+ revision: 0ff1de9d542ce96430e158708e62be04d87d65a4
settings:
base:
SWIFT_VERSION: '6.0'
diff --git a/native/smoke/document-window/Package.resolved b/native/smoke/document-window/Package.resolved
index 053b87b..9c09646 100644
--- a/native/smoke/document-window/Package.resolved
+++ b/native/smoke/document-window/Package.resolved
@@ -6,7 +6,7 @@
"kind" : "remoteSourceControl",
"location" : "https://amadan.net/rastrillo/native",
"state" : {
- "revision" : "4d40c6f145bbfd6d82f4c87a6226e2833f63704e"
+ "revision" : "0ff1de9d542ce96430e158708e62be04d87d65a4"
}
},
{