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
Good, builds fine. Now let's run the relevant test.
Assistant
Let's add a helper method in project.go and use it in both places.
Assistant
Now let's replace the two direct assignments with the helper call.
Assistant
Now let's check for other places where typingsFiles is set, potentially requiring invalidation too (e.g., DidUpdateATAState).
Assistant
Now let's also add a defensive fallback in
getCommandLineWithTypingsFilesin case something still ends up nil, to avoid ever passing nil Config to NewProgram:Assistant
Now let's also add extra defense directly in
SingleThreaded/OptionsorNewProgramto avoid crashing outright even if some other unexpected path passes nil Config. Let's check if that's reasonable without breaking things.Assistant
Now let's write a targeted reproduction test to confirm the crash scenario is actually fixed. Let's try to construct a scenario that triggers double invalidation within the same generation to actually hit the original nil-Config bug before the fix, then verify after fix it doesn't crash.
Assistant
Good, these look like they follow the intended immutable-per-object pattern, not resettable-with-invalidation like ours. Let's finalize by reviewing full diff and running the whole test suite for project + compiler + lsp packages.
Assistant
Now let's run broader test suite to make sure nothing broke.
Assistant
All pass. Now let's also run the race detector on the project tests to be extra sure about concurrency safety of our new code.
Assistant
Let's also run the full repo test suite briefly for good measure (at least go build all + broader tests), given time constraints focusing on affected areas.
Assistant
Good — everything compiles across the whole repo (this ran a "compile-only" pass by using
-run NOPE). Let's clean up temp files and do a final review.Assistant
Good, let's write the whitebox test now.
Assistant
Good, this pattern avoids the import cycle. Let's rewrite the test using this setup, with LoggingEnabled true to exercise logger paths, and manual ATA changes.
Assistant
Test passes with the fix. Now let's revert the fix temporarily to confirm this test actually reproduces the original crash (i.e., it fails without the fix).
Assistant
Now add debug in the ATA update site too:
Assistant
Good,
vfs.FSinterface itself hasWriteFile. Let's rewrite the test using this more realistic approach.Assistant
Good, fix restored cleanly. Now let's write the deterministic low-level test.
Assistant
Now let's write the finalized test file with a minimal fake FileSource + host.
Assistant
Test passes with the fix. Now let's verify it fails without the fix (by temporarily reverting invalidateCommandLineWithTypingsFiles to old behavior).
Assistant
We've confirmed both directions: the test fails on the pre-fix behavior and passes with the fix. Now let's also verify the defensive fallback works independently (in case someone forgets to use the helper) by testing that specific path too. But first, let's run full test suite again with everything in place.
Assistant
All tests pass. Let's check the full project package test result summary (not truncated) and race detector run.
Assistant
All green. Let's run gofmt/goimports check and go vet on the whole repo, plus a final full diff review.
Assistant
Clean. Let's view the final diff including the new test file.
Assistant
This all looks correct and well-tested. Let's do one more full check: build everything, run the whole project test suite once more, and run a broader compile check across the repo.
Assistant
Confirmed: this fswatch failure is pre-existing and unrelated to our changes (sandbox lacks fanotify support). All relevant tests pass with our fix.
Assistant
Good, no leftover debug code (grep found nothing, exit code 1 as expected). Let's do a final full test run and submit.
Assistant
Everything is working as expected. Let's do a final review of the complete diff before submitting.
Assistant
This looks complete and well-verified. Let's go through the checklist explicitly:
Assistant
Everything passes. The fix is complete and thoroughly validated. Let's do the final submission.
Summary
Root cause: In
internal/project/project.go,Project.getCommandLineWithTypingsFiles()caches its result incommandLineWithTypingsFiles, guarded by a (). Several call sites invalidate the cache by setting to force recomputation (e.g. when changes, or when ATA updates ). However, only ever runs its body once per value — resetting the cached pointer to has no effect if the already fired for that value. Since a value can be mutated more than once within the same "generation" (the box is cloned only on the call; subsequent calls mutate the same object), a second invalidation after the already fired left permanently returning . That was then passed as to , which crashed inside ( returned , then dereferenced a nil pointer) — exactly matching the reported stack trace.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.