am-freescan/docs/superpowers/plans/2026-10-22-resource-scheduling.md
2026-10-22 16:18:37 +08:00

5.6 KiB

Resource scheduling implementation plan

For agentic workers: Use superpowers:executing-plans for this approved change. Track completed steps here and in the ledger; preserve requested demo records.

Goal: Connect task preparation, device/lab reservations, actual occupation and release through the scan-only execution lifecycle.

Architecture: Keep existing booking tables and robot batch guard. Add stable runtime-device-to-master links and a common durable resource lease table shared by scan tasks, native workflows and manual movement. A dedicated service implements scheduling instead of calling the legacy all-resource readiness service. Shared laboratories remain locations; exclusive laboratories/workstations participate in booking and leases.

Tech stack: Java 17, Spring transactions/JDBC, MySQL, existing CMVR runtime, Vue 3/Element Plus.

Spec: User-approved recommendation in this conversation: mandatory physical-device constraints, conditional exclusive labs, inline immediate/scheduled booking, atomic acquisition, batch retention, safe release and common entry guards.

Constraints and rulings

  • Only am-freescan changes. Database only 192.168.28.10/am-freescan. Additive, rerunnable migrations. Preserve two DEMO tasks, their records, and persistent simulated robot/device.
  • Repository has no HEAD; work in its existing user-selected checkout without creating an unrelated baseline commit/worktree.
  • Immediate mode creates reservations when acquiring resources; scheduled mode books on saving preparation. Expected duration defaults to 60 minutes for the whole batch. Explicit extension checks future bookings; expiry never frees real occupation.
  • Acquisition occurs before the UI opens physical-loading confirmation. Legacy API callers also acquire atomically at start. Occupied preparation cannot change bindings; an explicit pre-execution release allows editing again.
  • Exclusive labs/workstations have capacity one. Shared room capacity scheduling is out of scope: represent independent exclusive workstations as separate lab records. Required labs derive from mapped devices, so a client cannot bypass them by unchecking a flag.
  • Runtime identity is robotId + deviceId; bindings point to lab_device. Creating a mapping on demand creates a persistent representation of the same discovered resource, not a disposable test fixture.
  • Native workflow entry acquires common leases, released on success; failure/stop keeps them pending until physical stop acknowledgement. Manual movement holds common leases until explicit acknowledged stop/release. Read-only state queries stay available.
  • Existing active reservations are respected, including IN_USE records past their planned end. Schedule and actual occupancy are separate. All paths lock resource master rows in deterministic order.

Review focus

Concurrent booking versus acquisition; same laboratory through different robots; expired but still occupied resources; paused/failed batch retention; old completed demo compatibility and cleanup ownership.

Tasks

  • 1. Add policy regressions (time windows, exact identity, resource set and ownership) and observe RED. Add schema 006/configuration and guarded migration, then GREEN migration/policy tests.
  • 2. Implement resource scheduling service and shared leases; cover calendar overlap, exact task/resource matching, atomic rollback and safe releases with database-backed tests.
  • 3. Integrate scan prepare/precheck/acquire/start/extension/cancel/completion and native/manual guards. Update existing regressions for injected service; prove retention across samples/pause/stop failure.
  • 4. Add task workspace scheduling component, acquisition before loading, reservation/occupation snapshots, extension and safe release; expose exclusive-lab setting and current occupation in resource center. Type/build and component/behavior regressions.
  • 5. Apply guarded migration, package all backend tests, restart, run real API and browser integration including multi-sample execution and reservation conflicts. Fresh review, fix findings, clean only this run's fixtures/files and preserve DEMO tasks.

Interfaces

  • Config/request: reservationMode IMMEDIATE|SCHEDULED, plannedStartAt/plannedEndAt millisecond timestamps (existing Yudao JSON contract), expectedMinutes 1..10080, laboratoryId, requireLaboratory, resourcesAcquiredAt.
  • Scan endpoints: POST acquire-resources (taskId, expectedRevision); POST release-resources (taskId, reason, unloadedConfirmed=true, only before first execution); POST extend-resources (taskId, endAt). GET resource-state(taskId) returns resources/bookings/leases/laboratories. GET resource-occupations and POST clear-occupation(ownerKey,reason) for admin stop confirmation.
  • Resource service: configure(task,config,request), state(config), validate(config), acquire(task,config), release(taskId,cancel), extend(config,endAt), assertRobotAvailable(robotId,nativeTaskId), occupyNative(instId,nativeTaskId,robotIds), finishNative(instId,success), beginManual(robotId), clearOccupation(ownerKey,reason).
  • Native guard adds default occupy/release lifecycle callbacks so existing consumers stay compatible; runtime entry and context unregister invoke them.

Verification

Targeted RED/GREEN first, then full Maven package once integrated. Full Vue types/build and all JS/Python regression suites. Real API exercises scheduled and immediate paths, real overlap and concurrent requests, task/lab/device binding, pause and between-sample retention, expiry/extension, normal/cancel stop release, native/manual bypass protection. Cleanup script extended for new lease/link ownership and temporary labs. Document actual results in docs/verification.md.