Skip to content

Sync Pipeline

The sync pipeline handles non-streaming Requests API calls end to end. It is the simpler of GodeX's two execution paths: send a single request to the upstream provider, reconstruct the response into the OpenAI Responses format, validate any output contracts, persist the session, and return the complete ResponseObject. Understanding the sync pipeline is the foundation for understanding the more complex streaming pipeline.

At a Glance

ConcernComponentKey File
Pipeline orchestratorSyncRequestPipelinesync-request-pipeline.ts:25
Provider exchangeProviderExchangeprovider-exchange.ts:25
Bridge interfaceResponsesBridgebridge.ts:7
Runtime wiringResponsesBridgeRuntimeruntime.ts:19
Session persistencesaveResponseSessionresponse-session-persistence.ts:5

Pipeline Steps

SyncRequestPipeline.request (sync-request-pipeline.ts:31) executes seven steps in sequence:

StepOperationKey Code
1Build provider request and call upstreamexchange.request(ctx)
2Reconstruct response objectreconstructResponseObject(...)
3Validate output contractvalidateResponseOutputContract(...)
4Record trace usagerecordTraceUsage(ctx, response.usage)
5Log completionctx.logger.info(...)
6Log diagnosticslogDiagnostics(ctx, ...)
7Save response sessionsaveResponseSession(...)

Provider Exchange

ProviderExchange (provider-exchange.ts:25) encapsulates the interaction with the upstream provider. For sync requests:

  1. Build request: buildProviderRequest(ctx, false) constructs the provider-specific chat completion request, including tool planning and output contract setup (provider-exchange.ts:73)
  2. Patch and trace request: The provider edge applies patchRequest, then onPatchedRequest records the final patched provider request into trace_requests plus a body-less provider.request.prepared lifecycle event
  3. Call upstream: Awaits ctx.provider.request(providerRequest) -- the actual HTTP call after patching
  4. Trace response: Records the sync provider response body
  5. Return: Provides both the raw response and the built request metadata

The exchange also records tool decision diagnostics (provider-exchange.ts:102) and sets the output contract slot on the context (provider-exchange.ts:98).

Response Reconstruction

After the exchange returns, the pipeline calls reconstructResponseObject (sync-request-pipeline.ts:34) with:

ParameterSource
requestIdctx.requestId
responseIdctx.responseId
createdAtctx.createdAt
completedAtMath.floor(Date.now() / 1000)
providerctx.provider.name
modelctx.resolved.model
providerResponseRaw provider response
accessorctx.provider.spec.response
toolIdentityBuilt tool declarations
outputContractBuilt output contract plan
echoRequest echo fields from responseRequestEchoFields

The echo fields (response-request-echo.ts:4) mirror selected request parameters back onto the response object, including instructions, temperature, tools, tool_choice, and many others.

Output Contract Validation

After reconstruction, validateResponseOutputContract checks that the output satisfies the planned contract. This is especially important when json_schema was degraded to json_object: the requiresValidJson flag triggers a JSON.parse on the output text. See Output Contracts for the full validation logic.

Session Persistence

saveResponseSession (response-session-persistence.ts:5) stores the response session if ctx.request.store !== false. The stored session includes:

SectionFields
Session metadataid, previous_response_id, created_at, completed_at, status
Request snapshotinput, instructions, model, tools, tool_choice, reasoning, text, truncation
Response snapshotid, output, output_text, usage, error, incomplete_details

Session save errors are caught and logged at warn level, never failing the request (sync-request-pipeline.ts:62).

Runtime Wiring

ResponsesBridgeRuntime (runtime.ts:19) creates a shared ProviderExchange instance and wires it to both the SyncRequestPipeline and StreamPipeline. It implements the ResponsesBridge interface:

Logging and Observability

The sync pipeline emits structured log events at key points:

EventLevelContext
provider.request.sendingdebugprovider, model, stream=false
provider.response.receiveddebugprovider, model, upstreamDurationMillis
responses.request.completedinfostatus, model, outputCount, durationMillis, usage, cacheHitRatio
session.save.errorwarnrequest_id, response_id, error

Trace records capture the final patched request body in trace_requests, the body-less provider.request.prepared lifecycle event in trace_events, the sync response body via provider.response.body, and usage metrics via recordTraceUsage.

Cross-References

References