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
Program.SingleThreadedimplementation, then trace its callers and relevant tests to identify the snapshot-update race or invalid state behind the crash. - Assistant
The crash point is a dereference through
p.Options()(p.opts.Config.CompilerOptions()), whileSingleThreadedis invoked very early during construction. I’ll inspectProgramOptions, project program creation, and config lifecycles to determine which component can legitimately be absent and what fallback semantics are expected elsewhere. - Assistant
Configis supplied byProject.CreateProgram, so a simple missing config is unlikely. The more plausible nil isConfig.CompilerOptions(): snapshot cloning may encounter a transient or partially initialized parsed command line. I’ll inspect that accessor and all parsed-command-line constructors/mutators, plus recent history around the implicated lines for known concurrency-related changes. - Assistant
I’ll now read the parsed command line storage and project clone/cache reset logic closely. In particular, the project clone may copy a
sync.Oncewhile clearing or replacing the associated cached command line, which can makegetCommandLineWithTypingsFilesreturn nil during snapshot updates. - Assistant
The root cause is now concrete:
getCommandLineWithTypingsFilesmarkscommandLineWithTypingsFilesOncedone. Later snapshot updates clear onlycommandLineWithTypingsFiles, not thesync.Once. A subsequentCreateProgramskips the initializer and passes nilConfig, causing the fatal dereference inSingleThreaded. I’ll inspect all typing/config mutation paths and project locking/copy-on-write guarantees, then implement a centralized cache reset that resets both fields everywhere the inputs change. - Assistant
There is a second invalidation input:
typingsFilesitself changes, but that path currently does not invalidate the augmented command line at all. I’ll inspect those ATA update flows and then patch both config and typings mutations. The reset is safe because project mutations occur on copy-on-write clones under the dirty container lock; no active goroutine shares the clone’ssync.Once. - Assistant
I’ll add a private invalidation helper and use it whenever either dependency (
CommandLineortypingsFiles) changes. This fixes both the reported nil-config crash and stale ATA roots. I’ll then run the focused project test before/after as available, broader project/compiler tests, and race/static checks if practical. - Assistant
The patch is minimal and all known invalidation sites now reset the guard. I’ll run the existing regression test that exercises command-line replacement after ATA, plus the full
internal/projectandinternal/compilersuites. - Assistant
The prior test command was malformed due to a quoting typo and did not execute. I’ll rerun it correctly.
- Assistant
Tests are blocked only because this environment has both
GOMODCACHEandGOPATHunset. I’ll inspect the Go/tooling setup and configure a temporary external cache rather than altering the repository. - Assistant
I’ll use
/tmp/gopathfor Go’s cache and rerun the focused and package tests. - Assistant
Dependencies downloaded successfully; Go also requires an explicit build cache because
HOMEis unset. I’ll setGOCACHE=/tmp/gocacheand rerun. - Assistant
The focused regression and both affected package suites pass. I’ll confirm the named subtest actually ran (verbose mode), run it under the race detector, and run
go veton the changed package to catch unsafe lock/sync.Onceusage. - Assistant
Validation passed, including the exact ATA/config subtest under
-raceandgo vet. I’ll do a final audit for any remaining direct cache mutations, review the diff/status, and ensure no generated/cache files entered the repository.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.