Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5f3f779
fix(review): gate the recovered incremental anchor on the model that …
wenshao Aug 14, 2026
cb366f5
fix(review): certify the ledger anchor with the runtime model identity
wenshao Aug 15, 2026
4938c6b
fix(review): pin the posted marker's model wiring and tighten the anc…
qwen-code-dev-bot Aug 15, 2026
79acdfd
Merge origin/main into fix/review-anchor-model-gate
qwen-code-dev-bot Aug 15, 2026
7b7fa1e
fix(review): shed the anchor pair first and pin the round-3 findings
qwen-code-dev-bot Aug 15, 2026
c16d871
fix(review): scope the identity-channel claims and pin the branch-1 gate
qwen-code-dev-bot Aug 15, 2026
37923d4
fix(review): shed the dead anchor tie-break and pin the reprieve clauses
qwen-code-dev-bot Aug 15, 2026
0791c2f
Merge branch 'main' into fix/review-anchor-model-gate
qwen-code-dev-bot Aug 16, 2026
cc5d36e
Merge remote-tracking branch 'origin/main' into fix/review-anchor-mod…
qwen-code-dev-bot Aug 16, 2026
5e0e625
Merge branch 'main' into fix/review-anchor-model-gate
wenshao Aug 16, 2026
cc7a514
fix(review): stamp the round's model at capture, qualify it by provider
wenshao Aug 16, 2026
06c07ac
docs(review): correct the absent-stamp and model-cap notes
wenshao Aug 16, 2026
73dbd4d
Merge branch 'main' into fix/review-anchor-model-gate
qwen-code-dev-bot Aug 16, 2026
59d25be
Merge branch 'main' into fix/review-anchor-model-gate
wenshao Aug 17, 2026
e862d00
style(review): prettier the reapplied round-model helper
wenshao Aug 17, 2026
148ba9a
fix(review): rule the same-model gate in the CLI, key the identity pe…
wenshao Aug 17, 2026
f01c75b
Merge branch 'main' into fix/review-anchor-model-gate
wenshao Aug 17, 2026
bb66bce
Merge branch 'main' into fix/review-anchor-model-gate
wenshao Aug 17, 2026
a3de5af
fix(review): make the blanked identity fall back, and drop the anchor…
wenshao Aug 17, 2026
ef2e5f3
fix(review): rule the anchor verdict on the sha the side file actuall…
wenshao Aug 18, 2026
4112877
fix(review): move the last identity comparison out of prompt text
wenshao Aug 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions packages/cli/src/commands/review/compose-review.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,67 @@ describe('composeReviewCommand handler (the CLI glue)', () => {
}
});

it('injects the session model into the marker — QWEN_CODE_MODEL reaches the anchor (wiring)', async () => {
// The certifying identity must be the model the session ACTUALLY runs —
// Config publishes it per session, the shell tool injects it into this
// subprocess — not the id the state JSON typed. Dropping the runtime
// argument from the handler's composeReview call leaves the pure-function
// tests green while the posted anchor is certified by the typed id again.
const dir = mkdtempSync(join(tmpdir(), 'compose-runtime-model-'));
const inputPath = join(dir, 'compose.json');
const commentsPath = join(dir, 'comments.json');
const outPath = join(dir, 'composed.json');
writeFileSync(
inputPath,
JSON.stringify({
modelId: 'typed-by-the-model',
planPath: coveredPlan(['verify', 'reverse-audit'], {
prNumber: 8255,
fetchedSha: 'deadbeef00112233',
}),
}),
'utf8',
);
writeFileSync(
commentsPath,
JSON.stringify([
{ path: 'a.ts', line: 3, body: '**[Suggestion]** prefer x' },
]),
'utf8',
);
// The handler strips `env` off the state JSON, so coverage resolves the
// fixture transcripts from the process environment.
const prevDir = process.env['QWEN_CODE_PROJECT_DIR'];
const prevSession = process.env['QWEN_CODE_SESSION_ID'];
const prevModel = process.env['QWEN_CODE_MODEL'];
process.env['QWEN_CODE_PROJECT_DIR'] = ENV['QWEN_CODE_PROJECT_DIR'];
process.env['QWEN_CODE_SESSION_ID'] = ENV['QWEN_CODE_SESSION_ID'];
process.env['QWEN_CODE_MODEL'] = 'the-session-model';
try {
await runComposeReviewCommand({
input: inputPath,
comments: commentsPath,
out: outPath,
});
const written = JSON.parse(
readFileSync(outPath, 'utf8'),
) as ComposeReviewResult;
const ledger = parseLedger(written.body)!;
expect(ledger.sha).toBe('deadbeef00112233');
expect(ledger.model).toBe('the-session-model');
} finally {
for (const [key, prev] of [
['QWEN_CODE_PROJECT_DIR', prevDir],
['QWEN_CODE_SESSION_ID', prevSession],
['QWEN_CODE_MODEL', prevModel],
] as const) {
if (prev === undefined) delete process.env[key];
else process.env[key] = prev;
}
rmSync(dir, { recursive: true, force: true });
}
});

it('pins the persisted footer to the inherited startup version, not the resolved one', async () => {
// Same pin as `submit`: a shared runner rewrites installs under running
// processes, so the version resolved at compose time can disagree with
Expand Down Expand Up @@ -4333,6 +4394,134 @@ describe('the ledger marker reaches the POSTED body', () => {
expect(parseLedger(r.body)?.sha).toBe('deadbeef00112233');
});

it('the anchor carries its model — the same-model contract survives recovery', () => {
// The cache pairs `lastCommitSha` with `lastModelId`, and Step 1 refuses
// the incremental shortcut across models — but the marker's anchor rode
// bare, so a cross-model round that recovered it from the posted body
// scoped `sha..HEAD` past code the current model never reviewed. The
// model that certified the range now travels beside it.
const r = composeReview({
planPath: coveredPlan(['verify', 'reverse-audit'], {
prNumber: 8255,
fetchedSha: 'deadbeef00112233',
}),
env: ENV,
modelId: MODEL,
criticalsInline: 0,
suggestionsInline: 0,
draftedComments: [
{ path: 'src/a.ts', line: 3, body: '**[Suggestion]** untested' },
],
});
const ledger = parseLedger(r.body)!;
expect(ledger.sha).toBe('deadbeef00112233');
expect(ledger.model).toBe(MODEL);
});

it('attribution off: the marker withholds the model WITH the footer', () => {
// `review.attribution` is "whether the posted review names its model".
// The footer is the visible half; the marker rides the same posted body,
// so a model id inside it publishes exactly what the setting removes —
// readable through the API and the raw-body edit view — on a write this
// module calls public and irreversible. Withheld, the anchor degrades to
// the skill's specified fail-safe: absent model → mismatch → full-range.
const r = composeReview(
{
planPath: coveredPlan(['verify', 'reverse-audit'], {
prNumber: 8255,
fetchedSha: 'deadbeef00112233',
}),
env: ENV,
modelId: MODEL,
criticalsInline: 0,
suggestionsInline: 0,
draftedComments: [
{ path: 'src/a.ts', line: 3, body: '**[Suggestion]** untested' },
],
},
'unknown',
false,
);
const ledger = parseLedger(r.body)!;
expect(ledger.sha).toBe('deadbeef00112233');
expect(ledger.model).toBeUndefined();
expect(r.body).not.toContain(MODEL);
});

it('attribution off, modelId absent: the marker SURVIVES — only the model is withheld', () => {
// Attribution off skips the `modelId is required` validation, so a state
// JSON without the field is legal on a clean round. A marker path that
// threw on it would drop the WHOLE marker, not just the model: the round
// counter resets (the next round re-issues ids the PR already carries)
// and the findings work list is lost. Measured: deleting the typeof guard
// survived the suite, so this pins the branch by name.
const r = composeReview(
{
planPath: coveredPlan(['verify', 'reverse-audit'], {
prNumber: 8255,
fetchedSha: 'deadbeef00112233',
}),
env: ENV,
modelId: undefined as unknown as string,
criticalsInline: 0,
suggestionsInline: 0,
draftedComments: [
{ path: 'src/a.ts', line: 3, body: '**[Suggestion]** untested' },
],
},
'unknown',
false,
);
const ledger = parseLedger(r.body)!;
expect(ledger.sha).toBe('deadbeef00112233');
expect(ledger.model).toBeUndefined();
});

it('the anchor carries the RUNTIME identity — injected at the CLI boundary, never typed by the model', () => {
// The certifying model used to be `input.modelId` — a field of the
// model-written state JSON. A review running under one model could type
// another's id, and the posted anchor would certify the range to a model
// that never reviewed it: a later run of that model accepts `sha..HEAD`
// and skips the earlier code. The boundaries now inject the identity the
// session ACTUALLY runs (Config publishes QWEN_CODE_MODEL); the typed
// field is only the fallback for runs no session published.
const r = composeReview(
{
planPath: coveredPlan(['verify', 'reverse-audit'], {
prNumber: 8255,
fetchedSha: 'deadbeef00112233',
}),
env: ENV,
modelId: 'typed-by-the-model',
criticalsInline: 0,
suggestionsInline: 0,
draftedComments: [
{ path: 'src/a.ts', line: 3, body: '**[Suggestion]** untested' },
],
},
'unknown',
true,
'the-session-model',
);
const ledger = parseLedger(r.body)!;
expect(ledger.sha).toBe('deadbeef00112233');
expect(ledger.model).toBe('the-session-model');
});

it('withholds the model WITH the sha on a capped round — it qualifies the anchor, nothing else', () => {
const r = composeReview({
planPath: plan({ fetchedSha: 'deadbeef00112233' }),
modelId: 'm',
criticalsInline: 0,
suggestionsInline: 0,
draftedComments: [{ path: 'a.ts', body: '**[Critical]** boom' }],
});
expect(r.cappedBy.length).toBeGreaterThan(0);
const ledger = parseLedger(r.body)!;
expect(ledger.sha).toBeUndefined();
expect(ledger.model).toBeUndefined();
});

it('withholds the sha when the module ITSELF caps the round', () => {
// The four input fields are not the only fail-closed signals: cappedBy is
// computed in this module from conditions with no input channel at all
Expand Down
48 changes: 46 additions & 2 deletions packages/cli/src/commands/review/compose-review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ export interface ComposeReviewInput {
* handler strips it, as it does `env` and `prBodyFetcher`).
*/
draftedComments?: Array<{ path?: unknown; line?: unknown; body?: unknown }>;
/** Model id for the footer, e.g. `qwen3.7-max`. */
/**
* Model id for the footer, e.g. `qwen3.7-max`. The marker's anchor takes
* the session-published identity instead when the CLI boundary injects one
* (`composeReview`'s `runtimeModelId`); this field is its fallback for runs
* no session published, and what the visible footer names either way.
*/
modelId: string;
}

Expand Down Expand Up @@ -474,14 +479,27 @@ export function composeReview(
input: ComposeReviewInput,
cliVersion = 'unknown',
attribution = true,
/**
* The model identity the RUNTIME publishes as active — `QWEN_CODE_MODEL`,
* injected by the two CLI boundaries from the environment the session
* exports. The marker's anchor certifies with THIS, never with the
* model-written state field alone; `input.modelId` is the fallback for
* runs no session published. Undefined in tests that call this directly.
*/
runtimeModelId?: string,
): ComposeReviewResult {
const result = composeReviewBody(input, cliVersion, attribution);
// The ledger marker rides the body THIS function returns, because this — not
// the CLI handler — is what `submit` calls and posts. Appending it in the
// handler left the feature inert end to end: the marker reached only the
// composed JSON on disk, which nothing in the posting path reads, so no
// posted review ever carried one and every round recovered `null`.
const marker = ledgerMarkerFor(input, result.cappedBy);
const marker = ledgerMarkerFor(
input,
result.cappedBy,
attribution,
runtimeModelId,
);
return marker ? { ...result, body: `${result.body}\n\n${marker}` } : result;
}

Expand All @@ -493,6 +511,8 @@ export function composeReview(
function ledgerMarkerFor(
input: ComposeReviewInput,
cappedBy: string[],
attribution: boolean,
runtimeModelId: string | undefined,
): string | null {
try {
if (!input.planPath) return null;
Expand Down Expand Up @@ -543,6 +563,25 @@ function ledgerMarkerFor(
!failClosed && typeof plan.fetchedSha === 'string'
? plan.fetchedSha
: undefined;
// The anchor's same-model qualifier: "clean up to `sha`" is THIS model's
// verdict, and Step 1's recovered-anchor gate refuses to scope another
// model's round to it. The identity is the one the RUNTIME published —
// the boundaries inject it, a model cannot type it — with the
// model-written field only as the fallback for runs no session published
// (and boundary-validated then whenever attribution is on): a review
// running under one model could otherwise type another's id and certify
// the range to a model that never reviewed it. Withheld entirely when
// attribution is off: the setting's contract is "whether the posted
// review names its model", the marker rides the posted body, and a
// suppression the footer honours must reach the invisible half too — the
// anchor then degrades to the skill's absent-model fail-safe. The
// serializer writes it only beside a sha.
const runtime =
typeof runtimeModelId === 'string' ? runtimeModelId.trim() : '';
Comment on lines +999 to +1000

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted — the trim→declared-fallback branch is unpinned as described, and the proposed test is the right shape. Deferred this round for two recorded reasons: the growth brake forbids further changes of any kind this round, and tests are exactly the bucket over budget (482/400), so even a one-test pin grows the overage. Slated for the same bounded round as the R6-1 fix if the maintainer approves the handoff recommendation; otherwise it will be tracked with it as a follow-up. Thread stays open.

中文说明

接受 —— trim→填写值回退分支确实如描述所述没有被测试固定,提议的测试形态也是对的。本轮延后,记录两条原因:增长刹车禁止本轮做任何改动;测试恰是超预算的桶(482/400),即便只加一个测试也会扩大超出量。若维护者批准交接中的建议,它与 R6-1 的修复安排在同一有界轮次;否则作为跟进事项一并追踪。线程保持开放。

const declared =
typeof input.modelId === 'string' ? input.modelId.trim() : '';
const certifying = runtime !== '' ? runtime : declared;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still escalated for a maintainer decision — deliberately unchanged this round. The point turns on the identity contract: accept the bare runtime model id (QWEN_CODE_MODEL, typed-state fallback) and record the two-provider collision as a documented limitation, or track a provider-aware identity (auth type + provider/endpoint discriminator) as a follow-up. That call is a maintainer's, not the review loop's, so the thread stays open with the same question as rounds 1–2. One fact for the decision: the platform/provider abstraction that landed on main since the last escalation is about review platforms (GitHub vs Aone Code), not model providers — it does not settle this. No other round-3 finding touches the identity contract.

中文说明

仍在等待维护者决策——本轮刻意未做改动。这一点取决于身份契约的选择:接受裸运行时模型 id(QWEN_CODE_MODEL,以模型填写的 state 字段为回退)并把双 provider 碰撞作为已记录的局限,还是将 provider 感知的身份(auth type + provider/endpoint 区分信息)作为跟进任务追踪。该决定权在维护者而非审查循环,因此线程保持打开,问题与第 1–2 轮相同。为决策补充一个事实:自上次升级后 main 上落地的 platform/provider 抽象针对的是审查平台(GitHub 与 Aone Code),而非模型 provider,并不能解决本问题。第 3 轮其余反馈均不涉及身份契约。

Comment on lines +999 to +1003

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round disposition: escalated to maintainers — no code change this round (thread stays open).

Re-verified at this head: both identity arms are still bare model strings (runtime = QWEN_CODE_MODEL env, declared = state.modelId), with no authType/provider/endpoint discriminator — the finding's code reading is accurate. The collision scenario itself is not reproduced here: demonstrating it needs a live two-provider setup resolving one model id to two different underlying models (this round's witness is likewise "not run"). Rounds 1–3 already established this as a maintainer decision rather than a code fix, and that decision is still open, so this round implements neither direction.

The decision requested is one of:

  • Option A (the recorded recommendation): accept the bare runtime id as this PR's identity contract, record the limitation in DESIGN.md, and track a provider-aware identity (auth type + provider/endpoint discriminator, same identity for the cache and posted-ledger gates) as a follow-up. Rationale: the failure scenario is narrow (two live configurations colliding on one model id, plus an anchor shared across environments), and option B spans the core auth/provider/config surface and would grow this PR's diff far past the current window's budget.
  • Option B: require the provider-aware identity in this PR.

Either answer lands as ordinary feedback next round; option A would add the limitation note to DESIGN.md before merge.

中文说明

本轮处置:升级给维护者——本轮不改代码(线程保持开放)。

已在当前 head 上复核:两个身份分支仍是裸的模型字符串(runtime = QWEN_CODE_MODEL 环境变量,declared = state.modelId),没有 authType/provider/endpoint 区分信息——本条反馈对代码的读取准确。碰撞场景本身未在此处复现:要证明它需要一套真实的双 provider 环境,使同一个模型 id 解析为两个不同的底层模型(本轮见证同样是"未运行")。第 1–3 轮已把这一点确定为维护者决策而非代码修复,该决策仍未落地,因此本轮不实施任一方向。

请求的决策二选一:

  • 选项 A(记录在案的建议):接受裸运行时 id 作为本 PR 的身份契约,把该局限记录进 DESIGN.md,并将 provider 感知的身份(auth type + provider/endpoint 区分信息,缓存与已发布 ledger 两个闸门使用同一身份)作为跟进任务追踪。理由:失败场景窄(需要两个真实配置在同一个模型 id 上碰撞,且 anchor 跨环境共享);选项 B 横跨 core 的 auth/provider/config 表面,会把本 PR 的 diff 撑到远超当前窗口预算。
  • 选项 B:在本 PR 中就要求 provider 感知的身份。

任一答复都会在下一轮作为普通反馈落地;若选 A,合入前会把局限说明补进 DESIGN.md。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still escalated, not implemented — this finding turns on the maintainer decision that has been open since round 1, and this round changed nothing about the identity (verified at 37923d4b9d: both arms of certifying = runtime !== '' ? runtime : declared in ledgerMarkerFor remain bare model-id strings).

The decision, as before:

  • Option A — accept the bare runtime model id as this PR's identity contract; record the two-provider limitation (two provider/endpoint configurations exposing the same model ID while resolving to different underlying models ⇒ the second configuration accepts the first's anchor and scopes past code it never reviewed) in DESIGN.md, and track a richer identity as a follow-up issue.
  • Option B — persist and compare a stable resolved-model identity including the relevant auth type and provider/endpoint discriminator, using the same identity for the cache and posted-ledger gates.

Recommendation: Option A. The collision needs two live configurations that agree on a model id but disagree on the underlying model; the findings work list still crosses configurations intact (only the anchor travels on the id); and this PR is at round 5 under the diff-growth brake — option B adds identity machinery beside the auth path to a diff already over budget. If the limitation is unacceptable, B is the honest fix, but it is a design change a maintainer should shape.

Question for the maintainer: A or B (or a third option)? The answer lands as ordinary feedback next round; until then this thread stays open.

中文说明

仍然保持升级上报状态,未实施——该发现取决于自第 1 轮起一直开放的维护者决策,且本轮未对身份做任何改动(已在 37923d4b9d 上核实:ledgerMarkerFor 中 certifying = runtime !== '' ? runtime : declared 的两个分支仍是裸模型 id 字符串)。

决策与之前一致:

  • 选项 A — 接受裸运行时模型 id 作为本 PR 的身份契约;把双 provider 局限(两个 provider/endpoint 配置暴露相同的模型 ID、却解析为不同的底层模型 ⇒ 第二个配置会接受第一个配置的 anchor,并把范围缩小到它从未审查过的代码之后)记录进 DESIGN.md,将更丰富的身份作为跟进任务追踪。
  • 选项 B — 持久化并比较包含相关 auth type 与 provider/endpoint 区分信息的稳定解析模型身份,缓存与已发布 ledger 两个闸门使用同一身份。

建议:选项 A。该碰撞需要两套模型 id 相同、底层模型却不同的在线配置;findings 工作列表仍会完整跨配置传递(只有 anchor 依赖该 id);且本 PR 已进行到第 5 轮并处于 diff 增长刹车之下——选项 B 会在认证路径旁为已超预算的 diff 增加身份机制。若该局限不可接受,B 才是诚实的修法,但那是应由维护者主导的设计变更。

给维护者的问题: A 还是 B(或第三种方案)?答复将在下一轮作为普通反馈进入;在此之前本线程保持开放。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This round is a maintainer-decision handoff: the growth brake engaged (3+ rounds over budget), which forbids further code changes this round, and this finding has been escalated for exactly this decision since round 1. Re-verified at the current HEAD — both arms of certifying in ledgerMarkerFor are bare model-id strings with no provider discriminator, so the blocker stands as described.

The open question for the maintainer: option A — accept the bare runtime id as this PR's identity contract, record the two-provider limitation in DESIGN.md, and track a provider-aware identity as a follow-up issue; or option B — implement the provider-aware identity before merge. Recommendation on record: A — the collision trigger is exotic, the marker channel is already documented as not a forgery boundary, the gate fails safe on mismatch, and option B is follow-up-sized — but the call is the maintainer's. Thread stays open until it is answered.

中文说明

本轮是一次交由维护者决策的交接:增长刹车已触发(连续 3 轮以上超出预算),本轮禁止再做任何代码修改,而本条发现自第 1 轮起升级上报的正是这一决策。已在当前 HEAD 复核 —— ledgerMarkerFor 中 certifying 的两个分支都是裸模型 id 字符串,没有任何 provider 区分信息,阻断项所述仍然成立。

留给维护者的问题:选项 A —— 接受裸运行时 id 作为本 PR 的身份契约,把双 provider 局限记录进 DESIGN.md,并将 provider 感知的身份作为跟进 issue 追踪;或 选项 B —— 在合并前实现 provider 感知的身份。已记录的推荐:A —— 碰撞触发条件苛刻,marker 通道本就记录在案、不是防伪造边界,闸门在不匹配时 fail safe,且选项 B 属于跟进级别的工作量 —— 但决定权在维护者。线程保持开放,等待答复。

const model = attribution && certifying !== '' ? certifying : undefined;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This round deliberately leaves the blocker unresolved. At this commit the marker's certifying identity is still the bare runtime model string (QWEN_CODE_MODEL, with the model-written state field as the fallback) — no authType/provider/endpoint discriminator — so the round-1 claim still stands, and this round did not attempt to implement either remedy unilaterally.

The previous round escalated exactly this point for a maintainer decision, and that decision is still open. The two options, restated:

  • Option A — accept the bare runtime model id as this PR's identity contract, record the limitation (two provider/endpoint configurations exposing the same model id while resolving to different underlying models would share anchors), and track a provider-aware identity as a follow-up issue.
  • Option B — require the richer identity in this PR: persist and compare a stable resolved-model identity including the relevant auth type and provider/endpoint discriminator, used identically for the cache and posted-ledger gates.

Recommendation on record: Option A. This PR's threat model is forgery through model-typed channels, which the runtime injection closes; cross-provider id collision is a narrower scenario, and fixing it requires a design decision across the core auth/provider/config surface, which is maintainer-only per AGENTS.md. This thread stays UNRESOLVED until a maintainer chooses; the answer arrives as ordinary feedback next round.

中文说明

本轮有意保持该阻断项未解决。在本提交上,marker 的认证身份仍是裸的运行时模型字符串(QWEN_CODE_MODEL,以模型自己填写的 state 字段作为回退)——没有 authType/provider/endpoint 区分信息——因此第 1 轮的主张依然成立,本轮也没有单方面实施任何一种补救方案。

上一轮已就这一点升级上报、等待维护者决策,该决策仍未落地。两个选项重述如下:

  • 选项 A — 接受裸运行时模型 id 作为本 PR 的身份契约,记录其局限(两个暴露相同模型 id、却解析为不同底层模型的 provider/endpoint 配置会共享 anchor),并将 provider 感知的身份作为跟进 issue 追踪。
  • 选项 B — 在本 PR 中就要求更丰富的身份:持久化并比较包含相关 auth type 与 provider/endpoint 区分信息的稳定解析模型身份,缓存与已发布 ledger 两个闸门使用同一身份。

记录在案的建议:选项 A。本 PR 的威胁模型是经由模型可填写通道的伪造,运行时注入已经关闭了该通道;跨 provider 的 id 冲突是更窄的场景,其修复需要在 core 的 auth/provider/config 表面做设计决策——按 AGENTS.md 属维护者专属。该线程保持未解决,直到维护者作出选择;答复会在下一轮作为普通反馈到达。

return serializeLedger({
...buildLedger(
prevRound + 1,
Expand All @@ -556,6 +595,7 @@ function ledgerMarkerFor(
.filter((entry) => entry.trim() !== ''),
),
...(sha ? { sha } : {}),
...(model ? { model } : {}),
});
} catch {
// A carry-forward convenience, never worth failing the verdict over.
Expand Down Expand Up @@ -2342,6 +2382,10 @@ export const composeReviewCommand: CommandModule = {
footerVersion(process.env['QWEN_CODE_STARTUP_VERSION']) ??
(await getCliVersion()),
operatorReviewSettings().attribution,
// The anchor's certifying identity is the model the session ACTUALLY
// runs — Config publishes it per session, the shell tool injects it
// into this subprocess — not the id the state JSON typed.
process.env['QWEN_CODE_MODEL'],
);
// The exact terminal verdict, persisted beside the fields it is computed
// from. `event` + `cappedBy` alone cannot reconstruct it — a presubmit
Expand Down
83 changes: 83 additions & 0 deletions packages/cli/src/commands/review/lib/ledger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
LEDGER_MAX_FILE,
LEDGER_MAX_TITLE,
LEDGER_MAX_BYTES,
LEDGER_MAX_MODEL,
type Ledger,
} from './ledger.js';

Expand Down Expand Up @@ -116,6 +117,88 @@ describe('ledger marker', () => {
expect(parseLedger(body)).toEqual(anchored);
});

it('round-trips the anchor model beside the sha — incremental is a same-model contract', () => {
// The cache pairs `lastCommitSha` with `lastModelId`; the marker's anchor
// rode bare, so a round under another model that recovered it would scope
// `sha..HEAD` past code the current model never reviewed.
const anchored: Ledger = {
...LEDGER,
sha: 'abc1234def567890',
model: 'qwen3.7-max',
};
expect(parseLedger(`Reviewed.\n\n${serializeLedger(anchored)}`)).toEqual(
anchored,
);
});

it('the model rides and falls WITH the anchor, on write and on read', () => {
// A model naming no range qualifies nothing: the serializer withholds it
// wherever it withholds the sha (fail-closed, truncated), and the parser
// drops a hand-edited model whose sha did not survive.
expect(serializeLedger({ ...LEDGER, model: 'qwen3.7-max' })).not.toContain(
'model',
);
const truncated = serializeLedger({
v: 1,
round: 2,
sha: 'abc1234def567890',
model: 'qwen3.7-max',
findings: Array.from({ length: LEDGER_MAX_FINDINGS + 1 }, (_, i) => ({
id: `R2-${i}`,
sev: 'C' as const,
file: 'src/a.ts',
title: 'x',
})),
});
expect(parseLedger(truncated)!.model).toBeUndefined();
for (const forged of [
'<!-- qwen-review-ledger {"v":1,"round":1,"findings":[],"model":"qwen3.7-max"} -->',
'<!-- qwen-review-ledger {"v":1,"round":1,"findings":[],"sha":"not hex","model":"qwen3.7-max"} -->',
]) {
expect(parseLedger(forged)!.model).toBeUndefined();
}
});

it('normalises the model on both sides — trimmed, WHOLE, never a non-string', () => {
// The model rides whole or not at all: a truncated id is a prefix, and a
// prefix can equal a DIFFERENT model's full id — the same-model gate
// would then scope that other model past code it never reviewed
// (probe-measured: a 75-char id recovered as its 64-char prefix compared
// equal to the prefix's owner). On WRITE an over-cap model takes the
// anchor pair with it; on READ an over-cap model is one the serializer
// would never have written, so it drops — the gate reads the absence as
// a mismatch — and the sha survives.
const wide = serializeLedger({
v: 1,
round: 1,
findings: [],
sha: 'abc1234',
model: ` ${'m'.repeat(LEDGER_MAX_MODEL + 1)} `,
});
expect(wide).not.toContain('"model"');
expect(wide).not.toContain('"sha"');
const forged = parseLedger(
`<!-- qwen-review-ledger {"v":1,"round":1,"findings":[],"sha":"abc1234","model":${JSON.stringify('x'.repeat(LEDGER_MAX_MODEL + 1))}} -->`,
);
expect(forged!.sha).toBe('abc1234');
expect(forged!.model).toBeUndefined();
// Exactly at the cap the identity rides whole — trimmed on both sides.
const full = serializeLedger({
v: 1,
round: 1,
findings: [],
sha: 'abc1234',
model: ` ${'m'.repeat(LEDGER_MAX_MODEL)} `,
});
const recovered = parseLedger(full)!;
expect(recovered.model).toHaveLength(LEDGER_MAX_MODEL);
expect(recovered.model).toBe('m'.repeat(LEDGER_MAX_MODEL));
for (const model of ['', ' ', 42, null]) {
const raw = `<!-- qwen-review-ledger {"v":1,"round":1,"findings":[],"sha":"abc1234","model":${JSON.stringify(model)}} -->`;
expect(parseLedger(raw)!.model).toBeUndefined();
}
});

it('a truncated ledger loses its anchor — a partial work list must not certify a range', () => {
// Dropped entries reference code at or before the anchored head; a next
// round scoped to `sha..HEAD` would never re-see it, and Step 6 rules
Expand Down
Loading
Loading