feat: install platform agent as org root (Phase 1) #2371

Merged
devops-engineer merged 1 commits from feat/platform-agent-install into main 2026-06-06 22:18:52 +00:00
Member

Phase 1 of the org-level platform agent (RFC #2360). Stacked on #2361 (Phase 0) — base is feat/platform-agent-kind; will retarget to main once #2361 merges.

Adds the idempotent operation that makes the concierge the org root: POST /admin/org/platform-agent (AdminAuth) → installPlatformAgent(). In one transaction it (1) upserts the platform-agent row (kind=platform, parent_id NULL) via ON CONFLICT, (2) re-parents the org's existing root(s) under it, (3) moves the org-anchor refs that key off the root workspace id — org_api_tokens.org_id + org_plugin_allowlist.org_id — old root → platform agent.

Routing unchanged — platform-as-root reuses existing ancestor/descendant rules; sameOrg still isolates tenants.

The CP calls this at org-provision (new orgs) and the existing-org backfill (CTO-authorized to run post-merge, snapshot+rollback).

Tests

  • Unit: handler bad-input 400.
  • Real-Postgres integration: proves re-parent + both anchor migrations + orgRootID/sameOrg resolve to the platform agent + idempotency. Verified locally (postgres:15, all migrations apply, green).
  • Allowlisted in the workspaces-INSERT bulk-create regression guard with its ON CONFLICT safety note.

Audit note

The re-parent moves the org anchor; audit confirmed exactly 2 anchor tables (org_api_tokens, org_plugin_allowlist). rescue_bundles.org_id is the CP org UUID (MOLECULE_ORG_ID), a different namespace — not affected.

🤖 Generated with Claude Code

Phase 1 of the org-level platform agent (RFC #2360). **Stacked on #2361 (Phase 0)** — base is `feat/platform-agent-kind`; will retarget to `main` once #2361 merges. Adds the idempotent operation that makes the concierge the org root: `POST /admin/org/platform-agent` (AdminAuth) → `installPlatformAgent()`. In one transaction it (1) upserts the platform-agent row (`kind=platform`, `parent_id NULL`) via ON CONFLICT, (2) re-parents the org's existing root(s) under it, (3) moves the org-anchor refs that key off the root workspace id — `org_api_tokens.org_id` + `org_plugin_allowlist.org_id` — old root → platform agent. **Routing unchanged** — platform-as-root reuses existing ancestor/descendant rules; `sameOrg` still isolates tenants. The CP calls this at org-provision (new orgs) and the existing-org backfill (CTO-authorized to run post-merge, snapshot+rollback). ### Tests - Unit: handler bad-input 400. - **Real-Postgres integration**: proves re-parent + both anchor migrations + `orgRootID`/`sameOrg` resolve to the platform agent + idempotency. Verified locally (postgres:15, all migrations apply, green). - Allowlisted in the workspaces-INSERT bulk-create regression guard with its ON CONFLICT safety note. ### Audit note The re-parent moves the org anchor; audit confirmed exactly 2 anchor tables (`org_api_tokens`, `org_plugin_allowlist`). `rescue_bundles.org_id` is the CP org UUID (`MOLECULE_ORG_ID`), a different namespace — not affected. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
devops-engineer added the tier:medium label 2026-06-06 17:55:12 +00:00
devops-engineer changed target branch from feat/platform-agent-kind to main 2026-06-06 18:25:49 +00:00
devops-engineer added 1 commit 2026-06-06 18:26:01 +00:00
feat(workspace-server): install platform agent as org root (Phase 1)
ci-arm64-advisory / fast-checks (pull_request) Waiting to run
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 4s
CI / Python Lint & Test (pull_request) Successful in 3s
Lint forbidden tenant-env keys / Scan workspace_secrets writers for forbidden env keys (pull_request) Successful in 5s
Harness Replays / detect-changes (pull_request) Successful in 5s
Lint forbidden tenant-env keys / Scan for repo-host token write into tenant workspace surface (pull_request) Successful in 4s
CI / Detect changes (pull_request) Successful in 15s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 5s
gate-check-v3 / gate-check (pull_request_target) Successful in 7s
sop-checklist / review-refire (pull_request_target) Has been skipped
E2E API Smoke Test / detect-changes (pull_request) Successful in 18s
Lint shellcheck (arm64 pilot) / shellcheck-arm64 (pilot) (pull_request) Successful in 15s
E2E Chat / detect-changes (pull_request) Successful in 17s
sop-checklist / all-items-acked (pull_request) acked: 0/7 — missing: comprehensive-testing, local-postgres-e2e, staging-smoke, +4 — body-unfilled: comprehensive-testing, local-postgres-e2
sop-checklist / na-declarations (pull_request) N/A: (none)
sop-checklist / all-items-acked (pull_request_target) Successful in 5s
CI / Canvas (Next.js) (pull_request) Successful in 2s
sop-tier-check / tier-check (pull_request_target) Failing after 7s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 1s
qa-review / approved (pull_request_target) Failing after 13s
security-review / approved (pull_request_target) Failing after 12s
CI / Canvas Deploy Status (pull_request) Has been skipped
Harness Replays / Harness Replays (pull_request) Successful in 12s
E2E Chat / E2E Chat (pull_request) Successful in 3s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m0s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 57s
CI / Platform (Go) (pull_request) Successful in 9m5s
CI / all-required (pull_request) Successful in 9s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 6s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 1m6s
qa-review / approved (pull_request_review) Has been skipped
security-review / approved (pull_request_review) Has been skipped
sop-tier-check / tier-check (pull_request_review) Failing after 10s
audit-force-merge / audit (pull_request_target) Successful in 19s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Has been cancelled
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Has been cancelled
1c42488be7
Add the idempotent, transactional operation that makes the org-level concierge
the org root (RFC docs/design/rfc-platform-agent.md): POST /admin/org/platform-agent
(AdminAuth) + installPlatformAgent().

In ONE transaction it:
  1. upserts the platform-agent row (kind='platform', parent_id NULL, tier 0)
     via ON CONFLICT (id) DO UPDATE;
  2. re-parents the org's existing root(s) under it;
  3. moves the org-anchor references that key off the root workspace id —
     org_api_tokens.org_id and org_plugin_allowlist.org_id — from each old root
     to the platform agent, so a tenant's admin tokens + plugin allowlist never
     point at a stale anchor.

Routing is UNCHANGED: once the platform agent is the root, the existing
ancestor/descendant rules in registry/access.go give it universal in-org reach
and org_scope.go keeps tenant isolation intact.

The CP calls this at org-provision (new orgs, clean) and during the existing-org
backfill rollout. Idempotent: a second call is a no-op.

Tests: handler bad-input unit test; real-Postgres integration test proving the
re-parent + both anchor migrations + orgRootID/sameOrg resolution + idempotency
(sqlmock cannot evaluate the post-tx row state). Allowlisted in the
workspaces-INSERT bulk-create regression guard with its ON CONFLICT safety note.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
devops-engineer force-pushed feat/platform-agent-install from 3665faa5ca to 1c42488be7 2026-06-06 18:26:01 +00:00 Compare
devops-engineer closed this pull request 2026-06-06 18:46:16 +00:00
devops-engineer reopened this pull request 2026-06-06 18:46:24 +00:00
molecule-code-reviewer approved these changes 2026-06-06 22:13:47 +00:00
molecule-code-reviewer left a comment
Member

Independent review confirmed: install op idempotently makes the platform agent the org root, re-parents the existing root, and migrates the 2 org-anchor tables (org_api_tokens + org_plugin_allowlist) in one tx; real-PG integration test proves re-parent + anchor migration + orgRootID/sameOrg resolution + idempotency; allowlisted in the bulk-INSERT guard. Required checks green. Approving.

Independent review confirmed: install op idempotently makes the platform agent the org root, re-parents the existing root, and migrates the 2 org-anchor tables (org_api_tokens + org_plugin_allowlist) in one tx; real-PG integration test proves re-parent + anchor migration + orgRootID/sameOrg resolution + idempotency; allowlisted in the bulk-INSERT guard. Required checks green. Approving.
core-security approved these changes 2026-06-06 22:18:50 +00:00
core-security left a comment
Member

Security review: transactional re-parent + anchor migration is atomic; no routing change (platform==root reuses existing rules); sameOrg isolation preserved. Approving.

Security review: transactional re-parent + anchor migration is atomic; no routing change (platform==root reuses existing rules); sameOrg isolation preserved. Approving.
devops-engineer merged commit 96f6dff691 into main 2026-06-06 22:18:52 +00:00
Sign in to join this conversation.
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: molecule-ai/molecule-core#2371