Skip to content

fix(claude-plugin): capture only new turns when a subagent stops again - #6323

Merged
t0saki merged 1 commit into
volcengine:mainfrom
t0saki:fix-cc-subagent-capture-cursor
Oct 22, 2026
Merged

t0saki merged 1 commit into
volcengine:mainfrom
t0saki:fix-cc-subagent-capture-cursor

Conversation

@t0saki

@t0saki t0saki commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Description

A Claude Code subagent can stop more than once: a background task notification or SendMessage wakes it again, and each wake fires SubagentStop with the subagent's whole transcript. Before this change, subagent-stop.mjs sent every turn in that transcript and committed every time. It also deleted its state file after a successful push. So each wake re-uploaded all earlier turns into the same OpenViking session and committed a new archive holding all of them. Extraction work grew quadratically with the number of wakes.

The main-session capture path (auto-capture.mjs) already avoids this with a capturedTurnCount cursor. This PR applies the same cursor to subagent capture.

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue

N/A

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • subagent-stop.mjs: the subagent state file is kept after a successful capture and stores a capturedTurnCount cursor. Only turns past the cursor are pushed. If there are none, the hook returns without pushing or committing. The cursor advances only when every turn was sent or queued, so an enqueue failure leaves it in place for a retry.
  • subagent-start.mjs: when it rewrites the state for an agent_id that already has a state file, it keeps the existing capturedTurnCount.
  • Claude Code plugin version bumped to 0.7.13 (plugin.json and package.json).

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

New test in scripts/auto-capture.test.mjs. It runs SubagentStart, then SubagentStop, then appends one turn to the transcript, then runs SubagentStart, SubagentStop, and one more SubagentStop with nothing new. All of this runs against a mock OpenViking server. The test checks that the second push carries only the new turn and that there are exactly two commits. With subagent-stop.mjs reverted to main, the test fails with a third batch; with only subagent-start.mjs reverted, the second batch resends all three turns. The full Claude plugin suite (node --test examples/claude-code-memory-plugin/scripts/*.test.mjs examples/claude-code-memory-plugin/scripts/lib/*.test.mjs) passes, 55/55, and .github/scripts/check-plugin-version-bumps.sh upstream/main passes. I did not test this with a live Claude Code session or a real OpenViking server.

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Additional Notes

Subagent state files in the temp directory now persist after a successful capture, as auto-capture's state files already do. Without the file, a later wake could not know which turns were already sent.

Upgrade note: on main the state file is deleted after a successful stop, so a subagent that already stopped once before the upgrade and is woken again afterwards pushes its full transcript one more time; after that it uses the cursor.

@t0saki
t0saki force-pushed the fix-cc-subagent-capture-cursor branch from ec30099 to 0ed17b0 Compare October 21, 2026 02:56
@t0saki
t0saki marked this pull request as ready for review October 21, 2026 07:16
Copilot AI balanced review requested due to automatic review settings October 21, 2026 07:16

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

A subagent woken again by a background task notification or SendMessage
fires SubagentStop once more with its whole transcript. The stop hook
pushed every turn and committed each time, and it deleted its state file
after a successful push, so each wake re-uploaded all earlier turns into
a new archive.

Keep the state file and track a capturedTurnCount cursor in it, as
auto-capture does for the main session: push only turns past the cursor,
skip the commit when there are none, and have SubagentStart preserve the
cursor when it rewrites the state.
@t0saki
t0saki force-pushed the fix-cc-subagent-capture-cursor branch from 0ed17b0 to a3c303f Compare October 22, 2026 08:18
@t0saki
t0saki merged commit e296620 into volcengine:main Oct 22, 2026
8 of 9 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Oct 22, 2026
mangxy added a commit to mangxy/OpenViking that referenced this pull request Oct 24, 2026
- toast刀5/config-schema/auto-recall/session-start 三处全活
- statusline 三刀全活(modelCtx 5处=注释态基线)
- recall 止血刀双路 query_expansion off 在位;官方新 recallQueryExpansion 仅显式配置才覆盖,默认不翻车
- 新吃官方: volcengine#6297 api-request-blob 跳过(CC301+防重复上传)、volcengine#6323 subagent cursor、volcengine#6394 Stop 重放 pending
- captureRedact(gitleaks) 官方已 revert,不带

Co-Authored-By: Claude Code <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants