Invalidate component freshness by source generation

This commit is contained in:
udo
2026-07-17 23:14:42 +00:00
parent 075ce0bc07
commit e176ff09d9
5 changed files with 68 additions and 3 deletions
+14 -3
View File
@@ -1121,6 +1121,7 @@ private:
{
std::chrono::steady_clock::time_point checked_at;
bool stale = false;
String source_generation;
};
std::map<String, ComponentFreshnessState> component_freshness;
@@ -1528,6 +1529,8 @@ private:
std::vector<wasmtime::Func> host_funcs; // keep host imports alive
bool stale_component_mutation_blocked = false;
String stale_component_mutation_status;
bool component_source_generation_checked = false;
String component_source_generation;
wasmtime::Store::Context ctx()
{
@@ -2197,6 +2200,11 @@ private:
bool can_serve_stale = compiler_request_can_serve_stale_artifact(context);
String method = context ? to_upper(trim(context->params["REQUEST_METHOD"])) : String("");
bool read_request = method == "GET" || method == "HEAD" || method == "OPTIONS";
if(can_serve_stale && read_request && !component_source_generation_checked)
{
component_source_generation = compiler_source_generation(context);
component_source_generation_checked = true;
}
bool stale = false;
if(artifact_exists)
{
@@ -2204,14 +2212,17 @@ private:
auto cached_freshness = worker.component_freshness.find(resolved);
// HTTP reads may serve a complete stale artifact, so bound their graph
// stat work; CLI and mutations always check the current graph.
bool generation_available = component_source_generation != "";
bool check_freshness = !can_serve_stale || !read_request ||
cached_freshness == worker.component_freshness.end() ||
std::chrono::duration_cast<std::chrono::milliseconds>(
now - cached_freshness->second.checked_at).count() >= 1000;
(generation_available ?
cached_freshness->second.source_generation != component_source_generation :
std::chrono::duration_cast<std::chrono::milliseconds>(
now - cached_freshness->second.checked_at).count() >= 1000);
if(check_freshness)
{
stale = compiler_unit_needs_recompile(context, resolved, 0, can_serve_stale && read_request, true);
worker.component_freshness[resolved] = { now, stale };
worker.component_freshness[resolved] = { now, stale, component_source_generation };
}
else
stale = cached_freshness->second.stale;