Hosted gateway integration
The hosted gateway integration gives OpenSRE an account-scoped way to inspect and use an organization's managed gateway. It protects the request boundary between agent workflows and the hosted service while providing health, lifecycle, remote prompt, and prompt cancellation actions.
System role
The hosted gateway is a managed Fargate service that runs CI/CD repair loops and related remote work away from the local machine. The integration connects the signed-in OpenSRE account to the app's gateway control plane, which selects the gateway for that account's organization.
The integration provides four related capabilities:
- Health checks that tell an agent whether the organization has a gateway and whether it can serve work.
- Lifecycle controls that let a user start or stop an existing gateway for the organization.
- Remote prompts that let an agent send a complete request to the running gateway and read its result.
- Prompt cancellation that lets a user stop queued or running remote work by its prompt ID.
Hosted gateway client
The primary client is integrations/…/client.py. It is a narrow request boundary between local OpenSRE workflows and the hosted gateway control plane. Callers do not provide an organization or gateway identifier.
Account-scoped authentication
The client uses the account record and token created by OpenSRE sign-in. The token goes to the signed-in app URL. The app maps that identity to the user's organization and then to its gateway. This keeps service selection outside the caller and prevents a workflow from choosing another organization's service.
The token is accepted only for an HTTPS app origin. Plain HTTP is allowed for loopback hosts used by local development. The client does not expose the token in its stable error values.
References: integrations/…/client.py• L1-7 integrations/…/client.py• L202-230 integrations/…/client.py• L589-592
Request boundary
The client sends health, lifecycle, prompt, and prompt-cancellation requests to the app. Health uses a read-only request. Start and stop change the gateway service. Prompt requests submit, read, answer, or cancel work on that service. Each request carries bearer authentication and uses the app's fixed route set.
The client does not follow redirects. It accepts only structured response data and maps transport, authentication, route, permission, state, capacity, and response-shape problems to stable error codes. This gives callers a small contract without passing through response bodies or sensitive request data.
Prompt submission and answer requests can carry a request ID. The gateway uses that ID to accept one logical request at most once. A connection failure is retried because no request byte reached the app. A later transient failure is retried only when the same request ID can prevent duplicate work.
References: integrations/…/client.py• L202-221 integrations/…/client.py• L337-413
Gateway and prompt records
The client returns two kinds of records. GatewayHealth separates gateway provisioning from service health. PromptRecord describes one remote request and whether it is queued, running, done, waiting for input, or failed.
Health identifies the gateway and reports its control state. It also includes the size profile, the last control-plane error, and the update time. A prompt record includes its gateway-issued ID, state, answer, question, error detail, progress lines, failed integrations, and structured choice data when the gateway needs input. The client also records the parent prompt for a follow-up answer.
Prompt records also carry the conversation that handled the request. They can link a question to the follow-up that answered it and show when cancellation was requested but the running turn has not stopped yet. These fields let a caller resume or inspect work without sending the same work again.
The public hosted-gateway interface re-exports the prompt choice, question, and progress types with the client and its stable error codes. Agent tools can therefore use the same record contract when they pause, resume, cancel, or report remote work.
References: integrations/…/client.py• L125-199 integrations/…/client.py• L488-586 integrations/…/__init__.py• L3-57
Gateway tools
The hosted gateway tools expose the client through agent actions. They use the signed-in account to choose the service, and their shared result format keeps app reachability separate from gateway health or prompt completion. The tool set covers health, lifecycle, remote prompts, and prompt cancellation.
The following flow shows how an agent request becomes an account-scoped gateway result.
flowchart LR
A[Agent workflow] --> B[Hosted gateway tool]
B --> C[Signed-in account]
C --> D[OpenSRE app]
D --> E[Organization gateway]
E --> D
D --> B
B --> F[State and response text]
Health checks
The check_hosted_gateway tool is the read-only agent entry point for service availability. It takes no organization or gateway input. The signed-in account determines which service the app checks.
The tool reports whether the app answered and, separately, whether the gateway is provisioned and healthy. A successful tool call can therefore say that no gateway exists, that the gateway is starting, or that it has failed. Agent workflows can use this result before they delegate work.
| Condition | Meaning for an agent workflow |
|---|---|
| No gateway | An organization admin must provision one before remote work can run. |
| Running and healthy | The gateway is available for the next workflow decision. |
| Provisioning | The service is starting; check again later. |
| Failed or stopped | Do not delegate remote work until the service is restored. |
The health tool also records a positive health signal when the gateway is healthy. For other states it returns the gateway state and directs the user to the gateway settings page. If the request fails, it returns a failure result instead of treating the gateway as absent.
References: integrations/…/gateway_health.py• L27-67 integrations/…/gateway_health.py• L70-80 integrations/…/results.py• L119-148
Gateway lifecycle controls
The start_hosted_gateway and stop_hosted_gateway tools manage an existing organization's service. They are action tools because they change a service used by the organization.
Starting resumes the gateway with its existing configuration and credentials. The start action is still requested when a best-effort health read already shows a running gateway; in that case the result reports that there is nothing to start. A running gateway can incur hosted service cost until a user stops it. Stopping keeps that configuration and stops the loops and chat integrations served by the gateway until a user starts it again. Neither action creates a gateway or deletes its data.
References: integrations/…/gateway_lifecycle.py• L29-89 integrations/…/gateway_lifecycle.py• L100-134 integrations/…/gateway_lifecycle.py• L137-162
Remote prompt requests
The ask_hosted_gateway tool sends one complete prompt to the running gateway or reads a prior prompt by its ID. The request must include the facts the gateway needs because the remote run cannot ask the user a follow-up question in the same turn. A prompt can continue the user's gateway conversation or start a separate conversation for unrelated work.
The submission also carries the active GitHub connection context when one is available. This lets the hosted run use the connection selected by the local workflow without making the caller choose a gateway or organization.
Each logical submission has a request ID. If contact fails before the app confirms the request, the same ID makes a retry safe because the gateway accepts the prompt at most once. A later read uses the prompt ID after the gateway has accepted the work, so a lost response does not cause a blind resend.
The tool waits for a settled result within a time budget. A settled result is done, needs input, or failed. While the gateway works, new progress lines can be relayed to the shell. If the wait budget ends first, the tool returns the prompt ID so a later call can read it instead of treating the remote run as failed. If the gateway stops answering after it accepted the prompt, the tool also returns that prompt ID and tells the caller to read it later. A prompt that stays busy too long to accept the request returns a clear failure rather than waiting without a limit. A full prompt queue refuses the request without queuing work and gives the caller a later retry point.
When the gateway needs a decision, it returns structured choice data. The shell parks that choice in its own user menu, so the user's selection becomes the answer rather than a model-generated argument. A later call with the same prompt ID sends that selection to the gateway. If no interactive shell is available, the result carries the question and prompt ID for the user to continue there.
The tool also reports integrations that failed during the remote request. These credentials belong to the organization gateway rather than the local machine. The response links to the app's integration settings so an organization admin can update the credential. The gateway picks up the new credential within about a minute. The next action depends on whether the prompt is waiting for input, failed, or completed. This keeps a partial remote result distinct from a request that never ran.
References: integrations/…/gateway_prompt.py• L123-168 integrations/…/gateway_prompt.py• L171-258 integrations/…/gateway_prompt.py• L260-309 integrations/…/gateway_prompt.py• L364-507 integrations/…/client.py• L260-309
Prompt cancellation
The cancel_hosted_gateway_prompt tool stops one of the signed-in user's prompts by its prompt ID. A queued prompt never runs. A running prompt stops at its next check, so the cancellation result can show that a stop was requested while the prompt is still running.
Cancellation applies only to work that the current user's gateway still owns. A prompt that already settled has nothing to cancel, and work held by a gateway task being replaced must be read or cancelled again after the replacement completes. This keeps cancellation separate from stopping the whole gateway.
References: integrations/…/gateway_prompt_cancel.py• L17-72 integrations/…/client.py• L311-326 integrations/…/client.py• L447-448
Shared result contract
The tools return machine-readable state with short user-facing response text. For health and lifecycle actions, success means that the app answered. It does not mean that the gateway is healthy. For prompt actions, success means that the prompt reached a settled state; a queued or running prompt remains resumable through its prompt ID. For cancellation, success means that the gateway accepted the cancel request, even if a running prompt still needs one more check to stop.
Tool availability is gated by the hosted_gateway capability. When a call cannot produce a trusted result, the tools return a stable error_kind and safe guidance. They do not expose the account token or raw app response.
References: integrations/…/results.py• L31-36 integrations/…/results.py• L119-148 integrations/…/results.py• L164-225 integrations/…/gateway_prompt_cancel.py• L51-72
Failure handling
The client reports failures as stable codes so the tools can give clear guidance without exposing raw app responses. Missing sign-in, expired access, an unsupported app route, and an insecure app URL are setup or compatibility conditions. A full prompt queue refuses new work without accepting it. Network failures and malformed successful responses mean that the check did not produce a trusted result.
The tools keep these cases distinct from a gateway that answered with an unhealthy state. Expected account, service-state, capacity, and prompt-state errors receive direct user guidance. Unexpected errors use the run-error path and still return a stable error_kind to the caller.
Failure responses
A failed tool result means that the requested operation did not produce a trusted service result. It sets healthy and provisioned to false, while signed_in shows whether a local sign-in was available. This prevents an unavailable check from being mistaken for proof that the gateway is absent.
Lifecycle and prompt refusals add meaning to the same contract. A missing gateway cannot be started. A stopped gateway cannot take a prompt. An unknown prompt ID cannot be read as a valid remote result. An answer that does not match the gateway's choices reopens the question instead of silently completing the prompt. An answer sent after the question is no longer waiting is rejected rather than applied to a different prompt state. A settled or gateway-owned-by-replacement prompt cannot be cancelled as if it were still running.
References: integrations/…/results.py• L164-225 integrations/…/client.py• L415-485 integrations/…/gateway_prompt.py• L325-354 integrations/…/gateway_prompt_cancel.py• L58-72
Related pages
- Integration platform describes the wider integration model.
- Integration catalog explains how integrations are exposed to the system.
- Integration setup and credentials covers account and credential setup.
- Integration verification covers health checks across integrations.
- Gateway runtime explains the hosted gateway's remote runtime behavior.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the app routes, authentication boundary, response fields, and lifecycle permissions aligned between the client and the hosted gateway service.
- Preserve the rule that organization and gateway selection come from the signed-in account rather than tool input.
- Keep
successdistinct fromhealthyand from prompt settlement so an answered app cannot create an ambiguous agent result. - Keep lifecycle, prompt, capacity, and cancellation state mappings aligned with the app's refusal responses.
- Keep prompt IDs opaque and valid for result lookup without allowing caller input to become an unsafe route segment.
- Keep request IDs, conversation IDs, follow-up links, and connection context aligned so retries and resumed prompts do not run work twice or use the wrong session.
- Keep prompt choice data, shell handoff state, and follow-up answer handling aligned so the user's selection—not the model's text—answers a parked question.
- Keep transient contact loss resumable through the returned prompt ID, and do not turn an accepted prompt into a blind resend.
- Keep cancellation state and ownership errors aligned between the client, tool result, and later prompt reads.
- Keep capability gating and stable error guidance aligned when hosted-gateway tools are added or changed.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No local account record or token | The client cannot identify the organization's gateway. | Return not_signed_in and direct the user to OpenSRE sign-in. |
| Non-HTTPS app URL outside loopback | The account token could be sent over an unsafe connection. | Reject the client before making a request. |
| App returns an unauthorized response | The sign-in is expired or revoked. | Return unauthorized and request sign-in again. |
| App route is missing | The app is older than the client or does not support the operation. | Return not_supported rather than treating the gateway as absent. |
| Gateway is absent or stopped when a prompt is sent | The remote prompt cannot run. | Return not_provisioned or not_running and keep the prompt unsent. |
| Prompt exceeds the gateway limit | The app rejects the remote request. | Return prompt_too_large and ask for a shorter prompt. |
| Prompt queue is full | No new prompt is queued, so an immediate duplicate retry adds no value. | Return too_many_prompts with Retry-After when available and retry later. |
| User answer does not match the gateway's choices | The gateway rejects the follow-up and leaves the original question open. | Return invalid_answer, reopen the question, and ask for a menu selection. |
| User answers after the prompt is no longer waiting | The gateway cannot apply the answer to the prior state. | Return not_waiting or already_answered and read the current prompt state. |
| User cancels a settled prompt or one owned by a replacement task | The gateway cannot stop that prompt from the current task. | Return already_settled or not_owned and read the prompt again when the replacement is ready. |
| User cancels a running prompt | The work may continue until its next check. | Return the prompt ID and cancel_requested; read it later to confirm the final state. |
| Accepted prompt loses gateway contact | A resend could run the same work twice, while the prompt may still exist. | Return the in-flight prompt ID and read it later; resend only if the gateway no longer holds it. |
| Network error or malformed response before a trusted result | The tool cannot trust the service state or prompt result. | Return a stable failure code and do not expose the token or raw response. |
Key files
| File | Why to read it |
|---|---|
| integrations/…/client.py | Defines account-scoped authentication, the app request boundary, health and prompt records, idempotent prompt requests, connection context, cancellation, and stable error contracts. |
| integrations/…/__init__.py | Defines the public hosted-gateway types and error names available to other modules. |
| integrations/…/gateway_health.py | Defines the read-only availability check and its state-to-message behavior. |
| integrations/…/gateway_lifecycle.py | Defines start and stop actions for an existing organization gateway. |
| integrations/…/gateway_prompt.py | Defines remote prompt submission, progress reporting, user-menu handoff, conversation continuation, result lookup, bounded waiting, and resumable contact loss. |
| integrations/…/gateway_prompt_cancel.py | Defines user-requested cancellation for queued or running prompts. |
| integrations/…/results.py | Defines capability gating and the shared success, state, and failure result shape. |
| integrations/…/__init__.py | Registers the hosted gateway tool modules, including prompt cancellation. |
| config/…/hosted_gateway.py | Defines shared hosted-gateway routes, the integration settings link, and transport limits. |
| tests/…/test_client.py | Shows the authentication, origin, redirect, response, lifecycle, prompt, cancellation, retry, and network contracts. |
| tests/…/test_gateway_health_tool.py | Shows how the health tool reports gateway states and expected versus unexpected failures. |