장시간 무응답 attempt를 안전하게 fence하고 provider health와 분리 관측해야 중복 출력 없이 기존 recovery budget으로 재실행할 수 있다.
18 KiB
Provider Execution Runtime Contract
Contract metadata
- id:
iop.execution-runtime - boundary: inner
- status: active
- source evidence:
packages/go/execution/types.gopackages/go/execution/liveness.gopackages/go/execution/registry.gopackages/go/execution/emitter.gopackages/go/execution/failure.goapps/node/internal/node/runtime_bridge.goapps/node/internal/node/health_probe.goapps/node/internal/node/command_handler.goapps/node/internal/node/liveness_watchdog.goapps/node/internal/transport/session.goapps/edge/internal/service/model_queue_release.goapps/edge/internal/service/node_command.goapps/edge/internal/openai/stream_gate_runtime.goapps/edge/internal/openai/stream_gate_stall_recovery_test.go
Scope
The execution package defines host-neutral provider primitives. It owns provider registration, lifecycle, execution events, typed failures, cancellation, token usage, and the three provider commands capabilities, transport_status, and ollama_api.
session_id is an opaque correlation value. It does not select, create, resume, or terminate a process. Repeated requests with the same value are independent executions. Cancellation targets a non-empty run_id only.
Requirements
- Providers implement the narrow
Providerinterface and may expose optional lifecycle, command, or tunnel capabilities. - Event emitters preserve order and publish exactly one terminal event.
- Registry lookup uses provider identity and returns typed failures for missing or unavailable providers.
- Callers must reject commands outside the closed provider-command allowlist before provider lookup.
- Token usage remains observation data attached to execution or tunnel results.
DefaultResponseStallTimeoutMS = 300000is the documented default.ResolveStallTimeoutMS(ms)validates then maps zero to the default; safe positive values pass through, while negative or overflow values return an error.ClassifyRuntimeEventreturnsstartforEventTypeStart,progressfor non-emptydelta/messageor non-terminal usage,terminalforcomplete/error/cancelled(before usage check), andnonefor empty/unknown events.ClassifyProviderTunnelFramereturnsprogressforresponse_start(with or without headers) and non-emptybody,terminalforend/error(before payload check),progressforusage, andnonefor empty/unknown frames.ValidateStallTimeoutMS(ms)rejects negative values and values exceedingmaxSafeStallTimeoutMS; zero is allowed (use default).NodeProviderConf.EffectiveResponseStallTimeoutMS()returns the effective timeout for a provider candidate.RunRequest.ResponseStallTimeoutMSandProviderTunnelRequest.ResponseStallTimeoutMScarry the selected provider's effective timeout; zero on the wire means the Node applies the documented default.- The Node wire boundary normalizes zero to
300000and rejects negative or overflow values before router/provider invocation. response_stalledis a stable typed failure. Node transport mappers (runEventToProtoandtunnelFrameToProto) populate the optional wireExecutionFailuremessage only forFailureCodeResponseStalled, attaching a defensive clone of allowlisted metadata keys (failure_code,provider_health,liveness_classification,idle_duration_ms,run_id,attempt_id,attempt_fence,adapter,target, andhealth_observation_seq); nil and non-stalled failures leave wireExecutionFailureabsent while preserving legacy error string fields (RunEvent.Error/ProviderTunnelFrame.Error). Caller metadata cannot override these values, and no raw payload, credential, orrecovery_eligiblesignal is admitted.- The Node watchdog starts from attempt admission, resets only on the documented progress dispositions, stops on provider terminal, and emits one typed stall terminal. It does not retry providers or infer recovery eligibility.
Retryable=truemeans only that the local provider ownership fence was confirmed within the bounded close grace. - After the watchdog claims a stall it joins two independent bounded outcomes without extending either serially — the fixed close-grace fence and the exact-target health probe — then assembles exactly one allowlisted terminal. The joined
liveness_classification/provider_healthpair is exactlyrequest_stalled/available,provider_unhealthy/unavailable, orhealth_unknown/unknown(fail-closed default). Provider availability observed here is evidence only: it never resets progress, changes the fence, revives output, or authorizes retry, and late provider output stays fenced. health_observation_seqis a connection-scoped monotonic sequence sourced from the transport Session. A new connection starts at zero, so the first finalized observation is one; normalized and tunnel observations on the same connection share the source and receive unique, increasing values under concurrency. Internal or unbound execution paths omit the key entirely and never encode a process-global generation.ProviderPoolDispatchRequestcarries two request-local recovery-hint fields:AvoidProviderID(non-empty to prefer a runtime-eligible alternate over the avoided provider) andAllowAvoidedProviderFallback(explicit permission to retain the avoided provider when no alternate exists and it remains runtime eligible). The queue applies identical avoidance filtering to both initial and queued re-resolution. Zero values preserve current selection behavior. This is selection policy only: it does not create a retry loop, reserve a slot, change provider priority, persist the hints, or count retries. The fallback permission is always derived from exact probe-backedavailableevidence by the caller (never from current overlay state).- A Node
capabilitiescommand performs the same bounded exact-targetProbeHealthoperation. Its stable result evidence is the requested adapter instance key (adapter_key), exacttarget, fail-closed normalizedprovider_status, and the nexthealth_observation_seqfrom that same transport Session. Probe errors, unsupported probing, and adapter/instance/target mismatches reportunknown; raw capability status is not recovery evidence. - Edge accepts a typed stall observation for provider-wide projection only after authoritative reception
(node_id, connection_generation)matches the tracked immutable dispatch lease(node_id, connection_generation, provider_id, adapter, target), the local attempt fence is confirmed, and the observation sequence is strictly newer. A current terminal still releases its lease exactly once when health evidence is absent, malformed, mismatched, or stale; a reception-owner mismatch changes neither overlay nor lease state. - Every validated current bound stall is annotated with Edge-owned
provider_id, the validatedprovider_health, andrecovery_handoff=confirmed, including an out-of-order terminal whose health projection is sequence-stale. Only a freshunavailableobservation lowers the generation-scoped runtime overlay. The token proves reception, lease binding, and local-fence handoff only; it is neverrecovery_eligibleand never authorizes retry. - Every supported OpenAI Chat/Responses normalized or tunnel request enters one request-local StreamGate runtime, which is the sole liveness owner even when configured semantic filtering is disabled. That runtime may consume the confirmed handoff as a raw-free
response_stalledprovider error while its endpoint adapters preserve the disabled-semantic native status, headers, JSON/SSE/tunnel order, validation, usage, cancellation, and terminal behavior. It retains only the stable failure code, confirmed-handoff token, andavailable|unavailable|unknownhealth classification; Node/provider messages and arbitrary metadata are not copied. Exact replay additionally requires the existing uncommitted, uncancelled, side-effect-safe, snapshot-backed, shared-budget gate. A confirmed old terminal closes its Edge transport without anotherCancelRun; pool re-admission consumes the provider once asAvoidProviderID, with same-provider fallback only for exactavailableevidence. - The runtime overlay is keyed by
(node_id, connection_generation, provider_id)and remains separate from configuration health. It excludes the provider from effective admission and projects it unavailable in status snapshots. Recovery requires a later CAPABILITIES result for the same current adapter/target mapping with strictly higher sequence and exact normalizedavailable; malformed, ambiguous, stale-generation, unknown, and unavailable results are no-ops.
Health probe contract
The execution package owns the stable, fail-closed probe outcome vocabulary consumed by Node terminal assembly. It is the typed three-way boundary between an inconclusive probe and a definitive provider-health classification; nothing else maps provider probe results to health.
ProviderHealthis the stable normalized value:request_stalled,provider_unhealthy, orhealth_unknown(fail-closed default).LivenessClassificationis the stable observable category a probe outcome reduces through:available,unavailable,timeout,error,unsupported,unknown, andidentity_mismatch.ProbeOutcomeis the typed, target-aware input;ClassifyProbeOutcomereduces it to a classification andNormalizeProbeOutcomemaps it to health. The mapping is exactly: available →request_stalled; a validated matching unavailable result →provider_unhealthy; every error, timeout, unsupported adapter, unknown status, empty/mismatched adapter or target, and instance mismatch →health_unknown.- A returned error takes precedence over any reported status, so endpoint construction, request/network, non-success HTTP, and decode failures can never be confused with a positive exact-target-absent result.
- The Node probe coordinator (
ProbeHealth) roots its own five-second bounded context from the background, re-checks that deadline/cancellation after the probe returns, validates exact adapter and target identity (including a pinned instance key when set), and feeds only the typed normalizer. It never copies arbitrary provider metadata. ResolveProbeFuncreturnsnilfor an adapter that does not implementProviderProber; anilhook makesProbeHealthfail closed tohealth_unknownwithout invoking any endpoint.
Probe completion is evidence only. The probe itself must never reset original request progress, change the attempt fence, authorize retry, sequence the watchdog terminal, directly mutate the Edge overlay, or infer recovery. Node owns the stall-terminal join and the connection-scoped health_observation_seq. Edge owns reception-generation and immutable-lease validation, the separate runtime overlay, candidate exclusion, snapshot projection, and exact later CAPABILITIES recovery. The ingress recovery host remains the sole owner of commit, cancellation, side-effect, budget, candidate, and replay eligibility decisions.
Prohibited ownership
The package must not own interactive shells, persistent processes, terminal emulation, working-directory mutation, resumable conversations, local quota probing, or arbitrary host command execution. It must not import application-internal packages or generated transport types.
Operational evidence projections
The Node and Edge owners expose bounded operational projections derived exclusively from the established stall terminal, health-overlay, and recovery decisions documented above. These projections never widen the Node↔Edge wire protocol: they carry no new frame, field, ordering rule, or retry semantic, and they are emitted only after the authoritative decision is finalized.
Node stall observations (owner: Node process-global)
iop_node_response_stalls_total(counter): labelsexecution_path,provider_health,liveness_classification,attempt_fence. Every claimed stall increments exactly one series.iop_node_response_stall_duration_seconds(histogram): same four labels. Samples the idle duration in seconds.- Dedicated structured log
node_response_stall_observation: fieldsexecution_path,provider_health,liveness_classification,attempt_fence,idle_duration_ms. - Label values are closed and low-cardinality:
execution_path∈ {normalized,provider_tunnel,unknown};provider_health∈ {available,unavailable,unknown};liveness_classification∈ {request_stalled,provider_unhealthy,health_unknown};attempt_fence∈ {confirmed,unconfirmed,unknown}. - Prohibited from metric labels and general logs: raw prompt/response, credential, caller metadata,
recovery_eligible. High-cardinality inputs normalize tounknown. - Observer failure is fire-and-forget and never suppresses the terminal.
- Source:
apps/node/internal/node/liveness_observability.go; test:apps/node/internal/node/liveness_observability_test.go::TestNodeLivenessObservability.
Edge provider-health overlay observations (owner: Edge service queue process-global)
iop_edge_provider_health_evidence_total(counter): labelssource,evidence_health,decision. Records authoritative overlay decisions.iop_edge_provider_health_transitions_total(counter): labelsfrom_health,to_health. Records overlay state transitions.- Dedicated structured log
edge_provider_health_observation: fieldssource,evidence_health,decision,from_health,to_health,state_changed. - Label values are closed:
source∈ {stall,probe,unknown};evidence_health∈ {available,unavailable,unknown};decision∈ {applied,rejected_stale,rejected_binding,rejected_ambiguous,inconclusive};from_health/to_health∈ {available,unavailable,unknown}. - Prohibited from metric labels and general logs: provider, node, run, session, adapter, target, payload, or credential values.
- Edge delivery is synchronous after decision/release/pump and after the queue lock is released; observer latency can delay handler return but cannot retain the lock or change the finalized transition.
- Source:
apps/edge/internal/service/provider_health_observability.go; test:apps/edge/internal/service/provider_health_observability_test.go::TestProviderHealthObservabilityandTestProviderHealthObservabilityDoesNotExposeSentinels.
Edge OpenAI recovery observations (owner: Edge OpenAI server request-local wrapper with process-global collectors)
iop_edge_liveness_recovery_eligibility_total(counter): labelsexecution_path,provider_health,commit_state,eligibility. Records eligibility decisions per liveness cycle.iop_edge_liveness_recovery_results_total(counter): labelsexecution_path,provider_health,recovery_result. Records at most one final result per liveness cycle.- Dedicated structured log
edge_liveness_recovery_observation: fieldsphase,execution_path,provider_health,commit_state,eligibility,recovery_result. - Label values are closed:
execution_path∈ {normalized,provider_tunnel,unknown};provider_health∈ {available,unavailable,unknown};commit_state∈ {transport_uncommitted,stream_open,terminal_committed,unknown};eligibility∈ {eligible,no_owner,post_commit,unconfirmed_fence,caller_cancelled,tool_side_effect,budget_exhausted,no_candidate,same_provider_forbidden,other};recovery_result∈ {redispatched,plan_rejected,abort_failed,rebuild_failed,dispatch_failed,not_selected,terminal,other}. - Prohibited from metric labels and general logs: correlation, attempt, run, session, model, provider, node, plan, shared_attempt_id, credential, or slot identifiers.
- Each request owns one fresh wrapper; the collectors are process-global and registered once at package init.
phaseis the bounded request-local cycle phase:idlebefore any eligible observation,eligible_pendingafter aneligibleeligibility decision until the cycle resolves (redispatched, plan_rejected, abort_failed, rebuild_failed, dispatch_failed, not_selected, or terminal). Only these two values appear in the lifecycle; every other row carries one of them.- Empty
eligibilityandrecovery_resultrows belong to the lifecycle transitions that do not record a metric row: private filter rows that are notfilter_evaluated, a second eligibility whileeligible_pending, provider errors the liveness filter did not treat as a stall, and non-ExactReplay recovery observations that fall outside the private cycle. They are documented here so the safe-log field vocabulary is complete and not read as implying a missing classification. - Current immutable observations yield
provider_health=unknownbecause the predecessor's privatefilter_evaluatedobservation does not carry provider health — health lives only in the request-local recovery state bridge, never in the immutable timeline. The closed classifier reservesavailableandunavailablefor future health-bearing observations without claiming either is currently emitted. - Source:
apps/edge/internal/openai/liveness_recovery_observability.go; test:apps/edge/internal/openai/liveness_recovery_observability_test.go::TestOpenAILivenessObservationSinkandTestOpenAILivenessRecoveryObservability.
Fresh health recovery in provider snapshots
A recovered provider appears in the existing Edge provider snapshot overlay as status=available, health=available, with effective capacity restored to configured values. The snapshot reflects the same (node_id, connection_generation, provider_id) key used by the runtime overlay. A newer connection generation does not inherit the old overlay.
Leakage boundary
Operational projections exclude raw payloads, credentials, caller-controlled identities, and any unbounded identifier from metric labels and general structured logs. The exclusion applies to metric labels and general logs only; valid typed terminal metadata (e.g. run_id, adapter, target on the allowlisted stall metadata map) remains on the wire as already required by the typed terminal contract.
Verification
go test -count=1 ./packages/go/executiongo test -race -count=1 ./packages/go/executiongo vet ./packages/go/execution