Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 6, 2025

When lake new initialization fails partway through, it leaves an incomplete project directory. Subsequent runs fail with "package already initialized" because the directory exists without lakefile.lean.

Changes

  • src/form/lean.cpp: Clean up incomplete LEAN project directories before re-initialization
    • Check if project directory exists without lakefile.lean
    • Remove incomplete directory using rmDirRecursive() before running lake new
  • CHANGELOG.md: Document bugfix

Logic Flow

// Check if project is already initialized
if (isFile(lakeFilePath)) {
  initialized = true;
  return true;
}

// If directory exists but lakefile doesn't, clean up incomplete initialization
if (isDir(projectDir)) {
  Log::get().info("Removing incomplete LEAN project at " + projectDir);
  rmDirRecursive(projectDir);
}

// Proceed with lake new...

This ensures lake new always runs against a clean slate when the project isn't fully initialized.

Original prompt

This section details on the original issue you should resolve

<issue_title>test-lean fails with error: package already initialized</issue_title>
<issue_description>After repeated attempts to run loda test-lean on the same machine, I ran into this error:

2025-11-30 22:32:14|INFO |Starting LODA developer version. See https://loda-lang.org/
2025-11-30 22:32:14|INFO |Using LODA home directory "/home/me/loda/"
2025-11-30 22:32:26|INFO |Loaded 377622/390211 A-sequences in 11.88s
2025-11-30 22:32:34|INFO |Loaded stats for 147545 programs in 7.52s
2025-11-30 22:32:34|INFO |Checking 102 terms of A000004: def a (_ : Int) : Int := 0
2025-11-30 22:32:57|INFO |Checking 105 terms of A000007: def a (n : Int) : Int := Bool.toInt (n==0)
2025-11-30 22:32:58|INFO |Checking 10 terms of A000008: def a (n : Int) : Int := Int.tdiv (120*(Int.fdiv n 5)*(-(Int.fdiv ((n%5)^2) 8)+(Int.fdiv ((-1)^(Int.toNat (n%5))+1) 2))+15*n*(-1)^(Int.toNat n)+(n+17)*(20*n+2*n^2+81)) 1200
2025-11-30 22:33:00|INFO |Checking 90 terms of A000012: def a (_ : Int) : Int := 1
2025-11-30 22:33:01|INFO |Checking 15 terms of A000023: def a : Nat -> Int | 0 => 1 | 1 => -1 | 2 => 2 | 3 => -2 | n+4 => ((Int.ofNat n)+3)*(2*(a (n+2))+(a (n+3)))-(a (n+3))
2025-11-30 22:33:02|INFO |Checking 77 terms of A000027: def a (n : Int) : Int := n
2025-11-30 22:33:04|INFO |Checking 102 terms of A000034: def a (n : Int) : Int := n%2+1
2025-11-30 22:33:06|INFO |Checking 105 terms of A000035: def a (n : Int) : Int := n%2
2025-11-30 22:33:07|INFO |Checking 105 terms of A000038: def a (n : Int) : Int := 2*(Bool.toInt (n==0))
2025-11-30 22:33:08|INFO |Checking 10 terms of A000042: def a (n : Int) : Int := Int.fdiv (10^(Int.toNat n)) 9
2025-11-30 22:33:10|INFO |Checking 10 terms of A000051: def a (n : Int) : Int := 2^(Int.toNat n)+1
2025-11-30 22:33:11|INFO |Checking 9 terms of A000058: mutual
  def a (n : Nat) : Int := (b n)+1
  def b : Nat -> Int | 0 => 1 | n+1 => (b n)*((b n)+1)
end
2025-11-30 22:33:12|INFO |Checking 51 terms of A000064: mutual
  def a (n : Nat) : Int := b (n+1)
  def b : Nat -> Int | 0 => 0 | 1 => 1 | 2 => 2 | 3 => 4 | 4 => 6 | 5 => 9 | 6 => 13 | 7 => 18 | 8 => 24 | 9 => 31 | n+10 => (b n)+(Int.fdiv (((Int.ofNat n)+17)*(11*(Int.ofNat n)+2*((Int.ofNat n)+9)^2+117)) 120)
end
2025-11-30 22:33:13|INFO |Checking 15 terms of A000078: def a : Nat -> Int | 0 => 0 | 1 => 0 | 2 => 0 | 3 => 1 | 4 => 1 | 5 => 2 | 6 => 4 | n+7 => (a (n+6))+(a (n+5))+(a (n+4))+(a (n+3))
2025-11-30 22:33:15|INFO |Checking 10 terms of A000079: def a (n : Int) : Int := 2^(Int.toNat n)
2025-11-30 22:33:16|INFO |Checking 15 terms of A000100: def a : Nat -> Int | 0 => 0 | 1 => 0 | 2 => 0 | 3 => 1 | 4 => 2 | 5 => 5 | 6 => 11 | 7 => 23 | 8 => 47 | 9 => 94 | 10 => 185 | 11 => 360 | n+12 => 2*(a (n+11))-(a (n+9))-(a (n+7))-2*(a (n+8))+(a (n+10))
2025-11-30 22:33:19|INFO |Checking 66 terms of A000115: def a (n : Int) : Int := Int.fdiv ((n+4)^2+9) 20
2025-11-30 22:33:21|INFO |Checking 8 terms of A000133: def a (n : Int) : Int := Int.fdiv (Int.fdiv (2^(Int.toNat (2^(Int.toNat n)))+(2^(Int.toNat n)-1)*2^(Int.toNat (2^(Int.toNat (n-1))+1))) (2^(Int.toNat n))) 2
2025-11-30 22:33:24|INFO |Checking 60 terms of A000134: def a (n : Int) : Int := -(Int.tdiv (97*n-194) 113)+(max (4*n-4) 1)+(Bool.toInt ((n-1)==1))+1
2025-11-30 22:33:26|INFO |Checking 23 terms of A000142: def a (n : Int) : Int := Int.ofNat (Nat.factorial (Int.toNat n))
2025-11-30 22:33:26|INFO |Initializing LEAN project at /home/me/loda/cache/loda-lean/
error: package already initialized
2025-11-30 22:33:27|WARN |lake new failed with exit code 1
2025-11-30 22:33:27|ERROR|Failed to initialize LEAN project
terminate called after throwing an instance of 'std::runtime_error'
  what():  Failed to initialize LEAN project

Please fix this issue.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix initialization error in test-lean execution Fix test-lean failure when LEAN project directory exists but is incomplete Dec 6, 2025
Copilot AI requested a review from ckrause December 6, 2025 14:46
@ckrause ckrause marked this pull request as ready for review December 6, 2025 14:50
@ckrause ckrause merged commit dba99d4 into main Dec 6, 2025
7 checks passed
@ckrause ckrause deleted the copilot/fix-test-lean-initialization-error branch December 6, 2025 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test-lean fails with error: package already initialized

2 participants