ISSUE DESCRIPTION Fatal crash in (*Program).SingleThreaded on snapshot update [code]…
- User
ISSUE DESCRIPTION
Fatal crash in
(*Program).SingleThreadedon snapshot updateinternal/compiler.(*Program).SingleThreaded() internal/compiler/program.go:416 internal/compiler.NewProgram() internal/compiler/program.go:274 internal/project.(*Project).CreateProgram() internal/project/project.go:376 internal/project.(*ProjectCollectionBuilder).updateProgram.func2.1() internal/project/projectcollectionbuilder.go:1055 internal/project/dirty.(*Box[...]).Change() internal/project/dirty/box.go:41 internal/project.(*ProjectCollectionBuilder).updateProgram.func2() internal/project/projectcollectionbuilder.go:1052 internal/project/dirty.(*Box[...]).Locked() internal/project/dirty/box.go:57 internal/project.(*ProjectCollectionBuilder).updateProgram() internal/project/projectcollectionbuilder.go:1051 internal/project.(*ProjectCollectionBuilder).DidRequestFile() internal/project/projectcollectionbuilder.go:397 internal/project.(*Snapshot).Clone() internal/project/snapshot.go:353 internal/project.(*Session).updateSnapshot() internal/project/session.go:1101 internal/project.(*Session).getSnapshot() internal/project/session.go:819 internal/project.(*Session).getSnapshotAndDefaultProject() internal/project/session.go:877 internal/project.(*Session).GetLanguageService() internal/project/session.go:890 internal/lsp.init.func1.registerLanguageServiceDocumentRequestHandler[...].13() internal/lsp/server.go:826 internal/lsp.(*Server).handleRequestOrNotification() internal/lsp/server.go:669Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- Assistant
I'll start by examining the crash location and surrounding code to understand the failure.
- Assistant
Let me inspect the crash site in
program.goand related update logic. - Assistant
The nil likely comes from
p.optsorp.Options(); I'll inspect Program construction next. - Assistant
So
NewProgramis called and during construction it immediately callsp.SingleThreaded()at line 274. Then Options() is: - Assistant
I'll check how CreateProgram builds Program options and whether Config can be nil.
- Assistant
Next I'll inspect
getCommandLineWithTypingsFilesand the update path that triggers the crash. - Assistant
Looking more carefully at getCommandLineWithTypingsFiles - if ATA is not enabled, maybe it returns something different.
- Assistant
I'll check when inferred projects are created and under what conditions CommandLine stays nil.
- Assistant
Let me look at NewInferredProject and also search for recent commits or tests related to this crash. Also look at processAllProgramFiles and when Config.CompilerOptions() would panic. I see the crash is happening in
SingleThreadedwhenConfigis nil. The double-locked pattern inupdateProgramis suspicious — there's a window between the twoLockedcalls where the project could be deleted or updated.Let me check the code around
updateProgrammore carefully. - Assistant
Let me look at NewProject
- Assistant
If
CompilerOptions()returns nil, calling.SingleThreadedwould panic—I'll verify that next. - Assistant
Let me look at recent git history and issues related to this crash, and also look at CHANGES.md. Also search for related TODOs or FIXMEs.
- Assistant
There's already a nil-config fix in history — I'll inspect that commit and the CreateProgram race fix for patterns.
- Assistant
I'll inspect the dirty box helpers — Change might not persist across the two Locked calls.
- Assistant
Oops, can't open a directory with open
- Assistant
I'll dig into SyncMap next, since configured projects may load through it.
- Assistant
Looking at the crash again:
- Assistant
I'll examine Clone and DidRequestFile, since the crash stack goes through them.
- Assistant
I'll inspect ancestor project loading and when updateProgram is invoked without acquiring, because that can leave CommandLine nil.
- Assistant
Let me look more carefully at findOrCreateDefaultConfiguredProjectWorker and around line 723, and also acquireConfigForProject.
- Assistant
If Config is set but CompilerOptions is nil, that access panics—I'll find how such a ParsedCommandLine can be produced.
- Assistant
I'll check reloadIfNeeded and when commandLine can stay or become nil.
- Assistant
Looking at reloadIfNeeded:
- Assistant
Look at newConfigFileEntry - pendingReload starts as PendingReloadFull hopefully.
- Assistant
I'll check whether snapshot updates are serialized or can run concurrently, and whether that can clear CommandLine between the two locks.
- Assistant
Looking at GetLanguageServiceWithAutoImports - it clones without snapshotUpdateMu! That could mean concurrent clones of the same snapshot. Each clone has its own builder though, so data shouldn't race...
- Assistant
Let me show the CreateProgram race fix
- Assistant
Stack lines point at Box helpers; I'll match those offsets to the current dirty and updateProgram code.
- Assistant
The stack runs through Box.Change/Locked, so this is the inferred-project path — I'll dig into how its CommandLine can become nil.
- Assistant
I'll look for CompilerOptions being nil on NewParsedCommandLine and edge cases around inferred options.
- Assistant
Look at updateInferredProjectRoots more carefully:
- Assistant
Look at this comment:
Let me break this down: 1. - Assistant
There's df4272127 "Ensure inferred project has up to date program when it might contain the requested File" - let meVocabulary look at that and recent issues.
- Assistant
Look at line 463 in project.go:
- Assistant
Wait - the stack has box.go but maybe Go generics names get summarized as Box even for similar tric structures? Unlikely - other is SyncMapEntry.
- Assistant
Older code crashed when both CommandLine were nil and dirty; the nil check should prevent that—I'll verify GetParsedCommandLine still can't yield Config with nil CompilerOptions.
- Assistant
I'll search the tree for notes and related failing tests, and try reproducing from existing tests.
- Assistant
I'll inspect HandleAPIRequest and API project opening next.
- Assistant
I'll inspect the file-close snapshot update path next.
- Assistant
I'll inspect DidRequestProjectTrees for concurrent updateProgram on the inferred project.
- Assistant
I'll look through branches and recent checking for related WIP.
- Assistant
I'll inspect deleteConfiguredProject and how it interacts with concurrent updates.
- Assistant
I'll search for Fatalf and other fatal-log paths around that code.
- Assistant
There's a panic recover that re-panics in snapshot.go:241. Let me look at that.
- Assistant
Found it:
commandLineWithTypingsFilesis cleared whilesync.Oncestays spent, so later calls return nil. I'll confirm all clear paths and fix them. - Assistant
There's already a test covering this — I'll open it.
- Assistant
There's already a test for this — I'll run it to see if it fails.
- Assistant
Need to set up Go environment.
- Assistant
I'll check paths that set dirty outside Change, which would skip cloning and leave Once spent.
- Assistant
I'll check other CreateProgram callers and whether Once can be spent while dirty stays true.
- Assistant
I'll check the history of the typings-files plumbing and that test.
- Assistant
Let me look at the fix commit a94299b15
- Assistant
I'll pin lineup numbers at older commits to match the stack.
- Assistant
I'll write a focused unit test that reproduces the Once/clear nil path without cloning.
- Assistant
Oops, file can't be named _test.go forgoing go run.
- Assistant
Box stays dirty across updates while Project.dirty is cleared — that can leave Once spent and cache nil. Checking cleanupInferredProject.
- Assistant
Reproduced the root cause: spent
sync.Onceplus cleared cache returns nil. Implementing the fix. - Assistant
I'll drop
sync.Once, recompute when the cache is nil, and invalidate on ATA/root updates. - Assistant
Removing the duplicate comment and finishing the remaining edits.
- Assistant
Still have duplicateline—fixing with replace.
- Assistant
Next I'll remove the unused
syncimport and fixgetCommandLineWithTypingsFiles. - Assistant
Need to open the top of the file.
- Assistant
There's still "context" in import which might have been unused before too. Let me check.
- Assistant
context is used, sync is not after our change. Remove脚本 sync.
- Assistant
Now fix getCommandLineWithTypingsFiles
- Assistant
Replace the getCommandLineWithTypingsFiles function.
- Assistant
I'll also clear the cache when ATA updates typingsFiles so root lists don't go stale.
- Assistant
Need to open the file at that line.
- Assistant
Now I can replace.
- Assistant
Cleaning up the comment typos I introduced.
- Assistant
I'll script a temp repro for the spent-Once + cleared-cache path, then verify the fix.
- Assistant
I'll add a temporary same-package test that hits the spent-Once clear path.
- Assistant
I'll add a proper same-package temporary test next.
- Assistant
I'll rewrite that as a cleaner white-box unit test.
- Assistant
I'll construct the Project manually to avoid NewProject watcher setup.
- Assistant
Fix verified; removing the temp test and running the project package suite.
- Assistant
All project tests passed. Checking for leftover Once references and reviewing the final diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.