Skip to content
TheChatArchiveThe Chat Archive
GLMz-ai/glm-5.2· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION Fatal crash in (*Program).SingleThreaded on snapshot update [code]…

  1. User

    ISSUE DESCRIPTION

    Fatal crash in (*Program).SingleThreaded on snapshot update

    internal/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:669
    

    Interface

    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 using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to 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-$

  2. GLM Assistant

    I'll start by exploring the repository structure to understand the codebase and then investigate the crash.

  3. GLM Assistant

    Let me start by exploring the repository structure.

  4. GLM Assistant

    Let me look at the relevant files in the stack trace.

  5. GLM Assistant

    I'll look at the relevant files one at a time.

  6. GLM Assistant

    Now let me understand the crash. The crash is at SingleThreaded() which calls p.Options().SingleThreaded. The Options() method returns p.opts.Config.CompilerOptions(). Let me look at what could be nil here. The crash happens during NewProgram at line 274. Let me look at the DefaultIfUnknown method and the Tristate type.

    Let me look at the crash more carefully. The stack trace shows:

    internal/compiler.(*Program).SingleThreaded()
    	internal/compiler/program.go:416
    internal/compiler.NewProgram()
    	internal/compiler/program.go:274
    

    So SingleThreaded() at line 416 is:

    return p.opts.SingleThreaded.DefaultIfUnknown(p.Options().SingleThreaded).IsTrue()
    

    The crash could be because p.opts.Config is nil, or p.opts.Config.CompilerOptions() returns nil and .SingleThreaded panics, or p.Options() returns nil.

    Let me check the CompilerOptions type and SingleThreaded field.

  7. GLM Assistant

    So CompilerOptions() can return nil if p is nil or p.ParsedConfig.CompilerOptions is nil. Let me look at the SingleThreaded field in core.CompilerOptions.

  8. GLM Assistant

    p.opts.SingleThreaded is a value type (core.Tristate), so DefaultIfUnknown won't panic. The issue is p.Options().SingleThreaded - if p.Options() returns nil (i.e., p.opts.Config is nil or p.opts.Config.CompilerOptions() returns nil), then p.Options().SingleThreaded would be a nil pointer dereference.

    Let me look at how the program is created from the project path.

  9. GLM Assistant

    Let me look at tsoptions.NewParsedCommandLine and ParseCommandLine to understand if it could result in a nil CompilerOptions.

  10. GLM Assistant

    Let me look at the project collection builder code mentioned in the stack trace.

  11. GLM Assistant

    Let me look at the acquireConfigForProject function which returns a commandLine.

  12. GLM Assistant

    Let me look at GetParsedCommandLineOfConfigFilePath and ReloadFileNamesOfParsedCommandLine.

  13. GLM Assistant

    Let me look at ParseJsonSourceFileConfigFileContent to understand how CompilerOptions is set in the resulting ParsedCommandLine.

  14. GLM Assistant

    Let me look at how parsedConfig.options is set, and where the ParsedCommandLine is created from parsedConfig.

  15. GLM Assistant

    So the CompilerOptions field in ParsedCommandLine can be parsedConfig.options which can be nil if parseConfig returns nil options. Let me look at parseConfig to confirm.

    Actually, let me look at parseConfig.

  16. GLM Assistant

    Let me look at parseOwnConfigOfJsonSourceFile and parseOwnConfigOfJson to understand when ownConfig.options could be nil.

  17. GLM Assistant

    So in parseOwnConfigOfJsonSourceFile, the options is always non-nil (from getDefaultCompilerOptions). Let me check getDefaultCompilerOptions.

  18. GLM Assistant

    In the circular config case in parseConfig, the result has options: nil! Let me check mergeCompilerOptions to see if it handles nil parsedConfig.options.

  19. GLM Assistant

    Let me look at how Options() is used across the codebase and understand whether it's expected to never be nil.

  20. GLM Assistant

    Many places use p.Options() and assume it's non-nil. Let me look at how the original TypeScript handles this and check the git history for context.

  21. GLM Assistant

    The submodule isn't checked out. Let me look at the circular config case more carefully, which seems to be the root cause. Let me reproduce the issue first.

  22. GLM Assistant

    Interesting. In processAllProgramFiles, it does compilerOptions := opts.Config.CompilerOptions() and uses compilerOptions.Lib, compilerOptions.NoLib, etc. If compilerOptions is nil, this would crash even before SingleThreaded. But the crash is at SingleThreaded (line 274), which means p.opts.Tracing is nil (skipping line 272). Let me investigate where a project's CommandLine with nil CompilerOptions could come from. Let me look at how projects are initially set up.

  23. GLM Assistant

    Let me look at where configured projects are created initially.

  24. GLM Assistant

    So NewConfiguredProject doesn't set CommandLine. The CommandLine is set later via acquireConfigForProject. Let me look at the ensureConfiguredProjectAndAncestorsForFile and where the configured project's CommandLine gets set for the first time. Let me look at line 998 and the surrounding context in projectcollectionbuilder.go.

  25. GLM Assistant

    Let me look at the test infrastructure to write a reproduction.

  26. GLM Assistant

    Let me write a reproduction test using the test infrastructure. First, let me look at the tsoptionstest helpers.

  27. GLM Assistant

    Let me write a reproduction test for the circular extends case.

  28. GLM Assistant

    The environment doesn't have the necessary env vars set. Let me set them.

  29. GLM Assistant

    The test passed, meaning CompilerOptions() is NOT nil in this case. Let me debug more.

  30. GLM Assistant

    The circular case here doesn't produce nil options because the merge handles it. Let me search for all callers of NewProgram and ProgramOptions to find where a nil Config or nil CompilerOptions could come from.

  31. GLM Assistant

    Let me look at getExtendedConfig and how extended configs are parsed, since there might be a path where a config with nil options becomes a top-level project config.

  32. GLM Assistant

    Let me look at the git history for the SingleThreaded method to understand recent changes.

  33. GLM Assistant

    Let me look at the SingleThreaded method git history specifically.

  34. GLM Assistant

    Let me look at the current NewProgram and the verifyCompilerOptions to understand the order of operations.

  35. GLM Assistant

    Let me check GetTypeAcquisition since getCommandLineWithTypingsFiles calls it.

  36. GLM Assistant

    Let me look at the full updateProgram function in projectcollectionbuilder.go.

  37. GLM Assistant

    Let me look at newConfigFileEntry and when commandLine is first set on a config entry.

  38. GLM Assistant

    The Options() returns nil if p.opts.Config is nil (since CompilerOptions() handles nil receiver). Let me search for NewProgram callers that might not set Config or pass a config with nil CompilerOptions.

  39. GLM Assistant

    Let me look at handleConfigChange and how extended configs are reloaded.

  40. GLM Assistant

    Let me look at the project system test infrastructure to understand how to reproduce a session scenario.

  41. GLM Assistant

    Let me look at the extended config cache implementation.

  42. GLM Assistant

    Let me look at the project's extended config cache implementation.

  43. GLM Assistant

    Let me look at the ExtendedConfigParseArgs and how the cache parses the extended config.

  44. GLM Assistant

    Let me search for all callers of NewParsedCommandLine.

  45. GLM Assistant

    Let me re-examine the CreateProgram at line 376 and the typings files path at line 289.

  46. GLM Assistant

    Let me look at the existing extended config cache test for circular config scenarios.

  47. GLM Assistant

    Let me look at the recent commit that touched program.go and may have introduced this.

  48. GLM Assistant

    Let me look at the config file changes test to understand scenarios where a config becomes invalid.

  49. GLM Assistant

    Let me look at ParseJsonSourceFileConfigFileContent.

  50. GLM Assistant

    Let me check convertMapToOptions to see if it can return nil CompilerOptions, for the ParseCommandLine path.

  51. GLM Assistant

    Let me check the harnessutil and other callers to see if Config could be nil.

  52. GLM Assistant

    Let me look at the full UpdateProgram method.

  53. GLM Assistant

    Let me write a reproduction test using the project session with a circular extends chain.

  54. GLM Assistant

    Let me look at the context around line 998 in projectcollectionbuilder.go.

  55. GLM Assistant

    Let me look at the compilerOptionsParser to see if CompilerOptions field could be nil.

  56. GLM Assistant

    The stack trace shows concurrency (Snapshot.Clone, dirty.Box). Let me look at the dirty.Box and SyncMapEntry mechanism to understand the cloning/race.

  57. GLM Assistant

    Let me look at Project.Clone() to see how CommandLine is handled during cloning.

  58. GLM Assistant

    Let me empirically test various broken tsconfig scenarios to find one that produces nil CompilerOptions.

  59. GLM Assistant

    All configs produce non-nil CompilerOptions, so the nil must come from Config being nil — i.e., p.CommandLine is nil when CreateProgram is called. Let me find all callers of CreateProgram.

  60. GLM Assistant

    Let me look at the full DidRequestFile and findDefaultProject to find a path where updateProgram runs without first acquiring config.

  61. GLM Assistant

    Let me look at cleanupInferredProject and related inferred project handling.

  62. GLM Assistant

    Let me search for places where a ParsedCommandLine might be constructed as a zero-value or without setting CompilerOptions.

  63. GLM Assistant

    Let me look at the session snapshot update path mentioned in the stack trace.

  64. GLM Assistant

    Let me look at updateSnapshot and Snapshot.Clone to understand the dirty project handling.

  65. GLM Assistant

    Let me look at the ATA flow and how typingsFiles gets set on projects.

  66. GLM Assistant

    The stack trace shows dirty.(*Box[...]) (non-thread-safe Box, not SyncMapEntry). Let me check which project uses Box.

  67. GLM Assistant

    The crash is on the inferred project (uses Box). Let me check the Project.dirty default in NewProject/NewInferredProject.

  68. GLM Assistant

    Let me check all usages of dirty.Box to confirm which entries use it.

  69. GLM Assistant

    The crash is on the inferred project. Let me look at how ATA is set up in tests and find existing ATA-related tests to model a reproduction.

  70. GLM Assistant

    Let me run the existing ATA/inferred project test to establish a baseline.

  71. GLM Assistant

    Let me re-examine the exact lines around CreateProgram's NewProgram call to confirm line numbers.

  72. GLM Assistant

    Let me search for any assignment that could set a project's CommandLine to nil.

  73. GLM Assistant

    Line 724 acknowledges project.CommandLine can be nil for configured projects. Let me look at that context.

  74. GLM Assistant

    I found a strong lead. Let me verify by examining the commandLineWithTypingsFilesOnce usage and where commandLineWithTypingsFiles is reset to nil.

  75. GLM Assistant

    I found the root cause. The commandLineWithTypingsFilesOnce (a sync.Once) is marked done after the first getCommandLineWithTypingsFiles computation, but commandLineWithTypingsFiles can be reset to nil (in updateInferredProjectRoots line 999 and updateProgram line 1038) within the same snapshot without resetting the Once. Since Box.Change doesn't re-clone after the first mutation in a snapshot, the Once stays "done" and the next getCommandLineWithTypingsFiles returns nil.

    Let me confirm how multiple DidRequestFile calls happen in one snapshot (multiple documents).

  76. GLM Assistant

    This is the root cause: commandLineWithTypingsFilesOnce (a sync.Once) is never reset when commandLineWithTypingsFiles is invalidated to nil, so a later getCommandLineWithTypingsFiles call returns nil (the Once.Do body is skipped). Let me confirm the clone behavior — Clone() does NOT copy commandLineWithTypingsFilesOnce.

  77. GLM Assistant

    Let me look at the projecttestutil SetupWithTypingsInstaller and ATA driving.

  78. GLM Assistant

    Let me write a reproduction test with ATA + lazy configured project loading + multi-document request.

  79. GLM Assistant

    The scenario didn't crash. Let me debug by examining findDefaultProject and whether configured projects get loaded during the multi-doc request.

  80. GLM Assistant

    findDefaultProject -> findDefaultConfiguredProject -> findDefaultConfiguredProjectFromProgramInclusion which checks if a configured project CONTAINS the file (via program inclusion). So it only finds EXISTING (already-loaded) configured projects. It doesn't LOAD new ones.

    So loading a configured project happens via ensureConfiguredProjectAndAncestorsForFile (called when b.defaultProjectsInvalidated is true in DidRequestFile). Let me re-check DidRequestFile:

    func (b *ProjectCollectionBuilder) DidRequestFile(uri, configuredProjectsOnly, logger) {
        fileName := uri.FileName()
        path := b.toPath(fileName)
        if b.defaultProjectsInvalidated {
            b.ensureConfiguredProjectAndAncestorsForFile(fileName, path, logger)  // loads configured project for this file
            if !b.fs.isOpenFile(path) { return }
        }
        if b.fs.isOpenFile(path) {
            ...
            if result := b.findDefaultProject(fileName, path); result != nil {
                ...
            }
            ...
        }
    }
    

    So ensureConfiguredProjectAndAncestorsForFile(A) loads configuredA (if defaultProjectsInvalidated). So for DidRequestFile(A) to load configuredA, b.defaultProjectsInvalidated must be true.

    When is defaultProjectsInvalidated set? DidChangeCustomConfigFileName (if custom config changed) and... let me check DidChangeFiles / config change. Let me look at where defaultProjectsInvalidated = true is set.

  81. GLM Assistant

    defaultProjectsInvalidated is set by DidChangeCustomConfigFileName (custom config name change), NOT by adding a new tsconfig. New tsconfigs are loaded during DidChangeFiles. Let me check whether DidChangeWatchedFiles immediately updates the snapshot or queues changes that could be batched with a later request.

  82. GLM Assistant

    Let me look at how custom config file name is set in tests, since DidChangeCustomConfigFileName sets defaultProjectsInvalidated which triggers lazy configured project loading per DidRequestFile.

  83. GLM Assistant

    Let me look at Configure to understand how custom config name changes propagate.

  84. GLM Assistant

    Configure queues pendingUserConfigChanges=true, processed on the next flush. So I can batch the custom config change with the multi-doc request. Let me verify flushChanges handles pendingUserConfigChanges.

  85. GLM Assistant

    Let me check how SnapshotChange.Documents is populated from the ResourceRequest.

  86. GLM Assistant

    I've worked out the exact scenario. Let me write the reproduction test using the custom config name to trigger lazy configured project loading across multiple DidRequestFile calls in one snapshot.

  87. GLM Assistant

    I've reproduced the exact crash from the issue — the stack trace matches perfectly. The root cause is confirmed: commandLineWithTypingsFilesOnce (a sync.Once) is never reset when commandLineWithTypingsFiles is invalidated to nil, so a subsequent getCommandLineWithTypingsFiles returns nil (the Once.Do body is skipped), making Config nil and crashing SingleThreaded.

    Since getCommandLineWithTypingsFiles is only called single-threaded within the snapshot build, the sync.Once is unnecessary. Let me replace it with a plain nil-check lazy init. Let me view the exact code.

  88. GLM Assistant

    Now let me apply the fix. First, replace the Once.Do block with a plain nil-check lazy init.

  89. GLM Assistant

    Now let me also invalidate commandLineWithTypingsFiles when typingsFiles change in DidUpdateATAState (currently it isn't, leaving a stale augmented command line). Let me view that code.

  90. GLM Assistant

    The indentation is tabs. Let me check the actual whitespace. The displayed lines show tabs. Let me use the exact indentation. Let me re-read the lines with sed -n to get exact content.

  91. GLM Assistant

    Let me use sed to insert the reset after the typingsFiles assignment (line 569).

  92. GLM Assistant

    Now let me remove the commandLineWithTypingsFilesOnce field from the Project struct.

  93. GLM Assistant

    Let me remove the commandLineWithTypingsFilesOnce field. First, let me check if sync is used elsewhere in project.go.

  94. GLM Assistant

    sync is only used for sync.Once. Let me remove the field and the now-unused import.

  95. GLM Assistant

    Let me run gofmt and build, then run the reproduction test.

  96. GLM Assistant

    The fix works — the reproduction now passes. Let me build the whole repo and run the broader project test suite to ensure nothing is broken.

  97. GLM Assistant

    All project tests pass. Let me run with the race detector to be safe.

  98. GLM Assistant

    Now let me remove my temporary reproduction test files (per instructions not to add new tests).

  99. GLM Assistant

    Let me run go vet and a broader set of tests (compiler, lsp) to ensure nothing is affected.

  100. GLM Assistant

    Let me run the LSP tests since they use the session/project.

  101. GLM Assistant

    All tests pass. Let me review my final changes with git diff.

  102. GLM Assistant

    Let me verify no remaining references to commandLineWithTypingsFilesOnce exist anywhere.

  103. GLM Assistant

    No references remain. Let me run the internal/ls tests as well since they consume programs/projects.

  104. GLM Assistant

    Let me verify Clone() doesn't reference the removed field and do a final review.

  105. GLM Assistant

    Everything is consistent. Let me do a final build, vet, and test run to confirm green.

  106. GLM Assistant

    Let me do a final confirmation by re-adding the reproduction test, running it, then removing it.

  107. GLM Assistant

    The fix is confirmed. Let me verify the repro test is removed and check final git status.

  108. GLM Assistant

    Only the two intended source files are modified, with no test files added. Let me do a final review of the complete diff.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.