Repair VoidBot swarm state migration

This commit is contained in:
Meta Vens 2026-06-08 19:20:11 +01:00
commit 1150823e2a
7 changed files with 163 additions and 8 deletions

View file

@ -406,7 +406,7 @@ export const voidSelfProfileSchema = z.object({
updatedAt: timestampSchema,
}).strict();
export const voidModerationCursorSchema = z.object({
const voidModerationCursorDocumentBodySchema = z.object({
schemaVersion: z.literal(1),
lastReviewedMessageId: z.string().trim().min(1).optional(),
lastReviewedTimestamp: timestampSchema.optional(),
@ -415,6 +415,20 @@ export const voidModerationCursorSchema = z.object({
updatedAt: timestampSchema,
}).strict();
export const voidModerationCursorSchema = z.preprocess((raw) => {
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
return raw;
}
const document = raw as Record<string, unknown>;
if (!("userStatuses" in document)) {
return raw;
}
const { userStatuses: _legacyUserStatuses, ...currentDocument } = document;
return currentDocument;
}, voidModerationCursorDocumentBodySchema);
export const voidSpeechReceiptsSchema = z.object({
schemaVersion: z.literal(1),
recentReceipts: z.array(deliveryReceiptSchema).default([]),
@ -466,7 +480,7 @@ export const voidAgencyPressureSchema = z.object({
updatedAt: timestampSchema,
}).strict();
export const voidFaceAffectSchema = z.object({
const voidFaceAffectDocumentBodySchema = z.object({
schemaVersion: z.literal(1),
needs: z.array(faceAffectNeedSchema).default([]),
socialBonds: z.array(faceSocialBondSchema).default([]),
@ -477,6 +491,31 @@ export const voidFaceAffectSchema = z.object({
updatedAt: timestampSchema,
}).strict();
export const voidFaceAffectSchema = z.preprocess((raw) => {
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
return raw;
}
const document = raw as Record<string, unknown>;
if (!("userStatuses" in document) && !("stressResponses" in document)) {
return raw;
}
const {
userStatuses: legacyUserStatuses,
stressResponses: _legacyStressResponses,
...currentDocument
} = document;
if ("statusReads" in currentDocument) {
return currentDocument;
}
return {
...currentDocument,
statusReads: legacyUserStatuses,
};
}, voidFaceAffectDocumentBodySchema);
export const voidSelfProfileDocument = defineDocumentType({
type: VOID_SELF_STATE_DOCUMENT_TYPES.selfProfile,
schema: voidSelfProfileSchema,
@ -525,6 +564,12 @@ export const voidFaceAffectDocument = defineDocumentType({
global: true,
});
export const legacyVoidPersonaAffectDocument = defineDocumentType({
type: "void.persona_affect",
schema: voidFaceAffectSchema,
global: true,
});
export const voidSelfStateDocumentRegistry = defineDocumentRegistry(
voidSelfProfileDocument,
voidModerationCursorDocument,
@ -534,6 +579,7 @@ export const voidSelfStateDocumentRegistry = defineDocumentRegistry(
voidAgencyPressureDocument,
voidCandidateInterventionsDocument,
voidFaceAffectDocument,
legacyVoidPersonaAffectDocument,
);
export const voidSelfStateOperationSchema = z.discriminatedUnion("operation", [

View file

@ -11,6 +11,7 @@ import {
type VoidSelfStateOperation,
type VoidSpeechReceipts,
type VoidThoughtMemory,
legacyVoidPersonaAffectDocument,
voidCandidateInterventionsDocument,
voidFaceAffectDocument,
voidAgencyPressureDocument,
@ -125,7 +126,10 @@ function readTypedStateOrEmpty(
agencyPressure: cache.getGlobal(voidAgencyPressureDocument) ?? empty.agencyPressure,
candidateInterventions:
cache.getGlobal(voidCandidateInterventionsDocument) ?? empty.candidateInterventions,
faceAffect: cache.getGlobal(voidFaceAffectDocument) ?? empty.faceAffect,
faceAffect:
cache.getGlobal(voidFaceAffectDocument) ??
cache.getGlobal(legacyVoidPersonaAffectDocument) ??
empty.faceAffect,
};
if (identity) {
repairSelfProfileIdentity(state, identity);
@ -148,6 +152,7 @@ async function writeTypedState(
await cache.putGlobal(voidAgencyPressureDocument, stripUndefined(state.agencyPressure));
await cache.putGlobal(voidCandidateInterventionsDocument, stripUndefined(state.candidateInterventions));
await cache.putGlobal(voidFaceAffectDocument, stripUndefined(state.faceAffect));
await cache.deleteGlobal(legacyVoidPersonaAffectDocument);
}
function repairSelfProfileIdentity(