Active Context: Handle empty repositories
Description
This adds support for Active Context to handle empty repositories. If a repository is empty or doesn't exist, we will mark it as ready.
Testing
I tested this locally by creating an empty repository and creating a new entry to index it with Ai::ActiveContext::Code::Repository. Then, we can see it become ready. Incremental indexing also works.
- Creating the code repository as
pending:
[23] pry(main)> Ai::ActiveContext::Code::Repository.create!(project_id: 19, connection_id: 1, enabled_namespace_id: 1)
=> #<Ai::ActiveContext::Code::Repository:0x0000000137822098
id: 2,
project_id: 19,
connection_id: 1,
enabled_namespace_id: 1,
metadata: {},
last_commit: "0000000000000000000000000000000000000000",
state: "pending",
indexed_at: nil,
created_at: Tue, 23 Sep 2025 11:40:07.917359000 UTC +00:00,
updated_at: Tue, 23 Sep 2025 11:40:07.917359000 UTC +00:00,
initial_indexing_last_queued_item: nil,
incremental_indexing_last_queued_item: nil,
last_error: nil>
- It becomes
ready:
[25] pry(main)> repository = Ai::ActiveContext::Code::Repository.second
=> #<Ai::ActiveContext::Code::Repository:0x0000000137761550
id: 2,
project_id: 19,
connection_id: 1,
enabled_namespace_id: 1,
metadata: {},
last_commit: "0000000000000000000000000000000000000000",
state: "ready",
indexed_at: nil,
created_at: Tue, 23 Sep 2025 11:40:07.917359000 UTC +00:00,
updated_at: Tue, 23 Sep 2025 11:41:07.635199000 UTC +00:00,
initial_indexing_last_queued_item: nil,
incremental_indexing_last_queued_item: nil,
last_error: nil>
- After pushing changes to the repository, incremental indexing works as expected:
[27] pry(main)> repository = Ai::ActiveContext::Code::Repository.second
=> #<Ai::ActiveContext::Code::Repository:0x0000000138263700
id: 2,
project_id: 19,
connection_id: 1,
enabled_namespace_id: 1,
metadata: {"incremental_indexing_last_queued_item"=>"6fab21bcd79d1bfe6367f8cd35a218f41317d3958594501163d01650280c0a69"},
last_commit: "0f78e4550ae0bfa830429a7582bad2fc99895335",
state: "ready",
indexed_at: Tue, 23 Sep 2025 11:43:55.862359000 UTC +00:00,
created_at: Tue, 23 Sep 2025 11:40:07.917359000 UTC +00:00,
updated_at: Tue, 23 Sep 2025 11:43:55.862710000 UTC +00:00,
initial_indexing_last_queued_item: nil,
incremental_indexing_last_queued_item: "6fab21bcd79d1bfe6367f8cd35a218f41317d3958594501163d01650280c0a69",
last_error: nil>
Related to #554437 (closed).
Edited by Arturo Herrero