{"record":{"id":"22d7e651a48ea2d9","repo":"microsoft/typescript-go","slug":"w-failed-to-update-temporary-snapshot-w","errorCode":null,"errorMessage":"%w: failed to update temporary snapshot: %w","messagePattern":"%w: failed to update temporary snapshot: %w","errorType":"error_code","errorClass":"ErrClientError","httpStatus":null,"severity":"error","filePath":"internal/api/session.go","lineNumber":1075,"sourceCode":"\t\tChanges:  changes,\n\t}, nil\n}\n\n// handleUpdateTemporarySnapshot creates a temporary snapshot that overrides the\n// content of a single file, without opening/closing any projects or files and\n// without advancing the session's latest snapshot.\nfunc (s *Session) handleUpdateTemporarySnapshot(ctx context.Context, params *UpdateTemporarySnapshotParams) (*UpdateSnapshotResponse, error) {\n\tbaseSD, err := s.retainSnapshotData(params.Snapshot)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer func() { _ = s.releaseSnapshot(params.Snapshot) }()\n\n\turi := params.File.ToURI(s.projectSession.GetCurrentDirectory())\n\n\tsnapshot, err := s.projectSession.APIUpdateTemporary(ctx, baseSD.snapshot, uri, params.NewText)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%w: failed to update temporary snapshot: %w\", ErrClientError, err)\n\t}\n\n\thandle := snapshotHandle(snapshot)\n\ts.snapshotsMu.Lock()\n\tsd, exists := s.snapshots[handle]\n\tif exists {\n\t\tsnapshot.Deref(s.projectSession)\n\t\tsd.refCount++\n\t} else {\n\t\tsd = &snapshotData{\n\t\t\tsnapshot:                snapshot,\n\t\t\trefCount:                1,\n\t\t\tsymbolRegistry:          make(map[SymbolID]*ast.Symbol),\n\t\t\tsymbolCanonicalProjects: make(map[SymbolID]ProjectID),\n\t\t\tprojectRegistries:       make(map[ProjectID]*projectRegistryData),\n\t\t}\n\t\ts.snapshots[handle] = sd\n\t}","sourceCodeStart":1057,"sourceCodeEnd":1093,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/internal/api/session.go#L1057-L1093","documentation":"updateTemporarySnapshot failed inside projectSession.APIUpdateTemporary, wrapped in ErrClientError. This call builds a scratch snapshot by applying params.NewText at the given file URI on top of the base snapshot; it fails when the base snapshot does not contain the file/project state needed (e.g. the file was never opened into that snapshot) or when the context is canceled.","triggerScenarios":"Calling updateTemporarySnapshot for a file that was not passed via openedFiles in the base updateSnapshot; using a base snapshot handle that was already released or superseded; cancellation mid-reparse.","commonSituations":"Completion-style flows that send didChange-style text without a prior open; client state machines that reuse a stale snapshot after the editor closed and reopened the file.","solutions":["Ensure the target file was opened (openedFiles) in an updateSnapshot and use the handle from that response as params.Snapshot","Do not reuse snapshot handles after calling release on them","Retry with a fresh updateSnapshot if the editor reopens the file"],"exampleFix":"// before\nupdateSnapshot(ctx, changes) // changes does NOT include the file\nupdateTemporarySnapshot(base, file, newText) // fails\n\n// after\nresp, _ := updateSnapshot(ctx, changesWithFileOpened)\nupdateTemporarySnapshot(resp.Snapshot, file, newText)","handlingStrategy":"validation","validationCode":"// Ensure the file is open in the base snapshot before a temporary update.\nopened := false\nfor _, f := range lastUpdateResponse.Changes /* or your tracked openedFiles */ {\n    if f == targetFile { opened = true }\n}\nif !opened {\n    resp, err := updateSnapshot(ctx, openFile(targetFile))\n    if err != nil { return err }\n    baseSnapshot = resp.Snapshot\n}","typeGuard":"func canUpdateTemporary(base api.SnapshotID, baseValid bool, fileOpened bool) bool {\n    return base != 0 && baseValid && fileOpened\n}","tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"temporary snapshot\") {\n        // re-open the file via updateSnapshot, then retry with the fresh handle\n    }\n    return err\n}","preventionTips":["Model open/close state client-side and mirror editor didOpen/didClose into updateSnapshot","Always pair a temporary update with the handle from the update that opened the file","Never call updateTemporarySnapshot with a handle you already released"],"tags":["snapshot","temporary-snapshot","file-tracking","api"],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}