feat(missions): Continuous Research harvests at launch, and cards launch by clicking
The card shipped in e20b321 could not actually be used. Three things were
missing, each of which failed at a different distance from its cause.
**1. `default_team_template` was parsed and never read.** Every recipe declares
one; `WorkflowRecipe` carries the field; nothing consumed it. A mission created
from a card with no explicitly chosen team was rejected at LAUNCH with "no
team_id, no team_template_id, no config.phase_teams" — one step removed from the
real cause, which is that creation ignored the recipe. Create now resolves it
via `team_templates::get_by_key`, only when the caller named no team of any
kind, so an explicit choice still wins. A test asserts every shipped recipe
names a template that has a `templates/teams/<key>.toml`, because a mismatch
there produces an unlaunchable card.
**2. The harvest ran nowhere.** `harvest_for_mission` existed and nothing called
it. `on_launch` now runs it for `continuous_research` missions, before the
phases start, and threads the blob store through from `main` (the route already
had it on `AppState`; the scheduler needed it). Deliberately non-fatal: a
harvest that fails still starts the phases, because the phase is what reports
whether today was quiet or broken and those must stay distinguishable — but
never silent, so both outcomes log their counts.
**3. Nothing wrote the manifest.** `templates/teams/continuous_research.toml`
has pointed its reader role at `ContinuousResearch/<date>/harvest.jsonl` since it
was authored, and the file did not exist — agents aimed at a path nothing
produced. `run_to_vault` now writes it beside the notes and stages it, but only
for a mission-attributed run. `Harvest` carries the shelved `Paper`s to build
it; re-parsing the notes we had just written would have been a parse of our own
output and one more place for the two to drift.
Also: the blob root. `storage.data_dir` defaults to "./data" and the container's
cwd is `/`, so the server tried to create `/data` as uid 65532 and EVERY shelve
failed with "storage io: Permission denied". The image now creates
/var/lib/clawmates-blobs owned by 65532 so a mounted volume inherits it rather
than arriving root:root. Kept off /var/lib/clawmates-missions on purpose: that
tree is swept, and a paper shelved there would be deleted out from under its own
catalogue note.
Proven end to end on a real mission: 15 candidates, 2 already held, 13 shelved,
0 failed; branch auto-merged as additive-only; manifest on vault `main` with
every documented key. The "already held" counts are the seen-set deduping across
topics within a single run, which is the behaviour the whole design exists for.
The project brief now comes from the mission description — `phase_task_text`
already places it under BRIEF verbatim, so no new field was needed.
346 tests pass.
Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5
parent
a2d7e3ea92
commit
a02e0cba69
@@ -279,12 +279,48 @@ pub async fn create(
|
||||
_ => return Err(ApiError::BadRequest),
|
||||
}
|
||||
|
||||
// Honour the recipe's `default_team_template`.
|
||||
//
|
||||
// Every recipe declares one and NOTHING read it: the field was parsed into
|
||||
// `WorkflowRecipe` and then ignored, so a mission created from a card with
|
||||
// no explicit team was rejected at launch with "no team_id, no
|
||||
// team_template_id, no config.phase_teams" — a card that cannot be launched
|
||||
// by clicking it. Only resolved when the caller named no team of any kind,
|
||||
// so an explicit choice always wins.
|
||||
let recipe = crate::workflow_registry::get(body.template_kind.trim());
|
||||
let mut team_template_id = body.team_template_id;
|
||||
let has_phase_teams = body
|
||||
.config
|
||||
.get("phase_teams")
|
||||
.and_then(|v| v.as_object())
|
||||
.is_some_and(|o| o.values().any(|v| v.as_array().is_some_and(|a| !a.is_empty())));
|
||||
if team_template_id.is_none() && body.team_id.is_none() && !has_phase_teams {
|
||||
if let Some(key) = recipe.and_then(|r| r.default_team_template.as_deref()) {
|
||||
match cm_db::repo::team_templates::get_by_key(&state.pool, key).await {
|
||||
Ok(Some(t)) => {
|
||||
eprintln!(
|
||||
"missions: {} defaults to team template {key}",
|
||||
body.template_kind.trim()
|
||||
);
|
||||
team_template_id = Some(t.id);
|
||||
}
|
||||
// Loud: a recipe naming a template that is not loaded would
|
||||
// otherwise fail at launch, one step removed from the cause.
|
||||
Ok(None) => eprintln!(
|
||||
"missions: recipe {} names default_team_template {key:?}, which is not loaded — the mission will have no team",
|
||||
body.template_kind.trim()
|
||||
),
|
||||
Err(e) => eprintln!("missions: looking up team template {key:?}: {e}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let new = NewMission {
|
||||
workspace_id: user.workspace_id.as_uuid(),
|
||||
title: body.title.trim(),
|
||||
template_kind: body.template_kind.trim(),
|
||||
team_id: body.team_id,
|
||||
team_template_id: body.team_template_id,
|
||||
team_template_id,
|
||||
repo_id: body.repo_id,
|
||||
schedule: body.schedule,
|
||||
description: body.description.as_deref(),
|
||||
@@ -1341,6 +1377,7 @@ pub async fn set_status(
|
||||
user.user_id,
|
||||
id,
|
||||
Some(state.node_hub.clone()),
|
||||
state.blobs.clone(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
@@ -1550,6 +1587,34 @@ mod tests {
|
||||
/// per-phase settings are read from at run time. Before this, every
|
||||
/// wizard-created mission stored a null config and every recipe setting
|
||||
/// was inert.
|
||||
/// Every shipped recipe must name a team template that is actually
|
||||
/// authored. `default_team_template` was parsed and never read, so a
|
||||
/// mismatch here used to surface as "launch rejected — no team_id" on a
|
||||
/// card the user simply clicked.
|
||||
#[test]
|
||||
fn every_recipe_names_a_team_template_that_exists() {
|
||||
let dir = concat!(env!("CARGO_MANIFEST_DIR"), "/../../templates/teams");
|
||||
let authored: std::collections::HashSet<String> = std::fs::read_dir(dir)
|
||||
.expect("templates/teams is readable")
|
||||
.filter_map(Result::ok)
|
||||
.filter_map(|e| {
|
||||
let n = e.file_name().to_string_lossy().to_string();
|
||||
n.strip_suffix(".toml").map(str::to_string)
|
||||
})
|
||||
.collect();
|
||||
for r in crate::workflow_registry::load() {
|
||||
let Some(key) = r.default_team_template.as_deref() else {
|
||||
continue;
|
||||
};
|
||||
assert!(
|
||||
authored.contains(key),
|
||||
"recipe {:?} defaults to team template {key:?}, which has no \
|
||||
templates/teams/{key}.toml — the card would be unlaunchable",
|
||||
r.key
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn phase_config_is_backfilled_from_the_recipe() {
|
||||
let recipe = test_recipe();
|
||||
|
||||
Reference in New Issue
Block a user