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.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /typescript-go, current file: none) bash-$
- Assistant
I'll start by examining the repository structure and the crash location in the stack trace.
- Assistant
Let me inspect the crash site and surrounding SingleThreaded logic.
- Assistant
I'll inspect NewProgram and Options next, since the crash looks like a nil deref there.
- Assistant
So
Options()returnsp.opts.Config.CompilerOptions(). If Config is nil, that would crash. - Assistant
Checking Project.CreateProgram next for a nil Config path.
- Assistant
I'll look into getCommandLineWithTypingsFiles and how updateProgram is invoked.
- Assistant
Let me look at getCommandLineWithTypingsFiles more closely and also git log/blame for recent related changes.
- Assistant
Looking at how CommandLine is set on projects and when it can be nil.
- Assistant
Looking at updateProgram more carefully:
- Assistant
If Options() returns nil, accessing SingleThreaded on it would panic. Checking CompilerOptions next.
- Assistant
I'll dig through git history and related code around SingleThreaded for recent changes.
- Assistant
Let me look for when SingleThreaded method was introduced and if Options can return nil. Also check processAllProgramFiles.
- Assistant
Looking at CompilerOptions method - if ParsedConfig is nil, it would panic too.
- Assistant
Examining how inferred projects initialize CommandLine.
- Assistant
Looking at NewProject and newInferredProject
- Assistant
Reviewing the recent race-related fix next.
- Assistant
Searching the repo and recent changes for similar nil-Config handling.
- Assistant
Tracing snapshot Clone and DidRequestFile for how programs get updated.
- Assistant
Searching for assignments that clear CommandLine.
- Assistant
Searching for all CreateProgram call sites.
- Assistant
Looking at line 416 of SingleThreaded more carefully again:
- Assistant
Looking at defaultIfUnknown on Tristate when the argument is obtained from nil. The panic is on the field access. The panic you're seeing is coming from
(*Program).SingleThreaded()at line 416, which does:return p.opts.SingleThreaded.DefaultIfUnknown(p.Options().SingleThreaded).IsTrue()That means `p.
- Assistant
There's a recent commit that might relate: treating empty tsconfigs. I'll inspect that next.
- Assistant
I'll inspect GetTypeAcquisition andJoystick whether nil CommandLine can reach CreateProgram.
- Assistant
Checking updateInferredProjectRoots and configuration update paths.
- Assistant
Checking when finishedProcessing is set relative to SingleThreaded usage.
- Assistant
I'll dig into processAllProgramFiles and nil-Config handling next.
- Assistant
These look related — inspecting those nil-config crash fixes.
- Assistant
Checking the other related nil-config crash fix.
- Assistant
Checking DefaultIfUnknown and related Tristate helpers.
- Assistant
Checking deleteConfiguredProject and concurrent updateProgram interactions.
- Assistant
Let me look atdeleteConfiguredProject fully and alsolook at the dirty box more carefully. Alsomaybe the issue isdifferent - maybe comps Options method changed.
- Assistant
Wait a minute - look at Locked:
- Assistant
Inspecting changeLocked for how deleted entries are handled.
- Assistant
Note that
changeLockedapplies toe.valueeven when deleted! I see the race condition you're describing—Thread B can delete the project while Thread A is still holding the oldCommandLinepointer, and thechangeLockedlogic inSyncMapEntryis applying updates to the stalevalueeven after deletion. - Assistant
I'll look at tsconfig parsing for paths that can leave CompilerOptions nil.
- Assistant
Checking when SingleThreaded was first called during NewProgram relative to file processing.
- Assistant
I'll look at projectcollection.go handling of nil CommandLine and when programs are created during project tree loading.
- Assistant
I found the bug:
commandLineWithTypingsFilesis cleared without resettingsync.Once, so later lookups return nil. Verifying all clear sites and related tests. - Assistant
There's already a test covering this. I'll run it to confirm it fails.
- Assistant
Need to set up go environment.
- Assistant
I'll inspect config acquisition and reload to see when CommandLine is replaced while the project is already dirty.
- Assistant
Checking paths that update inferred roots more than once per snapshot.
- Assistant
Looking at how ATA snapshot updates apply and rebuild programs.
- Assistant
Looking at snapshot Clone for ATA:
- Assistant
Stack line 353 was DidRequestFile in current code at 355. Close enough - lint/shifts. I understand the issue you're describing—it's a classic race condition in how we handle project state updates for Type Acquisition changes. Let me break this down step by step.
The core problem is in
DidUpdateATAStatewhere we updatep.typingsFilesbut don't clearp.commandLineWithTypingsFiles(or reset the Once cache). When we later callgetCommandLineWithTypingsFiles, if the cache is non-nil (from a previous clone), theOnceskips regeneration, leaving us with stale command line that doesn't include the new typings.This manifests as a crash in
SingleThreadedbecauseupdateProgramis called again after the cache is "stuck" in a bad state.Here's my fix:
- Clear the cache properly in
DidUpdateATAState - Make
getCommandLineWithTypingsFilesalways regenerate when typings change
- Clear the cache properly in
- Assistant
I'll write a small repro for the Once/cache bug.
- Assistant
Oops, need non _test.go name.
- Assistant
Confirming the bug. I'll check all callers of getCommandLineWithTypingsFiles and apply a proper fix.
- Assistant
Implementing apiece helper to clear the typings command-line cache and reset Once, and using it at all clear sites (including ATA updates).
- Assistant
Checking why Once was introduced for this cache.
- Assistant
Narrowing in on when Once was added to this cache.
- Assistant
No rg. Use grep.
- Assistant
I'll_check other sync usage in project.go before removing Once.
- Assistant
Applying the fix: remove Once and properly invalidate the typings command-line cache.
- Assistant
I'll restore the top of the file and apply a cleaner edit.
- Assistant
There's also a context import—checking whether it's used.
- Assistant
I'll remove sync.Once field and the Once.Do wrapper, keep simple nil-check lazy init. Alsoadd clearCommandLineWithTypingsFiles method.
- Assistant
Need to remove the once field and fix the getCommandLineWithTypingsFiles and Clear调用 sites.
- Assistant
Now fix getCommandLineWithTypingsFiles
- Assistant
Need to goto the line first.
- Assistant
Now replace the function
- Assistant
Updating call sites to clear the cache on CommandLine and ATA typings changes.
- Assistant
Need goto
- Assistant
Now I can replace both occurrences.
- Assistant
Replace the second occurrence and ATA update.
- Assistant
Now update FTA DidUpdateATAState:
- Assistant
Update ATA to clear the cache when typingsFiles change.
- Assistant
I'll also harden updateProgram so CreateProgram never runs on a deleted/nil project.
- Assistant
goto first
- Assistant
Building and running the related project tests.
- Assistant
Writing a temporary integration reproduction for the clear/rebuild path.
- Assistant
Checking for leftover Once references and verifying the build.
- Assistant
Empty error. Let me run separately.
- Assistant
Adding a temporary in-package test to verify the cache clear/rebuild behavior.
- Assistant
Updating the temporary test to use the project test harness for a real host.
- Assistant
Typo in path.
- Assistant
Where is projecttestutil?
- Assistant
Simplify temp test - mock host IFS briefly. Looking at FS interface:
- Assistant
Let me look at compilerHost struct
- Assistant
Removing the temporary test and re-running the project tests.
- Assistant
Tests passed. Checking the full diff.
- Assistant
Running broader tests to make sure nothing regressed.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →