Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(hogql): show playground server connection status (#102795)

Paweł Szczured8637ed3acf
diff --git a/docs/internal/hogql-language-service-demo.md b/docs/internal/hogql-language-service-demo.md
index 01a696ed71c3..14a7de3914d0 100644
--- a/docs/internal/hogql-language-service-demo.md
+++ b/docs/internal/hogql-language-service-demo.md
@@ -24,6 +24,9 @@ Forward port `8092` and open the forwarded URL.
This mode accepts the forwarded hostname and HTTP or HTTPS origins matching that hostname.
The demo has no authentication; use your development environment's private forwarding controls.
Only the demo page listens on a port; the embedded service has no separate listener.
+The connection indicator checks the embedded service's health handler through the demo server.
+It reports whether that handler is reachable, not whether a query is valid or supported.
+The page checks periodically while visible and reconnects automatically after a temporary failure.
Go may download the module's required toolchain on the first run.
Agents must request elevated execution when starting the demo because it opens a local HTTP listener.
@@ -53,6 +56,7 @@ Do not add the demo to deployment configuration or the production server's route
- Select **Quoted identifiers** and insert `billing address` to inspect identifier quoting. The service supplies quoted insertion text; the page does not add quotes.
- Use **CTE completion** and **Subquery completion** to inspect current derived-relation support. Empty suggestions are shown as returned by the service, without a browser fallback.
- Open raw responses to inspect parser errors, diagnostics, pagination cursors, physical table names, and catalog revisions.
+- Stop and restart the demo to confirm that the connection indicator changes to disconnected and recovers.
Ctrl/Command+Enter validates; Ctrl/Command+Shift+Enter completes.
Ctrl+Space is left available for the operating system's input-source shortcut.
@@ -108,6 +112,7 @@ They are not evidence that a query would succeed or fail in the full PostHog com
| Editor integration | A textarea keeps the page dependency-free. Optional debounced validation and completion run after edits. Monaco highlighting, squiggles, and completion inside already quoted identifiers are not provided. Insertion replaces an ordinary identifier around the captured cursor. | Add a locally bundled editor adapter when testing editor behavior, with cursor/range tests for quoted names, escaped characters, and mid-token edits. |
| Custom catalog editing and permissions | One synthetic team/user catalog is seeded at startup. There is no upload UI, identity picker, catalog refresh button, permission mutation, or JWT workflow. | Add isolated synthetic catalog variants for permission/tenant testing; verify catalog revisions and isolation through authenticated endpoints before adding identity controls. |
| Performance conclusions | The fixture is small and timings are exploratory. This page is not a load test or latency acceptance gate. | Use the existing large-catalog benchmarks and dedicated latency test; add query-shape benchmarks for the shared analyzer as needed. |
+| Connection status | The indicator checks only whether the embedded service health handler responds successfully. It does not reflect catalog freshness, query correctness, or support for a specific HogQL construct. | Inspect validation and completion responses for query-level behavior. |
| Hosting and production | Private development port forwarding is supported with `-host 0.0.0.0`. The demo serves HTTP without authentication or built-in TLS and stays excluded from production. | Use authenticated development forwarding. Public hosting would need a separate authentication and TLS design; production service endpoints remain outside this demo. |
| Persistence | Query text and results live only in the page; refreshing discards them. This avoids silently storing pasted query text. | If useful, add explicit local export/import of synthetic examples with a documented file format. |
diff --git a/services/hogql-language-service/cmd/demo/assets/app.js b/services/hogql-language-service/cmd/demo/assets/app.js
index ce24067473fa..48d39f4411c9 100644
--- a/services/hogql-language-service/cmd/demo/assets/app.js
+++ b/services/hogql-language-service/cmd/demo/assets/app.js
@@ -72,6 +72,62 @@ let composing = false
const requests = { validation: null, completion: null }
const feedback = { validation: '', completion: '' }
const copying = { validation: false, completion: false }
+const healthCheckInterval = 5000
+const healthCheckTimeout = 2000
+let healthTimer = null
+let healthController = null
+let healthCheckGeneration = 0
+
+function setServerStatus(connected) {
+ const status = byId('server-status')
+ status.classList.toggle('connected', connected)
+ status.classList.toggle('disconnected', !connected)
+ const statusText = byId('server-status-text')
+ const nextStatusText = connected ? 'Server connected' : 'Server disconnected'
+ if (statusText.textContent !== nextStatusText) {
+ statusText.textContent = nextStatusText
+ }
+}
+
+function stopHealthChecks() {
+ clearTimeout(healthTimer)
+ healthTimer = null
+ healthCheckGeneration += 1
+ healthController?.abort()
+ healthController = null
+}
+
+function resumeHealthChecks() {
+ clearTimeout(healthTimer)
+ healthTimer = null
+ checkServerHealth()
+}
+
+async function checkServerHealth() {
+ if (healthController || document.hidden) {
+ return
+ }
+ const generation = ++healthCheckGeneration
+ const controller = new AbortController()
+ healthController = controller
+ const timeout = setTimeout(() => controller.abort(), healthCheckTimeout)
+ try {
+ const response = await fetch('/api/health', { signal: controller.signal, cache: 'no-store' })
+ if (generation === healthCheckGeneration) {
+ setServerStatus(response.ok)
+ }
+ } catch {
+ if (generation === healthCheckGeneration) {
+ setServerStatus(false)
+ }
+ } finally {
+ clearTimeout(timeout)
+ if (generation === healthCheckGeneration) {
+ healthController = null
+ healthTimer = setTimeout(checkServerHealth, healthCheckInterval)
+ }
+ }
+}
function captureFeedback(kind, exchange) {
feedback[kind] = JSON.stringify(exchange, null, 2)
@@ -415,12 +471,21 @@ editor.addEventListener('compositionend', () => {
})
window.addEventListener('pagehide', () => {
cancelScheduledAnalysis()
+ stopHealthChecks()
for (const kind of Object.keys(requests)) {
if (requests[kind]) {
invalidate(kind)
}
}
})
+document.addEventListener('visibilitychange', () => {
+ if (document.hidden) {
+ stopHealthChecks()
+ } else {
+ resumeHealthChecks()
+ }
+})
+window.addEventListener('pageshow', resumeHealthChecks)
for (const event of ['input', 'keyup', 'click', 'select']) {
editor.addEventListener(event, syncSelection)
}
@@ -435,6 +500,7 @@ editor.addEventListener('keydown', (event) => {
}
})
loadExample()
+resumeHealthChecks()
fetch('/api/catalog')
.then(async (response) => {
if (!response.ok) {
diff --git a/services/hogql-language-service/cmd/demo/assets/index.html b/services/hogql-language-service/cmd/demo/assets/index.html
index e06515f50c84..83a61b74a5ce 100644
--- a/services/hogql-language-service/cmd/demo/assets/index.html
+++ b/services/hogql-language-service/cmd/demo/assets/index.html
@@ -11,7 +11,13 @@
<header>
<div>
<span class="eyebrow">Developer tools</span>
- <h1>HogQL playground</h1>
+ <div class="title-row">
+ <h1>HogQL playground</h1>
+ <span id="server-status" class="server-status" role="status" aria-live="polite">
+ <span id="server-status-dot" class="server-status-dot" aria-hidden="true"></span>
+ <span id="server-status-text">Checking server</span>
+ </span>
+ </div>
</div>
<span class="badge">Local only · synthetic catalog</span>
</header>
diff --git a/services/hogql-language-service/cmd/demo/assets/style.css b/services/hogql-language-service/cmd/demo/assets/style.css
index 3020588abde0..9ad78ec34ada 100644
--- a/services/hogql-language-service/cmd/demo/assets/style.css
+++ b/services/hogql-language-service/cmd/demo/assets/style.css
@@ -46,6 +46,38 @@ h1 {
letter-spacing: -0.7px;
}
+.title-row,
+.server-status {
+ display: flex;
+ gap: 8px;
+ align-items: center;
+}
+
+.title-row {
+ flex-wrap: wrap;
+}
+
+.server-status {
+ margin-top: 5px;
+ font-size: 12px;
+ color: #706c65;
+}
+
+.server-status-dot {
+ width: 8px;
+ height: 8px;
+ background: #9a968d;
+ border-radius: 50%;
+}
+
+.server-status.connected .server-status-dot {
+ background: #267442;
+}
+
+.server-status.disconnected .server-status-dot {
+ background: #ae3329;
+}
+
h2 {
margin: 0;
font-size: 16px;
diff --git a/services/hogql-language-service/cmd/demo/main.go b/services/hogql-language-service/cmd/demo/main.go
index b9606e2994a5..48a12894b2bf 100644
--- a/services/hogql-language-service/cmd/demo/main.go
+++ b/services/hogql-language-service/cmd/demo/main.go
@@ -68,6 +68,15 @@ func demoHandler(backend http.Handler, host string, payload []byte) http.Handler
// nosemgrep: go.lang.security.audit.xss.no-direct-write-to-responsewriter.no-direct-write-to-responsewriter
_, _ = w.Write(payload)
})
+ mux.HandleFunc("GET /api/health", func(w http.ResponseWriter, r *http.Request) {
+ request, err := http.NewRequestWithContext(r.Context(), http.MethodGet, "/health", nil)
+ if err != nil {
+ http.Error(w, "Could not check the service. Restart the demo.", http.StatusInternalServerError)
+ return
+ }
+ request.RemoteAddr = r.RemoteAddr
+ backend.ServeHTTP(w, request)
+ })
for _, operation := range []string{"autocomplete", "validate"} {
mux.HandleFunc("POST /api/"+operation, func(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(http.MaxBytesReader(w, r.Body, 128<<10))
diff --git a/services/hogql-language-service/cmd/demo/main_test.go b/services/hogql-language-service/cmd/demo/main_test.go
index 18a13a38597f..992f2492a9ef 100644
--- a/services/hogql-language-service/cmd/demo/main_test.go
+++ b/services/hogql-language-service/cmd/demo/main_test.go
@@ -51,6 +51,7 @@ func TestDemoEmbeddedService(t *testing.T) {
method, path, body string
status int
}{
+ {http.MethodGet, "/api/health", "", http.StatusOK},
{http.MethodPost, "/api/validate", `{"query":"WITH t AS (SELECT uuid FROM events) SELECT uuid FROM t"}`, http.StatusOK},
{http.MethodPost, "/api/autocomplete", `{"query":"SELECT events.tim FROM events","position":17}`, http.StatusOK},
{http.MethodPost, "/api/validate", `{"query":"SELECT 1","unknown":true}`, http.StatusBadRequest},
@@ -66,7 +67,7 @@ func TestDemoEmbeddedService(t *testing.T) {
if response.Code != test.status {
t.Fatalf("response = %d %s, want %d", response.Code, response.Body.String(), test.status)
}
- if test.status != http.StatusOK {
+ if test.status != http.StatusOK || test.path == "/api/health" {
return
}
var revision struct {
@@ -90,6 +91,23 @@ func TestDemoEmbeddedService(t *testing.T) {
}
}
+func TestDemoHealthForwardsServiceFailure(t *testing.T) {
+ backend := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodGet || r.URL.Path != "/health" {
+ t.Fatalf("forwarded request = %s %s", r.Method, r.URL.Path)
+ }
+ http.Error(w, "unhealthy", http.StatusServiceUnavailable)
+ })
+ request := httptest.NewRequest(http.MethodGet, "http://127.0.0.1:8092/api/health", nil)
+ response := httptest.NewRecorder()
+
+ demoHandler(backend, "127.0.0.1:8092", nil).ServeHTTP(response, request)
+
+ if response.Code != http.StatusServiceUnavailable {
+ t.Fatalf("status = %d, want %d", response.Code, http.StatusServiceUnavailable)
+ }
+}
+
func TestDemoForwardsLanguageRequests(t *testing.T) {
for _, test := range []struct {
operation, host, origin, allowedHost string