Skip to main content

gRPC Services Reference

This document is the gRPC reference for Cordum control plane services.

Source of truth:

  • core/protocol/proto/v1/api.proto
  • core/protocol/proto/v1/context.proto
  • core/protocol/proto/v1/output_policy.proto
  • core/protocol/pb/v1/pb.go (re-exports SafetyKernel from CAP module)
  • core/controlplane/scheduler/safety_client.go
  • core/controlplane/scheduler/output_safety_client.go
  • core/controlplane/safetykernel/kernel.go

Service Inventory

ServicePackageRPC methodsProto source
CordumApicordum.v1SubmitJob, GetJobStatuscore/protocol/proto/v1/api.proto
ContextEnginecordum.v1BuildWindow, UpdateMemorycore/protocol/proto/v1/context.proto
OutputPolicyServicecordum.v1CheckOutputcore/protocol/proto/v1/output_policy.proto
SafetyKernelcordum.agent.v1Check, Evaluate, Explain, Simulate, ListSnapshotsRe-exported via core/protocol/pb/v1/pb.go from github.com/cordum-io/cap/v2/cordum/agent/v1
Healthgrpc.health.v1Check, WatchStandard gRPC health protocol

Streaming coverage:

  • grpc.health.v1.Health/Watch is server-streaming.
  • All other RPCs above are unary.

Connection and TLS

Runtime endpoints and TLS env

ServiceDefault listen addrServer TLS envClient TLS env
CordumApi (API gateway gRPC):8080GRPC_TLS_CERT, GRPC_TLS_KEYn/a (client-specific)
SafetyKernel + OutputPolicyServicelocalhost:50051SAFETY_KERNEL_TLS_CERT, SAFETY_KERNEL_TLS_KEYSAFETY_KERNEL_TLS_CA, SAFETY_KERNEL_TLS_REQUIRED, SAFETY_KERNEL_INSECURE
ContextEngine:50070CONTEXT_ENGINE_TLS_CERT, CONTEXT_ENGINE_TLS_KEYCONTEXT_ENGINE_TLS_CA, CONTEXT_ENGINE_TLS_REQUIRED, CONTEXT_ENGINE_INSECURE

Production behavior from code:

  • API gateway gRPC: TLS is required in production.
  • Safety kernel: TLS is required in production.
  • Context engine: TLS is required in production.

Example env config (YAML)

services:
cordum-api-gateway:
environment:
GATEWAY_GRPC_ADDR: ":8080"
GRPC_TLS_CERT: "/certs/gateway.crt"
GRPC_TLS_KEY: "/certs/gateway.key"

cordum-safety-kernel:
environment:
SAFETY_KERNEL_ADDR: "0.0.0.0:50051"
SAFETY_KERNEL_TLS_CERT: "/certs/safety.crt"
SAFETY_KERNEL_TLS_KEY: "/certs/safety.key"

cordum-scheduler:
environment:
SAFETY_KERNEL_ADDR: "cordum-safety-kernel:50051"
SAFETY_KERNEL_TLS_CA: "/certs/ca.crt"
SAFETY_KERNEL_TLS_REQUIRED: "true"
SAFETY_KERNEL_INSECURE: "false"

cordum-context-engine:
environment:
CONTEXT_ENGINE_ADDR: ":50070"
CONTEXT_ENGINE_TLS_CERT: "/certs/context.crt"
CONTEXT_ENGINE_TLS_KEY: "/certs/context.key"

CordumApi (cordum.v1)

RPC signatures:

rpc SubmitJob(SubmitJobRequest) returns (SubmitJobResponse);
rpc GetJobStatus(GetJobStatusRequest) returns (GetJobStatusResponse);

SubmitJobRequest fields

FieldTypeNotes
promptstringRequired job prompt payload.
topicstringJob topic, for example job.default.
adapter_idstringAdapter identifier.
prioritystringPriority string (interactive, batch, critical).
org_idstringTenant/org identifier for isolation.
team_idstringTeam scope.
project_idstringProject scope.
principal_idstringPrincipal identity.
idempotency_keystringClient idempotency key.
actor_idstringActor id metadata.
actor_typestringActor type (human, service).
pack_idstringPack id metadata.
capabilitystringCapability metadata.
risk_tagsrepeated stringRisk tags metadata.
requiresrepeated stringRequired capabilities/dependencies.
labelsmap<string,string>Arbitrary labels.
memory_idstringContext memory id.

SubmitJobResponse fields

FieldTypeNotes
job_idstringCreated or deduplicated job id.
trace_idstringTrace id for job lineage.

GetJobStatus request/response

MessageFieldTypeNotes
GetJobStatusRequestjob_idstringJob id lookup key.
GetJobStatusResponsejob_idstringEchoed job id.
GetJobStatusResponsestatusstringJob state string.
GetJobStatusResponseresult_ptrstringResult pointer (redis://...) when present.

Error behavior

Common status codes from core/controlplane/gateway/gateway_grpc.go:

  • InvalidArgument: invalid request fields
  • PermissionDenied: tenant access violations
  • AlreadyExists: idempotency key conflict
  • ResourceExhausted: backpressure/rate limits
  • Unavailable: backing store or bus unavailable
  • Internal: internal idempotency/memory policy failures

grpcurl example

grpcurl -plaintext \
-H "x-api-key: ${CORDUM_API_KEY}" \
-d '{"prompt":"hello","topic":"job.default","org_id":"default"}' \
localhost:8080 cordum.v1.CordumApi/SubmitJob

ContextEngine (cordum.v1)

RPC signatures:

rpc BuildWindow(BuildWindowRequest) returns (BuildWindowResponse);
rpc UpdateMemory(UpdateMemoryRequest) returns (UpdateMemoryResponse);

ContextMode enum

  • CONTEXT_MODE_UNSPECIFIED = 0
  • CONTEXT_MODE_RAW = 1
  • CONTEXT_MODE_CHAT = 2
  • CONTEXT_MODE_RAG = 3

BuildWindowRequest fields

FieldTypeNotes
memory_idstringMemory partition key.
modeContextModeRAW/CHAT/RAG behavior.
modelstringTarget model name (advisory).
logical_payloadbytesInput payload blob for context extraction.
max_input_tokensint32Input budget hint.
max_output_tokensint32Output budget hint.

BuildWindowResponse fields

FieldTypeNotes
messagesrepeated ModelMessageModel-ready prompt messages.
input_tokensint32Estimated input token usage.
output_tokensint32Suggested output token budget.

ModelMessage:

FieldType
rolestring
contentstring

UpdateMemoryRequest/Response

FieldTypeNotes
memory_idstringMemory partition key.
logical_payloadbytesInput payload.
model_responsebytesModel output payload.
modeContextModeMemory behavior mode.

UpdateMemoryResponse is empty.

grpcurl example

grpcurl -plaintext \
-d '{"memory_id":"m-123","mode":"CONTEXT_MODE_CHAT","logical_payload":"eyJwcm9tcHQiOiJoZWxsbyJ9"}' \
localhost:50070 cordum.v1.ContextEngine/BuildWindow

OutputPolicyService (cordum.v1)

RPC signature:

rpc CheckOutput(OutputCheckRequest) returns (OutputCheckResponse);

This service is hosted by the Safety Kernel process (pb.RegisterOutputPolicyServiceServer in core/controlplane/safetykernel/kernel.go).

OutputCheckRequest fields

FieldType
job_idstring
topicstring
tenantstring
labelsmap<string,string>
result_ptrstring
artifact_ptrsrepeated string
error_messagestring
error_codestring
worker_idstring
execution_msint64
output_size_bytesint64
content_hashstring
workflow_idstring
step_idstring
output_contentbytes
capabilitiesrepeated string
risk_tagsrepeated string
principal_idstring
pack_idstring
content_typestring
original_labelsmap<string,string>

OutputCheckResponse fields

FieldTypeNotes
decisionOutputDecisionALLOW, QUARANTINE, REDACT.
reasonstringRule reason or scanner reason.
rule_idstringMatched output rule id.
policy_snapshotstringActive policy snapshot id/hash.
findingsrepeated OutputFindingScanner findings.
redacted_ptrstringPointer to sanitized output when available.

OutputDecision enum

  • OUTPUT_DECISION_ALLOW = 0
  • OUTPUT_DECISION_QUARANTINE = 1
  • OUTPUT_DECISION_REDACT = 2

OutputFinding fields

FieldType
typestring
severitystring
detailstring
offsetint64
lengthint64
scannerstring
confidencefloat
matched_patternstring

grpcurl example

grpcurl -plaintext \
-d '{"job_id":"job-1","topic":"job.default","tenant":"default","output_content":"c2VjcmV0Cg=="}' \
localhost:50051 cordum.v1.OutputPolicyService/CheckOutput

SafetyKernel (cordum.agent.v1)

SafetyKernel is re-exported in this repository via core/protocol/pb/v1/pb.go.
Underlying generated source is from CAP module github.com/cordum-io/cap/v2/cordum/agent/v1 (safety.proto).

RPC signatures:

rpc Check(PolicyCheckRequest) returns (PolicyCheckResponse);
rpc Evaluate(PolicyCheckRequest) returns (PolicyCheckResponse);
rpc Explain(PolicyCheckRequest) returns (PolicyCheckResponse);
rpc Simulate(PolicyCheckRequest) returns (PolicyCheckResponse);
rpc ListSnapshots(ListSnapshotsRequest) returns (ListSnapshotsResponse);

PolicyCheckRequest fields

FieldTypeNotes
job_idstringJob id.
topicstringJob topic.
tenantstringTenant id.
priorityJobPriorityScheduling priority.
estimated_costdoubleOptional cost hint.
budgetBudgetOptional execution budget.
principal_idstringPrincipal id.
labelsmap<string,string>Policy label context.
memory_idstringContext memory key.
effective_configbytesMarshaled effective config JSON.
metaJobMetadataStructured actor/capability metadata.

PolicyCheckResponse fields

FieldTypeNotes
decisionDecisionTypePolicy decision enum.
reasonstringDecision reason.
redacted_context_ptrstringOptional sanitized context pointer.
policy_snapshotstringPolicy snapshot id/hash.
rule_idstringMatched rule id.
constraintsPolicyConstraintsOptional execution constraints.
approval_requiredboolHuman approval required.
approval_refstringApproval correlation ref.
remediationsrepeated PolicyRemediationSuggested alternative actions.

DecisionType enum

  • DECISION_TYPE_UNSPECIFIED
  • DECISION_TYPE_ALLOW
  • DECISION_TYPE_DENY
  • DECISION_TYPE_REQUIRE_HUMAN
  • DECISION_TYPE_THROTTLE
  • DECISION_TYPE_ALLOW_WITH_CONSTRAINTS

grpcurl example

grpcurl -plaintext \
-d '{"job_id":"job-1","topic":"job.default","tenant":"default"}' \
localhost:50051 cordum.agent.v1.SafetyKernel/Check

Health Service (grpc.health.v1)

Registered in:

  • core/controlplane/safetykernel/kernel.go
  • cmd/cordum-context-engine/main.go

RPC signatures:

rpc Check(HealthCheckRequest) returns (HealthCheckResponse);
rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse);

Health RPCs are treated as public in gateway gRPC rate limiting logic (/grpc.health.v1.Health/Check, /grpc.health.v1.Health/Watch).

Example:

grpcurl -plaintext localhost:50051 grpc.health.v1.Health/Check

Scheduler Client Timeouts and Circuit Breakers

Safety client (core/controlplane/scheduler/safety_client.go)

  • Request timeout: 2s
  • Open duration: 30s
  • Failures to open: 3
  • Half-open max probes: 3
  • Half-open successes to close: 2

State machine:

CLOSED --(3 failures)--> OPEN --(30s elapsed)--> HALF_OPEN
HALF_OPEN --(2 successes)--> CLOSED
HALF_OPEN --(failure)------> OPEN

When Safety RPC fails, scheduler records SafetyUnavailable (decision fallback) instead of hard-failing scheduling.

Output safety client (core/controlplane/scheduler/output_safety_client.go)

  • Metadata check timeout: 100ms
  • Content check timeout: 30s
  • Content cap: 2 MiB
  • Circuit breaker constants mirror Safety client (3 failures, 30s open, half-open probes 3, close after 2 successes)

If output checks fail, scheduler currently treats that as skipped/fail-open for output policy evaluation path.

Regenerating Protobuf Code

Cordum local proto generation:

make proto

Current Makefile proto target generates code for local files:

  • api.proto
  • context.proto
  • output_policy.proto

SafetyKernel proto is sourced from CAP module and re-exported; updating those definitions requires updating the module version and generated CAP artifacts.

Cross-References