Reuse-first reconstruction program: refreshed audit matrix (Stage A) #150
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
P1
P2
P3
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Creatidy/scarcity-router#150
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Purpose
Durable anchor for the owner-authorized reuse-first reconstruction program (ZCode, GLM-5.3-Flash). Stage A revalidated the prior adversarial reuse audit's hypotheses against canonical
develop@f574e51ce5300fbadaf3a4645a0df5e30969ce73(2026-09-28), with upstream evidence pinned at exact revisions. Work is isolated in thescarcity-router-reuse-programworktree; slices land as separate issues/branches/PRs targetingdevelop.Refreshed reuse matrix (Stage A)
resource_state.py,scarcity.py,capacity.pyinternal/proxy/usage@e5133a68f30985fd4677f6e2a78375bc4becbd1eusage_test.goinvariants (Go→Python; not vendored)ExhaustedAsOf("a window whose ResetAt has passed is no longer exhausted even at 100% cached") and reset-bounded retention. Implemented in Slice A.providers/zai.pySources/CodexBarCore/Resources/Plugins/zai.js@491ae688a89a3b7dacecff1587351bd3c05d8de0(v0.68.0-line HEAD)(unit=1,number=30)30-day window,TIME_LIMIT (5,1)monthly sentinel) is a serialized capacity-vocabulary/evidence decision → owner gate, see below.providers/openai_http_adapter.py(~300 lines overhttp.client)26d48e06(current stable; 21-month stable gap, 1.0 beta churn)verify=False+trust_env, unconditional response decompression (no off switch), no response size bounds, no absolute deadline, no sync cancellation event, httpcore suppresses ambiguous mid-request write errors (httpcore 1.0.9 _sync/http11.py:89-95), +5-6 transitive deps into a stdlib-only core. Our invariants (verified TLS, no bypass, loopback-only plain HTTP, redirect refusal, marker-based loop prevention, ambiguity taxonomy, bounded reads, deadline/cancellation interleaving) are cheaper to keep than re-derive.SseStreamParserinproviders/openai_http_core.py(~110 lines)e8fcd9e1; sseclient-py 1.9.0 @456873c1; requests-sse 0.5.3errors="replace"; requests-sse silently reconnects = hidden re-execution). httpx-sse's pure decoder is a possible future differential-test oracle (dev-only; not scheduled).worker_codex_adapter.py,providers/openai_codex*.pyrust-v0.157.1@36650394(pin:rust-v0.155.1)item/tool/call+thread/start.dynamicTools(present since 0.155.1, tagged experimental)contentItems+success). Constraints: requiresexperimentalApiopt-in at initialize; protocol has NO timeout (app must impose one); interrupt resolves pending calls withturnTransition. Decisive input for #132 child E; implementation belongs there, not to this program.TurnStartParams/Modelschema @rust-v0.157.1turn.rs,ModelListResponse.json) — confirms #136's fail-closed normalization-above-proven-hard-max direction. Context window is only client-visible viathread/tokenUsage/updated.modelContextWindow.gateway_openai.py,gateway_adapters.py,providers/openai_http_core.py(~1.9k lines strict fail-closed)4a2c8186(MIT); LiteLLM v1.102.1 @1ceeefbf(MIT)system→user), silent thinking-block drops, silent tool renaming, silent model substitution, hidden retries/fallbacks. One bounded PORT candidate recorded for a future bridging surface: LiteLLM_build_anthropic_tool_name_maps(collision-safe reversible tool-name normalization) — no current consumer (no Anthropic Messages bridge exists), so not implemented per the no-speculative-layers rule.selector.py,routing_core.py,policy.py,eligibility.pyDeletion estimate
No mass deletion is supported. The audited custom code is ~300 lines (transport), ~110 lines (SSE), thin translation seams — each KEEP decision above is affirmative, not default. The genuine reduction is in maintenance risk (evidence re-pin, adopted test invariants), not LOC. The prior 60%-deletion hypothesis is unsupported against current
develop.Owner decision items (recorded, not silently implemented)
CREDIT_LIMIT(fixtures at(3,5)/(6,1)withusage/remaining/percentage),(unit=1,number=30)rolling-30-day window,TIME_LIMIT (5,1)monthly-MCP sentinel — as Scarcity Router provider evidence. Requires a capacity-vocabulary position (newresource="credits"value vsresource="unknown"+ kind/duration) because diagnostic/resource sets are closed serialized contracts, and a routing-economics position (credits entering D-037 strategic/tactical roles changes blending). Needs dedicated comparative tests per the "any routing-preference change" rule.Slices
Rules
Branch from
develop, PRs targetdevelop, left open for human review; bounded review lifecycle; never merged by agents.Numbering correction: D-057 has been consumed by #136 (gateway effective limits, commit
cdf4ac6ongateway/effective-limits, 2026-09-28). The Z.ai evidence-allowlist extension decision item above ("D-057 candidate") should be read as the next free decision number, currently D-058. No other content of this matrix changes.Stage A+ — audit-completeness and adversarial keep-challenge report
Base:
develop@6fec46ca82901a5fb8761909778c16d8322bbb97(2026-09-28), verified against canonical Forgejo; includes D-057, D-058 (#136/#152), D-059 (#154/#155) and Slice A (#151/#153, mergede25de16b). Worktree note: the owner's post-merge cleanup removed the program worktree mid-task; it was recreated non-destructively, detached at the same SHA, with no data loss (reuse/reset-aware-quota-statewas already merged and its deletion expected). All external evidence lives under/tmp/scarcity-router-reuse-audit/with pinned SHAs; no production file was modified.This pass re-opened the prior KEEP conclusions with the burden of proof on KEEP. Method: the 7 previously-unassessed seed repositories were assessed at source level; the covered seeds were re-pinned and deepened per-mechanism; a disposable failure-injection experiment and an SSE differential probe were run outside the tree; a 2026 ecosystem sweep was performed. Every claim below carries a pinned SHA and file-level citation in the working notes.
A. Coverage ledger — every original seed
e5133a6, usage pkg)e5133a6Apache-2.00e3c41afMIT — passive rollout-JSONL probe with fail-closed rollover semantics; strictly weaker than our app-server Codex collector36d68450MIT — bash account rotator; persisted credentials + bearer-in-argv violate our credential-transiency invariantrouter-for-me/CLIProxyAPI; prior pin4a2c8186is a canonical commit (2026-09-27)4b681031; canonicalacdace936MIT45f4fa5fMIT — ~70-line conservative tool-sequence repair (core/anthropic/conversion.py:142-211) + 805-line test file84027634CC BY-NC-SA 4.0 (incompatible) + silent conversation flattening discards tool traffic3e8a033e— no LICENSE file (package.json MIT metadata does not authorize copying), stale, OAuth persistence, heuristic tool-call synthesis555980ddMIT — account-pooling product with plaintext token persistence; Anthropic unified-ratelimit header names (server.ts:222-233) + stale-utilization cooldown sweep (token-pool.ts:33-84) = evidence for a future Anthropic collectord4125870MIT — 139k LOC LiteLLM delegate; quota guessed at 50%/0.0 under failure; claude.ai browser scraping1ceeefbf)2c9b0e00(v1.104.0-line) — see matrix491ae68)14bdca166(ancestor confirmed; vocabulary unchanged; reset-plausibility now independently implemented upstream)36650394= rust-v0.157.1)/tmp)New 2026 candidates found and assessed: KarpelesLab/teamclaude
9418c667(PORT candidate, quota pressure), supermemoryai/llm-bridge9ebb7c70(design+vectors), onllm-dev/onwatch3e5ed15(GPL-3.0 — ideas-only), ndycode/codex-multi-authf3b176f(reference), HJunLong601/codex-client-providerb7516c0(independent protocol-shape cross-check of our Codex adapter), openchamber25c28a4+ guyinwonder168/opencode-glm-quotaf31d4f2(Z.ai evidence sources), CodexMonitor/EchoBird/Zai-Gateway (CC BY-NC)/OmniRoute/tuxevil-rotator (REJECT EARLY with evidence). No seed disappeared silently.B. Authoritative reuse matrix (one row per mechanism)
openai_http_adapter.py893 lnretries=0;except WriteError: passverified at http11.py:89-95SseStreamParser~110 lngenerate-json-schemaCLI + official generated SDK; zero drift vs our consumed surface; no output-token control anywhere (D-058 premise re-confirmed)worker_codex_adapter.pyopenai_http_core.py+gateway_openai.pystrict fail-closed"stop","error"→"stop", reasoning dropped in Responses direction, conversation leaked into errors; llm-bridge: thinking→text merge, SSE catch-continue,end_turndefaults; CLIProxyAPI: developer→user, reasoning_effort silent defaultinternal/translator/common/(3 algorithms + 629 lines of tests, conservative, "never rewritten or stolen" guarantees); LiteLLM_build_anthropic_tool_name_maps(collision-safe reversible maps,transformation.py:190-268); suparious_repair_openai_tool_message_sequencetests/lib/streaming/fixtures/(16 raw SSE transcripts incl. padded/truncated JSON, MIT); llm-bridge malformed-shape checklist; LiteLLM finish-reason token inventorye25de16b)band-decision.js: passed-reset = known zero (identical to our obsolescence rule); non-finite-utilization absence variant (equivalent to our strict validation)providers/zai.pyworker_protocol.py/worker_endpoint.pyserver_store.py(~25 ln migration machinery)user_versionloses provenance; WAL unneeded (no concurrent readers; identity store already correctly uses WAL)C. Kill List
Empty. Affirmative justification per subsystem: transport (893 ln) — httpx would add deps and only yield ~40 lines of exception mapping we can port in ~20; SSE (110 ln) — every candidate is semantically unsafe for execution (silent drop or fabricated completion on truncation); Codex schemas (~25 types) — the generated alternative is a 13k-line pydantic module behind a new dependency; scoring core — no upstream implements capability ∩ channel ∩ owner-policy with fail-closed evidence; worker protocol — every candidate documents weaker guarantees (REAPI explicitly permits duplicate execution); persistence — a migration dependency to replace ~25 transactional lines. The prior 60%-deletion hypothesis remains unsupported; this pass found no wholesale replacement either.
D. Reuse List (exact, evidence-based)
_sync/http11.py:89-95, verified at 1.0.9): on OSError during request-body send, still attemptgetresponse(); a received response is a definitive outcome, silence stays ambiguous. Our_sendcurrently mislabels a definitive early-4xx-with-undrained-body (common oversized-request provider behavior) as ambiguous. ~10 lines.4421d56a, MIT): whitespace-padded JSON, emptypartial_jsonfragments, ping events, mid-stream truncation, usage-absent honesty → OpenAI-shaped fixtures assertingSseStreamParser/ToolCallAccumulatorbehavior. MIT notice + provenance required.9ebb7c70, MIT): shapes llm-bridge asserts silent defaults for become our explicit-4xx tests.core_helpers.py:197-250) as documented-drift test evidence: each real provider token asserted to remain an explicit refusal innormalize_finish_reason.codex-rs/app-server-protocol/schema/json/+precomputed/, Apache-2.0, provenance header): machine-diff our consumed method/field list in a test (mirroring upstreamschema_fixtures_tests.rs) — converts the recurring manual re-pin into a mechanical check.worker_endpoint.py:222,226-229):_chunksgrows unbounded if a consumer stalls (chunk size and attempt count are capped, chunk count is not); cap with fail-closed overflow, ~10 lines. The one genuine gap found in the worker challenge.common/alignment algorithms + tests (Go→Python, MIT); LiteLLM_build_anthropic_tool_name_maps; suparious_repair_openai_tool_message_sequence; SQLitebackup()/quick_checkhardening; CC-Router's Anthropic unified-ratelimit header names (evidence for a future Anthropic collector).E. Keep List (affirmative justification, current-source grounded)
route_output_code) and effective-limit intersection have no upstream analog.F. Rejected Reuse List (with concrete reasons)
user_versionswap, WAL-for-server-store: dependency or churn for no property we lack.G. Updated target architecture (smallest core after maximal sensible reuse)
Unchanged in shape — the stdlib+mcp-only core stands: presets →
openai_http_adapter(transport + suppress-and-read + ND classification) →openai_http_core(translation + SSE + reasoning carrier [decision-gated]) →gateway_*(intersection + effective limits) →selector/routing/scarcity/policy(frozen scoring) →resource_state(reset-aware state) →providers/*(Z.ai incl. future CREDIT_LIMIT lane; Codex adapter with mechanized schema evidence) →worker_*(dispatch protocol + bounded chunk buffer) →server_store(explicit migrations). Net effect of this pass: +1 contract-level capability (reasoning carrier, owner-gated), +~30 lines of transport/worker hardening, +1 evidence-automation test, +1 test-vector batch — and the recurring Codex re-pin labor drops to a mechanical step.H. Deletion estimate
No forced number. Mass deletion is unsupported: 0% of custom subsystem LOC is replaceable by any assessed upstream at equal-or-better semantics. The honest reduction is in maintenance risk (mechanized Codex schema re-pin; adopted test corpora), not LOC — roughly a 0–5% LOC effect, and in the wrong direction if the two small hardening ports land. The prior 60% hypothesis, and any 5–15% reading, are both unsupported against current
develop.I. Ordered implementation candidates (recorded for the owner; no issues created)
UnicodeDecodeError→ typedTranslationErrortyping gap (the docstring already promises fail-closed viaTranslationError; the coordinator catch-all contains the raw error today asunexpected_error—gateway_coordinator.py:775) + UTF-8 BOM strip hardening (all three compared parsers silently drop a BOM-prefixed first event; the spec says strip); D.2 ND classification (optional).delta.reasoning_content(DeepSeek, Z.ai) anddelta.reasoning(OpenRouter); the chunk vocabulary cannot express reasoning — this violates our own "reasoning must never be silently dropped" rule (openai_http_core.py:783-822,:514-564,gateway_adapters.py:106-116). Represent-or-refuse, with llm-bridgeuniversal.ts:63-98+ LiteLLMtransformation.py:2605-2634as design references (never their code). Frozen-contract addition → backwards-compat or versioned migration decision required.resource/kind, not the token vocabulary) and the routing-economics position (D-037 blending), with comparative tests per the routing-preference rule. Legacy TOKENS_LIMIT/TIME_LIMIT accounts still exist in parallel and must keep parsing. The 30-day(1,30)window remains UNKNOWN (synthetic evidence only); TIME_LIMIT monthly sentinel remains diagnostics-only.J. Stop / Start / Continue (against current
develop, incl. D-058/D-059)/tmp/scarcity-router-reuse-audit/http-probes/as disposable oracles when the transport/SSE surfaces next change.Final verdict
INCREMENTAL_EVOLUTION_SUPPORTED.Because the ecosystem's center of gravity is semantically opposite to this product, not merely less polished — specific, verified differences: (1) at-most-once discipline — the one mature protocol with our problem shape (Remote Execution API) explicitly documents that it MAY execute an action multiple times, and every cloud job API resolves ambiguity by polling durable state we deliberately do not keep; silent retry/relabel is default behavior in LiteLLM (
"error"→"stop", unmapped→"stop") and llm-bridge (catch-continue SSE,end_turndefault) — each occurrence is a place where our frozen D-043/D-044 guarantees would break, not a style difference. (2) Fail-closed evidence semantics — every quota-touching candidate fabricates state under uncertainty (llm-router 50%, onwatch drop heuristics, LiteLLMdrop_params), while our collectors are contractually forbidden from guessing missing telemetry; adopting their mechanics would fail our own capacity-model rules. (3) Credential transiency — every subscription-pooling candidate persists OAuth/refresh tokens by design (CLIProxyAPI object store, CC-Router plaintext accounts.json, claw-router keychain write-back); our invariant admits only D-044's bounded gateway store. (4) The differentiated core has no analog — capability × channel × owner-policy intersection with provenance-carrying UNKNOWN discipline (now incl. D-058's effective limits) exists in none of the ~20 assessed repositories; what they route is traffic, not scarcity-under-evidence. (5) Scale economics run the wrong way — our replaceable custom surfaces are small (transport ~300, SSE ~110, schemas ~25 types, migrations ~25), so a replacement must be more correct to win, and the more correct mechanisms found are ~10–300 line algorithms — which are now precisely enumerated as port candidates (section D), not wholesale dependencies. The audit's reusable yield is real but bounded: two transport refinements, one worker buffer bound, one contract decision (reasoning), one evidence mechanization, three test-corpus adoptions, and one evidenced vocabulary decision (CREDIT_LIMIT). That is incremental evolution, recorded at mechanism granularity.