Skip to content

feat(tape): add explicit subagent tape lineage#1980

Merged
yyhhyyyyyy merged 17 commits into
devfrom
feat/subagent-tape-lineage
Jul 16, 2026
Merged

feat(tape): add explicit subagent tape lineage#1980
yyhhyyyyyy merged 17 commits into
devfrom
feat/subagent-tape-lineage

Conversation

@yyhhyyyyyy

@yyhhyyyyyy yyhhyyyyyy commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Model production subagents as durable, independently linked Tapes instead of misleading Tape merges.
  • Preserve true fork copy-on-merge semantics with atomic and idempotent persistence.
  • Add authorized cross-Tape search and context recall with frozen head and Tape-incarnation boundaries.

Changes

  • Replace production mergeSubagentTape / discardSubagentTape flows with typed linkSubagentTape.
  • Append idempotent subagent/tape_linked events for completed, errored, and cancelled tasks.
  • Freeze the child head, entry count, lifecycle outcome, and Tape-incarnation identity in each link.
  • Keep failed or unavailable link persistence retryable instead of reporting successful finalization.
  • Make true fork delta and merge receipt writes atomic in one SQLite transaction.
  • Reject missing, discarded, or malformed forks without creating empty merge receipts.
  • Add current, linked_subagents, and current_and_linked Tape view scopes.
  • Add source sessionId to search results and sourceSessionId to context expansion.
  • Authorize every linked read through the persisted direct-child relationship.
  • Enforce frozen-head and Tape-incarnation checks to prevent deleted or rebuilt Tapes from impersonating old snapshots.
  • Use projection/FTS ranking only when every selected source has exact-head coverage.
  • Batch linked-session and incarnation lookups without SQLite bind-variable scaling limits.
  • Preserve legacy external fork/merge records as compatible read-only links; legacy fork/discard remains audit-only.
  • Update the Tape baseline, runtime architecture contracts, and lineage SDD

Summary by CodeRabbit

  • New Features
    • Added linked subagent Tape recall with frozen-head, read-only behavior.
    • Tape search now supports scope (current, linked, both) and includes sessionId in results.
    • Tape context can target a specific sourceSessionId for linked recall.
    • Subagent task Tape finalization now uses tape-link outcomes.
  • Documentation
    • Updated architecture/workflow docs to cover Tape linking, lineage, authorization, and cross-tape recall rules.
  • Bug Fixes
    • Improved isolation, authorization, retry behavior, and handling for unavailable/invalid linked sources and rebuilt tapes.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 05b75c90-9461-41a3-bfe6-84f3ba418c85

📥 Commits

Reviewing files that changed from the base of the PR and between ac88903 and a1f2b90.

📒 Files selected for processing (6)
  • src/main/presenter/agentRuntimePresenter/tapeService.ts
  • src/main/presenter/sqlitePresenter/tables/deepchatTapeEntries.ts
  • src/main/presenter/sqlitePresenter/tables/deepchatTapeSearchProjection.ts
  • src/shared/contracts/routes/sessions.routes.ts
  • test/main/presenter/agentRuntimePresenter/tapeService.test.ts
  • test/main/presenter/sqlitePresenter/deepchatTapeEntriesTable.test.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/shared/contracts/routes/sessions.routes.ts
  • test/main/presenter/sqlitePresenter/deepchatTapeEntriesTable.test.ts
  • src/main/presenter/sqlitePresenter/tables/deepchatTapeSearchProjection.ts
  • src/main/presenter/sqlitePresenter/tables/deepchatTapeEntries.ts
  • src/main/presenter/agentRuntimePresenter/tapeService.ts
  • test/main/presenter/agentRuntimePresenter/tapeService.test.ts

📝 Walkthrough

Walkthrough

The change replaces subagent Tape merge/discard operations with frozen-head Tape links, adds authorized cross-Tape search and context retrieval, hardens fork merge persistence, and updates orchestration, routes, tools, tests, and architecture documentation.

Changes

Subagent Tape lineage

Layer / File(s) Summary
Typed link contracts and runtime wiring
src/shared/types/*, src/main/agent/*, src/main/presenter/sessionApplication/*, src/main/presenter/toolPresenter/*
Subagent Tape APIs now accept structured link inputs and return link receipts across agent backends, coordinators, presenters, routes, and tools.
Tape identity, lineage persistence, and effective reads
src/main/presenter/agentRuntimePresenter/tapeService.ts, src/main/presenter/sqlitePresenter/tables/*
Tape incarnations, frozen child heads, transactional/idempotent links, bounded fork merges, authorized linked-source resolution, and effective search/context queries are implemented.
Subagent finalization and retry behavior
src/main/presenter/toolPresenter/agentTools/subagentOrchestratorTool.ts
Terminal completed, errored, and cancelled children finalize through validated Tape links, with retry handling during wait and log operations.
Lineage, recall, and routing validation
test/main/agent/*, test/main/presenter/*, test/main/routes/*
Tests cover link routing, frozen-head reads, incarnation replacement, authorization, projection fallback, fork atomicity, legacy compatibility, and finalization retries.
Architecture and compatibility documentation
docs/architecture/*, docs/FLOWS.md
Documentation defines true-fork versus production-subagent lineage, linked read scopes, frozen heads, compatibility rules, implementation phases, and validation status.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the main change: explicit subagent tape lineage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/subagent-tape-lineage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (1)
src/shared/contracts/routes/sessions.routes.ts (1)

370-371: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use EntityIdSchema for session IDs.

For consistency with other session ID validations in this file (e.g., sessionId, parentSessionId, targetMessageId), prefer using EntityIdSchema instead of defining an inline string schema.

♻️ Proposed fix to reuse the schema
-        maxTotalBytes: z.number().int().min(0).max(65536).optional(),
-        sourceSessionId: z.string().trim().min(1).optional()
+        maxTotalBytes: z.number().int().min(0).max(65536).optional(),
+        sourceSessionId: EntityIdSchema.optional()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/shared/contracts/routes/sessions.routes.ts` around lines 370 - 371,
Update the sourceSessionId field in the relevant route schema to reuse
EntityIdSchema instead of the inline trimmed non-empty string validation,
matching the existing sessionId, parentSessionId, and targetMessageId
definitions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/presenter/agentRuntimePresenter/index.ts`:
- Around line 1588-1592: Update the condition before TapeService.search in the
presenter method to call ensureSessionTapeReady for both the default/current
scope and the current_and_linked scope. Preserve the existing behavior for other
scopes, then execute search with the provided sessionId, query, and options.

In `@src/main/presenter/agentRuntimePresenter/tapeService.ts`:
- Around line 475-487: The consistency check in
assertSubagentTapeLinkReceiptMatchesInput must compare every normalized
persisted field, not only session IDs and outcome. Include slotId, taskTitle,
resultSummary, and all other frozen metadata fields represented by
SubagentTapeLinkReceipt and SubagentTapeLinkInput; reject any mismatch while
preserving idempotent acceptance for identical data. Add mismatch tests covering
changed frozen metadata, including the corresponding retry paths.

In `@src/main/presenter/sqlitePresenter/tables/deepchatTapeEntries.ts`:
- Around line 965-974: Update the fallback query construction around
serializeDeepChatTapeReadSources and queryPattern to use the same tokenized
search predicate as projection search, rather than only matching the full
normalized query as one contiguous substring. Preserve the existing candidate
payload, metadata, and name fields and bind parameters for every generated token
clause. Add coverage comparing projected and raw fallback searches, including
multi-term queries such as “alpha beta,” to ensure equivalent results.

In `@test/main/presenter/sqlitePresenter/deepchatTapeEntriesTable.test.ts`:
- Around line 108-111: Update the assertion for rebuiltIncarnation in the
deepchat tape entries test to first verify it is defined or otherwise present,
then retain the existing assertion that it differs from firstIncarnation. Ensure
the test cannot pass when rebuilt metadata is omitted.

---

Nitpick comments:
In `@src/shared/contracts/routes/sessions.routes.ts`:
- Around line 370-371: Update the sourceSessionId field in the relevant route
schema to reuse EntityIdSchema instead of the inline trimmed non-empty string
validation, matching the existing sessionId, parentSessionId, and
targetMessageId definitions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 93b5fa7b-cc17-4dd2-907a-85dfc42bfc60

📥 Commits

Reviewing files that changed from the base of the PR and between 1034903 and ac88903.

📒 Files selected for processing (44)
  • docs/FLOWS.md
  • docs/architecture/agent-system-layered-runtime/migration-and-validation.md
  • docs/architecture/agent-system-layered-runtime/modules/shared-data-and-io.md
  • docs/architecture/agent-system-layered-runtime/modules/tape-and-observability.md
  • docs/architecture/deepchat-tape-baseline/spec.md
  • docs/architecture/retire-agent-session-presenter/spec.md
  • docs/architecture/session-application-coordinators/spec.md
  • docs/architecture/session-management.md
  • docs/architecture/subagent-run-guardrails/spec.md
  • docs/architecture/subagent-tape-lineage/plan.md
  • docs/architecture/subagent-tape-lineage/spec.md
  • docs/architecture/subagent-tape-lineage/tasks.md
  • src/main/agent/manager/deepChatAgentBackend.ts
  • src/main/agent/manager/directAcpAgentBackend.ts
  • src/main/agent/manager/sessionHandles.ts
  • src/main/agent/shared/agentSharedData.ts
  • src/main/presenter/agentRuntimePresenter/index.ts
  • src/main/presenter/agentRuntimePresenter/tapeService.ts
  • src/main/presenter/index.ts
  • src/main/presenter/sessionApplication/agentAssignmentCoordinator.ts
  • src/main/presenter/sessionApplication/ports.ts
  • src/main/presenter/sqlitePresenter/tables/deepchatTapeEntries.ts
  • src/main/presenter/sqlitePresenter/tables/deepchatTapeSearchProjection.ts
  • src/main/presenter/sqlitePresenter/tables/newSessions.ts
  • src/main/presenter/toolPresenter/agentTools/agentTapeTools.ts
  • src/main/presenter/toolPresenter/agentTools/subagentOrchestratorTool.ts
  • src/main/presenter/toolPresenter/index.ts
  • src/main/presenter/toolPresenter/runtimePorts.ts
  • src/shared/contracts/routes/sessions.routes.ts
  • src/shared/types/agent-interface.d.ts
  • test/main/agent/manager/agentManager.test.ts
  • test/main/agent/manager/deepChatAgentBackend.test.ts
  • test/main/agent/manager/directAcpAgentBackend.test.ts
  • test/main/presenter/agentRuntimePresenter/agentRuntimePresenter.test.ts
  • test/main/presenter/agentRuntimePresenter/tapeService.test.ts
  • test/main/presenter/sessionApplication/agentAssignmentCoordinator.test.ts
  • test/main/presenter/sessionApplication/projectionCoordinator.test.ts
  • test/main/presenter/sessionApplication/sessionApplication.integration.test.ts
  • test/main/presenter/sqlitePresenter/deepchatTapeEntriesTable.test.ts
  • test/main/presenter/sqlitePresenter/newSessionsTable.test.ts
  • test/main/presenter/toolPresenter/agentTools/agentTapeTools.test.ts
  • test/main/presenter/toolPresenter/agentTools/subagentOrchestratorTool.test.ts
  • test/main/presenter/toolPresenter/toolPresenter.test.ts
  • test/main/routes/dispatcher.test.ts

Comment thread src/main/presenter/agentRuntimePresenter/index.ts
Comment thread src/main/presenter/agentRuntimePresenter/tapeService.ts Outdated
Comment thread src/main/presenter/sqlitePresenter/tables/deepchatTapeEntries.ts Outdated
@yyhhyyyyyy yyhhyyyyyy merged commit 8b121ed into dev Jul 16, 2026
4 checks passed
@yyhhyyyyyy yyhhyyyyyy deleted the feat/subagent-tape-lineage branch July 16, 2026 01:35
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