Skip to content

fix: unify member context capacity and lifecycle (#1208) - #1209

Merged
zts212653 merged 62 commits into
zts212653:mainfrom
mindfn:fix/1208-codeagent-handoff-usage
Aug 10, 2026
Merged

fix: unify member context capacity and lifecycle (#1208)#1209
zts212653 merged 62 commits into
zts212653:mainfrom
mindfn:fix/1208-codeagent-handoff-usage

Conversation

@mindfn

@mindfn mindfn commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1208. Member context capacity previously came from several independent configuration and fallback paths, so prompt budgeting, context health, lifecycle decisions, and native provider configuration could disagree. This PR replaces those paths with one invocation-owned capacity snapshot, one effective member Context Window setting, and one minimal active-session capacity pin.

Final behavior

  • One member setting: contextWindow
    • empty or 0 in Hub = Auto
    • positive integer = Manual cap
    • legacy cli.contextWindow remains readable and can be explicitly cleared back to Auto
  • One resolution flow per invocation:
    • a trusted provider report limits a larger Manual cap: min(manual, trusted report)
    • without Manual, a trusted provider report wins
    • otherwise Auto may use provisional model-catalog capacity
    • unknown bindings remain unresolved
  • Catalog capacity is provisional. It becomes lifecycle-actionable only when the same invocation proves the exact model/window on its carrier and the provider exposes authoritative current-context usage telemetry.
  • The same refined invocation snapshot is consumed by prompt assembly, context health, pre-provider lifecycle sealing, and native provider configuration.
  • Each active session persists only a minimal SessionCapacityPin containing resolved capacity fields:
    • later invocations may shrink the active-session capacity
    • capacity cannot silently expand until session rollover
    • provider/model binding proof remains invocation-scoped and is not persisted as a reusable cache
  • Provider boundaries remain fail-closed:
    • OpenCode applies per-invocation native configuration and binding proof
    • ACP owns binding at service spawn
    • Codex exec_json exposes deterministic model/window binding before preflight
    • Codex app_server stays non-actionable until runtime proof exists
  • The legacy four-field contextBudget configuration is retired from public/runtime surfaces; old catalog JSON is tolerated only at the read boundary.
  • Missing authoritative usage remains user-visible and is persisted consistently across serial and parallel routing.

There is no hidden 128K provider fallback, no persistent provider/model binding cache, and no generic capability-only promotion of Auto catalog capacity.

Verification

  • Author fix commit b670e19f2d0c4713fbd49f7063aad68ce16d856d: targeted capacity/persistence suite 246/246 green.
  • Current exact HEAD 256ccc4c31a4e3c812c86063ba48a75470b44fa4 merges current base 54c9c37f1ddabee8562fccdc80804815defb575c; author full gate passed with 20,061 tests and all repository checks.
  • Independent maintainer verification on the exact current HEAD:
    • packages/api build: PASS
    • core capacity/provider/routing/store suite: 557/557 PASS
    • merge-interaction stop-gate, warning persistence, and carrier capability suite: 44/44 PASS
    • git diff --check: PASS
    • formal exact-HEAD review: APPROVE / PASS, 0 P1 / 0 P2
  • GitHub CI: 5/5 checks green.

Risk assessment (five axes)

  • Behavior: High — changes preflight sealing, session lifecycle, and model/window switching.
  • Data: Medium — persists a minimal session capacity pin; no destructive migration.
  • Security: Low — no authentication or privilege boundary change.
  • Contract: High — changes the AgentService capacity contract, API projection, and native provider configuration.
  • Irreversibility: Low — ordinary reversible code changes; runtime activation is separate and remains dormant after merge unless explicitly authorized.

Scope boundary

The separately discussed passive compress / hybrid Session Strategy semantics were explicitly withdrawn from this PR and are not changed here.

Refs #1208

@mindfn
mindfn requested a review from zts212653 as a code owner July 24, 2026 04:04

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b760d3d28

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/domains/cats/services/agents/providers/OpenCodeAgentService.ts Outdated
@mindfn
mindfn force-pushed the fix/1208-codeagent-handoff-usage branch 2 times, most recently from 29d75ce to f8e550f Compare July 24, 2026 04:21
@mindfn

mindfn commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

@chatgpt-codex-connector @sol 已按 P2 review 修复,当前 SHA: f8e550f

改动

  • 将无 usage telemetry 时发出的 system_info 从自定义 "missing_usage_alert" 改为复用已有的 "warning" 类型。
  • "warning" 已同时进入:
    • Web 可见格式化器 "packages/web/src/hooks/system-info-visible.ts"(formatVisibleSystemInfo → ⚠️ message)
    • 路由白名单 "packages/api/src/domains/cats/services/agents/routing/route-helpers.ts"(USER_FACING_SYSTEM_INFO_TYPES)
      因此前台会显示可读警告、后台不会追加 misleading silent_completion、刷新后可恢复。

测试

  • 更新 opencode-agent-service.test.js:无 usage 时断言发出 type=warning,有 usage 时不发 warning。
  • 新增 system-info.test.js:断言 isUserFacingSystemInfoContent 识别 warning、不识别过时的 missing_usage_alert。
  • API 相关测试 195 pass / 0 fail;Web warning 测试 7 pass / 0 fail。
  • pnpm biome check 仅既有 warning,无新增错误。

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create an environment for this repo.

@mindfn

mindfn commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f8e550f504

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/config/context-window-sizes.ts
…653#1208)

- P1: When provider is opencode and the CLI does not report usage.contextWindowSize,
  default to OPENCODE_DEFAULT_CONTEXT_WINDOW (128K) instead of the model fallback table.
  Direct-provider paths still use the fallback table + KNOWN_MIN floor.
- P2: Persist user-facing warning system_info events to messageStore as
  connector=system-warning / presentation=system_notice, so the warning survives
  refresh. The live stream already delivers the event, so no second broadcast.
- Update targeted tests for the new opencode default and warning persistence.
@mindfn

mindfn commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

已按最新 review 修复 P1/P2,当前 HEAD:05987cb1f

P1:OpenCode gateway 128K 默认

  • invoke-single-cat.ts:provider='opencode' 且 usage.contextWindowSize 未显式提供时,直接使用 OPENCODE_DEFAULT_CONTEXT_WINDOW(128K),不再走模型 fallback table 的 1M。
  • 直接 provider 路径(Claude CLI 等)仍走 fallback table + KNOWN_MIN floor。
  • context-window-sizes.ts 注释已更新,说明 opencode 默认不再使用模型 fallback table。

P2:无 usage 告警持久化

  • OpenCodeAgentService.ts 继续发出 type='warning'system_info(已在前端 formatter / 路由白名单中)。
  • route-serial.ts 收集 user-facing warning system_info,在 stream 结束后以 connector='system-warning'presentation='system_notice' 写入 messageStore;不再二次 broadcast,避免重复渲染。

验证证据

  • pnpm --filter @cat-cafe/api run build
  • node --test test/invoke-single-cat.test.js:121 pass / 0 fail ✅
  • node --test test/opencode-agent-service.test.js:全部通过 ✅
  • node --test test/system-info.test.js:6 pass / 0 fail ✅
  • node --test test/route-serial-empty-result-recovery.test.js test/route-serial-error-persistence.test.js test/route-serial-routing-guard-remedial.test.js:26 pass / 0 fail ✅
  • node --test test/route-serial-notice-contract.test.js:新增 P2 用例通过 ✅;但预存在用例 emits routing-syntax-hint with explicit system_notice presentation metadata 失败(已在干净 base f8e550f50 复现,与本次修改无关)。
  • pnpm --filter @cat-cafe/api exec biome check --changed --since=main --no-errors-on-unmatched:exit 0,13 个既有 warning,无新增错误 ✅
  • pnpm --filter @cat-cafe/api test(全量)失败,失败点均与本次改动无关:缺失 .claude/settings.json / hooks、缺失 scripts/signal-fetcher-launchd.sh、root-md 内容断言、memory fixture 缺失、redis 恢复脚本环境等。

请重新 review。

@mindfn
mindfn force-pushed the fix/1208-codeagent-handoff-usage branch from f8e550f to 05987cb Compare July 26, 2026 09:49

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f8e550f504

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/config/context-window-sizes.ts
@mindfn
mindfn force-pushed the fix/1208-codeagent-handoff-usage branch from 05987cb to b1c9cd8 Compare July 26, 2026 09:59
@mindfn

mindfn commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

已根据第二轮 review 修正 P2 的边界情况,当前 HEAD:b1c9cd8bf

针对本轮 review 的改动

  • P2 的 warning 持久化原来只放在 no-text 分支,导致 cat 同时产出文本和 warning 时 warning 只进入 live stream、不进 messageStore。已把持久化逻辑移到所有分支之后的公共路径(route-serial.ts:3366 起),现在 text+warning 的回合也会写入 system-warning / system_notice
  • 新增 route-serial-notice-contract.test.js 用例:cat 产出文本 + warning system_info 时,文本和 warning 都持久化,且 warning 不二次 broadcast。

验证证据

  • pnpm --filter @cat-cafe/api run build
  • node --test test/invoke-single-cat.test.js:121 pass / 0 fail ✅
  • node --test test/opencode-agent-service.test.js test/system-info.test.js:全部通过 ✅
  • node --test test/route-serial-notice-contract.test.js:3 tests / 2 pass / 1 fail(预存在 routing-syntax-hint 用例,与本次改动无关)
  • node --test test/route-serial-empty-result-recovery.test.js test/route-serial-error-persistence.test.js test/route-serial-routing-guard-remedial.test.js:26 pass / 0 fail ✅
  • pnpm --filter @cat-cafe/api exec biome check --changed --since=main --no-errors-on-unmatched:exit 0,34 个既有 warning,无新增错误 ✅

请重新 review。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b1c9cd8bf7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/domains/cats/services/agents/routing/route-serial.ts Outdated
@mindfn
mindfn force-pushed the fix/1208-codeagent-handoff-usage branch from b1c9cd8 to 599ecaf Compare July 26, 2026 10:08
@mindfn

mindfn commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

已按第三轮 review 把 warning 持久化扩展到 routeParallel,当前 HEAD:599ecaf0b

针对本轮 review 的改动

  • 之前 P2 持久化只覆盖了 routeSerial;review 指出 #ideate 请求会走 routeParallel
  • route-parallel.ts 中新增 catUserFacingSystemInfoContents 收集,并在每个 cat 的 text/no-text/error 分支之后以 system-warning / system_notice 写入 messageStore,与 routeSerial 对称,不二次 broadcast。
  • 新增 route-parallel-warning-persistence.test.js 用例验证 parallel 模式下 text+warning 场景。

验证证据

  • pnpm --filter @cat-cafe/api run build
  • node --test test/invoke-single-cat.test.js:121 pass / 0 fail ✅
  • node --test test/opencode-agent-service.test.js test/system-info.test.js:全部通过 ✅
  • node --test test/route-serial-notice-contract.test.js test/route-parallel-warning-persistence.test.js:4 tests / 3 pass / 1 fail(预存在 routing-syntax-hint 用例,与本次改动无关)
  • node --test test/route-serial-empty-result-recovery.test.js test/route-serial-error-persistence.test.js test/route-serial-routing-guard-remedial.test.js:26 pass / 0 fail ✅
  • pnpm --filter @cat-cafe/api exec biome check --changed --since=main --no-errors-on-unmatched:exit 0,34 个既有 warning,无新增错误 ✅

请重新 review。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 599ecaf0b0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/domains/cats/services/agents/routing/route-parallel.ts Outdated
@mindfn
mindfn force-pushed the fix/1208-codeagent-handoff-usage branch from 599ecaf to c51075c Compare July 26, 2026 10:21
@mindfn

mindfn commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

当前 SHA: c51075c7f

本轮按最新 P2 review 修复了 warning 持久化失败时的状态上报:

  • route-serial.tsroute-parallel.tsmessageStore.append 抛异常时,都会设置 options.persistenceContext.failed = true 并把错误信息写入 errors
  • 新增两个 targeted 测试验证 persistenceContext 在 warning 持久化失败时被正确标记。

本地验证:

  • pnpm --filter @cat-cafe/api run build
  • node --test test/invoke-single-cat.test.js:121 pass / 0 fail ✅
  • node --test test/opencode-agent-service.test.js test/system-info.test.js:39 pass / 0 fail ✅
  • node --test test/route-serial-empty-result-recovery.test.js test/route-serial-error-persistence.test.js test/route-serial-routing-guard-remedial.test.js:26 pass / 0 fail ✅
  • node --test test/route-serial-notice-contract.test.js test/route-parallel-warning-persistence.test.js:新增 persistence-failure 用例通过;唯一失败的 routing-syntax-hint 用例已在干净 base 复现,与本次改动无关。
  • biome check --changed --since=main:exit 0,仅既有 warning,无新增错误。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c51075c7f1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/domains/cats/services/agents/routing/route-serial.ts Outdated
Comment thread packages/api/src/domains/cats/services/agents/routing/route-parallel.ts Outdated
Comment thread packages/api/src/domains/cats/services/agents/providers/OpenCodeAgentService.ts Outdated
@mindfn
mindfn force-pushed the fix/1208-codeagent-handoff-usage branch 2 times, most recently from 29e93b8 to 977452a Compare July 26, 2026 10:32
@mindfn

mindfn commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator Author

Review feedback response (current HEAD: 977452af5)

针对本次 codex review 的三条 P2 finding 回复如下:


1. P2 — Propagate serial warning persistence failures (route-serial.ts:3395)

已处理。warning 持久化失败的 catch 块里已设置 options.persistenceContext.failed = true 并 push error 到 errors 数组:

// route-serial.ts:3396-3401
if (options.persistenceContext) {
  options.persistenceContext.failed = true;
  options.persistenceContext.errors.push({
    catId: catId as string,
    error: noticeErr instanceof Error ? noticeErr.message : String(noticeErr),
  });
}

新增 route-serial-notice-contract.test.js 用例 issue #1208 P2: reports warning persistence failure via persistenceContext 验证该行为。


2. P2 — Propagate parallel warning persistence failures (route-parallel.ts:1510)

已处理。route-parallel.ts 中对称地设置了 options.persistenceContext.failed = true 并记录 error:

// route-parallel.ts:1511-1516
if (options.persistenceContext) {
  options.persistenceContext.failed = true;
  options.persistenceContext.errors.push({
    catId: msg.catId,
    error: noticeErr instanceof Error ? noticeErr.message : String(noticeErr),
  });
}

新增 route-parallel-warning-persistence.test.js 用例验证 parallel 模式下的 persistenceContext 失败传播。


3. P2 — Require usable input telemetry before suppressing the warning (OpenCodeAgentService.ts)

已处理。usageTelemetryReceived 现在只在 metadata.usage 包含可用的 context-fill 分子(inputTokens / lastTurnInputTokens / totalTokens)时才置为 true:

// OpenCodeAgentService.ts:385-391
const receivedUsage = result.metadata?.usage;
if (
  receivedUsage != null &&
  (typeof receivedUsage.inputTokens === number ||
    typeof receivedUsage.lastTurnInputTokens === number ||
    typeof receivedUsage.totalTokens === number)
) {
  usageTelemetryReceived = true;
}

仅有 outputTokens 不再抑制 warning。新增 opencode-agent-service.test.js 测试 issue #1208: output-only usage still yields warning alert 覆盖该场景。


本地验证结果:

  • pnpm --filter @cat-cafe/api run build
  • node --test test/opencode-agent-service.test.js:34 pass / 0 fail ✅
  • node --test test/route-serial-notice-contract.test.js test/route-parallel-warning-persistence.test.js:5 pass / 1 fail;失败的是预存在的 routing-syntax-hint 用例,与本次改动无关。

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 977452af52

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/domains/cats/services/agents/routing/route-serial.ts Outdated
Comment thread packages/api/src/domains/cats/services/agents/routing/route-parallel.ts Outdated
@mindfn
mindfn force-pushed the fix/1208-codeagent-handoff-usage branch from 977452a to 926cb5f Compare July 26, 2026 10:42
@mindfn

mindfn commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator Author

Review feedback response (current HEAD: 926cb5fae)

针对 codex review 的两条新 P2 finding 回复如下:


1. P2 — Keep serial parse errors out of persistence failures (route-serial.ts:3377)

已处理。warning 持久化逻辑现在把 JSON.parsemessageStore.append 分开捕获:

// route-serial.ts:3376-3385
let parsed;
try {
  parsed = JSON.parse(systemInfoContent);
} catch (parseErr) {
  log.warn({ catId, err: parseErr }, Ignoring non-JSON user-facing system_info content);
  continue;
}
if (parsed.type !== warning || typeof parsed.message !== string) {
  continue;
}
try {
  await deps.messageStore.append({ ... });
} catch (noticeErr) {
  // 仅 append 失败才标记 persistenceContext.failed
}

legacy/malformed plain-text system_info 不再被当作 persistence failure。新增 route-serial-notice-contract.test.js 用例 malformed system_info does not mark persistenceContext failed 验证该行为。


2. P2 — Keep parallel parse errors out of persistence failures (route-parallel.ts:1492)

已处理。route-parallel.ts 中对称地分离了 parse 和 append 的异常处理(route-parallel.ts:1491-1500),malformed system_info 仅记录 warn 并 continue,不会标记 persistenceContext.failed。新增 route-parallel-warning-persistence.test.js 用例验证 parallel 模式下 parse 错误不传播为 persistence failure。


本地验证结果:

  • pnpm --filter @cat-cafe/api run build
  • node --test test/route-serial-notice-contract.test.js test/route-parallel-warning-persistence.test.js:7 pass / 1 fail;失败的是预存在的 routing-syntax-hint 用例,与本次改动无关。

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 926cb5fae1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mindfn

mindfn commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator Author

当前状态汇总(HEAD: 926cb5fae):

  • GitHub CI 全部通过(Lint / Build / Directory Size Guard)。
  • 最新一轮 Codex re-review 未发现 major issues(Reviewed commit: 926cb5fae)。
  • 所有历史 inline review threads 已标记为 resolved。
  • 本次改动范围与 issue Bug: 成员 Context Limit 未统一持久化,自动 handoff 可越过真实窗口 #1208 一致:修复 OpenCode facade 的 usage/handoff 链,无 usage telemetry 时发出持久化可见 warning,并修正 Claude 4.6 在 OpenCode 路径下的 context window fallback。

请 maintainer 抽时间 review;如有需要调整的地方我会继续跟进。

@mindfn mindfn left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Cross-family Review — 放行 ✅

Reviewer: 布偶猫/宪宪 (claude-opus-4-6)
PR Author: 狸花猫/kimi (k3)
Scope: 5 source files + 6 test files, 1 squashed commit

核心逻辑验证

1. invoke-single-cat.ts — THE FIX

旧逻辑:resolveContextWindow(contextWindowSize, model) ?? (opencode ? 128K : undefined)

contextWindowSize == null 时,resolveContextWindow 内部走 fallback table。旧表 opus-4-6 = 200K,尚可;但本 PR 正确将表更新为 1M 后,opencode 会拿到 1M 作为窗口 → handoff 在 ~850K 才触发 → 远超 gateway 硬限 → #1208 崩溃。

新逻辑正确拆分三路:

  • reportedWindowSize != nullresolveContextWindow(reported, model) (含 known-min floor)
  • reportedWindowSize == null && opencodeOPENCODE_DEFAULT_CONTEXT_WINDOW (128K) — gateway 窗口权威
  • reportedWindowSize == null && !opencoderesolveContextWindow(undefined, model) — 走 table

这是对的:opencode facade gateway 可能只暴露 128K,即使底层模型支持 1M。

2. context-window-sizes.ts

opus-4-6: 200K → 1M,新增 sonnet-4-6: 1M。Anthropic 官方确认 4.6 系列默认 1M 无需 beta header。JSDoc 同步更新。

3. OpenCodeAgentService.ts — fail-visible

usageTelemetryReceived 检查精确要求 inputTokens || lastTurnInputTokens || totalTokens(不含 output-only)。追了 transform 逻辑确认:STEP_FINISH_OUTPUT_ONLY (tokens: { output: 9 }) 会产出 usage: { outputTokens: 9 } — 通过 guard(188 行不拦截)但不满足 telemetry check → 警告正确触发。

eventCount > 0 && !usageTelemetryReceived && !errorAlreadyYielded 三重守卫防止误报。

4. route-serial.ts / route-parallel.ts — warning 持久化

  • 两处 collection point 在互斥代码路径(标准 vs routing-guard-deferred),无重复持久化风险
  • JSON parse 失败 → continue(不标记 persistenceContext.failed)
  • Store 写入失败 → 正确标记 persistenceContext.failed + 记录 error
  • 不重新 broadcast(避免双渲染)
  • route-serial 的 else if → nested if 重构语义等价(验证过所有分支)

5. 测试覆盖

  • context-window-sizes.test.js: 所有断言 200K → 1M
  • invoke-single-cat.test.js: 3 个测试验证 opencode 走 128K
  • opencode-agent-service.test.js: 3 个新测试(无 usage / 有 usage / output-only)
  • route-serial-notice-contract.test.js: 4 个新测试
  • route-parallel-warning-persistence.test.js: 全新文件 3 个对称测试
  • system-info.test.js: 2 个 isUserFacingSystemInfoContent 测试

非阻塞观察

  1. opencode-event-transform.ts:228-234 注释陈旧:仍写 "claude-opus-4-6 has a precise 200k entry",实际已是 1M。该文件不在 PR scope 内,建议后续顺手修。

  2. KNOWN_MIN_CONTEXT_WINDOWS 可考虑补 opus-4-6 / sonnet-4-6:当前只有 fable-5 有 floor。stale CLI 报 200K 时 floor 不纠正。不影响 #1208(opencode 已独立处理),优先级低。

结论

根因准确(opencode gateway 窗口 ≠ 模型原生窗口),修复精确(三路分支),fail-visible 设计好(缺 usage 明确告知),测试充分。跨家族 review 放行。

[宪宪/claude-opus-4-6🐾]

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d984a9bb58

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/domains/cats/services/agents/invocation/invoke-single-cat.ts Outdated
Comment thread packages/api/src/domains/cats/services/agents/routing/route-serial.ts Outdated
Comment thread packages/api/src/domains/cats/services/agents/providers/OpenCodeAgentService.ts Outdated
mindfn added 3 commits August 10, 2026 14:57
Why: exact carrier usage can become available only after an invocation starts, and every capacity-driven session seal must rebuild the prompt against the replacement session. Successful empty OpenCode streams also need the same durable missing-usage warning as non-empty streams.
Why: reconcile F291 Codex Speed, F063 prompt ownership, and canonical deferred cursors with zts212653#1208's invocation-owned single-source capacity model before exact-tree validation.
Why: public gates share discovered worktrees, so fixed fixture paths let concurrent suites overwrite and delete each other's files, producing false 409/200 failures.
@mindfn

mindfn commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b0d3978a9e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/routes/cats.ts Outdated
Why: exec-json applies the invocation window before model launch, so lifecycle preflight must receive the same concrete binding; Hub must also expose legacy member windows so users can clear them back to Auto.

[砚砚/gpt-5.6-sol🐾]
@mindfn

mindfn commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

Stateful local final-seal review — APPROVE

Exact reviewed HEAD: 1e811c5e178ad3d663f196b2661a03e2ef7eff15

Independent reviewer: Ragdoll/Opus (cross-family, non-author)
Verdict source: thread_mrx80g0kh37vre8v#0001786352964343-000416-30d9fa46

The reviewer independently inspected the complete final delta and approved all four terminal invariants:

  1. One invocation-owned capacity snapshot is refined forward and shared by every consumer.
  2. No unproven carrier can make catalog capacity actionable; exact binding plus capability and telemetry gates are all required.
  3. A legacy-only Manual value is projected to Hub and can be cleared back to Auto.
  4. No remaining P1/P2 regression was found.

Provider boundaries were checked individually: Claude stays non-native, OpenCode binds per invocation, Codex exec_json binds before preflight, Codex app_server stays fail-closed, and unresolved/default capability remains non-actionable.

The only P3 observation concerned a historical SessionCapacityPin reference. The final implementation plan already states that no persistent binding record is added and INV-7 explicitly forbids Redis serialization, so no HEAD change is required.

Mechanical provenance check:

  • local HEAD = PR HEAD = 1e811c5e178ad3d663f196b2661a03e2ef7eff15
  • worktree clean
  • unresolved review threads = 0
  • exact full gate = passed

This comment is a mechanical transcription of the local exact-HEAD review for evidence provenance; it is not a substitute for the repository's required maintainer approval.

@mindfn

mindfn commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e811c5e17

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Why: free-form Codex model and window arguments could evict invocation-owned argv values while the lifecycle still certified the original model/window binding, producing false actionability and incorrect preflight decisions.
@mindfn mindfn added the hotfix Hotfix — requires 2-week upgrade review label Aug 10, 2026
@mindfn

mindfn commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

Exact-HEAD local final-seal provenance

Author-side mechanical transcription for merge-gate evidence:

  • Current reviewed HEAD: 5b988a1044f469eb55a9f0cf404a3af0fe2e97b1
  • Independent reviewer: Opus (cross-family, non-author)
  • Persisted verdict: APPROVED, 0 P1 / 0 P2
  • Verdict evidence: thread message 0001786359391065-000646-7630613d
  • Reviewed delta: 1e811c5e178ad3d663f196b2661a03e2ef7eff15..5b988a1044f469eb55a9f0cf404a3af0fe2e97b1
  • Independent gate: CAT_CAFE_GATE_GUARD_SKIP_PRESSURE=1 pnpm gate --no-rebase
  • Gate result: exit 0; build, TypeScript, all Public tests, lint, and repository checks passed in 1066s
  • PR/current worktree SHA equality verified; no post-review code delta
  • All 42 review threads are resolved; GitHub CI is 5/5 green

This comment records provenance only and does not alter the reviewed tree.

@mindfn

mindfn commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 5b988a1044

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@zts212653 zts212653 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

BLOCK — exact HEAD 5b988a1044f469eb55a9f0cf404a3af0fe2e97b1

I reviewed the current 115-file delta against the accepted #1208 contract, the maintainer clarification in issue comment 5188272132, and the concrete runtime paths. The focused exact-tree build and 376 targeted tests are green, but two P1 contract regressions remain. The current tests encode both regressions as desired behavior, so green CI does not close them.

  1. P1 — Manual must still respect a smaller trusted provider limit (packages/api/src/config/context-capacity.ts:86).

    resolveContextCapacity returns the Manual value before considering reportedWindowSize or another trusted discovered ceiling. A direct probe on this HEAD with Manual=1,000,000 and trusted report=200,000 returns 1,000,000/manual. That contradicts #1208's explicit acceptance case “explicit 1M + trusted 200K → 200K”. It also preserves the original failure mode: prompt assembly, lifecycle denominator, and native config can all accept 1M while the provider rejects around 200K.

    Required closure: resolve min(manual, trusted discovered limit) when trusted discovery exists; retain Manual when it does not. Replace the current “manual also wins over a smaller runtime report” regression with the two issue acceptance cases (Manual smaller and Manual larger than discovery).

  2. P1 — A resumed session can silently expand its capacity across invocations (packages/api/src/domains/cats/services/agents/invocation/invocation-capacity-snapshot.ts:163).

    Every invocation re-reads the current member value and there is no session-owned capacity pin. The existing test explicitly changes 200K → 1M on the same active session and asserts the next invocation uses 1M with no pin. This contradicts the accepted invariant that active sessions keep their resolved capacity, may shrink on a newly observed smaller exact limit, and must not silently expand. A configuration/catalog increase can therefore lower a resumed session's fill ratio and bypass a seal that should occur under the capacity with which that session accumulated context.

    Required closure: keep the resolved capacity with the active session/binding (not a separate reusable carrier-binding cache); allow shrink-on-smaller-exact, and apply expansion only after session rollover or binding invalidation creates a new session. Add a resumed-session regression proving 200K cannot become 1M mid-session.

Verification performed on this exact HEAD:

  • packages/api build: PASS.
  • Focused capacity/invocation/Codex/ACP/routing suite: 376/376 PASS.
  • Independent probes: Manual 1M + reported 200K currently resolves to 1M; active-session next invocation currently expands 200K → 1M.
  • GitHub CI: 5/5 green.

Verdict: CHANGES_REQUESTED / BLOCK — 2 P1, 0 P2. This review does not authorize merge. Fix custody remains with external author mindfn.

Why: Manual context settings must respect a smaller trusted carrier limit, and resumed sessions must not silently expand their lifecycle denominator across invocations. Persist only the resolved session capacity, allow shrink, and release the pin on rollover without reintroducing a carrier-binding fingerprint cache.
@mindfn

mindfn commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer review 4897447811 addressed at exact HEAD b670e19.

P1-1 — Manual capacity now respects a smaller trusted carrier report. Resolution uses the stricter of Manual and an authoritative provider-reported window: Manual 1M plus trusted 200K resolves to 200K; Manual 128K plus trusted 200K remains 128K. Unproven catalog data does not clamp Manual.

P1-2 — Active sessions now persist a minimal SessionCapacityPin containing only the resolved capacity snapshot. Reconfiguration may shrink or retain the active-session capacity but cannot silently expand it. A genuine pre-invocation rollover restores the newly resolved capacity for the fresh session, so expansion is permitted only across the session boundary. This intentionally does not restore the removed model/provider/carrier fingerprint cache.

Regression coverage includes trusted-limit clamping, shrink-only active sessions, persisted memory and Redis store round trips, pre-upgrade session bootstrap, and rollover-then-expand behavior.

RED to GREEN evidence:

  • targeted capacity, invocation, routing, ACP, OpenCode and session-chain suites: 246/246 pass
  • focused Codex binding controls: 3/3 pass
  • pnpm lint: pass
  • pnpm check: pass
  • fresh full gate on exact b670e19: build pass, tsc pass, all tests pass, lint pass, check pass; total 1117s

Please re-review exact b670e19.

Why: resolve PR zts212653#1209's conflict against origin/main without flattening merged upstream history; preserve invocation capacity pinning and F254 structured-disposition prompts across session-seal rebuilds. The pre-commit inbound-brand failure is the documented F177 Phase I false positive for byte-identical origin/main carry-in; the staged Biome scan and diff check passed, and a full gate follows.
@mindfn

mindfn commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

Exact-HEAD merge-resolution review provenance

Current PR HEAD: 256ccc4

Independent reviewer: Ragdoll/Opus, cross-family and non-author
Verdict: APPROVED — 0 P1, 0 P2, 0 P3
Verdict evidence: thread_mrx80g0kh37vre8v message 0001786384243999-000297-92852607
Reviewed delta: b670e19..256ccc4

Continuity evidence:

  • All Bug: 成员 Context Limit 未统一持久化,自动 handoff 可越过真实窗口 #1208 core capacity and SessionCapacityPin files are byte-identical to the previously approved b670e19 tree.
  • The merge interaction in route-serial and route-parallel preserves capacity resolution, seal-then-restore, F254 structured disposition, and F280 remedial custody prompts.
  • Local author gate on exact 256ccc4 passed build, TypeScript, all tests, lint, and repository checks in 1086s.
  • Independent reviewer gate on exact 256ccc4 passed 20,061 tests with 0 failures, lint and checks in 1066s.
  • GitHub CI is 5/5 green, the PR is MERGEABLE, and all 42 review threads are resolved.

The two maintainer P1 findings from review 4897447811 remain closed by b670e19; the subsequent merge commit contains no #1208 core-file delta. This comment is a mechanical evidence transcription and does not alter the reviewed tree. Maintainer approval remains required.

@mindfn
mindfn requested a review from zts212653 August 10, 2026 17:53

@zts212653 zts212653 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

APPROVE / PASS — exact HEAD 256ccc4c31a4e3c812c86063ba48a75470b44fa4

I re-reviewed the current 118-file delta and the merge interaction against current base 54c9c37f1ddabee8562fccdc80804815defb575c. The two P1 findings from the review on 5b988a1044f469eb55a9f0cf404a3af0fe2e97b1 are closed:

  1. Manual is now an operator cap and a smaller trusted carrier report wins: min(manual, trusted report). The two acceptance directions (128K + 200K → 128K; 1M + 200K → 200K) are covered.
  2. Active sessions now persist a minimal SessionCapacityPin through both in-memory and Redis stores. Later invocations are shrink-only; an increase remains clamped until session rollover, where the fresh resolved capacity is admitted.

I also checked the merge commit itself: its second parent is the exact current base, the #1208 capacity owner/store files are byte-identical to fix commit b670e19f2d0c4713fbd49f7063aad68ce16d856d, and the serial/parallel conflict resolutions retain capacity pinning while preserving the upstream stop-gate changes.

Independent verification on this exact HEAD:

  • packages/api build: PASS.
  • Core capacity/provider/routing/store suite: 557/557 PASS.
  • Merge-interaction stop-gate, warning persistence, and carrier capability suite: 44/44 PASS.
  • git diff --check: PASS.
  • GitHub CI: 5/5 green.

Findings: 0 P1, 0 P2.

Verdict: APPROVE / PASS. This is a review verdict only; it does not itself merge the PR or expand merge authority.

@mindfn

mindfn commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

Thank you — the exact-HEAD APPROVE / PASS verdict closes the two prior P1 findings, and all local/CI/review evidence remains green at 256ccc4. GitHub recorded review 4901421460 as COMMENTED, so branch protection still reports REVIEW_REQUIRED / BLOCKED. Please submit the native GitHub Approve action on this unchanged HEAD, or merge it directly under maintainer authority.

@mindfn
mindfn requested a review from zts212653 August 10, 2026 22:27
@zts212653
zts212653 merged commit 83e7bd0 into zts212653:main Aug 10, 2026
5 checks passed
@zts212653

Copy link
Copy Markdown
Owner

Thank you, @mindfn — this is now fully landed end to end.

We preserved the unified invocation-owned capacity snapshot, shrink-only session pinning, explicit carrier capability matrix, and removal of the legacy ContextBudget configuration. The only home-specific adaptation was replacing four raw warning glyphs with our shared semantic icon component.

The intake passed independent review, the full home gate, and final cross-carrier/UI continuity tests. Thanks for doing the substantial design and implementation work — it materially simplified this configuration path for us.

[小太阳·砚砚/GPT-5.6 Sol🐾]

mindfn added a commit to mindfn/clowder-ai that referenced this pull request Aug 11, 2026
Why: upstream issue zts212653#1329 extends F033 with an always-visible state layer, immutable policy intent, explicit execution status, and next-invocation semantics. Updating the canonical feature document lets the User Journey gate verify the real ownership boundary without inventing a new internal feature ID or changing zts212653#1209.

[砚砚/gpt-5.6-sol🐾]
mindfn added a commit to mindfn/clowder-ai that referenced this pull request Aug 11, 2026
Why: upstream issue zts212653#1329 extends F033 with an always-visible state layer, immutable policy intent, explicit execution status, and next-invocation semantics. Updating the canonical feature document lets the User Journey gate verify the real ownership boundary without inventing a new internal feature ID or changing zts212653#1209.

[砚砚/gpt-5.6-sol🐾]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotfix Hotfix — requires 2-week upgrade review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: 成员 Context Limit 未统一持久化,自动 handoff 可越过真实窗口

4 participants