diff options
| author | soryu <soryu@soryu.co> | 2026-05-01 23:56:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-01 23:56:51 +0100 |
| commit | e11759447b1ac00becfb1e979e488f7f9c9cf478 (patch) | |
| tree | f8a58368de3f6dda3f2f5c1af34e869a0e714205 /makima/src/orchestration | |
| parent | 80085c7cfa9d679ed3e3fd54a7d55fa8ab1addef (diff) | |
| download | soryu-e11759447b1ac00becfb1e979e488f7f9c9cf478.tar.gz soryu-e11759447b1ac00becfb1e979e488f7f9c9cf478.zip | |
chore(cleanup): Phase 5 contracts removal + tmp directive + 30-day expiry + scroll fix (#118)
Sweeping cleanup across the surface and the wire. Net: -14k LOC of legacy
contracts code, plus the tmp/scroll/UX fixes the user asked for.
## Sidebar/editor independent scroll
Replace `height: calc(100vh - 80px)` (which assumed an 80px masthead and
quietly clipped or pushed the whole page below the fold when the masthead
was taller) with `h-screen + overflow-hidden` on the page root and proper
`flex-1 min-h-0` sizing on `<main>`. Sidebar and editor pane now manage
their own scroll independently; the page itself never scrolls.
Same fix in /tmp/:taskId.
## tmp directive — real backing for orphans/ephemerals
New migration `20260501100000_tmp_directive_and_clear_orphans.sql`:
* Adds `directives.is_tmp` BOOLEAN NOT NULL DEFAULT false.
* Partial unique index `(owner_id) WHERE is_tmp` — at most ONE tmp
directive per owner.
* Hard-deletes every existing orphan task (`directive_id IS NULL`).
Per the user spec: "ALSO there are TOO MANY old tasks in tmp, we
need to remove all of them as well."
New repository helpers:
* `get_or_create_tmp_directive(pool, owner_id) -> Directive`
INSERT ON CONFLICT DO NOTHING + fallback SELECT, race-safe.
* `list_all_tmp_directives` — drives the expiry sweep.
* `delete_expired_tmp_tasks(tmp_directive_id) -> u64`.
* `list_tmp_tasks_for_owner` (replaces `list_orphan_tasks_for_owner`).
`mesh::create_task`: every top-level task must have a directive. If a
caller doesn't supply `directive_id` and isn't a subtask, attach to the
caller's tmp directive (auto-creating it on first use).
`list_directives_for_owner` filters out `is_tmp=true` so the scratchpad
directive doesn't pollute the contract list — surfaced via the sidebar's
`tmp/` folder instead.
## 30-day expiry on tmp tasks
New `phase_tmp_expiry` in the directive reconciler. Throttled to once per
hour: enumerates every tmp directive, calls `delete_expired_tmp_tasks`,
logs the count. The actual delete is `WHERE created_at < NOW() - INTERVAL
'30 days'` and is fast on the existing index. Subtasks die via FK cascade.
## Phase 5 — contracts removed
### Frontend
Deleted entire `/contracts` surface:
* routes: `contracts.tsx`, `contract-file.tsx`
* components/contracts: ContractList, ContractDetail, ContractCliInput,
ContractContextMenu, CommandModePanel, PhaseBadge, PhaseHint,
PhaseDeliverablesPanel, PhaseProgressBar, QuickActionButtons,
RepositoryPanel, TaskDerivationPreview
* (Kept `PhaseConfirmationModal` — used outside the contracts surface
by `TaskOutput` and `PhaseConfirmationNotification`.)
* Routes deregistered from `main.tsx`; nav entry removed from
`NavStrip`.
### Backend handlers
Deleted: `contracts.rs` (2.4k LOC), `contract_chat.rs` (3.2k LOC),
`contract_daemon.rs` (~940 LOC), `contract_discuss.rs` (~590 LOC),
`transcript_analysis.rs` (~690 LOC). All `/api/v1/contracts/*` routes
deregistered. OpenAPI entries dropped. Module declarations removed from
`server/handlers/mod.rs`.
### CLI
Removed `makima contract` and `makima supervisor` subcommands. Deleted
`daemon/cli/contract.rs` and `daemon/cli/supervisor.rs`. Bin dispatch
trimmed (~377 LOC).
### Orchestrator
Removed the contract-spawn path from `phase_execution`
(`spawn_step_contract` and its caller). `directive_steps.contract_type`
now logs a warning and falls through to standalone-task spawn. Column
itself stays — old data still reads, just no longer triggers a
contract+supervisor spawn.
### TUI
`Action::PerformCreateContract` is now a no-op that surfaces a status
message: "Contracts have been removed. Use directives instead." The TUI
form is dead code pending a wider refresh.
## Out of scope (deliberately left)
* Contracts DB tables (`contracts`, `contract_repositories`,
`contract_chat_history`, `contract_events`, `contract_templates`) are
retained for historical data + because some peripheral code still
joins to them in TaskSummary queries.
* `mesh_supervisor` handlers are retained — they aren't only used by
contracts (some mesh-level supervisor behaviour persists), and the
cross-cutting cleanup is bigger than this PR.
* `directive_steps.contract_type` column itself isn't dropped; just no
longer functional.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'makima/src/orchestration')
| -rw-r--r-- | makima/src/orchestration/directive.rs | 229 |
1 files changed, 64 insertions, 165 deletions
diff --git a/makima/src/orchestration/directive.rs b/makima/src/orchestration/directive.rs index 1e004bf..80d8172 100644 --- a/makima/src/orchestration/directive.rs +++ b/makima/src/orchestration/directive.rs @@ -18,11 +18,22 @@ use crate::server::state::{DaemonCommand, SharedState}; pub struct DirectiveOrchestrator { pool: PgPool, state: SharedState, + /// Last time we ran the tmp-task expiry sweep. Throttled to once an + /// hour so the deletion query doesn't run on every 15-second tick. + last_tmp_sweep: std::time::Instant, } impl DirectiveOrchestrator { pub fn new(pool: PgPool, state: SharedState) -> Self { - Self { pool, state } + Self { + pool, + state, + // Initialise to 1 hour ago so the first tick after startup runs + // the sweep immediately — clears any tasks that aged out while + // the server was down. + last_tmp_sweep: std::time::Instant::now() + - std::time::Duration::from_secs(3600), + } } /// Run one orchestration tick — called every 15s. @@ -42,6 +53,14 @@ impl DirectiveOrchestrator { if let Err(e) = self.phase_completion().await { tracing::warn!(error = %e, "Directive phase_completion failed"); } + // Throttled to hourly — the actual delete is cheap (indexed + // partial scan) but we don't want to log a sweep every 15s. + if self.last_tmp_sweep.elapsed() >= std::time::Duration::from_secs(3600) { + self.last_tmp_sweep = std::time::Instant::now(); + if let Err(e) = self.phase_tmp_expiry().await { + tracing::warn!(error = %e, "Directive phase_tmp_expiry failed"); + } + } Ok(()) } @@ -100,40 +119,18 @@ impl DirectiveOrchestrator { let steps = repository::get_ready_steps_for_dispatch(&self.pool).await?; for step in steps { - // If the step has a contract_type, create a contract instead of a standalone task + // contract_type used to spawn a heavyweight contract+supervisor + // for a step. The contracts subsystem has been removed (Phase 5); + // we now treat any contract-backed step as a plain standalone + // task. The column itself is left in place for one more release + // so old data still reads cleanly, but it has no effect. if step.contract_type.is_some() { - tracing::info!( + tracing::warn!( step_id = %step.step_id, directive_id = %step.directive_id, - step_name = %step.step_name, contract_type = ?step.contract_type, - "Spawning contract for contract-backed step" + "Step has legacy contract_type; falling back to standalone task spawn" ); - - match self - .spawn_step_contract( - step.step_id, - step.directive_id, - step.owner_id, - &step.step_name, - step.step_description.as_deref(), - step.task_plan.as_deref(), - step.contract_type.as_deref().unwrap_or("simple"), - step.repository_url.as_deref(), - step.base_branch.as_deref(), - ) - .await - { - Ok(()) => {} - Err(e) => { - tracing::warn!( - step_id = %step.step_id, - error = %e, - "Failed to spawn contract for step" - ); - } - } - continue; } tracing::info!( @@ -647,141 +644,9 @@ impl DirectiveOrchestrator { Ok(()) } - /// Spawn a contract for a contract-backed step. - /// Creates a contract, adds the directive's repository to it, links it to the step, - /// creates a supervisor task, and marks the step as running. - async fn spawn_step_contract( - &self, - step_id: Uuid, - directive_id: Uuid, - owner_id: Uuid, - step_name: &str, - step_description: Option<&str>, - task_plan: Option<&str>, - contract_type: &str, - repo_url: Option<&str>, - base_branch: Option<&str>, - ) -> Result<(), anyhow::Error> { - // Build contract description from step info - let description = match (step_description, task_plan) { - (Some(desc), Some(plan)) => Some(format!("{}\n\n{}", desc, plan)), - (Some(desc), None) => Some(desc.to_string()), - (None, Some(plan)) => Some(plan.to_string()), - (None, None) => None, - }; - - // Create the contract - let contract_req = CreateContractRequest { - name: step_name.to_string(), - description, - contract_type: Some(contract_type.to_string()), - template_id: None, - initial_phase: None, - autonomous_loop: Some(true), - phase_guard: None, - local_only: None, - auto_merge_local: None, - }; - - let contract = repository::create_contract_for_owner(&self.pool, owner_id, contract_req).await?; - - tracing::info!( - step_id = %step_id, - contract_id = %contract.id, - contract_type = %contract.contract_type, - "Created contract for directive step" - ); - - // Link the contract to the step - repository::link_contract_to_step(&self.pool, step_id, contract.id).await?; - - // Add the directive's repository to the contract (if available) - if let Some(url) = repo_url { - if let Err(e) = repository::add_remote_repository( - &self.pool, - contract.id, - step_name, - url, - true, // is_primary - ) - .await - { - tracing::warn!( - contract_id = %contract.id, - error = %e, - "Failed to add repository to contract — continuing without it" - ); - } - } - - // Create supervisor task for the contract (following the pattern from contract handlers) - let supervisor_name = format!("{} Supervisor", step_name); - let supervisor_plan = format!( - "You are the supervisor for contract '{}'. Your goal is to drive this contract to completion.\n\n{}", - step_name, - contract.description.as_deref().unwrap_or("No description provided.") - ); - - let supervisor_req = CreateTaskRequest { - name: supervisor_name.clone(), - description: None, - plan: supervisor_plan.clone(), - repository_url: repo_url.map(|s| s.to_string()), - base_branch: base_branch.map(|s| s.to_string()), - target_branch: None, - parent_task_id: None, - contract_id: Some(contract.id), - target_repo_path: None, - completion_action: None, - continue_from_task_id: None, - copy_files: None, - is_supervisor: true, - checkpoint_sha: None, - priority: 0, - merge_mode: None, - branched_from_task_id: None, - conversation_history: None, - supervisor_worktree_task_id: None, - directive_id: Some(directive_id), - directive_step_id: Some(step_id), - }; - - let supervisor_task = repository::create_task_for_owner(&self.pool, owner_id, supervisor_req).await?; - - tracing::info!( - contract_id = %contract.id, - supervisor_task_id = %supervisor_task.id, - "Created supervisor task for contract-backed step" - ); - - // Link supervisor task to contract - let update_req = UpdateContractRequest { - supervisor_task_id: Some(supervisor_task.id), - version: Some(contract.version), - ..Default::default() - }; - if let Err(e) = repository::update_contract_for_owner(&self.pool, contract.id, owner_id, update_req).await { - tracing::warn!( - contract_id = %contract.id, - error = %e, - "Failed to link supervisor task to contract" - ); - } - - // Try to dispatch the supervisor task to a daemon - if self - .try_dispatch_task(supervisor_task.id, owner_id, &supervisor_task.name, &supervisor_task.plan, supervisor_task.version) - .await - { - repository::set_step_running(&self.pool, step_id).await?; - } else { - // Even if dispatch fails, mark step as running since contract is created. - // The supervisor task will be retried by the pending task retry logic. - repository::set_step_running(&self.pool, step_id).await?; - } - - Ok(()) - } + // spawn_step_contract was removed in Phase 5 — the contracts subsystem + // is gone. Step rows with `contract_type` set are now silently treated + // as standalone tasks (see the warn! in phase_execution). /// Try to dispatch a task to an available daemon. Returns true if dispatched. async fn try_dispatch_task( @@ -877,6 +742,40 @@ impl DirectiveOrchestrator { false } + /// Hourly sweep — delete top-level tasks attached to any tmp directive + /// that are older than 30 days. Per-owner; no global cap. Subtasks die + /// via the FK cascade. + async fn phase_tmp_expiry(&self) -> Result<(), anyhow::Error> { + let tmps = repository::list_all_tmp_directives(&self.pool).await?; + let mut total_deleted: u64 = 0; + for d in tmps { + match repository::delete_expired_tmp_tasks(&self.pool, d.id).await { + Ok(n) => { + if n > 0 { + tracing::info!( + directive_id = %d.id, + owner_id = %d.owner_id, + deleted = n, + "Expired tmp tasks deleted (>30 days old)" + ); + total_deleted += n; + } + } + Err(e) => { + tracing::warn!( + directive_id = %d.id, + error = %e, + "Failed to expire tmp tasks for owner" + ); + } + } + } + if total_deleted > 0 { + tracing::info!(total = total_deleted, "Tmp expiry sweep completed"); + } + Ok(()) + } + /// Phase 5: Completion — spawn PR-creation tasks for idle directives. async fn phase_completion(&self) -> Result<(), anyhow::Error> { // Part 1: Spawn completion tasks for idle directives |
