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:669ADDITIONAL 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.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- Assistant
I’ll inspect the repository state and the implicated compiler/project code first, then trace the lifecycle that can make
SingleThreadedcrash during snapshot cloning. After identifying the invariant violation, I’ll implement the smallest general fix and run focused plus broader tests. - Assistant
SingleThreadeddereferencesp.opts.Configthroughp.Options(). Since it is called at the start ofNewProgram, the crash likely means a project temporarily constructedProgramOptionswith a missing config during snapshot mutation. I’ll inspect exact line numbers,ProgramOptions,Project.CreateProgram, and all constructors/callers to determine whether the right fix is defensive option resolution or preserving project state. - Assistant
The exact failing expression can panic only if
ConfigorCompilerOptions()is nil.CreateProgramgets that config fromgetCommandLineWithTypingsFiles, so I’ll now inspect that cache and project cloning/copy semantics. Snapshot updates often expose shallow-copy aliasing, and the nearby mutation resetscommandLineWithTypingsFiles, which is a strong lead. - Assistant
I found a likely concrete bug:
Projectcaches the augmented command line withsync.Once, but update paths clear only the cached pointer, not thesync.Once. On a cloned project, if the once has already fired and the pointer is reset to nil,getCommandLineWithTypingsFilesskips initialization forever and returns nil—exactly causing this stack. I’ll inspect the clone and reset sites/tests to confirm and identify every invalidation that must reset both fields. - Assistant
The clone intentionally starts with a fresh
sync.Once, so a single invalidation after cloning is safe. The crash requires two phases in one snapshot build: the cloned project first reads the inherited non-nil cache (consuming its fresh once), then a later phase clears the pointer; because the dirty box no longer clones, the consumed once remains. That aligns with snapshot update ordering and the reported stack. I’ll inspect ATA invalidation and concurrency assumptions, then introduce one invalidation helper that atomically resets both cache state fields and replace both direct resets. - Assistant
There is another correctness issue at the ATA change site: changing
typingsFilesmust invalidate the augmented command line too, otherwise a previously computed cache can retain stale typings. I’ll inspect that path and then use a helper for all three state changes (inferred roots, configured command line, and ATA typings), ensuring the cache andsync.Onceare reset together. - Assistant
Before editing, I’ll run the existing focused regression test to see whether it reproduces under this checkout. Even if it doesn’t deterministically trigger the consumed-
Oncesequence, it exercises the same cache invalidation behavior and will be useful after the fix. - Assistant
The focused test is currently blocked by environment configuration (
GOMODCACHEandGOPATHare both unset), not by code. I’ll inspect repository setup documentation and Go environment, configure a temporary external cache as intended, and rerun it. - Assistant
I’ll set
GOPATH=/tmp/gofor test commands (keeping generated caches outside the repository) and retry the focused test. - Assistant
Dependencies downloaded successfully, but the stripped environment also lacks a build cache location. I’ll add
GOCACHE=/tmp/go-cacheand rerun. - Assistant
The existing test passes, confirming the bug is sequence-dependent rather than guaranteed by a simple command-line change. Instead of resetting
sync.Once(which is unsafe if invalidation ever overlaps a read), I’ll replace it with a mutex-protected invalidatable cache. This supports any number of updates, preserves concurrent safety, and lets one helper consistently invalidate on all dependency changes. - Assistant
The patch now makes cache invalidation repeatable and also fixes stale cache reuse after ATA changes. I’ll run the focused test repeatedly to stress snapshot sequencing, then the complete
internal/projectpackage tests. - Assistant
Focused and full project tests pass. I’ll now validate the directly adjacent compiler package and run
go veton the changed package; this also checks that the mutex is not accidentally copied and catches lock-related structural mistakes. - Assistant
Compiler tests and vet pass. Because this fix changes synchronization around a cache, I’ll run the focused project test under the race detector, then review the final diff and repository status for unintended files.
- Assistant
The race test passes and only the two intended source files are modified. To satisfy the reported-crash verification more directly without adding tests to the repository, I’ll inspect whether a small temporary standalone reproduction can construct the private project state; if feasible, I’ll run it from a disposable worktree and remove it afterward.
- Assistant
A truly minimal external reproducer would need substantial private host construction; forcing it via a temporary in-package test would violate the instruction not to add tests. The failing state is nevertheless directly established: a consumed
sync.Onceplus a nil cache deterministically returns nil, and the reported line then dereferences it. I’ll perform one broadinternal/...test run to check integration beyond the two focused packages.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.