Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/server/compiler/indexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,12 +1005,16 @@ kota::task<> Indexer::run_background_indexing() {
// running round, but staleness is re-judged per round anyway.
fv_verdicts.clear();

// Freeze this round's boundary before announcing it. Progress callbacks
// and failed tasks may enqueue more work; those entries belong to the
// next idle-delayed round, not the one currently being drained.
const auto round_end = index_queue.size();
std::stable_partition(
index_queue.begin() + index_queue_pos,
index_queue.end(),
index_queue.begin() + round_end,
[this](std::uint32_t id) { return workspace.path_to_module.contains(id); });

auto total = index_queue.size() - index_queue_pos;
auto total = round_end - index_queue_pos;
std::size_t dispatched = 0;
std::size_t completed = 0;

Expand All @@ -1025,7 +1029,7 @@ kota::task<> Indexer::run_background_indexing() {
ScopedTimer timer;
kota::task_group<> workers(loop);

while(index_queue_pos < index_queue.size()) {
while(index_queue_pos < round_end) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Compact consumed entries between retry rounds

When work keeps being requeued across multiple rounds—for example, while stateless workers remain unavailable—this bounded loop advances index_queue_pos but each retry appends another entry to index_queue. The cleanup at line 1077 only clears the vector when there is no retry tail, so a persistent outage or repeated preemption retains every consumed slot and grows memory by the number of retried files on every idle-delayed round. Erase or otherwise compact the consumed prefix at the round safe point while preserving the deferred tail.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • add a compaction threshold
    if(index_queue_pos == index_queue.size()) {
        index_queue.clear();
        index_queue_pos = 0;
    } else if(index_queue_pos >= index_queue_threshold) {
        index_queue.erase(
            index_queue.begin(),
            index_queue.begin() + index_queue_pos);
        index_queue_pos = 0;
    }

or

  • add a double buffer to swap index_queue

if(pause_depth > 0)
co_await resume_event.wait();

Expand Down
55 changes: 55 additions & 0 deletions tests/unit/server/indexer_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <limits>
#include <memory>

#include "test/cdb_helper.h"
#include "test/temp_dir.h"
#include "test/test.h"
#include "command/argument_parser.h"
Expand Down Expand Up @@ -1224,6 +1225,60 @@ TEST_CASE(DropIndexEvictsPersisted) {

TEST_SUITE(IndexerRequeue) {

TEST_CASE(UnavailableWorkerDoesNotSpinInCurrentRound) {
TempDir tmp;
IndexerFixture f;

tmp.touch("retry.cpp", "int retry_me;\n");
auto path = tmp.path("retry.cpp");
auto cdb = build_cdb_json({
{tmp.root, path, {}}
});
write_cdb(tmp, f.workspace.cdb, cdb);

// A started but empty pool returns worker_unavailable while still
// treating the outage as retryable -- the state that triggered the loop.
ASSERT_TRUE(f.pool.start({.stateless_count = 0, .stateful_count = 0}));

Comment thread
coderabbitai[bot] marked this conversation as resolved.
f.workspace.config.project.idle_timeout_ms = 0;

constexpr std::size_t runaway_threshold = 64;
std::size_t rounds = 0;
Indexer::Progress last_report;
auto progress_connection = f.indexer.on_progress_changed.connect([&] {
const auto& state = f.indexer.progress();
if(state.stage == Indexer::Progress::Stage::Begin) {
++rounds;
// A legitimate retry belongs to a later, idle-delayed round.
f.workspace.config.project.idle_timeout_ms = 60'000;
return;
}
if(state.stage != Indexer::Progress::Stage::Report)
return;

last_report = state;
if(state.completed == runaway_threshold)
f.indexer.pause_indexing();
});

auto id = f.workspace.path_pool.intern(path);
f.indexer.enqueue(id, ReindexReason::ContentChanged);
f.indexer.schedule();

auto stop_after_sample = [&]() -> kota::task<> {
co_await kota::sleep(25);
co_await f.indexer.stop();
co_await f.pool.stop();
};
f.loop.schedule(stop_after_sample());
f.loop.run();

ASSERT_TRUE(f.indexer.pending_reason(id).has_value());
ASSERT_EQ(rounds, 1u);
ASSERT_EQ(last_report.total, 1u);
ASSERT_EQ(last_report.completed, last_report.total);
}

TEST_CASE(PreemptionKeepsBudget) {
IndexerFixture f;
auto id = f.workspace.path_pool.intern("/proj/a.cpp");
Expand Down
Loading