Skip to main content

Proxy context protection and audit closure

Context checks run before native Anthropic, native Codex, and translated SDK provider dispatch. Each fallback uses its actual serving model. The proxy records estimated input, instruction, tool and output-schema tokens, the output/reasoning reserve, discovered/configured model limits, and retained tool counts. It never silently truncates conversation history.

NEUROLINK_PROXY_CONTEXT_POLICY is an optional JSON object:

{
"maxInputTokens": 100000,
"outputReserveTokens": 32768,
"enforceDiscoveredLimits": true,
"models": {
"provider/model-id": { "contextWindow": 200000, "maxOutputTokens": 32768 }
}
}

These numbers illustrate the schema, not recommended model limits. Unknown model context windows stay unknown; a guessed catalog default never becomes a hard limit. Successful Codex model discovery can register advertised limits without an additional discovery request. Codex does not support the bridged Claude max_tokens transport setting, so its reservation uses the known model output ceiling or configured/default output reserve instead.

An optional toolAllowlist selects tools by name. Tools referenced by prior calls and an explicit tool choice are retained; unnamed native tools are also retained. This is opt-in and can change which new tools the model can choose. The proxy preserves required instructions, history and call/result structure. Automated history summarization has not been introduced: reducing text without an application-specific quality evaluation can discard information required to complete a task.

Token quantities are estimates, including media estimates. Media requests are marked uncertain and are not rejected solely from a guessed combined context window. A configured estimated input cap is not an exact provider-token cap. Provider tokenization, media metering and model quality evaluations remain necessary before claiming exact limits or performance-preserving compression. Invalid configured policy and local context/budget refusals are explicit, nonretryable errors; automatic fallback cannot bypass them.

Shared account/session spending controls are described in proxy-updates-and-token-budgets.md. Collector durability and body separation are described in collector durability profile.

The telemetry doctor accepts --admission-lookback-minutes, --request-timeout-ms, and --ingestion-grace-ms. The lookback must exceed the default request deadline plus ingestion grace. If the effective queried window cannot cover a longer observed request deadline, admission reconciliation is unverified; it cannot establish that missing endings were detected.

Audit coverage

The table preserves every requirement in the incident audit. “Source” means implemented with deterministic isolated checks; it does not mean deployed. A package version on disk, a passing test or a merged PR does not prove the serving supervisor and workers adopted it.

ItemRequirementChange or evidence boundary
T01OTel-only application loggingExisting behavior retained. Retest file-write inactivity after authorized adoption; collector storage is distinct.
T02Native collector/backendExisting deployment choice retained. Native processes still consume CPU/RAM and backend disk.
T03Stored correlation and complete accountingSource: bounded admission-to-terminal reconciliation, explicit missing/out-of-window evidence, route attribution.
T04Retry copiesStable event identity deduplication retained; collector acknowledgment is not exactly-once storage.
T05Capture burst handlingSource: bounded shared body batching, independent metadata transport, per-capture export outcomes.
T06Persistent collector queueOpt-in durable native collector profile; isolated outage/restart replay tested. Requires operator activation.
T07Reasoning usageExisting reasoning accounting preserved. Reasoning remains included in output totals.
T08Capture completenessSource: source/processing truncation and redaction loss distinguished; body limits/rejections remain explicit. Universal losslessness is not promised.
T09Translation coverageSource: Claude/OpenAI/Gemini streaming/buffered attempts and finals preserve requested/served models, usage and known identity.
T10Query and body isolationSource: optional independent body endpoint/stream and bounded projected queries. Activation/retention policy remains operational.
T11Internal bridge duplicationSource: authenticated parent/child linkage, one client outcome owner and one billable usage owner.
T12Validation/unknown routesSource: explicit rejection and auxiliary accounting rather than unexplained missing finals.
T13Timing and aged admissionsSource: separate admission/worker/publication/export timings, bounded admission lookback and ingestion grace.
R01Safe automatic updatesSource: immutable staged packages, bounded progress-aware install, atomic selection/rollback, truthful version phases.
R02Rolling restart safetySource: all draining generations, candidate, queued sockets and transfers block unsafe refresh.
R03Supervisor SIGHUPPrior source regression retained; live signal behavior requires authorized activation evidence.
R04Shutdown ownershipPrior source regression retained; no production shutdown performed by these tests.
R05Claude tool fallbackExisting deterministic conversion coverage retained; previously lost original request shapes cannot be reconstructed.
R06Terminal/status reconciliationSource: one final owner survives late callbacks; unmatched history remains unknown.
R07Availability/latencySource: cancellation, deadlines, demand-driven reads and bounded queues. Internet/upstream failures and production latency still require observation.
R08Accepted requests without endingsSource: socket/abort terminal ownership independent of future pulls. Missing historical endings remain unrecoverable.
R09Screenshot correlationRequest/session/trace linkage improves future diagnosis. Exact historical screenshot is unidentified.
R10Disconnect before headersSource: compose client abort into provider work and settle cancellation once.
R11Loopback abortSource: propagate abort/deadline plus trace/session and internal linkage across the bridge.
R12Stream pressure/deadlinesSource: demand-driven provider iteration, full consumption deadline and bounded cancellation. No replay after visible output.
R13Structured fallback errorsSource: sanitized cause/code/retryability survive parent/child translation; policy denials stop fallback.
C01Cheaper fallback selectionExisting configured policy retained. Native client selection remains distinct from fallback selection.
C02Quota scopePrior structured quota regression retained; real quota recovery requires natural evidence.
C03Unknown quotaPrior provenance/unknown handling retained; unknown does not imply unused allowance.
C04Context reductionSource: model-aware estimated preflight, output reserve and explicit safe tool selection. Automatic history compaction requires task-quality evaluation.
C05Shared spending pressureSource: atomic reservations across worker generations, provider usage reconciliation, conservative unknown usage. Optional and not durable billing.
H01Other scanners/host loadOutside this repository's ownership. No unrelated process was stopped; causal attribution remains limited.
H02Exact past plan burnMissing historical provider allowance/billing baselines cannot be reconstructed. Token totals are not subscription invoices.

Active and rollback package selections are published together in one atomic selections.json record. Existing active.json and previous.json files are read only when no atomic record exists; malformed committed state cannot revive stale legacy selections.

Isolated verification

The suites use temporary HOME/config/credentials, fake providers and test-owned loopback sockets. They do not use a live proxy as a development target.

pnpm run build
pnpm exec vitest run test/codex-quota-observability.test.ts
pnpm exec tsx test/continuous-test-suite-proxy-context-preflight.ts
pnpm exec tsx test/continuous-test-suite-proxy-fallback-errors.ts
pnpm exec tsx test/continuous-test-suite-proxy-telemetry-reconciliation.ts
pnpm exec tsx test/continuous-test-suite-proxy-request-lifecycle.ts
pnpm exec tsx test/continuous-test-suite-proxy-http-disconnect.ts
pnpm exec tsx test/continuous-test-suite-proxy-route-accounting.ts
pnpm exec tsx test/continuous-test-suite-proxy-fallback-parent.ts
pnpm exec tsx test/continuous-test-suite-proxy-update-staging.ts
pnpm exec tsx test/continuous-test-suite-proxy-token-budget.ts
pnpm exec tsx test/continuous-test-suite-proxy-capture-pipeline.ts

For actual collector replay, set NEUROLINK_TEST_OTELCOL_BIN as documented in the collector guide. Without it that case is explicitly skipped. Production proof requires a separately authorized rollout and observation of actual serving versions, route coverage, stored metadata/body outcomes, latency, resource use, and loss/retry counters during representative traffic.