fix(ui): enforce durable org identity for runtime followups

This commit is contained in:
cgycorey
2026-08-02 17:20:34 +01:00
parent 734a2d5969
commit 15ab07cba2
9 changed files with 943 additions and 22 deletions
+31 -3
View File
@@ -22,7 +22,11 @@ from opc.core.active_task_runs import (
ActiveTaskRunAdmissionClosed,
ActiveTaskRunRegistry,
)
from opc.core.config import DEFAULT_EXTERNAL_AGENT_STARTUP_TIMEOUT_SECONDS, DEFAULT_ORGANIZATION_ID
from opc.core.config import (
DEFAULT_EXTERNAL_AGENT_STARTUP_TIMEOUT_SECONDS,
DEFAULT_ORGANIZATION_ID,
validate_organization_id,
)
from opc.core.models import (
AdaptiveRoleProfile,
AdaptiveSignalSpec,
@@ -1326,6 +1330,26 @@ class CompanyRuntimeSpecBuilder(CompanyRuntimeWorkItemHelper):
or "corporate"
).strip() or "corporate"
org_config = getattr(self.org_engine.config, "org", None)
selected_org_id = ""
if profile == "custom":
try:
selected_org_id = validate_organization_id(getattr(decision, "org_id", None))
except ValueError:
selected_org_id = ""
if not selected_org_id:
# A custom-organization run must carry a durable org_id on the
# decision. Never derive it from the process-wide active
# config; fail closed before any work items are created.
from opc.plugins.office_ui.services.models import ServiceError
raise ServiceError(
"org_id_required",
"org_id_required",
{
"company_profile": profile,
"reason": "custom_company_run_requires_durable_org_id",
},
)
decision.org_id = selected_org_id
metadata: dict[str, Any] = {
"source": "work_item_runtime",
"execution_mode": "company_mode",
@@ -1333,7 +1357,11 @@ class CompanyRuntimeSpecBuilder(CompanyRuntimeWorkItemHelper):
"runtime_model": "multi_team_org",
"work_item_driven": True,
"company_profile": profile,
"organization_id": str(getattr(org_config, "organization_id", "") or "").strip(),
"organization_id": (
selected_org_id
if profile == "custom"
else str(getattr(org_config, "organization_id", "") or "").strip()
),
"organization_name": str(getattr(org_config, "organization_name", "") or "").strip(),
"organization_config_file": str(getattr(org_config, "organization_config_file", "") or "").strip(),
"original_request": original_message,
@@ -1341,7 +1369,7 @@ class CompanyRuntimeSpecBuilder(CompanyRuntimeWorkItemHelper):
"domains": list(getattr(decision, "domains", []) or []),
"preferred_agent": getattr(decision, "preferred_agent", None),
"requested_sub_tasks": list(getattr(decision, "sub_tasks", []) or []),
"org_id": getattr(decision, "org_id", None),
"org_id": selected_org_id if profile == "custom" else getattr(decision, "org_id", None),
}
return CompanyRuntimeSpec(
profile=profile,
+15 -1
View File
@@ -64,8 +64,22 @@ class CustomRuntimeRunner:
) -> str:
from opc.engine import OPCEngine
from opc.layer2_organization.phase_hooks import unregister_dispatcher_wake
from opc.plugins.office_ui.services.models import ServiceError
org_config, resolved_org_id = self._build_org_config(org_id)
normalized_org_id = str(org_id or "").strip()
if not normalized_org_id:
# Isolated org mode must carry a durable org_id; resolving the
# active index here would silently route the run to whichever
# organization is currently loaded.
raise ServiceError(
"org_id_required",
"org_id_required",
{
"project_id": project_id or self.parent.project_id or "default",
"reason": "custom_company_run_requires_durable_org_id",
},
)
org_config, resolved_org_id = self._build_org_config(normalized_org_id)
normalized_project_id = str(project_id or self.parent.project_id or "default").strip() or "default"
shared_store = getattr(self.parent, "store", None)
runtime = OPCEngine(