Skip to content

fix(auth): 为普通定时任务发布创建者 CLI 凭证 - #1843

Merged
deepcoldy merged 2 commits into
deepcoldy:masterfrom
Kelvin65535:codex/fix-scheduled-cli-auth
Oct 13, 2026
Merged

deepcoldy merged 2 commits into
deepcoldy:masterfrom
Kelvin65535:codex/fix-scheduled-cli-auth

Conversation

@Kelvin65535

@Kelvin65535 Kelvin65535 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

开启 triggerUserAuth 后,普通定时任务虽然携带创建者的 TrustedCaller,却没有发布本轮 lark-cli / bytedcli 凭证:scheduler 只为 delegated 任务接入身份准备回调,而 schedule: 身份入口也只处理 delegated 任务。因此新会话会缺少凭证,复用会话可能因旧凭证的 turnId 不匹配而被拒绝。

本次将身份准备回调接入所有定时任务,并从主机端 ScheduleAuthorityStore 的任务记录解析普通任务创建者。凭证绑定每次触发的 scheduled turnId;首次执行、周期复用,以及恢复/续跑共用该入口。创建者的操作权限复用 canOperate,保留未配置白名单时的开放模式语义。创建者身份不完整、应用不匹配、已失去 Bot 操作权限或未授权时,对应工具收到拒绝结果。手动暂停/撤销及目标群不匹配在派发前拒绝。自动完成的一次性任务允许恢复/续跑。有限次数 interval/cron 最后一轮自动完成后的续跑问题仍未解决。委托任务继续使用现有 runScopes 与控制人校验。

身份准备在新会话注册前、复用会话修改路由和 prompt 前执行。准备失败时关闭新候选的持久化记录,保留已有会话状态以及并发注册者,避免留下占用话题的 workerless 会话或改写上一轮 deferred turn。

影响面:共享 daemon 调度路径,覆盖普通 CLI / RPC 使用的现有工具身份包装器;测试实际执行 lark-cli 与 bytedcli 包装脚本,并检查轮次交错时拒绝串用身份。开启/关闭开关对已有 CLI 进程的热更新不在本次范围。

验证(独立 checkout,Bun 1.4.2,Node 24.19.0):

  • 未修复 master 上,生产 scheduler 回调回归测试因未生成 bytedcli.env 而失败;修复后通过。
  • 此前在当前 head 01cd215 执行 bun run test test/turn-cli-identity.test.ts test/cli-identity.test.ts test/scheduled-turn-provenance.test.ts test/schedule-delegated-runtime.test.ts test/scheduler-silent-execute.test.ts:5 个测试文件、225 个测试通过,包含身份准备失败后的会话清理/保留及开放模式权限回归。
  • 此前在当前 head 01cd215 执行 bun run build:通过,包含源码、脚本和指定测试 mock 类型检查、dashboard 打包及构建审计。
  • git diff --check:通过。

尚未部署到 live daemon,也未验证真实飞书/ByteCloud 授权与定时任务运行。

@Kelvin65535
Kelvin65535 marked this pull request as ready for review October 12, 2026 16:25
Copilot AI balanced review requested due to automatic review settings October 12, 2026 16:25
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T16:33:22.431447Z d1a2fdd Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI 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.

🟡 Changes recommended

Identity-preparation failures can leave partially registered ghost sessions after concurrent pause or revocation.

1 open finding
What changed in this PR

Extends scheduled-turn CLI identity preparation to ordinary tasks so creator credentials are safely bound to each invocation.

Changes:

  • Resolves ordinary task creators from authoritative schedule records.
  • Publishes turn-bound lark-cli and bytedcli credentials or explicit denial.
  • Adds production callback and wrapper-level regression tests.
File Description
src/​daemon.ts Adds identity preparation for all scheduled tasks.
test/​turn-cli-identity.test.ts Tests credentials, denial, isolation, and scheduler wiring.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/daemon.ts
Comment on lines +30016 to +30019
{
prepareTurnIdentity: (session, turnId) =>
prepareTurnCliIdentity(session, turnId),
} : undefined,
},

@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: d1a2fddcb7

ℹ️ 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 src/daemon.ts Outdated
// was removed receive a denial, even if this session once held valid tokens.
const senderOpenId = caller?.requestLarkAppId === ds.larkAppId
&& caller.requestUserOpenId
&& getDashboardAdminOpenIds(ds.larkAppId).includes(caller.requestUserOpenId)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Honor open-mode schedule creators when publishing credentials

When a bot has no configured allowlist, /schedule creation is legitimately allowed by canOperate's open-mode fallback (src/im/lark/event-dispatcher.ts:2294), and the existing scheduled-turn owner gate explicitly preserves that behavior (src/daemon.ts:7553-7563). In that mode getDashboardAdminOpenIds is empty, so this condition always clears senderOpenId and publishes a denial even when the human creator has already authorized lark-cli/bytedcli; every such ordinary scheduled tool call therefore fails. Reuse the scheduled-owner/canOperate permission predicate rather than requiring membership in the dashboard admin list.

Useful? React with 👍 / 👎.

Comment thread src/daemon.ts
Comment on lines +30016 to 30018
{
prepareTurnIdentity: (session, turnId) =>
prepareTurnCliIdentity(session, turnId),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Roll back fresh sessions when identity preparation rejects

With triggerUserAuth enabled, if an ordinary run passes the callback's initial active-state check but is paused or removed while its precondition or Lark routing awaits, this new preparation callback rejects. On the fresh-session path, executeScheduledTask has already persisted and registered the DaemonSession before invoking it (src/core/session-manager.ts:4524-4539), and that catch only disarms silent state, so the failed run leaves a workerless initialStartPending owner occupying the chat/topic and blocking later turns. Run the revocation-sensitive preparation before registration or close/unregister the candidate on preparation failure.

Useful? React with 👍 / 👎.

@Kelvin65535
Kelvin65535 force-pushed the codex/fix-scheduled-cli-auth branch from 1aac76e to 01cd215 Compare October 13, 2026 07:29
@deepcoldy
deepcoldy force-pushed the codex/fix-scheduled-cli-auth branch from 01cd215 to cb5aaae Compare October 13, 2026 07:47
@deepcoldy
deepcoldy merged commit f2f7d07 into deepcoldy:master Oct 13, 2026
9 checks passed
@github-actions

Copy link
Copy Markdown

🚀 Released in v3.43.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants