Keep cached scene identities aligned with the current plan

This commit is contained in:
2026-11-22 09:37:16 +00:00
parent 8ea96dc7a4
commit 9074547e33
4 changed files with 223 additions and 0 deletions

View File

@@ -79,6 +79,24 @@ func (e *Extractor) Extract(ctx context.Context, req contracts.TypedExtractionRe
chunk := source.Chunk{ID: req.Chunk.ID, Ref: req.Chunk.Ref}
index := source.NewDocumentIndex(req.Source)
if cache := req.Operation.Cache; cache != nil && cache.Decode != nil {
owned := *cache
decode := cache.Decode
owned.Decode = func(content []byte) (dnd.SceneDescriptionList, error) {
value, err := decode(content)
if err != nil {
return value, err
}
if len(value.Scenes) != 1 || value.Scenes[0].SourceRef != chunk.Ref {
return dnd.SceneDescriptionList{}, fmt.Errorf("cached scene does not describe the current chunk range")
}
// Chunk ordinals can change without changing the semantic prompt.
value.Scenes = append([]dnd.SceneDescription(nil), value.Scenes...)
value.Scenes[0].ID = chunk.ID
return sceneFallback(&value, chunk, index)
}
req.Operation.Cache = &owned
}
materials := shared.PromptInputs(sourceInput, req.References)
inputs := make(map[string]promptkit.ArtifactRef, len(materials))
for name, material := range materials {