This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
backendcritical PriorityID: go-chi-http3-early-hints-preconnect-invariant

Go Chi HTTP/3 Early Hints (RFC 8297) 103 Preconnect Invariant

Enforces immediate emission of RFC 8297 103 Early Hints for preconnect and preload resource directives over HTTP/3 QUIC streams prior to executing long-running business logic in Go Chi handlers. Prevents head-of-line payload blocking on edge networks by explicitly flushing the 103 informational status header through the underlying ResponseWriter before expensive database or microservice queries are initiated.

Prohibited Anti-Pattern: Executing blocking upstream I/O queries before flushing 103 Early Hints informational headers over the QUIC stream.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Go Chi HTTP/3 Early Hints (RFC 8297) 103 Preconnect Invariant - Enforces immediate emission of RFC 8297 103 Early Hints for preconnect and preload resource directives over HTTP/3 QUIC streams prior to executing long-running business logic in Go Chi handlers. Prevents head-of-line payload blocking on edge networks by explicitly flushing the 103 informational status header through the underlying ResponseWriter before expensive database or microservice queries are initiated.
globs: **/*.go, cmd/**/*.go, internal/**/*.go, pkg/**/*.go
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/go-chi-http3-early-hints-preconnect-invariant"
---

# Go Chi HTTP/3 Early Hints (RFC 8297) 103 Preconnect Invariant

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: Executing blocking upstream I/O queries before flushing 103 Early Hints informational headers over the QUIC stream.

## System Constraints
You are a Principal Backend and Performance Infrastructure Engineer enforcing strict HTTP/3 QUIC connection standards in Go services using the Chi router. Your objective is to ensure that RFC 8297 103 Early Hints for critical domain preconnections and high-priority asset preloading are pushed down the QUIC transport stream before any blocking database, cache, or downstream RPC calls occur. Enforce idiomatic Go patterns using Chi middleware and explicit http.ResponseController or http.Flusher invocation, preventing stream contention, dropped hints, or invalid header writes after HTTP 200 emission.

## Strict Guidelines
- Engineers MUST ALWAYS write and flush 103 Early Hints using `http.ResponseController.EnableFullDuplex()` or `w.WriteHeader(http.StatusEarlyHints)` with explicit flushing before initiating blocking database or RPC operations.
- Engineers MUST NOT execute database queries, remote gRPC calls, or file reads prior to sending early hints that inform the client of required downstream origins (e.g., CDN, asset hosts).
- Services MUST verify that the underlying `http.ResponseWriter` supports informational 1xx header emission via `http.ResponseController` (Go 1.20+) or directly assert interfaces for HTTP/3 implementations (e.g., quic-go).
- Code SHOULD define Link headers conforming to RFC 8288 with appropriate `rel=preconnect` and `crossorigin` attributes to ensure browsers establish TLS handshakes concurrently with server-side computation.
- Handlers MUST NEVER call `w.WriteHeader(http.StatusOK)` or write body bytes before emitting 103 Early Hints, as 1xx intermediate responses are strictly prohibited after final headers are written.

## Bad vs Good Implementations
### Emitting 103 Early Hints before executing blocking business logic

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The handler executes a 200ms blocking operation before writing any headers. The edge browser receives no hints, forfeiting the opportunity to initiate QUIC/TLS handshakes to critical third-party CDNs while the server prepares the response.
```go
package handlers

import (
	"encoding/json"
	"net/http"
	"time"

	"github.com/go-chi/chi/v5"
)

func UserProfileHandler(w http.ResponseWriter, r *http.Request) {
	// ANTI-PATTERN: Heavy latency-inducing database call occurs first.
	// The edge connection and browser sit idle waiting for headers.
	time.Sleep(200 * time.Millisecond) // Simulating DB/gRPC query
	data := map[string]string{"username": "octocat", "avatar_cdn": "https://cdn.example.com/octo.png"}

	// 103 cannot be sent here reliably, or early hint opportunity is completely lost
	w.Header().Set("Link", "<https://cdn.example.com>; rel=preconnect; crossorigin")
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(http.StatusOK)
	_ = json.NewEncoder(w).Encode(data)
}
```

#### Production Standard (Correct)
> **Standard**: The handler emits and flushes 103 Early Hints immediately over the HTTP/3 stream using http.ResponseController. While the server executes its 200ms DB query, the client resolves DNS and opens a TLS session to the CDN concurrently.
```go
package handlers

import (
	"encoding/json"
	"net/http"
	"time"
)

func UserProfileHandler(w http.ResponseWriter, r *http.Request) {
	// Set Early Hints for critical static CDN upstream
	w.Header().Add("Link", "<https://cdn.example.com>; rel=preconnect; crossorigin")
	w.Header().Add("Link", "<https://cdn.example.com/assets/core.css>; rel=preload; as=style")

	// Emit RFC 8297 StatusEarlyHints (103) before any blocking operation
	w.WriteHeader(http.StatusEarlyHints)

	// Ensure early hints are dispatched immediately across the QUIC stream
	rc := http.NewResponseController(w)
	_ = rc.Flush()

	// Execute blocking upstream queries while client initiates preconnection
	time.Sleep(200 * time.Millisecond) // Simulating DB/gRPC query
	data := map[string]string{"username": "octocat", "avatar_cdn": "https://cdn.example.com/octo.png"}

	// Write final response headers and payload
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(http.StatusOK)
	_ = json.NewEncoder(w).Encode(data)
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Go Chi HTTP/3 Early Hints (RFC 8297) 103 Preconnect Invariant

Go Chi HTTP/3 Early Hints (RFC 8297) 103 Preconnect Invariant defines an industrial-grade behavioral standard for backend engineering. Enforces immediate emission of RFC 8297 103 Early Hints for preconnect and preload resource directives over HTTP/3 QUIC streams prior to executing long-running business logic in Go Chi handlers. Prevents head-of-line payload blocking on edge networks by explicitly flushing the 103 informational status header through the underlying ResponseWriter before expensive database or microservice queries are initiated. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Executing blocking upstream I/O queries before flushing 103 Early Hints informational headers over the QUIC stream. Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftExecuting blocking upstream I/O queries before flushing 103 Early Hints informational headers over the QUIC stream.Critical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS write and flush 103 Early Hints using `http.ResponseController.EnableFullDuplex()` or `w.WriteHeader(http.StatusEarlyHints)` with explicit flushing before initiating blocking database or RPC operations.

Engineers MUST ALWAYS write and flush 103 Early Hints using `http.ResponseController.EnableFullDuplex()` or `w.WriteHeader(http.StatusEarlyHints)` with explicit flushing before initiating blocking database or RPC operations.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT execute database queries, remote gRPC calls, or file reads prior to sending early hints that inform the client of required downstream origins (e.g., CDN, asset hosts).

Engineers MUST NOT execute database queries, remote gRPC calls, or file reads prior to sending early hints that inform the client of required downstream origins (e.g., CDN, asset hosts).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Services MUST verify that the underlying `http.ResponseWriter` supports informational 1xx header emission via `http.ResponseController` (Go 1.20+) or directly assert interfaces for HTTP/3 implementations (e.g., quic-go).

Services MUST verify that the underlying `http.ResponseWriter` supports informational 1xx header emission via `http.ResponseController` (Go 1.20+) or directly assert interfaces for HTTP/3 implementations (e.g., quic-go).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Code SHOULD define Link headers conforming to RFC 8288 with appropriate `rel=preconnect` and `crossorigin` attributes to ensure browsers establish TLS handshakes concurrently with server-side computation.

Code SHOULD define Link headers conforming to RFC 8288 with appropriate `rel=preconnect` and `crossorigin` attributes to ensure browsers establish TLS handshakes concurrently with server-side computation.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Handlers MUST NEVER call `w.WriteHeader(http.StatusOK)` or write body bytes before emitting 103 Early Hints, as 1xx intermediate responses are strictly prohibited after final headers are written.

Handlers MUST NEVER call `w.WriteHeader(http.StatusOK)` or write body bytes before emitting 103 Early Hints, as 1xx intermediate responses are strictly prohibited after final headers are written.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Go Chi HTTP/3 Early Hints (RFC 8297) 103 Preconnect Invariant critical for AI coding assistants?

Enforces immediate emission of RFC 8297 103 Early Hints for preconnect and preload resource directives over HTTP/3 QUIC streams prior to executing long-running business logic in Go Chi handlers. Prevents head-of-line payload blocking on edge networks by explicitly flushing the 103 informational status header through the underlying ResponseWriter before expensive database or microservice queries are initiated. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Executing blocking upstream I/O queries before flushing 103 Early Hints informational headers over the QUIC stream.) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Go