Skip to content

#26 criterion 3: the built-in operations engine and the Operations API (first slice) - #774

Merged
ephico2real2 merged 6 commits into
mainfrom
feat/26-operations
Dec 1, 2026
Merged

ephico2real2 merged 6 commits into
mainfrom
feat/26-operations

Conversation

@ephico2real2

Copy link
Copy Markdown
Owner

Part of #26

Story #26, criterion 3: "Built-in cluster-onboard, rebuild-verify, reconcile and tier re-render operations report progress, survive retries and honor approvals; optional workflow engines are not required." This is the first slice: the built-in engine, the Operations API and four templates. The Argo Workflows and Tekton adapters are out of scope (the criterion does not need them). No screen: the portal mockup has no Operations view, and a screen needs an approved mockup first.

What it builds

  • Built-in engine (cmapi/src/cmapi/core/operations.py): each step that is due is one operation_step job in the jobs table; state in operations and operation_steps (migration 0013, security class: two reviewers). One scheduler (advance) under an advisory lock creates the rows of ready steps, starts Pending rows within maxConcurrentSteps (integrations.yaml, default 4) and a fan-out step's parallelism/perCluster, and ends a run with nothing in flight (Succeeded, Failed, Error, Stopped) with its report in the row.
  • Step library and templates (cmapi/src/cmapi/ops/): tiers-rerender and rebuild-verify end to end; reconcile and cluster-onboard as far as what they need is built.
  • Operations API (cmapi/src/cmapi/routers/operations.py): POST /api/v1/operations (Idempotency-Key required), GET /api/v1/operations, GET /api/v1/operations/{id} (status of record: every step row with phase, attempts, outputs, last error; the report once ended), POST /api/v1/operations/{id}:cancel. Each needs operations:run where the run acts; reconcile also needs approvals:pause. New problems: operations-engine-unavailable (503), operation-template-unknown (422).
  • Approvals honoured: a step that changes a namespace opens an ordinary request (Pipeline.plan_namespace + submit) as svc-cmapi-workflows, with the starter as requester; it polls the request; the ledger refuses the starter as approver where self-approval is off.
  • Retries and crash safety: Argo's retryStrategy semantics (limit retries, limit + 1 attempts, backoff × factor); a step that dies mid-transaction leaves nothing, its job lease runs out and another worker reruns it; a per-row Idempotency-Key finds a request already opened.

Design decisions and sources

docs/reviews/2026-12-01-issue-26-operations/design.md (D1 to D14), each source fetched 2026-12-01: RFC 8693 §1.1 (delegation, the step identity), Argo Workflows workflow_types.go (RetryStrategy, Backoff, WithParam), Argo parallelism, argo stop, google longrunning/operations.proto (CancelOperation), draft-ietf-httpapi-idempotency-key-header-07 §2.3–2.4.

Not built (listed, each refuses with its issue)

Template Step Issue
cluster-onboard propose-registry (POST /api/v1/admin/clusters:propose; repository of clusters.yaml is an owner decision) #761
cluster-onboard smoke-test #765
cluster-onboard preflight's Thanos retention and root Application checks #763
reconcile rebuild a request from its bot PR (security design) #762

adoption-sweep and bulk-migrate templates, onExit, and the Argo/Tekton adapters are not built.

Tests

cmapi/tests/service/test_operations_26.py (20 tests): start and progress; an approval-gated step waiting until approver-platform approves; decrease below use skipped; rejection reported; retry with backoff; out of retries; a worker that dies mid-step (one request); batchSize and cancel; 403 without operations:run and outside the environment; refusals at start; Idempotency-Key replay; 503 operations-engine-unavailable; bad integrations.yaml; maxConcurrentSteps; rebuild-verify drift report; reconcile (both ways); cluster-onboard (registered, and waiting for an import); migration 0013 constraints, down and up. test_api_samples.py records the four new operations.

Measured locally (fakes, PostgreSQL 16, no cluster): test_operations_26.py 19 passed before the migration test was added (the 20th, test_0013_roundtrip_and_its_constraints, has not run); test_api_samples.py 3 passed (samples recorded); the contract written, Spectral lint clean, scripts/doc-citations.py --check 0 problems. After that run, cancel was changed to take the engine's lock before the run's row (a lock-order fix) and has not been run.

Not tested locally: a run of the related suites (docs, standard, authz walk, migrations, contract) was stopped on the coordinator's hold while it showed 3 failures not yet identified; CI is the gate. Nothing ran on kind or CRC.

Who wrote what

All commits and files: Opus 5.5 (high), the implementer. No review yet; one outside model family (Codex) is available for reviewer 1.

… 3, first slice)

The built-in engine runs each operation template's steps in the cmapi worker, as
jobs of kind operation_step, with their state in PostgreSQL (migration 0013:
operations, operation_steps). Templates: tiers-rerender and rebuild-verify end to
end; reconcile and cluster-onboard as far as what they need is built (#761, #762,
#763, #765). Routes: POST, GET /api/v1/operations, GET /api/v1/operations/{id},
POST /api/v1/operations/{id}:cancel, each needing operations:run where the run
acts. Steps open ordinary requests as svc-cmapi-workflows on behalf of the
starter, retry as the template's retry block says, survive a dead worker by the
job lease and a per-row Idempotency-Key, and an engine with no adapter answers
503 operations-engine-unavailable.
… types

docs/reviews/2026-12-01-issue-26-operations/design.md records the decisions the
design left open, with their sources. docs/02, 14, 16, 18, GLOSSARY and the build
tracker say what is built. contract/openapi.json, samples.json, docs/04 and the
portal's generated API types are regenerated.
…own approvals; starter identity checked; stored scope on replay and dispatch; cancel seen under the lock; start lock before the key; bounded step keys; Gitea paging; report order

Reviewer 1 (Codex gpt-6.2-astra) 12 of 13 accepted, #6 rejected; reviewer 2 (Fable) R2-1..R2-3. Applied by the coordinator
after a line-by-line read. Record: docs/reviews/2026-12-01-issue-26-operations/.
… the counts of the contract

- rebuild-verify passed the watch cache to watch_sync._live, which since #753 B4
  (merged from main) takes the cluster's reader and reads every object live: every
  verify-namespace step failed with AttributeError. It now passes the reader, so the
  verify reads the API server as the read that ends a request does.
- The start's Idempotency-Key description promises the original request in its
  current state, as #587 requires of every write's key (the operation the key
  started, as GET returns it now). Behaviour unchanged.
- core/plugins.py CORE gains operations: routers/operations.py is a core router
  (docs/02), so plugins.yaml cannot switch it and GET /admin/plugins lists it.
  test_plugins_switch's expected sets name the core parts, so they gain operations:
  the expectation changes because the core gained a part, not to pass a test.
- docs/diagrams/portal-architecture/README.md and docs/08: the contract has 50
  operations, and the four operations routes are listed as called by no mockup
  action (the mockup has no Operations view).
- The contract and the portal's generated types written again for the key's text.
@ephico2real2
ephico2real2 merged commit 390655a into main Dec 1, 2026
11 checks passed
ephico2real2 added a commit that referenced this pull request Dec 1, 2026
…ions relocated, docs/14 pipeline.py:298 corrected by hand
ephico2real2 added a commit that referenced this pull request Dec 1, 2026
…revises 0013

#774 merged first with 0013_operations revising 0012, so 0014 revises 0013 and REQUIRED_REVISION stays 0014.
Conflicts combined from both sides: REQUIRED_REVISION's comment names 0013; test_usage_verdicts_310 reads
REQUIRED_REVISION; docs/14 keeps this branch's step 5 and #789 rows with the citations relocated; GLOSSARY lists
0013 and 0014; docs/16's schema block written again at head 0014 (16 tables) with scripts/db-schema-doc.py.
citations.lock.json is the union of both sides (ours over theirs, except main.py:204-208, where main's text is
the file's), relocated and written; every entry's text is one side's, so no span changed. The texts that said
0013 was #774's and unmerged now say 0014 revises 0013; the 0014 tests start and downgrade at 0013.
BlackYuriJDU pushed a commit to BlackYuriJDU/cmapi that referenced this pull request Dec 1, 2026
…n approval and is an approvals row

ephico2real2#779 (security): :reject checked only requests:reject in the environment, so an approver in no approving group
of the request could veto it, and a requester could reject their own request where selfApproval is false.
:reject now locks the request, checks the environment and the state, and runs ApprovalLedger.reject, which
shares _eligible with approve: 403 not-eligible, 409 self-approval, 409 already-approved (a person decides a
request once). One eligible rejection still ends the request.

ephico2real2#780: docs/01 says "Each decision is an approvals row and an audit event". Migration 0014 adds
approvals.decision (approve | reject, default approve, check ck_approvals_decision); a rejection writes a row
with counted_for, the group of the open seat it was decided for. RequestRepo.approvals reads approvals only,
so no rejection fills a slot. The downgrade refuses while a rejection is stored (refuse, never drop).
REQUIRED_REVISION is 0014. 0014 revises 0012: 0013 is PR ephico2real2#774's, not merged.

Docs 01, 12, 14, 16, GLOSSARY, the authorization figure, openapi.json and the portal types updated; the design
and its sources are in docs/reviews/2026-12-01-issue-779-780/design.md.

Closes ephico2real2#779
Closes ephico2real2#780
Part of ephico2real2#18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant