Skip to content

refactor(harness): search frozen shot snapshots - #162

Merged
nanzhi84 merged 2 commits into
mainfrom
codex/issue-157-pr5-shot-search
Aug 2, 2026
Merged

nanzhi84 merged 2 commits into
mainfrom
codex/issue-157-pr5-shot-search

Conversation

@nanzhi84

@nanzhi84 nanzhi84 commented Aug 2, 2026

Copy link
Copy Markdown
Owner

目标

落实 #157 的 PR5:把 shot.search 改为基于完整冻结基础索引快照的无 embedding 检索,删除 partial detection candidate / 模型补建索引语义。

实现

  • 调用开始时冻结合法视频素材集;新素材只进入下一次搜索
  • 同步等待全部基础镜头索引 search_ready,并流式报告 ready / pending / failed
  • 任一索引失败或超时均返回稳定错误码及零部分结果;搜索本身不创建 job、不调用 VLM、不写标注
  • 从 PR4 持久 shot rows 读取固定 index_snapshot_id,返回精确 asset_id + persistent shot_id + boundary_version + 源帧区间
  • top_k 默认 12、上限 30;移除旧分页与 detection candidates
  • 增加版本化近义词、否定语义、结构化字段权重、质量/角色/时长/已使用区间过滤、多样性与稳定 tie-break
  • 更新 typed receipt、模型契约、工作流 fixtures 与真实注册工具 E2E

证据

  • make contracts
  • make test
  • make coverage:手写 Go 90.0%
  • make lint:0 issues
  • make vet-integration
  • make web:232 tests,主入口 gzip 276.20 kB
  • make e2e:9/9
  • 重复检索快照与排序确定;SQLite 业务事实、job、timeline、event 计数保持不变;无 embedding/vector 表

浏览器/API/SQLite/日志的真实模型验收将在 CI 全绿后作为 PR 评论补充,再决定是否合并。

Part of #157

@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: 14301dc0c2

ℹ️ 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 on lines +335 to +338
if status == "pending" || status == "running" {
pendingIDs = append(pendingIDs, frozen[index].asset.ID)
} else {
failedIDs = append(failedIDs, frozen[index].asset.ID)

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 Keep missing automatic-index jobs pending

When shot.search starts just after ProxyGenerated marks a video ready but before ensureBaseShotIndexForAsset enqueues its index job, baseShotIndexJobStatus returns missing and this branch immediately classifies the asset as failed. This is a real import window because go/internal/worker/ingest.go commits ingest_status='ready' at lines 82-89, may generate peaks, and only enqueues the base index at lines 107-114; searches during that interval therefore return shot_index_failed instead of waiting for automatic indexing. Treat a missing job as pending until the barrier timeout or until the enclosing ingest reaches a terminal failure.

Useful? React with 👍 / 👎.

Comment on lines +169 to +172
for _, tag := range input.Tags {
if strings.TrimSpace(tag) != "" {
tagQueries = append(tagQueries, buildShotSearchQuery(tag))
}

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 Verify tag matches with the same synonym semantics

When a tag matches only through the new synonym vocabulary—for example tags:["夕阳"] against a shot whose only matching field is 晚霞—the executor accepts it here, but validTypedToolRecoveryResult still checks tags through the literal-token-only shotMatchesAnyRequestedTag at go/internal/agent/tool_recovery.go:1220. The production middleware consequently replaces this legitimate successful result with tool_execution_error as unverifiable. The receipt verifier needs to share the executor's synonym-aware tag predicate.

Useful? React with 👍 / 👎.

Comment on lines +567 to +570
func queryNegatesAlias(query, alias string) bool {
for _, prefix := range []string{"无", "没有", "没", "非", "不要", "排除", "避免"} {
if strings.Contains(query, prefix+alias) {
return true

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 Detect negation across normal separators

When users write a negation with normal whitespace or punctuation, such as 不要 背光 or 不要,背光, normalizeSearchText preserves that separator while this check only searches for the concatenated 不要背光. The query is then treated as a positive 背光 synonym query and can return backlit shots, reversing the requested meaning. Normalize or skip separators between the negation prefix and alias before testing.

Useful? React with 👍 / 👎.

@nanzhi84

nanzhi84 commented Aug 2, 2026

Copy link
Copy Markdown
Owner Author

PR5 验收证据

最终提交:

  • 14301dc — refactor(harness): search frozen shot snapshots
  • f936393 — test(harness): harden deterministic shot search edges

本地门禁

  • make contracts:通过,OpenAPI/SSE/job-kind 无漂移,生产二进制不含 E2E scaffold
  • make test:通过(Go race)
  • make coverage:通过,手写 Go 覆盖率 90.2%(精确 90.1917%)
  • make lint:0 issues
  • make vet-integration:通过
  • make web:232 tests,通过;主入口 gzip 276.20 kB,低于 350 kB 预算
  • make e2e:9/9 通过;自动基础索引用例实际调用已注册的 shot.search
  • git diff --check:通过

首轮 CI 在临界覆盖率处报告 89.9%,因此补充了冻结集合、回执真值、稳定排序、取消和输入边界测试,将本地覆盖率提高到 90.2%。最终 CI run 30765555744 5/5 全绿:质量/契约/覆盖率、macOS race、Ubuntu race、Playwright、Web 全部通过。

内置浏览器真实验收

在隔离栈(API 18120 / Web 18121 / Worker metrics 18122)通过 UI 创建草稿、导入真实视频,并让真实模型连续调用 shot.search:

  1. 首次检索冻结 A+C;C 尚在“理解中”,工具等待到基础索引 ready 后一次性返回 5 个候选,无部分结果。快照 shot_search_eec44dc536a73c609a5d5372cb0f4bbc。
  2. 后导入 B 后再次检索,冻结集合变为 A+B+C,返回 7 个候选。快照 shot_search_5cb76f8fcf59a8359ce9120c2e4372fb。
  3. 相同参数重试:快照、顺序、ShotRef 完全一致。
  4. 导入 24 秒素材 F 后立即检索:基础索引 job 20:06:30.421682Z 开始、20:07:16.819062Z 完成;用户消息在 20:07:06.839594Z,工具结果在 20:07:16.856741Z,wait_duration_ms=9158。冻结/ready 共 5 个素材,18/18 候选一次性返回,证明 barrier 等待且没有泄漏 partial results。快照 shot_search_8560c371a6fd5d8967301a490107f144。
  5. 最终 top_k=5 只读检索复用同一快照,总命中 18、返回 5,UI 工具卡展示跨素材去重后的精确 ShotRef。
  6. 刷新编辑器后,全部素材状态、工具卡、回复和 ShotRef 均持久存在;浏览器 console 0 error / 0 warning。

API / SQLite / Worker 真值

  • 最终浏览器检索前后业务计数完全一致:assets=5, links=5, jobs=9, events=101, timelines=0, snapshots=4, shots=17, analyses=0, objects=12, transcripts=0, previews=0,证明 shot.search 未创建 job、未写分析、未改 timeline/event/business truth。
  • 对话状态:user_messages=6, assistant_replies=6, tool_steps=6, job_observations=0, suppressions=0, running_turns=0,无后台 job 观察续跑 Agent。
  • 五个素材经 API 均为 ready/usable;相同内容 hash 的 B 复用既有基础索引。
  • Worker 实际产出:A 3 shots/3 frames、C 3/3、D 3/3、F 8/8;Worker 日志无 error/warning。
  • API 日志仅有一次 context canceled,时间点对应我主动刷新页面造成的请求取消;非应用故障。
  • 动态工具面真实绑定为 4 个工具(含 shot.search),full catalog 为 15 tools / 16100 runes。

结论:PR5 的冻结快照检索、全就绪 barrier、无 embedding 排序、稳定 tie-break、回执真值与严格只读边界均通过代码门禁和真实运行时验收。

@nanzhi84
nanzhi84 merged commit 809cc6c into main Aug 2, 2026
5 checks passed
@nanzhi84
nanzhi84 deleted the codex/issue-157-pr5-shot-search branch August 2, 2026 20:34
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.

1 participant