am-freescan/docs/superpowers/plans/2026-10-21-scan-only-implementation.md
2026-10-22 16:18:37 +08:00

61 lines
7.4 KiB
Markdown

# Scan-only task workflow implementation
User approved the reviewed design and requested coding, plus moving all resource-collaboration submenus under Resource Center. Work only in E:/workspace/hybrid/am-freescan. Original three source repositories stay read-only. Target DB only 192.168.28.10/am-freescan. Preserve legacy data and execution behavior.
## Agreed scope
- Required import method number is native test-case ID (String); case must be enabled and have a published flow. Imported case is default, changing it before first start requires an audit reason.
- Positive integer quantity N creates N stable physical sample units. One task uses one confirmed case/version; units run separately, sequentially, with operator loading confirmation. Retry adds an attempt without repeating successful units.
- Five-stage preparation: import/receipt, dimensions and task attachments, fixture recommendation/confirmation, case/version/parameter/robot assignment, precheck/run/logs. Completed scan tasks do not require measurement batches or reports.
- Use existing CMVR engine and immutable releases, not legacy LOCAL engine or provider mocks. Preserve full historical workflow via task processType.
- Robot occupation persists across units and loading waits; native runtime/debug/trial respect occupation. Stop failure keeps STOP_PENDING occupation until a successful stop confirmation.
- Remove old AIMA task/running/vehicle/phone menu entries, move host execution entry into Intelligence Test. Move resource collaboration child pages into native Resource Center; remove empty former groups. Update bootstrap and live menus, permissions and old redirects.
## Work packages
1. Root: import v2 validation/commit mapping, task/execution model fields, pure native method/version mapping, native occupancy hook and debug action guard, callback integration and full verification.
2. Backend package: new scan-only controller/services/entities/mappers and idempotent SQL migration. Unit lifecycle, prepare, resources, fixtures, task attachments, batch occupation, callback aggregation, stop/retry handling. No edits to existing root-owned bridge/import/listener/native files.
3. Frontend package: task-first execution page and scan workbench, typed API, import descriptions, copy case ID, navigation redirects. No backend or menu bootstrap edits.
4. Menu/simulator package: idempotent owned-target schema/menu application script, bootstrap menu changes and live migration; simulator System stopAll service for stop verification. Do not touch scan table schema owned by backend.
## Shared API contract
Base /admin-api/lab/scan-task (host envelope code 0):
- GET /page: taskNo,status,pageNo,pageSize -> PageResult task rows, each {id,taskNo,taskName,externalTaskNo,status,ownerId,caseName,testCaseId,quantity,completedCount,processType}.
- GET /get?taskId= -> {task:{...LabTestTaskRespVO},config:{taskId,importedTestCaseId,selectedTestCaseId,versionId,versionNo,caseName,revision,sampleReceived,fixtureId,fixtureConfirmed,lengthMm,widthMm,heightMm,weightKg,requireFixture,runParams,runtimeAssignments,robotId,startedAt,stopPending},units:[{id,unitNo,status,attemptNo,currentExecutionId,physicalSerial,outputPath,attempts:[LabExecutionDO]}],flowData,inputConfig,recommendations:[{id,fixtureCode,fixtureName,fixtureSize,compatible,reason}],attachments:[]}.
- PUT /prepare body {taskId,expectedRevision,testCaseId,versionId?,changeReason?,sampleReceived,fixtureId?,fixtureConfirmed,lengthMm?,widthMm?,heightMm?,weightKg?,requireFixture,runParams:{},runtimeAssignments:[],robotId?} -> config. Preparation cannot create executions. Confirm/claim task atomically if needed, enforce task ownership/permissions. Parameter defaults from release config must be honored; reserved context keys cannot be supplied by users.
- POST /precheck {taskId} -> {passed,items:[{code,passed,message}]}.
- POST /start-unit {taskId,unitId,expectedRevision,loadedConfirmed:true,idempotencyKey,physicalSerial?,reason?} -> execution ID. Failed units may retry with reason, successful units cannot re-execute. Freeze all task configuration at first start. One active unit per task.
- POST /cancel {taskId,reason} -> void; stop active native instance after commit; no-active cancellation releases immediately, failures retain STOP_PENDING.
- POST /confirm-stop {taskId,reason} -> void; actually call edge stopAll again, release only on successful acknowledgement.
- GET /fixture-options?taskId=&lengthMm=&widthMm=&heightMm= -> fixture recommendations.
- GET /attachments?taskId=; POST /attachment {taskId,fileName,fileUrl,fileType}; DELETE /attachment?taskId=&id= (parent authorization).
## Backend/root interfaces (all under lab.service.scanonly)
ScanOnlyTaskService:
- boolean isScanTask(Long taskId)
- void initializeImported(Long taskId,String caseId,int quantity) (participates in caller transaction; original case immutable on draft reimport, current case updated with audit, validate drafts only)
- void onExecutionFinished(Long executionId,boolean success,String outputJson,String error) (idempotent terminal callback, owns scan execution/unit/task aggregation/output files; does not call measurement/report services)
- void onControl(Long executionId,String status) (PAUSED/RUNNING/CANCELLED; STOP_PENDING cancellation never releases until acknowledged)
- void assertRobotAvailable(String robotId,String nativeTaskId) (native task belongs to occupation owner via lab_cmvr_execution.cmvr_task_id -> execution.task_id; null task means trial/debug and cannot use occupied robot).
Root supplies CmvrMethodBindingService.ensureMethod(String caseId,String versionId) -> LabTestMethodRefDO, pure mapping/validation without selecting or creating executions. Existing bind remains legacy only. Root stores binding.cmvrTaskId before executeFrozen so occupation guard can identify the native request.
Root adds fields processType (String) to LabTestTaskDO and sampleUnitId(Long),attemptNo(Integer) to LabExecutionDO. Backend schema supplies these columns; existing rows become LEGACY_FULL, new imports SCAN_ONLY. Backend may add dimensions/ranges to master sample/fixture with migration; let frontend use config dimensions and recommendations, not new APIs on master forms.
Root adds native interface com.cmvr.test.flow.runtime.engine.RobotTaskOccupationGuard.check(String robotId,String nativeTaskId), used before native trial/formal execution and motion debug controllers. Root adapter calls ScanOnlyTaskService.assertRobotAvailable.
## Verification
- Meaningful Java tests: strict case/version mapping; per-unit aggregation/retry/idempotence; revision and case change audit; three units and shared occupation; stop failure retains occupation; legacy callback unchanged.
- Python migration dry-run and repeat apply idempotence. Only authorized target database.
- Frontend type/build and real API: import quantity 3 -> prepare -> unit1 -> block trial/second task -> unit2 fail/retry -> unit3 -> completed without result/report; cancelled/restart orphan and old menus do not resurrect.
- Source integrity fingerprints unchanged. Leave backend/frontend and simulator running with reviewable test records, no secrets in outputs.
## Rulings
- User's explicit coding request authorizes implementing the reviewed design; no repeated design permission gate.
- Existing target has no HEAD and all sources are untracked. Work in requested checkout, do not create a new empty worktree or commit unrelated baseline files.
- Technical execution logs/JSON outputs remain; business result confirmation, coverage judgment and reporting are outside SCAN_ONLY scope.