Skip to content

🤖 tests: validate persistent sub-agent compaction - #3832

Merged
ammario merged 7 commits into
mainfrom
tests/persistent-subagent-compaction
Aug 11, 2026
Merged

🤖 tests: validate persistent sub-agent compaction#3832
ammario merged 7 commits into
mainfrom
tests/persistent-subagent-compaction

Conversation

@ammar-agent

@ammar-agent ammar-agent commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds deterministic, no-live-LLM validation that persistent sub-agents remain seamless across chat compaction. Mechanical compact turns no longer advance child lifecycle state, reawakened continuation correlation and agent-initiated attribution survive compaction, and the mock AI runtime now mirrors real stream metadata closely enough for a true backend integration test.

The PR is also a net maintainability reduction: it removes the unused generic archive/unarchive/delete-worktree TaskService backend left behind after persistent sub-agents adopted the public active → inactive → removed lifecycle. The supported task_remove path now uses one direct, parent-scoped persistent-child removal implementation.

Background

The persistent sub-agent foundation from #3825 is merged into main. A child compaction stream was visible directly to TaskService and could be mistaken for the end of delegated work, moving an active child toward completion recovery. Mock streams also dropped workspace-turn correlation, preventing high-confidence end-to-end coverage for a reawakened persistent child.

The old generic lifecycle methods had no production callers; only TaskService tests exercised them. Historical task_workspace_lifecycle schemas and transcript rendering remain intact for old chats.

Implementation

  • Ignore compact-agent/mode stream ends in TaskService; only the post-compaction delegated follow-up may settle the child or continuation handle.
  • Preserve agentInitiated and resolved workspace-turn correlation on persisted compaction follow-ups and their crash-safe dispatch/retry path.
  • Carry agent identity, thinking level, and mux correlation through mock stream start, partial/final history, and stream-end events.
  • Replace the unused generic workspace lifecycle resolver/lock/archive/worktree operations with direct persistent-child removal that verifies scope, rejects active/non-leaf children, persists idempotency tombstones, and removes under the task-tree lock.
  • Delete lifecycle-only tests while retaining focused coverage for scope, deepest-first removal, active-state rejection, reawakening races, and idempotent retries.
  • Add layered compaction regression coverage from focused unit tests through a ServiceContainer/IPC integration test.

Validation

  • make static-check
  • bun test src/node/services/taskService.test.ts
  • bun test src/node/services/agentSession.autoCompaction.test.ts src/node/services/agentSession.workspaceTurnInheritance.test.ts src/node/services/agentSession.continueMessageAgentId.test.ts src/node/services/mock/mockAiStreamPlayer.test.ts
  • bun test src/node/services/tools/task_remove.test.ts
  • TEST_INTEGRATION=1 bun x jest tests/ipc/tasks/persistentSubagentCompaction.test.ts --runInBand
  • git diff --numstat origin/main...HEAD: 790 additions, 1,239 deletions, net −449 LoC

No test invokes a live LLM API.

Risks

Low-to-moderate product risk. Compaction changes are narrowly scoped and covered end-to-end. Lifecycle deletion removes backend methods with no production callers; the supported task_remove path retains scope, activity, descendant, race, and idempotency protections. Historical transcript rendering remains compatible.


Generated with mux • Model: openai:gpt-5.6-sol • Thinking: xhigh • Cost: $88.81

@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the complete stacked diff, focusing on persistent child lifecycle across compaction, workspace-turn correlation/agent attribution preservation, and deterministic no-live-LLM coverage.

@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: 2e8b0a9248

ℹ️ 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/node/services/agentSession.ts
@ammar-agent

Copy link
Copy Markdown
Collaborator Author

Addressed the mid-stream correlation finding: AgentSession now records the actual resolved workspace-turn-task metadata used by the active stream and persists it on the generated Continue follow-up before automatic compaction. The regression test now drives a correlated, agent-initiated stream through the real mid-stream compaction handoff and asserts both correlation and attribution are durable.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 60e70d70d3

ℹ️ 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".

Base automatically changed from feat/persistent-subagent-experience to main August 11, 2026 15:18
Keep active and reawakened children seamless across mechanical compaction turns, preserve internal attribution and workspace-turn correlation in follow-ups, and add deterministic no-provider coverage from unit through backend integration layers.

---

_Generated with `mux` • Model: `openai:gpt-5.6-sol` • Thinking: `xhigh` • Cost: `$41.38`_

<!-- mux-attribution: model=openai:gpt-5.6-sol thinking=xhigh costs=41.38 -->
Carry the resolved workspace-turn correlation through automatic mid-stream compaction so the post-compaction continuation settles the existing reawakened execution.

---

_Generated with `mux` • Model: `openai:gpt-5.6-sol` • Thinking: `xhigh` • Cost: `$41.38`_

<!-- mux-attribution: model=openai:gpt-5.6-sol thinking=xhigh costs=41.38 -->
@ammar-agent
ammar-agent force-pushed the tests/persistent-subagent-compaction branch from 60e70d7 to 362acf3 Compare August 11, 2026 16:57
@ammar-agent

Copy link
Copy Markdown
Collaborator Author

Rebased the two PR-only commits onto current main at 88580ca7d6 after #3825 merged, resolved the TaskService test conflict by retaining both upstream and compaction coverage, and reran the full TaskService suite, focused AgentSession/mock tests, no-live-LLM IPC integration, and make static-check.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 362acf3594

ℹ️ 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".

Replace the unused generic archive/unarchive/worktree lifecycle subsystem with the one supported persistent-child removal operation, and retain focused scope, active-state, ordering, race, and idempotency coverage.

---

_Generated with `mux` • Model: `openai:gpt-5.6-sol` • Thinking: `xhigh` • Cost: `$54.08`_

<!-- mux-attribution: model=openai:gpt-5.6-sol thinking=xhigh costs=54.08 -->
@ammar-agent

Copy link
Copy Markdown
Collaborator Author

Refactored the PR to net negative LoC through maintainability improvements: removed the unused generic archive/unarchive/delete-worktree TaskService backend and its lifecycle-only tests, while keeping historical transcript schemas/rendering and the supported direct task_remove path. The final diff is 610 additions / 1,235 deletions (net -625) against main; full TaskService, compaction, task_remove, integration, typecheck, and static checks pass.

@codex review

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

ℹ️ 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/node/services/taskService.ts Outdated
Only defer task settlement for compact turns that durably stage a follow-up; bare /compact continues normal child completion recovery.

---

_Generated with `mux` • Model: `openai:gpt-5.6-sol` • Thinking: `xhigh` • Cost: `$88.81`_

<!-- mux-attribution: model=openai:gpt-5.6-sol thinking=xhigh costs=88.81 -->
@ammar-agent

Copy link
Copy Markdown
Collaborator Author

Addressed the standalone compaction finding: TaskService now defers compact stream-end settlement only when the persisted compaction request actually contains a follow-up. Bare /compact remains on the normal child recovery path, and compact text cannot be mistaken for a final report. Added coverage for both continued compaction and an awaiting_report child receiving standalone compaction. The diff remains net -568 LoC and full TaskService, typecheck, static, and no-live-LLM integration validation pass.

@codex review

@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: 2a4260cf1b

ℹ️ 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/node/services/taskService.ts
Coordinate TaskService settlement with AgentSession's durable compaction outcome so successful continued compactions defer to their follow-up while rejected compactions resume normal child recovery.

---

_Generated with `mux` • Model: `openai:gpt-5.6-sol` • Thinking: `xhigh` • Cost: `$99.28`_

<!-- mux-attribution: model=openai:gpt-5.6-sol thinking=xhigh costs=99.28 -->
@ammar-agent

Copy link
Copy Markdown
Collaborator Author

Addressed the failed-compaction finding with an explicit AgentSession → TaskService outcome handshake keyed by the compact assistant message. TaskService now waits for persistence handling: successful continued compactions defer to the correlated follow-up; empty/invalid/persistence-failed compactions take normal child recovery. Coverage exercises successful continuation, bare /compact, and rejected continued compaction. The PR remains net -480 LoC; full TaskService, AgentSession, task_remove, no-live-LLM integration, typecheck, and static validation pass.

@codex review

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

ℹ️ 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/node/services/taskService.ts Outdated
Wait for AgentSession's compaction outcome, then inspect the durable compaction boundary to decide whether child settlement should defer to a real follow-up.

---

_Generated with `mux` • Model: `openai:gpt-5.6-sol` • Thinking: `xhigh` • Cost: `$109.89`_

<!-- mux-attribution: model=openai:gpt-5.6-sol thinking=xhigh costs=109.89 -->
@ammar-agent

Copy link
Copy Markdown
Collaborator Author

Addressed the real-stream metadata finding: TaskService no longer expects compaction-request metadata on stream-end. It waits for AgentSession's persistence outcome, then derives continuation intent from the durable latest compaction boundary (compaction-summary.pendingFollowUp). Tests now use realistic compact stream-end metadata with no request mux metadata and persist the boundary separately. The PR remains net -465 LoC; full TaskService, AgentSession, task_remove, no-live-LLM integration, typecheck, and static validation pass.

@codex review

@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: 688444553e

ℹ️ 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/node/services/agentSession.ts Outdated
Comment thread src/node/services/taskService.ts Outdated
Resolve TaskService's compaction decision only after the durable continuation is accepted, so failed dispatches and non-continuing compactions take normal child recovery.

---

_Generated with `mux` • Model: `openai:gpt-5.6-sol` • Thinking: `xhigh` • Cost: `$117.50`_

<!-- mux-attribution: model=openai:gpt-5.6-sol thinking=xhigh costs=117.50 -->
@ammar-agent

Copy link
Copy Markdown
Collaborator Author

Addressed both handshake findings. AgentSession now resolves the compaction decision in finally, only after dispatchPendingFollowUp() returns successfully; rejected boundaries, bare compaction, and failed follow-up startup resolve false and use normal child recovery. TaskService no longer performs a second boundary read, eliminating the transient-read race. Added AgentSession coverage for a persisted boundary whose follow-up dispatch fails. The PR remains net -449 LoC; focused/full TaskService, AgentSession, task_remove, no-live-LLM integration, typecheck, and static validation pass.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 6ae98bdd56

ℹ️ 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".

@ammario
ammario merged commit 3cb6e87 into main Aug 11, 2026
21 of 22 checks passed
@ammario
ammario deleted the tests/persistent-subagent-compaction branch August 11, 2026 21:18
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.

2 participants