- Fix 1: tasks_md_sync only sets MACP fields when columns exist in table headers - Fix 2: ACP dispatch now escalates instead of falsely completing - Fix 3: Removed premature collect_result() from dispatch_task() - Fix 4: Yolo brief staged via temp file (0600) instead of process args - Fix 5: cleanup_worktree validates path against configured worktree base
6.6 KiB
6.6 KiB
MACP Phase 1 Scratchpad
Objective
Implement MACP Phase 1 in mosaic-bootstrap by extending the orchestrator-matrix protocol, adding a dispatcher layer, wiring the controller, updating sync/config/CLI behavior, and preserving backward compatibility for legacy tasks.
Tracking
- Task ID:
MACP-PHASE1 - Issue:
#8 - Branch:
feat/macp-phase1 - Repo:
bootstrap
Budget
- User hard token budget: not specified
- Working assumption: complete in one implementation pass with focused verification and no unnecessary parallelization
- Budget response plan: keep scope limited to the requested file map and verification set
Plan
- Extend task and event schemas and add the MACP result schema.
- Build
dispatcher/macp_dispatcher.pywith isolated helpers for worktree, command, result, and cleanup logic. - Wire the controller to detect MACP-aware tasks, emit gated/escalated events, and preserve the legacy path for tasks without
dispatch. - Add MACP defaults to config, add
mosaic macprouting and shell script support, and extendtasks_md_sync.py. - Run backward-compatibility and MACP verification, then review/remediate before commit and PR flow.
Assumptions
dispatchpresence is the MACP-aware signal for the controller, matching the user brief.docs/tasks/MACP-PHASE1-brief.mdis an input artifact for this delivery and should remain available for reference.- A minimal developer-facing documentation update tied to the orchestrator README/CLI behavior will satisfy the documentation gate for this change surface.
Risks
- Worktree cleanup must be constrained to task-owned paths only.
- Gate-state transitions need to remain compatible with current event consumers.
- CLI submit behavior must avoid corrupting existing
tasks.jsonstructure.
Verification Plan
| Acceptance Criterion | Verification Method | Evidence |
|---|---|---|
| AC-1 legacy tasks still work | Run controller against old-style tasks without dispatch |
Passed: temp repo run completed legacy task and wrote completed result JSON |
AC-2 MACP exec flow works |
Run controller against MACP task queue and inspect result JSON/events/worktree cleanup | Passed: temp repo run produced task.gated and task.completed, wrote structured result JSON with files_changed, and removed the task worktree |
| AC-3 schemas are valid | Validate schema JSON loads and sample payloads parse/import cleanly | Passed: jsonschema.validate(...) succeeded for task, event, and result schema samples |
| AC-4 CLI works | Run mosaic macp submit/status/history against a test repo state |
Passed: bin/mosaic-macp submit/status/history succeeded and bin/mosaic --help exposed macp |
| AC-5 imports are clean | Run python3 -c "import ..." for updated modules |
Passed: importlib-based module loads and py_compile succeeded |
Progress Log
- 2026-03-27: Loaded global/project/runtime contracts and required delivery guides.
- 2026-03-27: Created provider issue
#8. - 2026-03-27: Drafted PRD, task tracking, and this scratchpad before implementation.
- 2026-03-27: Implemented MACP schemas, dispatcher lifecycle, controller integration, CLI support, sync updates, and developer docs.
- 2026-03-27: Added explicit worker escalation handling via the
MACP_ESCALATE:stdout marker. - 2026-03-27: Committed and pushed branch
feat/macp-phase1(7ef49a3,fd6274f). - 2026-03-27: Blocked in PR workflow when
~/.config/mosaic/tools/git/pr-create.shfailed to resolve the remote repository from this worktree. - 2026-03-28: Resumed from blocked state for a review-fix pass covering 5 findings in
docs/tasks/MACP-PHASE1-fixes.md.
Review Fix Pass
Scope
- Restore legacy
tasks_md_sync.pybehavior so rows without MACP headers do not become MACP tasks. - Make ACP dispatch fail-safe via escalation instead of a no-op success path.
- Move MACP result writes to the controller after quality gates determine the final task status.
- Remove brief text from yolo command arguments by switching to file-based brief handoff.
- Restrict worktree cleanup to validated paths under the configured worktree base.
TDD / Test-First Decision
- This is a bug-fix and security-hardening pass, so targeted reproducer verification is required.
- Repo appears to use focused script-level verification rather than a Python test suite for this surface, so reproducer checks will be command-driven and recorded as evidence.
Planned Verification Additions
| Finding | Verification |
|---|---|
| Legacy task reclassification | Sync docs/TASKS.md without MACP headers into tasks.json and confirm dispatch is absent so controller stays on run_shell() |
| ACP no-op success | Run controller/dispatcher with dispatch=acp and confirm status=escalated, exit path is non-zero, and task.escalated is emitted |
| Premature result write | Inspect result JSON after final controller state only; confirm gate results are present and no dispatcher pre-write remains |
| Brief exposure | Build yolo command and confirm the brief body is absent from the command text |
| Unsafe cleanup | Call cleanup against a path outside configured base and confirm it is refused |
Tests Run
python3 -m py_compile tools/orchestrator-matrix/controller/mosaic_orchestrator.py tools/orchestrator-matrix/controller/tasks_md_sync.py tools/orchestrator-matrix/dispatcher/macp_dispatcher.py- importlib module-load check for updated Python files
jsonschema.validate(...)for task/event/result samples- Temp repo legacy controller run with old-style
tasks.json - Temp repo MACP
execcontroller run with worktree/result/cleanup verification - Temp repo CLI checks using
bin/mosaic-macp submit,status, andhistory - Temp repo
tasks_md_sync.py --applyrun with MACP columns git diff --checkbash -n bin/mosaic bin/mosaic-macp
Review
- Automated review attempted with
~/.config/mosaic/tools/codex/codex-code-review.sh --uncommitted - Initial review attempt failed because generated
__pycache__files introduced non-UTF-8 diff content; generated caches were removed - Manual independent review completed on the dispatcher/controller/CLI delta
- Remediation applied: final MACP results are now written before worktree cleanup, and explicit worker escalation is handled instead of being ignored
Residual Risks
- The repo-local
bin/mosaicroute was verified through help output; full runtime routing depends on installation into$MOSAIC_HOME/bin. - Explicit worker escalation currently uses a stdout marker convention rather than a richer structured worker-to-controller handoff.
- Delivery is blocked on repository automation because PR creation failed before merge/CI/issue-closure stages could run.