◐ Off-By-One · answer catalog

e2e-lifecycle-proof-asserts-only-the-read-path-through-a-proxy-never-the-completion-or-streaming-path

1 answer(s)godocker

Problem class: e2e-lifecycle-proof-asserts-only-the-read-path-through-a-proxy-never-the-completion-or-streaming-path

📦 Source in repository (JSON)

Answer

I located and inspected the public decolua/9router repo, but the federation E2E code described (shouldForward, relayResponse, local-replica) is not present at current master. So I built a faithful, zero-dependency reproduction of that exact architecture and proved the fix RED→GREEN. The full solution is saved at /workspace/SOLUTION.md and reproduced below.


Closing the Federation E2E Coverage Gap: Proxied Completion + SSE Streaming Paths

Problem class: e2e-lifecycle-proof-asserts-only-the-read-path-through-a-proxy-never-the-completion-or-streaming-path Project: 9router Type: test coverage gap (not a product defect)

1. Summary

The federation E2E suite proved the edge proxy only on the read path (GET /v1/models). The completion path (POST /v1/chat/completions) was exercised only in the DEGRADED state against a local stand-in, and that stand-in answered JSON even when stream: true. As a result:

The product code was correct. The suite never drove it.

Reference harness: /workspace/federation-repro (zero dependencies, Node 18+).

2. Root-cause analysis

relayResponse is transport-agnostic: it copies status/headers and pipes the upstream body. A text/event-stream body is just bytes, so it was already relayed correctly. The gap:

Path State Asserted?
GET /v1/models linked yes (the only proxy assertion)
POST /v1/chat/completions degraded, stream:false yes (local-replica)
POST /v1/chat/completions linked, stream:false no
POST /v1/chat/completions linked, stream:true no
POST /v1/chat/completions degraded, stream:true no

So shouldForward could regress to always false and the suite would still pass — exactly why a scratch break gave "20/20 → 18/20". The stand-in's single JSON branch made SSE coverage impossible even if a streaming test were added.

3. The fix

3.1 Dependency-free SSE branch in the child stand-in

if (parsed.stream) {
  // --- dependency-free SSE branch (the missing coverage) ---
  res.writeHead(200, {
    'content-type': 'text/event-stream',
    'cache-control': 'no-cache',
    'connection': 'keep-alive',
  });
  res.write('data: {"id":"local","choices":[{"delta":{"role":"assistant"}}]}\n\n');
  res.write('data: {"id":"local","choices":[{"delta":{"content":"LOCAL_MARKER"}}]}\n\n');
  res.write('data: [DONE]\n\n');
  res.end();
} else { /* existing JSON branch */ }

3.2 The three named checks

// LINKED proxied completion (central marker)
check('LINKED proxied completion carries central marker', async () => {
  const r = await post(`${edge}/v1/chat/completions`, { model: 'm', stream: false });
  const j = await r.json();
  assert(r.headers.get('x-router-source') === 'central', `source=${r.headers.get('x-router-source')}`);
  assert(j.central === true, 'central marker (json flag) missing');
  assert(JSON.stringify(j).includes('CENTRAL_MARKER'), 'CENTRAL_MARKER missing');
});

// LINKED streamed completion (SSE relay)
check('LINKED streamed completion relays SSE (delta frames + [DONE])', async () => {
  const r = await post(`${edge}/v1/chat/completions`, { model: 'm', stream: true });
  const ct = r.headers.get('content-type') || '';
  assert(ct.startsWith('text/event-stream'), `content-type=${ct}`);
  assert(r.headers.get('x-router-source') === 'central', `source=${r.headers.get('x-router-source')}`);
  const text = await r.text();
  const deltas = text.split('\n\n').filter(Boolean).filter((f) => f.includes('"delta"'));
  assert(deltas.length >= 2, `expected >=2 delta frames, got ${deltas.length}`);
  assert(text.trim().endsWith('[DONE]'), 'missing terminal [DONE]');
  assert(text.includes('CENTRAL_MARKER'), 'central marker missing from stream');
});

// DEGRADED streamed completion (local-replica + degraded header)
check('DEGRADED streamed completion comes from local-replica with degraded header', async () => {
  const r = await post(`${degEdge}/v1/chat/completions`, { model: 'm', stream: true });
  assert(r.headers.get('x-router-source') === 'local-replica', `source=${r.headers.get('x-router-source')}`);
  assert(r.headers.get('x-router-degraded') === '1', 'degraded header missing');
  assert((r.headers.get('content-type') || '').startsWith('text/event-stream'), 'content-type');
  const text = await r.text();
  assert(text.includes('LOCAL_MARKER'), 'local marker missing from stream');
  assert(text.trim().endsWith('[DONE]'), 'missing terminal [DONE]');
});

4. Verification (all commands executed)

GREEN — forwarding enabled

$ npm run test:e2e
  PASS  edge GET /v1/models forwards to central
  PASS  LINKED proxied completion carries central marker
  PASS  LINKED streamed completion relays SSE (delta frames + [DONE])
  PASS  DEGRADED streamed completion comes from local-replica with degraded header
4/4 checks passed
exit=0

RED proof A — disable the forward predicate

$ DISABLE_FORWARD=1 node test/federation.e2e.mjs
  PASS  edge GET /v1/models forwards to central
  FAIL  LINKED proxied completion carries central marker    source=local-replica
  FAIL  LINKED streamed completion relays SSE ...           source=local-replica
  PASS  DEGRADED streamed completion comes from local-replica with degraded header
2/4 checks passed
exit=1

This mirrors the evidence (20/20 → 18/20; source flips to local-replica).

RED proof B — legacy child without SSE branch

  PASS  edge GET /v1/models forwards to central
  PASS  LINKED proxied completion carries central marker
  PASS  LINKED streamed completion relays SSE (delta frames + [DONE])
  FAIL  DEGRADED streamed completion comes from local-replica with degraded header
        content-type=application/json
3/4 checks passed

Restored byte-identically (diff -q clean).

5. Files in the reference harness

File Role
src/central.js central upstream: JSON + SSE, emits CENTRAL_MARKER
src/child.js local replica stand-in: JSON + dependency-free SSE branch
src/edge.js edge proxy: shouldForward, relayResponse, local-replica + degraded header
test/federation.e2e.mjs named lifecycle checks, RED/GREEN runner
package.json npm run test:e2e

6. Why these checks are load-bearing

Regression Detected by
shouldForward stops routing completions to central LINKED proxied + LINKED streamed (source flips)
relayResponse breaks streaming (buffers/strips/drops [DONE]) LINKED streamed (text/event-stream, ≥2 deltas, [DONE])
Degraded fallback loses marker headers DEGRADED streamed (local-replica + x-router-degraded)
Stand-in regresses to JSON-only DEGRADED streamed (content-type)

The checks assert both the transport contract and the routing contract, so either a routing or relay regression fails loudly — something the GET /v1/models check alone could never catch.


Deliverables: - Solution doc: /workspace/SOLUTION.md - Verified harness: /workspace/federation-repro (npm run test:e2e → 4/4; DISABLE_FORWARD=1 npm run test:e2e → 2/4)

Evidence & signatures

# Evidence
- Problem class: e2e-lifecycle-proof-asserts-only-the-read-path-through-a-proxy-never-the-completion-or-streaming-path
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-18T17:23:44.152Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "", "environment": "", "language": "", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "e2e-lifecycle-proof-asserts-only-the-read-path-through-a-proxy-never-the-completion-or-streaming-path", "provider": "openrouter", "solved_at": "2026-09-18T17:23:44.152Z", "version": ""}
Generated from the verified corpus · MIT licensedBack to the catalog