{
  "schema_version": "0.1",
  "artifact_type": "implementation_plan",
  "canonical": true,
  "artifact_id": "audit-boundary-fixes",
  "agent_summary": {
    "title": "Fix the reproduced audit boundary defects",
    "status": "complete",
    "summary": "All four repairs and documentation corrections are verified. Full unit tests, mock system tests, source-bound self-review, and release checks passed.",
    "last_reviewed_at": "2026-09-14"
  },
  "source_ids": [
    "TRK-166",
    "REQ-178",
    "REQ-179",
    "REQ-180",
    "REQ-181"
  ],
  "approval_gate": {
    "status": "approved",
    "implementation_authorized": true,
    "approved_by": "user"
  },
  "scope": {
    "included": [
      "Reject foreign-origin configuration writes to the local control surface",
      "Apply worker restrictions to request closure and delivery tools",
      "Preserve independent concurrent configuration changes across UI CLI and MCP",
      "Reject workflow judgment when its bound source files have changed or disappeared",
      "Correct the documentation discrepancies identified in the investigation"
    ],
    "excluded": [
      "New product features",
      "External model calls or subagents",
      "Edits to downstream repositories",
      "Existing uncommitted user artifacts"
    ]
  },
  "assumptions": [
    "Use existing file state and cross-runtime lock; keep legitimate local clients compatible.",
    "Current evidence is the investigation at 4077a97 and fresh regression runs.",
    "Integration base is published v0.16.62 at 9bb42c2; original checkout user changes remain separate."
  ],
  "phases": [
    {
      "id": "IMP-PHASE-049",
      "summary": "Repair and verify the existing boundaries"
    }
  ],
  "tasks": [
    {
      "id": "IMP-TASK-121",
      "phase_id": "IMP-PHASE-049",
      "summary": "Reject foreign-origin configuration writes to the local control surface",
      "status": "completed",
      "requirement_ids": [
        "REQ-178",
        "PRD-007"
      ],
      "architecture_ids": [
        "ARCH-007"
      ],
      "validation_ids": [
        "IMP-VAL-107"
      ],
      "files": [
        "scripts/prd_ui_serve.py"
      ],
      "complexity": "medium",
      "confidence": "high",
      "risk": "medium",
      "red_command": "python -m unittest tests.test_prd_ui_serve -q",
      "green_command": "python -m unittest tests.test_prd_ui_serve -q",
      "expected_behavior": "Foreign or malformed origins, hostile Host values, and non-JSON write requests are rejected before configuration changes; legitimate same-origin UI and non-browser local JSON clients keep working.",
      "regression_to_add": "Disposable HTTP probe returned 200 and changed autonomy when sent a foreign Origin with text/plain JSON.",
      "evidence_ids": [
        "EV-221"
      ]
    },
    {
      "id": "IMP-TASK-122",
      "phase_id": "IMP-PHASE-049",
      "summary": "Apply worker restrictions to request closure and delivery tools",
      "status": "completed",
      "requirement_ids": [
        "REQ-179",
        "PRD-002"
      ],
      "architecture_ids": [
        "ARCH-002"
      ],
      "validation_ids": [
        "IMP-VAL-108"
      ],
      "files": [
        "mcp/server.cjs"
      ],
      "complexity": "medium",
      "confidence": "high",
      "risk": "medium",
      "red_command": "python -m unittest tests.test_mcp_server tests.test_thread_close tests.test_request_routing -q",
      "green_command": "python -m unittest tests.test_mcp_server tests.test_thread_close tests.test_request_routing -q",
      "expected_behavior": "Every mutating request tool rejects worker sessions before touching canonical state or delivering peer messages; ordinary lead calls remain supported.",
      "regression_to_add": "With worker mode set, prd_update was denied but prd_close_thread resolved a canonical request thread.",
      "evidence_ids": [
        "EV-221"
      ]
    },
    {
      "id": "IMP-TASK-123",
      "phase_id": "IMP-PHASE-049",
      "summary": "Preserve independent concurrent configuration changes across UI CLI and MCP",
      "status": "completed",
      "requirement_ids": [
        "REQ-180",
        "PRD-007"
      ],
      "architecture_ids": [
        "ARCH-007"
      ],
      "validation_ids": [
        "IMP-VAL-109"
      ],
      "files": [
        "scripts/prd_config.py",
        "mcp/server.cjs"
      ],
      "complexity": "medium",
      "confidence": "high",
      "risk": "medium",
      "red_command": "python -m unittest tests.test_unified_config tests.test_reflections tests.test_mcp_server tests.test_prd_ui_serve -q",
      "green_command": "python -m unittest tests.test_unified_config tests.test_reflections tests.test_mcp_server tests.test_prd_ui_serve -q",
      "expected_behavior": "Supported configuration mutation operations share the canonical cross-process lock and preserve concurrent changes without introducing nested-lock deadlocks.",
      "regression_to_add": "Synchronized updates to two different settings both returned success while one setting reverted to its prior value.",
      "evidence_ids": [
        "EV-221"
      ]
    },
    {
      "id": "IMP-TASK-124",
      "phase_id": "IMP-PHASE-049",
      "summary": "Reject workflow judgment when its bound source files have changed or disappeared",
      "status": "completed",
      "requirement_ids": [
        "REQ-181",
        "PRD-008"
      ],
      "architecture_ids": [
        "ARCH-008"
      ],
      "validation_ids": [
        "IMP-VAL-110"
      ],
      "files": [
        "scripts/prd_workflows.py"
      ],
      "complexity": "medium",
      "confidence": "high",
      "risk": "medium",
      "red_command": "python -m unittest tests.test_prd_workflows tests.test_substrate_runtime_worker -q",
      "green_command": "python -m unittest tests.test_prd_workflows tests.test_substrate_runtime_worker -q",
      "expected_behavior": "Resume checks current source content against captured source hashes and refuses changed, missing, or escaped sources before advancing the run; unchanged sources and existing record-reference workflows remain compatible.",
      "regression_to_add": "A waiting review recorded a source hash, then accepted the original result envelope after that source changed.",
      "evidence_ids": [
        "EV-221"
      ]
    },
    {
      "id": "IMP-TASK-120",
      "phase_id": "IMP-PHASE-049",
      "summary": "Refresh stale tool and system-test documentation, verify downstream delivery, and complete release checks.",
      "status": "completed",
      "requirement_ids": [
        "REQ-178",
        "REQ-179",
        "REQ-180",
        "REQ-181"
      ],
      "architecture_ids": [
        "ARCH-002",
        "ARCH-007",
        "ARCH-008"
      ],
      "validation_ids": [
        "IMP-VAL-106"
      ],
      "complexity": "medium",
      "confidence": "high",
      "risk": "medium",
      "files": [
        "README.md",
        "wiki/mcp/mcp-state-server.md",
        "wiki/integrations/unified-configuration.md",
        "wiki/workflows/deterministic-workflow-engine.md",
        "tests/test_substrate_adapter.py",
        "wiki/skills/skills-and-the-router.md",
        "wiki/delivery/plugin-ui.md",
        "wiki/index.md",
        "wiki/log.md",
        "raw/operations/2026-09-14-runtime-boundary-audit.md"
      ],
      "dependencies": [
        "IMP-TASK-121",
        "IMP-TASK-122",
        "IMP-TASK-123",
        "IMP-TASK-124"
      ],
      "evidence_ids": [
        "EV-221"
      ]
    }
  ],
  "validations": [
    {
      "id": "IMP-VAL-107",
      "applies_to": [
        "IMP-TASK-121"
      ],
      "summary": "Foreign or malformed origins, hostile Host values, and non-JSON write requests are rejected before configuration changes; legitimate same-origin UI and non-browser local JSON clients keep working.",
      "evidence_expected": "Failing regression followed by passing regression and affected integration tests.",
      "status": "passed",
      "evidence_ids": [
        "EV-221"
      ]
    },
    {
      "id": "IMP-VAL-108",
      "applies_to": [
        "IMP-TASK-122"
      ],
      "summary": "Every mutating request tool rejects worker sessions before touching canonical state or delivering peer messages; ordinary lead calls remain supported.",
      "evidence_expected": "Failing regression followed by passing regression and affected integration tests.",
      "status": "passed",
      "evidence_ids": [
        "EV-221"
      ]
    },
    {
      "id": "IMP-VAL-109",
      "applies_to": [
        "IMP-TASK-123"
      ],
      "summary": "Supported configuration mutation operations share the canonical cross-process lock and preserve concurrent changes without introducing nested-lock deadlocks.",
      "evidence_expected": "Failing regression followed by passing regression and affected integration tests.",
      "status": "passed",
      "evidence_ids": [
        "EV-221"
      ]
    },
    {
      "id": "IMP-VAL-110",
      "applies_to": [
        "IMP-TASK-124"
      ],
      "summary": "Resume checks current source content against captured source hashes and refuses changed, missing, or escaped sources before advancing the run; unchanged sources and existing record-reference workflows remain compatible.",
      "evidence_expected": "Failing regression followed by passing regression and affected integration tests.",
      "status": "passed",
      "evidence_ids": [
        "EV-221"
      ]
    },
    {
      "id": "IMP-VAL-106",
      "applies_to": [
        "IMP-TASK-120"
      ],
      "summary": "Full test suite, tool/installer parity, state consistency, release and package checks pass with source-backed documentation.",
      "evidence_expected": "Fresh workflow and test receipts, code review, package dry run, and durable evidence.",
      "status": "passed",
      "evidence_ids": [
        "EV-221"
      ]
    }
  ],
  "craftesb": {
    "Correct": "Each reproduced defect has an observable acceptance test.",
    "Robust": "Cover malformed origins, worker tool coverage, concurrent writers, changed or missing sources, and valid existing calls.",
    "Aligned": "Fix all four defects and the documented discrepancies from the investigation.",
    "Faithful-to-method": "Validated intake, allocated IDs, canonical plan, TDD, workflow verification, code review, and release discipline.",
    "Tested": "Run regressions red before implementation, scoped tests after each fix, then full verification.",
    "Efficient": "Reuse current handlers, existing lock, and captured source hashes.",
    "Secure": "Reject untrusted requests and worker writes before mutation; keep evidence tied to current sources.",
    "Bounded": "No new server, storage backend, transport, model, or configuration option."
  },
  "risks_and_rollback": [
    "Avoid nesting Node and Python acquisition of the same lock.",
    "Keep loopback clients and same-origin embedded UI supported.",
    "Preserve waiting workflow state when refusing stale results.",
    "Revert the repair commit on its work branch if verification reveals regressions."
  ],
  "evidence_plan": [
    "Link red/green and final checks to all four requests and the active goal."
  ],
  "evidence_ids": [
    "EV-220",
    "EV-221"
  ]
}
