Skip to content

refactor: centralize site-scoped agent-context default in MaintenanceTask base#568

Merged
chubes4 merged 1 commit into
fix-disk-cleanup-agent-contextfrom
maintenance-task-base
Jun 6, 2026
Merged

refactor: centralize site-scoped agent-context default in MaintenanceTask base#568
chubes4 merged 1 commit into
fix-disk-cleanup-agent-contextfrom
maintenance-task-base

Conversation

@chubes4
Copy link
Copy Markdown
Member

@chubes4 chubes4 commented Jun 6, 2026

Closes #566

What

Introduce a thin MaintenanceTask abstract base class in inc/Tasks/ that sets the site-scoped agent-context default once, then reparent the five workspace-maintenance tasks to it and delete their five hand-copied requiresAgentContext() overrides (the ones PR #565 added as the symptom fix).

namespace DataMachineCode\Tasks;

use DataMachine\Engine\AI\System\Tasks\SystemTask;

abstract class MaintenanceTask extends SystemTask {
    public function requiresAgentContext(): bool {
        return false;
    }
}

Reparented (and override deleted) in:

  • inc/Tasks/WorkspaceDiskEmergencyCleanupTask.php
  • inc/Tasks/WorktreeCleanupTask.php
  • inc/Tasks/WorkspaceRetentionCleanupTask.php
  • inc/Tasks/WorkspaceHygieneReportTask.php
  • inc/Tasks/WorktreeCleanupChunkTask.php

Now-unused use DataMachine\Engine\AI\System\Tasks\SystemTask; was removed from the two files that no longer reference SystemTask directly (WorktreeCleanupTask, WorktreeCleanupChunkTask); MaintenanceTask is same-namespace so needs no use. No change to the schedule registration in data-machine-code.php (already per_agent => false).

Why this shape

Every DMC task is site-scoped workspace maintenance with no agent owner. Core SystemTask defaults requiresAgentContext() to true (the safe default for content-mutating agent tasks in data-machine core), so each DMC task author must remember to override it — and forgetting fails quietly: the agent-less recurring schedule is rejected at TaskScheduler::schedule()'s agent-context gate and the cleanup silently stops (the #564 failure: 213 identical hourly errors, disk never cleaned). Centralizing the correct-for-DMC default makes that failure mode impossible by omission, and gives one obvious place to document the site-scoped contract.

Core precedent

This mirrors core's DataMachine\Engine\AI\System\Tasks\Retention\RetentionTask, which already does the identical opt-out in its base:

abstract class RetentionTask extends SystemTask {
    public function requiresAgentContext(): bool {
        return false;
    }
    // ... plus a final executeTask() finalizer
}

Unlike RetentionTask, MaintenanceTask is kept a pure default base — no executeTask() finalizer, no abstract wrapper, no other behavior — because we only want the agent-context default centralized. A task that genuinely needs agent context can still override back to true.

No behavior change vs #565

All five tasks still report requiresAgentContext() === false — now inherited from MaintenanceTask rather than declared per-class.

Evidence

php -l clean on MaintenanceTask.php and all five reparented files:

No syntax errors detected in MaintenanceTask.php
No syntax errors detected in WorkspaceDiskEmergencyCleanupTask.php
No syntax errors detected in WorktreeCleanupTask.php
No syntax errors detected in WorkspaceRetentionCleanupTask.php
No syntax errors detected in WorkspaceHygieneReportTask.php
No syntax errors detected in WorktreeCleanupChunkTask.php

Reflection harness (loads core SystemTask, then MaintenanceTask + the five tasks, reflects requiresAgentContext() on each):

WorkspaceDiskEmergencyCleanupTask    requiresAgentContext()=false (declared in DataMachineCode\Tasks\MaintenanceTask)
WorktreeCleanupTask                  requiresAgentContext()=false (declared in DataMachineCode\Tasks\MaintenanceTask)
WorkspaceRetentionCleanupTask        requiresAgentContext()=false (declared in DataMachineCode\Tasks\MaintenanceTask)
WorkspaceHygieneReportTask           requiresAgentContext()=false (declared in DataMachineCode\Tasks\MaintenanceTask)
WorktreeCleanupChunkTask             requiresAgentContext()=false (declared in DataMachineCode\Tasks\MaintenanceTask)

PASS: all five return false
PASS: all five inherit the override from MaintenanceTask

getDeclaringClass() is now DataMachineCode\Tasks\MaintenanceTask for all five — proving the override is inherited from the base, not duplicated.

homeboy lint (PHPCS + PHPStan) on the 6 changed files: PHPCS passed, PHPStan passed. (The command's overall exit was non-zero only due to a pre-existing CI-parity meta-warning that the local data-machine validation-dependency checkout is behind origin/main — unrelated to these changes; the actual lint and static analysis ran clean.)

Target branch note

This PR targets fix-disk-cleanup-agent-context (the #565 branch), not main, because #565 is unmerged and this refactor builds on its override methods. Once #565 merges, retarget this PR to main (or rebase onto main).

…Task base

Introduce a thin MaintenanceTask abstract base (extends SystemTask) that
sets requiresAgentContext()=false once, then reparent the five workspace-
maintenance tasks to it and delete their five duplicated overrides.

Every DMC task is site-scoped workspace maintenance with no agent owner;
core SystemTask defaults requiresAgentContext() to true, so forgetting the
override fails quietly at TaskScheduler's agent-context gate (the #564
silent-cleanup failure). Centralizing the default makes that failure mode
impossible by omission. Mirrors core's RetentionTask, which performs the
same opt-out in its base. Kept as a pure default base (no executeTask
finalizer) since only the agent-context default needs centralizing.

No behavior change vs #565: all five tasks still report
requiresAgentContext()=false, now inherited from MaintenanceTask.

Closes #566
@chubes4 chubes4 merged commit 6555898 into fix-disk-cleanup-agent-context Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant