Skip to content

feat: support project asset references in AI scheduled tasks - #478

Open
HFUTcoder wants to merge 12 commits into
Tencent:mainfrom
HFUTcoder:feat/ai-scheduled-tasks
Open

HFUTcoder wants to merge 12 commits into
Tencent:mainfrom
HFUTcoder:feat/ai-scheduled-tasks

Conversation

@HFUTcoder

@HFUTcoder HFUTcoder commented Nov 13, 2026 •

Copy link
Copy Markdown

What changed

AI scheduled tasks previously accepted plain-text prompts without explicit project asset references. This adds selection of roles, skills, SOPs, issues, runs, and repositories to scheduled tasks, with search, filtering, removal, and a limit of 12 references.

The implementation reuses the existing assistant reference API and workbench context resolution. Only reference type and ID are persisted; each execution resolves the current asset. References are validated for supported types, existence, and project/shared visibility. Upstream execution identity, credential selection, session history/retention, and permission behavior are preserved.

Scope

  • Platform core / API / runner
  • Public adapter / deployment
  • Classic
  • Portable
  • Shared behavior contract
  • Installer / CLI
  • Documentation only

Compatibility

The references field is optional in the existing JSON payload. Existing scheduled tasks without references continue to work. No database schema migration or runner protocol change is required.

Validation

The following checks passed locally after merging main at 1535886:

  • go build ./...
  • go vet ./internal/httpapi ./internal/domain ./internal/repo ./web
  • go test ./internal/httpapi ./internal/domain ./internal/repo ./web -run 'Schedule|Scheduled|AssistantTask|Dispatch|SharedSkill|TestAppJSParses|TestAppBundleFilesAreEmbeddedAndListed' -count=1 -timeout=180s
  • 33 frontend tests covering schedule editing, shared schedules, execution history, asset references, and Escape/focus behavior
  • node --check web/app/sync-schedule.js
  • python3 scripts/check-public.py
  • Gitleaks 8.30.1 with the repository configuration on an export of candidate source files (official Darwin ARM64 binary; archive checksum verified)
  • git diff --check

New regression coverage exercises asset references with both new/fixed conversations and personal/shared keys, refreshes referenced asset data on each run, rejects missing references before a conversation opens, and preserves paused state and unsaved drafts in the editor.

The complete repository test and acceptance checks continue through pull request CI and the maintainer environment.

Safety

  • I did not include credentials, internal endpoints, production data, or organization-specific infrastructure.
  • I preserved user files and unrelated changes.
  • I updated generated Classic host bundles when applicable.
  • I documented third-party content and licensing changes when applicable.

Classic bundles and third-party licensing changes are not applicable to this change.

@HFUTcoder
HFUTcoder marked this pull request as ready for review November 13, 2026 09:41
@Robert0622

Copy link
Copy Markdown
Collaborator

LoopForge PR Review — head 6d0ea8c86ba0d4d20be53d787fcf4fd2c4ca2795

Verdict: ❌ Fail

  • Scope: 14 files, +353/-7 (base 223bd416 → head 6d0ea8c). Adds reference selection (roles/skills/SOPs/issues/runs/repositories, max 12, with search/filter/removal) to AI scheduled tasks via internal/httpapi/assistant_schedule.go (new), assistant_tasks.go, schedule.go, shared_schedules.go, internal/domain/assistant.go, internal/domain/sync.go, and web/app/sync-schedule.js + web/index.html + web/sync.css.
  • GitHub reports mergeable: false / mergeable_state: dirty. main has advanced 125 commits past this PR's base, and git merge-tree shows a real (non-cosmetic) <<<<<<< conflict in internal/httpapi/assistant_tasks.go, function executeAssistantTask: this PR still guards concurrent runs with h.active.LoadOrStore(user.ID, true) (one lock per user), while main's 2441f232e8 (fix(schedule): make unattended AI loops reliable #546, "make unattended AI loops reliable") replaced that with a per-task key (assistantTaskActiveKey(origin.TaskID, user.ID)) so multiple scheduled tasks for the same owner can run side by side. The nearby h.active.Load(current.ID) 429-check a few lines above is touched by both sides too. Taking either side as-is will either reintroduce the one-task-per-user bottleneck fix(schedule): make unattended AI loops reliable #546 fixed, or drop this PR's reference-resolution wiring in that function — needs a manual reconciliation, not a trivial rebase.
  • CI on this head never produced a real signal: platform/validate/e2e all show action_required (first-run contributor approval gate); only the opensource-scan pipeline actually ran. No official pass/fail evidence exists yet.
  • Review-sandbox limits: no Go toolchain available (read-only, no-credentials environment), so the Go side above could not be executed locally — assessed via git merge-tree + GitHub's own mergeable_state, both authoritative for conflict detection. node --check on web/app/sync-schedule.js passed syntactically, consistent with this PR's own validation notes, but that check doesn't cover the Go conflict above.

Blocking: real merge conflict with main in internal/httpapi/assistant_tasks.go::executeAssistantTask (interacts with #546's per-task concurrency key) — please rebase/merge main, reconcile the active-task locking with the reference-resolution changes, and push so CI can actually run — @HFUTcoder.

@HFUTcoder
HFUTcoder dismissed a stale review via 4fbddbd November 13, 2026 16:17
@HFUTcoder

Copy link
Copy Markdown
Author

已解决与最新 main 的合并冲突,保留了任务级并行执行逻辑和项目资产引用处理。

针对性测试、go vet、JS 语法检查及代码扫描均已通过。请基于最新提交 4fbddbd 重新 Review,谢谢。

@Robert0622

Copy link
Copy Markdown
Collaborator

LoopForge PR Review — head 4fbddbdff9b7a772f15d0a4f6464d51e86073fc5

Verdict: ✅ Pass

  • Re-review: head moved from 6d0ea8c86ba0d4d20be53d787fcf4fd2c4ca2795 (previously ❌ Fail — real merge conflict with main in executeAssistantTask) to 4fbddbdff9b7a772f15d0a4f6464d51e86073fc5 via "merge: reconcile scheduled task references with upstream". GitHub now reports mergeable: true (mergeable_state: unstable, CI-only). Verified directly: activeKey := assistantTaskActiveKey(origin.TaskID, user.ID) from fix(schedule): make unattended AI loops reliable #546 is intact, and this PR's normalizeScheduledReferences/scheduledMessageReferences calls are layered after the per-task lock — both sides are correctly reconciled, not one dropped.
  • Scope: 14 files, +524/-7 over eb4d4d5d…4fbddbd. Adds references (role/skill/SOP/issue/run/repository, ≤12, deduped, trimmed) to AssistantTask/ScheduleJob, persisted as identity-only (type+id); resolved fresh on every execution via normalizeScheduledReferences (validates type/existence/project visibility) and scheduledMessageReferences (fills display name/owner project, ignoring client-supplied name/projectId). putTask now requires workbenchProjectAllowed; scheduleJobs plumbs the same normalization and strips references for non-AI jobs.
  • Checked out this exact SHA in an isolated, credential-free sandbox (no production access): go build ./... clean; gofmt -l clean on touched Go files; go vet ./internal/httpapi/... ./internal/domain/... clean.
  • go test ./internal/httpapi/ -run 'Schedule|AssistantTask|ScheduledTask|PutAssistantTask' → pass (2.9s), plus targeted runs of each new/changed case: TestPutAssistantTaskStoresNormalizedReferences, TestScheduledTaskWithMissingReferenceFailsBeforeTurn, TestNormalizeScheduledReferencesLimitDedupAndTrim, TestScheduledMessageReferencesResolveOwnerProject, TestAssistantTaskReferenceSaveRequiresProjectAccess, TestScheduledTaskRunsAsChatTurn, TestAIScheduleReferencesPersistIdentityAndRefreshDisplayData — all pass. These cover the ≤12/dedup/trim rules, cross-project-reference rejection, permission-safe error messages (no existence leak to outsiders), and that stored references stay identity-only while the resolved prompt/response show live display data rather than a client-forged name/projectId.
  • go test ./web/... -run Dispatch (covers web/schedule_dispatch_limit_test.go, which asserts on #scheduleAddReference/#scheduleReferenceOptions markup and that the AI-job payload only sends {type,id}) → pass.
  • CI on this head: only GITHUB_OPENSOURCE_SCAN_PIPELINE ran (success); platform/validate/e2e still show no run, consistent with this being a first-time-contributor approval gate rather than a CI failure — same limitation noted in the prior review, not attributable to this change.

No blocking issues found; local build/vet/tests are green and the previously-blocking merge conflict is resolved without regressing #546's per-task concurrency fix.

Yanami-2K
Yanami-2K previously approved these changes Nov 14, 2026

@Yanami-2K Yanami-2K left a comment

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.

核对了 AI 定时任务引用项目资产的后端与前端改动。normalizeScheduledReferences 只接受 6 种类型,上限 12 个,去重并去掉空白。它复用 workbenchReference 校验存在性和项目/共享可见性,只持久化 type+id,客户端伪造的 name/projectId 不会落库。每次执行都重新解析资产,引用不可用时在调用模型前就失败;派发类任务会清空 references。putTask 顺带补上了 workbenchProjectAllowed 项目权限校验。新增测试断言了规范化结果、存储只保留身份、显示数据刷新、提示词里用的是最新标题而非伪造名称、缺失引用不触发生成,CI 全绿且与 main 无冲突。

一点产品层面的提醒(不阻塞):被引用的需求或运行被删除后,这个周期任务每次都会报错,直到有人编辑它。可以考虑在任务列表里标出失效的引用。另外 #664 也在改 ScheduleJob 和 sync-schedule.js,后合入的一方需要处理冲突。assistant_schedule.go 等文件的 patch 有截断。

@HFUTcoder

Copy link
Copy Markdown
Author

当前 Review 和 CI 均已通过,请问这个功能是否还有产品或设计方面需要确认的事项?如无其他阻塞,麻烦方便时协助合并,谢谢。

Preserve upstream execution identity, shared-key model restrictions, fixed-session history and session retention alongside asset references. Add regression coverage for session modes, shared keys, saved state and reference-picker Escape handling.
@HFUTcoder
HFUTcoder dismissed stale reviews from Yanami-2K and ghost via 8950e3b November 17, 2026 10:10
@HFUTcoder

Copy link
Copy Markdown
Author

已合并最新 main 并解决冲突,最新提交为 8950e3b,本地相关测试和构建已通过。目前 GitHub 显示无合并冲突,platform、validate、e2e 等待批准运行,之前的 Review 批准也因新提交失效。麻烦方便时批准 CI 并重新 Review,谢谢。

@HFUTcoder

Copy link
Copy Markdown
Author

已再次同步最新 main,解决与 Runner 账号登录改动的冲突,最新提交为 e78c07b。资产引用功能已保留,并补充验证了 Runner 登录及离线切换 API Key 场景;相关本地测试、构建和静态检查通过。目前无合并冲突,代码扫描通过,platform、validate、e2e 仍等待批准运行。麻烦方便时批准工作流运行并重新 Review,谢谢。

Merge upstream/main at 451d38c. Reconcile internal/httpapi/schedule_runner_login_test.go by keeping upstream's Claude Code and Antigravity cases and both scheduled asset reference and API-key fallback assertions.

Validation: targeted schedule, assistant-task, runner-login and dispatch Go tests; 33 schedule web tests; chatbot build; go build ./...; go vet on httpapi, domain and web.
@HFUTcoder

Copy link
Copy Markdown
Author

已推送提交 e85c8df,已解决与最新 main 的冲突,并保留项目资产引用及 Runner 登录相关改动。相关 Go 测试、前端测试、构建和静态检查均已通过。当前代码扫描已通过,麻烦方便时批准 platform、validate、e2e 工作流并重新 Review;如无其他阻塞,烦请协助合并,谢谢。

@cocofhu cocofhu left a comment

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.

整体方向没问题:只持久化 type+id、每次执行重新解析、客户端伪造的 name/projectId 不落库、派发任务清空 references 都做得对。我在 e85c8df 上跑了 go test ./internal/httpapi -run 'Schedule|Scheduled|AssistantTask|RunnerLogin',全部通过。有一个问题需要合并前修复。

需要修复:固定会话会把引用的需求永久绑定为主需求

定时任务实际走普通对话流程,所以会触发 linkMentionedIssue:首次执行时,引用的需求会被写进会话的 IssueID。此后每一轮,prepareWorkbenchContext 都会按 IssueID 读取并校验这个需求。

  • 新会话模式不受影响,每次都新开会话。
  • sessionMode=fixed 时绑定会一直留在固定会话里。用户在任务里移除这个引用后,每轮仍会注入该需求的上下文。
  • 需求随后被删除时,任务每次执行都会失败,而且在编辑界面里无法修复。

复现步骤:固定会话,引用需求 A 运行一次,此时 session.IssueID == A;清空 references 并删除需求 A,再运行一次,复用同一会话并报错 需求不存在或不属于当前项目。

修复方向,二选一即可:

  • 来源为 AssistantSourceScheduled 的会话跳过 linkMentionedIssue;
  • 或者执行前,如果会话的 IssueID 不在当前 references 中,就清除它。

请补一个"固定会话 + 移除引用 + 删除需求"的回归测试。

非阻塞建议

  1. 列表接口的开销和失效提示。 visibleScheduleJobs 每次列出任务都会对每个引用调用 scheduledMessageReferences,run 类型要读完整的 RunState,任务运行时前端还会轮询。另外解析是全有或全无:只要一个引用失效,这个任务的所有引用都退回成只有 id,用户看不出是哪个坏了。建议按单个引用分别解析,并标记失效项(与前面提到的"失效引用提示"是同一件事)。
  2. 重复解析。 一次执行中 runScheduleJobPromptReporting 和 executeAssistantTask 各调用一次 normalizeScheduledReferences,加上 scheduledMessageReferences 和对话流程里的 accessibleWorkbenchReference,同一批引用大约解析四次。可以去掉 runScheduleJobPromptReporting 中那次。scheduledMessageReferences 里按类型查所属项目的逻辑,也和 accessibleWorkbenchReference 基本重复,可以考虑复用。
  3. putTask 权限收紧。 新增的 workbenchProjectAllowed 对没有引用的老任务同样生效,已不是项目成员的用户将无法再编辑自己的老任务。方向是对的,但属于范围外的行为变化,建议在 PR 描述中说明。
  4. 小问题:
    • CloneAssistantReferences 注释写的是 "independent copy",但 Element 是指针,实际是浅拷贝;而且它在 scheduleJobs 里作用于刚解码的数据,可以直接删掉。
    • 前端选择器固定请求 offset=0,没有翻页。

@cocofhu

cocofhu commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

ab804f3 修复了上次提的固定会话问题:定时任务会话不再把引用的需求绑定为主需求,新加的回归测试也覆盖了"固定会话 + 移除引用 + 删除需求"的场景,这部分没问题。

但这个提交合并 main 后编译失败,core 检查挂在这里:

internal/httpapi/assistant_schedule.go:99:18: too many return values
	have (string, string, error)
	want (schedule.AssistantRunResult, error)

原因是 main 上的 #1123(d32304a)把这段逻辑移到了 runScheduleJobPromptResult,返回值改成了 (schedule.AssistantRunResult, error)。本 PR 新增的引用校验仍然是旧写法:

refs, err := h.normalizeScheduledReferences(job.ProjectID, job.References)
if err != nil {
	return "", "", err
}

git 层面没有冲突,所以 GitHub 显示可合并,但 CI 测的是合并后的代码。请同步最新 main,并把这里改成 return result, err。

我在本地用合并结果试过这一处改动:go build ./... 和 go vet ./internal/httpapi 通过。完整的 internal/httpapi 测试中有几个失败,但它们在未合入本 PR 的 main 上同样失败,属于本地环境问题,其余测试全部通过。修复推上来、CI 通过后我再 approve。

shenchen added 2 commits November 20, 2026 20:48
Use the existing workbench fixture so the conversation executor can load SSH host trust without dereferencing a nil repository. Keep the CLI version and source assertions intact.
@cocofhu

cocofhu commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

本地实测了 030435d,引用资产的主流程和上次修复的固定会话场景都正常。另外实测确认了之前提的一个非阻塞问题。

环境: PR head 编译的平台 + MySQL 8.0,内置前端用 npm --prefix chatbot run build 构建。模型用一个假的 Codex CLI(AGENTFLOW_CODEX_BIN)代替:它把收到的 prompt 记下来,回复里原样回显 prompt 中引用数据的需求标题,所以下面截图里的回复内容直接反映了运行时读到的数据。

1. 选择引用

选择器能列出当前项目的仓库、需求、角色、技能,按类型筛选和关键字搜索都正常,选中后显示"已引用"并生成标签。

选择器
筛选并选中

保存后数据库里只存了 type 和 id:

[{"id": "issue-login", "type": "issue"}, {"id": "repo-web", "type": "repository"}, {"id": "issue-temp", "type": "issue"}]

2. 修改资产后,运行时读取最新内容

把需求标题改成「登录页支持扫码(v2 最新标题)」后,重新打开编辑器,标签显示新标题:

重新打开显示最新标题

固定会话下连续执行两次:第一轮 prompt 里是旧标题,改名后第二轮是新标题。消息下方显示了引用标签。会话的 issueId 为空,说明 ab804f3 的修复生效,没有绑定主需求。

会话中两轮执行

3. 引用的资产被删除

删除「临时需求」后执行,在调用模型前就失败了,没有打开会话,错误信息写明了哪个资产不可用:

失效引用导致执行失败

在编辑器里移除这个引用并保存(任务保持停用状态,没有被自动启用),再执行一次就成功了,而且仍然在同一个固定会话里继续(3 轮共 6 条消息,issueId 仍为空)。这正是上次 review 提的场景,现在正常。

执行记录

实测确认的非阻塞问题

只要有一个引用失效,visibleScheduleJobs 就会把这个任务的所有引用都退回成只有 id。编辑器里三个标签全部显示原始 id,包括另外两个仍然有效的引用,用户看不出是哪个坏了,只能对照执行记录里的错误信息去删:

一个引用失效后所有标签都显示 id

建议按单个引用分别解析,并把失效的标签标红或标注"已失效"。这一点可以放到后续 PR 处理。

cocofhu
cocofhu previously approved these changes Nov 20, 2026

@cocofhu cocofhu left a comment

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.

之前提的问题都已修复:固定会话不再绑定主需求(ab804f3),和 main 合并后的编译错误已修(5b85a0e)。CI 全部通过,本地实测也正常,详见上一条评论。失效引用的提示可以放到后续 PR 处理。LGTM。

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.

4 participants