Skip to content

Commit 5bd692f

Browse files
committed
Merge origin/dev (lidge-jun#7627 landed as 0929e6e) into perf/bun144-native-audit-utf8
# Conflicts: # tests/claude-integration/claude-picker-upload.test.ts
2 parents 7834a09 + c2bcb52 commit 5bd692f

51 files changed

Lines changed: 1607 additions & 113 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/enforce-pr-target.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ jobs:
4444
github.event.label.name == 'test-exception-approved' ||
4545
github.event.label.name == 'suppression-approved' ||
4646
github.event.label.name == 'generated-change-approved' ||
47-
github.event.label.name == 'dependency-change-approved'))
47+
github.event.label.name == 'dependency-change-approved' ||
48+
github.event.label.name == 'attribution-approved'))
4849
runs-on: ubuntu-latest
4950
permissions:
5051
contents: read
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# 261025 Command Code MODEL_NOT_IN_PLAN refusal (#7684)
2+
3+
Command Code answers a model the account's plan excludes with HTTP 403
4+
`{"success":false,"error":{"code":"FORBIDDEN","status":403,"message":"MODEL_NOT_IN_PLAN: <detail>"}}`.
5+
OpenCodex forwards that 403, and Codex treats any 403 as a retryable `UnexpectedStatus`: a scratch
6+
probe against Codex CLI 0.163.0 counted 6 sends (`Reconnecting... 1/5` to `5/5`) for the 403 and
7+
exactly 1 send for an HTTP 400 (`.tmp/m5/codex-retry-probe.ts`, not committed). Inside a combo the
8+
same 403 cools the whole Command Code provider row (`comboFailureCooldownScope` returns
9+
`provider` for 401/402/403), so every other Command Code model in that combo is skipped. This unit
10+
makes the refusal a single, non-retryable, model-scoped answer.
11+
12+
## Loop spec
13+
14+
- Archetype: satisfy-spec, one work-phase (wp1). Trigger: lane M5 brief for issue #7684.
15+
- Goal: one upstream send per turn for a plan-excluded model, a clear client error naming the
16+
model and the plan, combos hop to the next target and cool only the refused target.
17+
- Non-goals: catalog/discovery removal of plan-excluded models (unverifiable without an
18+
authenticated account), sibling-account rotation on a plan refusal, a per-account denial cache
19+
(generic OAuth has none; `src/codex/observed-model-denials.ts` is Codex-pool only and none is
20+
added), the Command Code API-key `openai-chat` preset, the shared error formatter allowlist,
21+
docs-site (guides/providers.md is owned by lane M4), the known failure at
22+
`tests/claude-integration/claude-desktop-remote-hub.test.ts:249`.
23+
- Verifier: `bun test tests/providers/command-code-plan-denial.test.ts` red before / green after;
24+
credit refusal suites stay green; typecheck, test:changed, privacy:scan, structure:check exit 0;
25+
Codex probe through the real proxy route counts 1 send.
26+
- Stop: PR open on dev with independent review PASS at the exact head and CI state reported.
27+
- Memory artifact: this file plus the goalplan under `.codexclaw/goalplans/`.
28+
- Terminal outcomes: DONE as above; BLOCKED if push/PR/review surfaces fail repeatedly; UNSAFE if
29+
the fix needs credential handling changes; NEEDS_HUMAN if review demands excluded scope.
30+
- Escalation: a reviewer asking for catalog removal or account rotation goes to the origin.
31+
- Resource bounds: none stated; host limits apply.
32+
33+
## Diff-level plan
34+
35+
1. `src/adapters/command-code.ts`: generalize the credit normalizer into
36+
`normalizeCommandCodeRefusal(response, oauth, modelId, signal)`. Status 400 keeps the existing
37+
OAuth-only credit rewrite byte-for-byte. Status 403, for every auth mode, reads at most 8 KiB
38+
(fatal UTF-8, display-safe) and matches only `success === false`, `error.code === "FORBIDDEN"`
39+
and a message starting with `MODEL_NOT_IN_PLAN` followed by `:` or the end. It returns HTTP 400 with
40+
`{"error":{"type":"invalid_request_error","code":"model_not_in_plan","message":...}}`, headers
41+
`x-opencodex-upstream-status: 403` and `x-opencodex-refusal: model-not-in-plan` (both diagnostic).
42+
`commandCodePlanRefusalMessage` is fixed copy naming the canonical model; the upstream detail is
43+
never quoted. The adapter marks the Response it builds in memory
44+
(`markVerifiedModelNotInPlanResponse`); that object identity is the only provenance. Any other 403, a malformed or
45+
oversized body, or malformed UTF-8 is returned untouched. The reasoning-effort retry send uses the
46+
same normalizer. No account, key or provider cooldown is recorded; nothing is logged.
47+
2. `src/combos/failover.ts`: `comboFailureDecision` hops on `model_not_in_plan` only when the caller
48+
passes `verifiedPlanRefusal` (combo loop from `consumeComboFailure`, policy fallback from the
49+
envelope mark); a bare, passthrough, streamed or run-turn code is read like any unknown code.
50+
`comboFailureCooldownScope` then falls through to `target` for the 400, so only the refused
51+
provider/model target cools.
52+
3. `tests/providers/command-code-plan-denial.test.ts` (registered in
53+
`scripts/test-layout/layout-adapters.json` and on an existing line of
54+
`tests/fixtures/test-layout-expected.json`): OAuth two-account dispatch (one send, 400, active
55+
account unchanged, the same account then serves another model), key row (one send, 400), an
56+
unrelated FORBIDDEN 403 stays 403, combo `[plan-refused model, sibling model]` on the same
57+
provider completes on the sibling, and the failover predicates for the code.
58+
4. `structure/providers-and-adapters.md`: extend the existing command-code row in place (net zero
59+
lines; the doc is at 600/600).
60+
61+
## Risks
62+
63+
- A 400 is a status change for this one refusal; clients that branched on 403 for it now see
64+
`invalid_request_error`. The upstream status is kept in `x-opencodex-upstream-status`.
65+
- The client body keeps the dispatch wrapper (`Provider error 400: {...}`); the formatter
66+
keeps `model_not_in_plan` as the top-level code so clients and policy fallback can read it. The
67+
wire code is not provenance; only the boundary that verified the refusal marks the envelope.
68+
69+
## Audit r1 amendment (GOAT task m5-plan-audit-r1, codex/gpt-6.1-sol high: GO-WITH-FIXES)
70+
71+
1. Accepted (P2 policy fallback): `policy-fallback.ts` hops on the final envelope's `error.code`,
72+
which `adapter-dispatch.ts` never forwards. The constant `MODEL_NOT_IN_PLAN_CODE` lives in
73+
`src/lib/errors.ts`; `formatErrorResponse` keeps it when a caller passes it (same rule as
74+
`undeclared_tool_call`). `adapter-dispatch.ts` passes it only when `isModelNotInPlanRefusal`
75+
accepts the response: a 400 with the canonical body code whose Response object the adapter
76+
marked in memory. The header is diagnostic only and is never read as provenance.
77+
2. Accepted (P2 misleading detail): the message is fixed wording built from the request's
78+
canonical model id (accepted only if it matches a conservative id pattern). Upstream detail is
79+
never quoted, so effort-repair, opaque-recovery and subagent quota classifiers cannot fire on it.
80+
The adapter also skips its effort-repair branch for a normalized plan refusal.
81+
3. Accepted (P1 logging): no upstream text reaches the client body or the combo warning. A test
82+
puts synthetic account/key canaries plus effort and quota phrases in the upstream detail and
83+
asserts their absence from the client body and captured console output.
84+
4. Accepted (P2 matrix): adapter-level negatives for malformed JSON, invalid UTF-8, oversized body,
85+
wrong `success`/`code`, a `MODEL_NOT_IN_PLAN_OTHER` prefix lookalike, abort propagation,
86+
key/forward/OAuth modes, normalization after a genuine effort-repair send; dispatch tests on the
87+
Responses, Chat and Messages inbound paths; combo hop plus a second request that skips only the
88+
cooled target; a policy-route hop.
89+
5. Noted: attribution moves from `credential-rejected` to `payload-rejected` by the status table;
90+
documented in the PR, not pinned by a test that would restate the table.
91+
92+
## Review rounds (PR #7696)
93+
94+
Independent review via GOAT task (codex/gpt-6.1-sol, high), each round at the exact head:
95+
96+
- r1 MUSTFIX: the combo trust gate matched only the lowercase code while failover folds case,
97+
space and hyphens. Fixed with `namesModelNotInPlanCode` (`6d92c0657`).
98+
- r2 MUSTFIX: policy fallback trusted a passthrough envelope's code. Fixed with the explicit
99+
`verifiedPlanRefusal` option on `comboFailureDecision` (`5d41c59f5`).
100+
- r3 MUSTFIX: status, code and marker header are all upstream-forgeable. Fixed by making
101+
provenance in-memory object identity (`bbc39eab6`). r4 PASS at `bbc39eab6`.
102+
- CodeRabbit: `formatErrorResponse` minted the mark from a caller-supplied code, which run-turn
103+
combo children take from an adapter event. Fixed by marking only at the verifying boundaries
104+
(`adapter-dispatch.ts`, `consumeComboFailure`); this plan text was also corrected.
105+
- r5 MUSTFIX: the web-search and image sidecar loops rebuilt a failed first iteration as their own
106+
envelope, dropping the fixed copy, code and mark, so a sidecar combo or policy stopped instead of
107+
moving on. Fixed with `verifiedPlanRefusalMessage` in both loops and mark propagation across the
108+
`sidecar-execution.ts` stream wrappers.
109+
- r6 MUSTFIX: a refusal on a later sidecar iteration lands inside an already committed 200 stream,
110+
where `model_not_in_plan` made Codex CLI 0.163.0 reconnect (6 sends). It now ends as `invalid_prompt`
111+
with `retryable: false` and the same copy (1 send), via `sidecarLoopTerminalEvent`.
112+
- CodeRabbit (tests): whole-body assertion and positive streamed combo/policy fallbacks.
113+
- r7 MUSTFIX: on Chat inbound the later-iteration `invalid_prompt` arrived without a numeric status,
114+
and both the streamed projection and the buffered collector inferred 502 `server_error` from the
115+
wording. `src/chat/outbound.ts` now treats every `isTerminalRefusalCode` code as a 400-class
116+
verdict that keeps its code (the existing cyber-policy rule, generalized).
117+
- CodeRabbit (tests): the sidecar route test asserts the injected `web_search` function tool.
118+
- Manager Linux verification: `adapter-dispatch.ts` grew to 2,007 lines, failing the file-size ratchet
119+
and the responses-core module cap. The plan-refusal branch moved into `formatUpstreamFailureResponse`
120+
(`src/bridge/errors.ts`); `adapter-dispatch.ts` is back to 1,999 lines with a one-call change.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# 000 — moonshot_k31_seed: Plan
2+
3+
Issue #7653 (lane M4). Single-cycle C3 change; docs-first roadmap cycle skipped (one work-phase).
4+
5+
## Objective
6+
7+
The `moonshot` preset (Kimi API, `https://api.moonshot.ai/v1`) seeds `kimi-k3` plus legacy K2 ids
8+
(`src/providers/registry/model-seeds.ts:772-773`) but not Kimi K3.1 Pro, so the picker never offers
9+
`kimi-k3.1-pro` / `kimi-k3.1-pro-highspeed`, and a routed request gets no 1M window or effort ladder.
10+
#7657 (46f23cab5e) already added the price rows for both ids (`src/usage/expected-prices.ts:467-468`)
11+
but deliberately left the seeds out.
12+
13+
Evidence base (official Moonshot platform docs only, fetched 2026-10-25):
14+
15+
- https://platform.kimi.ai/docs/models.md — both `kimi-k3.1-pro` and `kimi-k3.1-pro-highspeed` listed
16+
as current multi-modal models ("native visual understanding and a 1M-token context window";
17+
highspeed = "same intelligence, about 2-3x the speed").
18+
- https://platform.kimi.ai/docs/pricing/chat.md — "All K3 series models support a 1,048,576-token
19+
context window"; price rows $2/$10/$0.20/$2(5m) and $4/$20/$0.20/$4(5m) (already in tree, unchanged).
20+
- https://platform.kimi.ai/docs/guide/kimi-k3-1-pro-quickstart.md — always thinking; top-level
21+
`reasoning_effort` low/high/max, default max; temperature/top_p/n/penalties fixed; vision via base64
22+
or ms:// file ids; return the complete assistant message (reasoning_content) on multi-turn.
23+
- https://platform.kimi.ai/docs/api/models-overview.md — "kimi-k3.1-pro and kimi-k3.1-pro-highspeed
24+
also have the same parameter constraints as kimi-k3"; `tool_choice` auto/none/required supported.
25+
- https://platform.kimi.ai/docs/guide/use-reasoning-effort.md — low/high/max, default max.
26+
27+
## Loop-spec
28+
29+
- Loop archetype: verifier-defined (parity + wire tests, typecheck, gates).
30+
- Write scope: model-seeds.ts KIMI_API_* constants; entries-extended.ts moonshot entry wiring;
31+
tests/providers/provider-registry-parity.test.ts; tests/codex-integration/reasoning-effort.test.ts;
32+
docs-site/src/content/docs/guides/providers.md (English canonical); structure/providers-and-adapters.md
33+
(in-place, file stays at 600 lines); this devlog unit.
34+
- Out of scope (owner decision, noted in PR): K2 retirement, moonshot defaultModel (kimi-k2.7-code,
35+
entries-extended.ts:475), rename migrations, kimi-k3's own max-only ladder (docs now list low/high/max
36+
for kimi-k3 too — follow-up), coding presets, prices, GUI, translated docs (English-only addition
37+
does not contradict them).
38+
- Budget / bounds: none stated; host limits apply. Tool scope: local repo, gh (push/PR authorized by
39+
lane brief), GOAT task.create for review.
40+
41+
## Work-phase map (one phase = one full PABCD cycle)
42+
43+
| WP | Doc | Slice | Depends on |
44+
|----|-----|-------|------------|
45+
| wp1 | 010_phase1.md | seed + tests + docs + gates + PR + review | — |
46+
47+
## Accept criteria
48+
49+
- c-1 moonshot seeds both ids with 1M window, text+image, low/high/max default max, K3 effort map,
50+
fixed sampling, preserve reasoning, not auto-tool-choice-only; kimi-k3 / K2 / default unchanged.
51+
- c-2 regression tests red on base (0aeaf0cb6b) and green after the fix.
52+
- c-3 typecheck, test:changed, privacy:scan, structure:check, docs-site build green on final head.
53+
- c-4 PR open on dev, GOAT-linked, independent review PASS at exact head, CI state reported.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# 010 — Phase 1 (moonshot_k31_seed) — consolidated after audit rounds 1-2 and manager scope update
2+
3+
## MODIFY / NEW / DELETE map
4+
5+
### MODIFY src/providers/registry/model-seeds.ts (KIMI_API_* block, ~lines 772-809)
6+
7+
```ts
8+
export const KIMI_LEGACY_API_MODELS = [...unchanged];
9+
// 261025 Kimi K3.1 Pro on the Moonshot API (#7653): evidence comment (models.md, pricing/chat.md,
10+
// kimi-k3-1-pro-quickstart.md, api/models-overview.md; China platform.kimi.com/docs/models.md), verified 2026-10-25.
11+
export const KIMI_API_K31_MODELS = ["kimi-k3.1-pro", "kimi-k3.1-pro-highspeed"];
12+
export const KIMI_API_K3_SERIES_MODELS = ["kimi-k3", ...KIMI_API_K31_MODELS];
13+
export const KIMI_API_MODELS = [...KIMI_API_K3_SERIES_MODELS, ...KIMI_LEGACY_API_MODELS];
14+
// Frozen previous seed for the saved-roster repair (literal, not derived).
15+
export const KIMI_API_MODELS_BEFORE_K31 = ["kimi-k3", "kimi-k2.7-code", "kimi-k2.7-code-highspeed", "kimi-k2.6", "kimi-k2.5"];
16+
export const KIMI_API_NO_REASONING_MODELS = KIMI_API_MODELS.filter(id => !KIMI_API_K3_SERIES_MODELS.includes(id));
17+
// none -> omit: thinking cannot be disabled; value mirrors REASONING_EFFORT_OMIT_SENTINEL (src/reasoning-effort.ts:30)
18+
export const KIMI_API_K31_REASONING_EFFORT_MAP = { ...KIMI_CODING_K3_REASONING_EFFORT_MAP, none: "__omit__" };
19+
export const KIMI_API_REASONING_EFFORTS = KIMI_API_MODELS -> K3.1: ["low","high","max"]; kimi-k3: ["max"] (unchanged); K2: [].
20+
export const KIMI_API_DEFAULT_REASONING_EFFORTS = { "kimi-k3.1-pro": "max", "kimi-k3.1-pro-highspeed": "max" };
21+
export const KIMI_API_REASONING_EFFORT_MAPS = { both K3.1 ids: KIMI_API_K31_REASONING_EFFORT_MAP };
22+
export const KIMI_API_MODEL_CONTEXT_WINDOWS = K3 series 1_048_576, K2 262_144;
23+
export const KIMI_API_MODEL_INPUT_MODALITIES = K3 series ["text","image"];
24+
```
25+
26+
(The omit literal is used because model-seeds.ts imports nothing from src/reasoning-effort.ts and the
27+
registry must not depend on the request-path module; a test asserts the literal equals the exported
28+
constant.)
29+
30+
### MODIFY src/providers/registry/entries-extended.ts (moonshot entry)
31+
32+
Add `modelDefaultReasoningEfforts: KIMI_API_DEFAULT_REASONING_EFFORTS` and
33+
`modelReasoningEffortMap: KIMI_API_REASONING_EFFORT_MAPS` (+ imports). defaultModel stays kimi-k2.7-code.
34+
35+
### MODIFY src/providers/stale-model-roster-migration.ts (STALE_MODEL_ROSTERS)
36+
37+
```ts
38+
{
39+
provider: "moonshot", from: KIMI_API_MODELS_BEFORE_K31, to: KIMI_API_MODELS,
40+
contextWindows: KIMI_API_MODEL_CONTEXT_WINDOWS, defaultReasoningEfforts: KIMI_API_DEFAULT_REASONING_EFFORTS,
41+
destinationBaseUrls: [MOONSHOT_INTL_BASE_URL, MOONSHOT_CN_BASE_URL],
42+
}
43+
```
44+
45+
### MODIFY docs-site/src/content/docs/guides/providers.md (English canonical, after the Kimi Coding price paragraph)
46+
47+
One paragraph: moonshot seeds kimi-k3.1-pro / -highspeed next to kimi-k3 and the K2 ids; 1M context,
48+
text+image, always-on thinking, low/high/max (default max; medium->high, xhigh->max, none omits the field);
49+
sampling params omitted; untouched saved model lists on the International/China URLs gain both ids at
50+
startup; default stays kimi-k2.7-code; link the official model list (K2 closes to new accounts 2026-10-31,
51+
retirement planned end of December 2026).
52+
53+
### Structure docs: no edit
54+
55+
providers-and-adapters.md is owned by lane M5 (manager). Its line 87 (Kimi Coding seeds) and line 394
56+
(generic stale-roster contract) remain accurate: this change adds a data row to an existing mechanism and
57+
seeds; no contract changes. chat-compat.md (600/600) describes wire compat, not seeds. Per
58+
structure/AGENTS.md ("a reviewed document whose content remains accurate does not need copied unchanged
59+
prose") no structure edit is required. Recorded in the PR.
60+
61+
## TESTS (all in tests/providers/)
62+
63+
- provider-registry-parity.test.ts, moonshot section: exact models, defaultModel, exact context windows,
64+
per-K3.1 metadata (no-reasoning absent, ladder, default max, modalities, fixed-sampling + preserve lists,
65+
not auto-tool-choice-only, map == K3 map with none "__omit__"), kimi-k3 unchanged (["max"], no default/map),
66+
omit literal === REASONING_EFFORT_OMIT_SENTINEL; catalog entry default_reasoning_level "max".
67+
New test: persisted OLD moonshot row (old models list, old modelContextWindows/modelReasoningEfforts) routed
68+
via routeModel to moonshot/kimi-k3.1-pro[-highspeed]: configuredReasoningEfforts low/high/max; wire none -> no
69+
reasoning_effort, low->low, medium->high, high->high, xhigh->max, max->max, ultra->max; temperature/top_p/penalties stripped.
70+
- model-roster-seed-repair.test.ts: untouched moonshot seed on intl URL, cn URL, and no URL -> refreshed, existing
71+
containers gain 1M windows + max defaults; custom URL and hand-edited list unchanged.
72+
73+
Red run first on base 0aeaf0cb6b with test edits only.
74+
75+
## Verification (C)
76+
77+
| Command | Expected |
78+
|---|---|
79+
| bun test tests/providers/provider-registry-parity.test.ts tests/providers/model-roster-seed-repair.test.ts tests/usage/usage-cost.test.ts tests/codex-integration/reasoning-effort.test.ts tests/codex-integration/codex-catalog.test.ts | exit 0 |
80+
| bun run typecheck | exit 0 |
81+
| OCX_TEST_RUNNER_BUN=<bun 1.4.3> bun run test:changed | exit 0 except known claude-desktop-remote-hub.test.ts:249 |
82+
| bun run privacy:scan | exit 0 |
83+
| bun run structure:check | exit 0 |
84+
| cd docs-site && bun install --frozen-lockfile && bun run build | exit 0 |
85+
86+
## Audit history
87+
88+
- Round 1 FAIL: (1) none sent on wire for always-thinking K3.1 -> own map with omit; (2) saved rows keep old
89+
roster -> STALE_MODEL_ROSTERS entry. Both folded.
90+
- Round 2 NEAR-PASS: chat-compat.md is 600/600 -> resolved by making no structure edit (rationale above);
91+
stale superseded sections -> this consolidated rewrite.

‎docs-site/src/content/docs/guides/integrations.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ every Codex agent role found in `$CODEX_HOME/agents/*.toml`, with the model each
760760
to. Codex runs a role on that pin no matter which model the parent asks for, so this is where a
761761
role's model is actually decided. LazyCodex counts as installed when the `omo@sisyphuslabs`
762762
Codex plugin is enabled in `$CODEX_HOME/config.toml` and an installed copy under
763-
`$CODEX_HOME/plugins/cache/sisyphuslabs/omo/` carries its `lazycodex-install.json`. A `~/.omo`
763+
`$CODEX_HOME/plugins/cache/sisyphuslabs/omo/` carries its plugin manifest or `lazycodex-install.json`. A `~/.omo`
764764
folder on its own does not count, because Pi-based omo creates it too. Without LazyCodex the
765765
section is hidden and the command line reports it as not installed. Pick a model and a reasoning
766766
effort on a row and press Save. A row whose role has no model pin can save an effort on its own;

0 commit comments

Comments
 (0)