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 inspect the repository and the
Program.SingleThreadedimplementation plus its construction/update call paths, then identify the unsafe state transition and reproduce it with the most relevant tests. - Assistant
The crash point dereferences
p.opts.Configthroughp.Options()whileNewProgramis still initializing. I’ll trace howProgramOptions.SingleThreadedandConfigare populated during project snapshot cloning, and inspect recent history/tests for the intended precedence and nil-state semantics. - Assistant
Configis supplied in the normal path, so this is more likely a concurrency failure than an ordinary nil input. The project code recently addressed a relatedCreateProgram/UpdateProgramrace; I’ll inspect that change and snapshot/project cloning to determine whetherSingleThreadedis reading mutable project configuration concurrently. - Assistant
I’ll inspect the configuration container’s synchronization and the dirty-box cloning model. The key question is whether
Programstores a pointer whose compiler-options field can temporarily be nil or replaced during snapshot construction. - Assistant
The dirty lock is intentionally a no-op because each builder owns copy-on-write boxes, while cloned projects share immutable pointers until mutation. I’ll inspect
Project.Cloneand command-line augmentation for copied synchronization primitives or shared mutable option pointers, then run race-focused project tests. - Assistant
One concrete defect is visible in
SingleThreaded:DefaultIfUnknown(p.Options().SingleThreaded)eagerly callsp.Options()even when the explicitProgramOptions.SingleThreadedoverride is known. That violates the override’s purpose and can panic for partially configured programs, but the snapshot path normally leaves it unknown. I’ll inspect all constructors and option parsing invariants and use the race detector on project tests to see whether the reported snapshot path exposes a second issue. - Assistant
The race tests were blocked only because this environment has no default Go module cache path; I’ll rerun with an isolated cache. In parallel, I’ll inspect
processAllProgramFilesto see whether nil compiler options are intentionally supported—if they are,SingleThreadedis the exceptional unsafe dereference and the guard is the direct fix. - Assistant
Nil config is not supported by file loading, so a simple nil guard would only obscure the failure. The snapshot path often enters
UpdateProgram, which shallow-copiesprocessedFiles; I’ll inspect that structure for mutexes/atomics and its update operations, since copying active synchronization state can produce fatal runtime crashes whose goroutine stack happens to be inSingleThreaded. - Assistant
The race suite passes, and
processedFilesitself has no copied synchronization primitives. The failure is therefore localized to option resolution. I’ll examine malformed/deleted-config snapshot tests and parser guarantees, then implementSingleThreadeddefensively with explicit short-circuiting (known override first, compiler option only when available). This is safe for later calls and prevents a snapshot’s temporarily incomplete config from turning a scheduling hint into a fatal crash. - Assistant
A guard inside
SingleThreadedalone would merely move a nil-options panic into file loading. To make the fix complete, I need to establish whether parser output can have a nilCompilerOptions; if so, the correct boundary isNewProgram, normalizing it once before any option access. I’ll inspect the parser construction paths and existing conventions for default options. - Assistant
Parser-created command lines always allocate compiler options, so malformed JSON is not the cause. I’ll use blame/history around
SingleThreadedto see whether its fallback behavior changed recently and inspect snapshot concurrency tests for explicit single-thread mode; this should distinguish a regression in eager fallback evaluation from broader config normalization. - Assistant
History confirms
SingleThreadedused to read a cached compiler-options pointer; after that cache was removed, the method began eagerly traversing the config pointer even when the explicit scheduling override was authoritative. I’ll make resolution short-circuit and treat unavailable config options as the zero/default scheduling value. This preserves all valid-program behavior, avoids mutating shared parsed configs, and makes this boolean scheduling query non-fatal during snapshot transitions. - Assistant
The targeted compiler/project tests pass. I’ll now run the full repository suite and re-run the affected packages under the race detector after the change, then inspect the final diff/status. The pre-fix crash cannot be deterministically reproduced from existing tests; I’ll explicitly note that in the requested checklist rather than overstate verification.
- Assistant
Final verification and requested checklist:
- Successfully reproduced the reported error: I did not reproduce the exact production snapshot crash; the repository’s snapshot/project tests and race runs did not trigger it. Inspection did confirm the unsafe eager config dereference at the reported top frame.
- Confirmed the fix resolves the error: The changed method no longer dereferences config options when an explicit
SingleThreadedvalue is available, and safely defaults when options are unavailable. Targeted compiler/project tests and race tests pass. - Considered edge cases: Known true/false overrides now both short-circuit; unknown values still inherit valid compiler options; absent options default to normal multi-threaded behavior rather than crashing.
- Ran affected existing tests:
go test ./internal/compiler ./internal/projectandgo test -race ./internal/compiler ./internal/projectpass.go test ./...passes except environment-dependentinternal/fswatchfanotify tests because the filesystem reportsname_to_handle_at: operation not supported; this is unrelated to the change.
The final diff is limited to
Program.SingleThreaded, with formatting and diff checks clean. I’ll submit it now.
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 →