Skip to content

🤖 fix: align task lifecycle tool contracts - #3859

Open
ammar-agent wants to merge 10 commits into
mainfrom
fix/task-id-tool-consistency
Open

🤖 fix: align task lifecycle tool contracts#3859
ammar-agent wants to merge 10 commits into
mainfrom
fix/task-id-tool-consistency

Conversation

@ammar-agent

Copy link
Copy Markdown
Collaborator

Summary

Align task ID prompting and follow-up tool schemas with the runtime lifecycle contract, while hardening task/workflow stop behavior against scope bypasses, stale statuses, cleanup failures, and concurrency races.

Background

The task tools mixed camelCase result handles with snake_case follow-up inputs, contained contradictory guidance for inactive children and workflow rediscovery, and could mask not_found/invalid_scope results. Workflow-owned workers were also inconsistently isolated across direct lifecycle operations, and stopping workflows exposed races between task creation, resume/retry, interruption, and cleanup.

Implementation

  • Documents explicit taskId/taskIds to task_id/task_ids mappings and corrects task rediscovery and inactive-child guidance.
  • Preserves precise task_await statuses with active-handle suggestions instead of replacing them with speculative sequencing errors.
  • Rejects direct lifecycle operations on workflow-owned internal workers and background processes.
  • Makes terminal task_stop behavior idempotent across agent tasks, workspace turns, and workflow runs.
  • Serializes workflow create/resume/retry/interrupt transitions with task-tree lifecycle locks.
  • Defers workflow workspace sweeps until locks are released, retries interrupted cleanup safely, and includes nested workflow runs.
  • Cleans workflow-owned background bash processes during interruption while ensuring cleanup failures do not abandon task teardown.
  • Retains legacy task_terminate schemas solely for rendering historical transcripts and updates generated docs/skills.

Validation

  • make static-check
  • Task tool suites: toolDefinitions, task_await, task_stop, task_remove, task_send_message, background bash integration
  • Workflow suites: WorkflowRunner, WorkflowService, WorkflowTaskServiceAdapter
  • Full TaskService unit suite
  • Independent read-only review of lifecycle scope, deadlock, retry, and race behavior

Risks

The main risk is in workflow/task lifecycle coordination. Coverage now exercises lock ordering, early and already-aborted signals, workflow cleanup retries, nested deferred sweeps, workflow-owned background processes, and stop-versus-start/resume races.


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

Align task ID prompting with follow-up tool schemas, preserve precise await statuses, and enforce workflow-owned task isolation across lifecycle operations.

Serialize workflow starts, resumes, retries, and interrupts with task-tree lifecycle locks while keeping cleanup retryable and deadlock-safe.

---

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

<!-- mux-attribution: model=openai:gpt-5.6-sol thinking=xhigh costs=87.15 -->
@mintlify

mintlify Bot commented Aug 16, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
Mux 🟢 Ready View Preview Aug 16, 2026, 1:19 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the task ID prompting, lifecycle scope, workflow locking, cleanup retry, and deadlock handling changes.

@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: 157ac63607

ℹ️ 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/tools/task_stop.ts Outdated
Provide the lifecycle and cleanup methods required by the hardened WorkflowService in router unit-test contexts.

---

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

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

Copy link
Copy Markdown
Collaborator Author

@codex review

Updated the router workflow test mocks to cover the new lifecycle lock and cleanup dependencies. Local static checks and all previously failing router tests pass.

@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: 8b89611165

ℹ️ 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
Resolve workflow lifecycle services from each descendant owner's session before listing or interrupting child-owned runs.

---

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

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

Copy link
Copy Markdown
Collaborator Author

Addressed Codex finding PRRT_kwDOPxxmWM6Zj6B9 (Resolve descendant runs from their owning session):

  • Added a per-workspace workflow lifecycle service resolver to tool configuration.
  • task_stop now lists and interrupts each descendant owner's runs through that owner's session-backed WorkflowRunStore, never the parent store.
  • AIService constructs the resolver with owner-specific task adapters, lifecycle locks, status callbacks, and background-process cleanup.
  • Added a regression test that makes the parent workflow store unusable and verifies the child-owned service is selected.

Local make static-check, task-stop/background-bash tests, router workflow tests, AI workflow tests, TaskService tests, and typecheck pass.

@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

The child-owned workflow session finding has been addressed and its thread resolved. Please re-review the updated branch.

@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: 6cd78039e1

ℹ️ 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/tools/task_stop.ts Outdated
Comment thread src/node/services/taskService.ts
Stop workflow worker streams before taking the final background-process snapshot so concurrently registering bash tasks are included in cleanup.

---

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

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

Copy link
Copy Markdown
Collaborator Author

Addressed Codex finding PRRT_kwDOPxxmWM6Zj9e2 (Clean up processes after stopping the worker stream):

  • Moved the final background-process cleanup after stopStream, so bash processes registered while the worker stream is winding down are included.
  • Kept cleanup best-effort so process disposal failures cannot block stream/task status teardown.
  • Added ordering coverage proving each workflow worker stream stops before its process cleanup, including a cleanup rejection path.

Local make static-check and all affected task/workflow/router/AI/TaskService suites pass.

@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

The process cleanup ordering finding has been addressed and its thread resolved. Please re-review the updated branch.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 3bf1b1bdc4

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

Interrupt workflows owned by every descendant session and remove archived workflow-owned workers when deleting their user-owned parent subtree.

---

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

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

Copy link
Copy Markdown
Collaborator Author

Addressed both Codex findings from the latest review:

  1. PRRT_kwDOPxxmWM6ZkAqoInclude workflow-owned session owners in the stop sweep

    • The stop sweep now resolves workflow services for the target and every descendant workspace, including workflow-owned workers.
    • Independent background workflows launched from a workflow worker's own session are now interrupted and swept before the user-owned ancestor stop returns.
    • Regression coverage verifies both the user-owned child session and workflow-worker session are opened; the parent store is never used.
  2. PRRT_kwDOPxxmWM6ZkAqpAllow removing parents with archived workflow children

    • Removing a user-owned task now internally removes inactive archived workflow-owned descendants deepest-first while retaining invalid_scope for direct public operations on workflow workers.
    • Active or non-archived descendants still block removal normally.
    • Regression coverage removes an archived workflow worker followed by its user-owned parent and verifies cleanup order.

Local make static-check and all affected task/workflow/router/AI/TaskService suites pass.

@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

Both latest workflow-tree cleanup findings have been addressed and their threads resolved. Please re-review the updated branch.

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

ℹ️ 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/tools/task_stop.ts
Comment thread src/node/services/tools/task_stop.ts Outdated
Wrap task invocation examples as inline code so generated hook documentation parses correctly in Mintlify.

---

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

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

Copy link
Copy Markdown
Collaborator Author

@codex review

Pushed the final generated-doc formatting fix; make static-check-full now passes, including Mintlify broken-link/MDX parsing. Please re-review the latest branch.

@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: 1cab3a3b38

ℹ️ 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
Keep ordinary task stops working without workflow services, validate every active workflow worker against its exact owner run, and retain lifecycle resolvers for cleanup even when workflow tools are disabled.

---

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

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

Copy link
Copy Markdown
Collaborator Author

Addressed both latest Codex findings:

  1. PRRT_kwDOPxxmWM6ZkEQEDon't require workflow services for ordinary task stops

    • Workflow lifecycle resolution is now available internally even when model-facing workflow tools are disabled.
    • The stop sweep skips unavailable workflow services for ordinary task trees and only requires a service when an active workflow-owned worker must be reconciled.
    • Added a regression proving a normal descendant tree stops successfully with no workflow service configured.
  2. PRRT_kwDOPxxmWM6ZkEQFCorrelate every active worker with its owning run

    • Descendant task metadata now includes the effective inherited workflow run ID and the workspace session that owns it.
    • Every active workflow-owned worker is validated against that exact run; missing, unreadable, completed, or failed owner runs now block the stop instead of being masked by another healthy branch.
    • Independent workflows owned by every descendant session are still scanned and interrupted.
    • Added regressions for inherited workflow metadata and for a healthy run failing to mask an orphaned worker.

Local make static-check-full and all affected task/workflow/router/AI/TaskService suites pass.

@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

Both latest workflow service/correlation findings have been addressed and their threads resolved. Please re-review the updated branch.

@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: 1c3c2c70b9

ℹ️ 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
Prevent stale or removal-racing workflow requests from recreating session state after their workspace has been deleted.

---

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

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

Copy link
Copy Markdown
Collaborator Author

Addressed Codex finding PRRT_kwDOPxxmWM6ZkGE6 (Reject workflow starts when the workspace is missing):

  • withWorkspaceOwnedWorkStartLock now rejects a missing workspace before invoking the workflow operation.
  • This prevents stale or removal-racing starts from recreating session directories and ghost workflow runs.
  • Added regression coverage verifying the operation is never called for a removed workspace.

Local make static-check-full and all affected task/workflow/router/AI/TaskService suites pass.

@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

The missing-workspace workflow start finding has been addressed and its thread resolved. Please re-review the updated branch.

@ammar-agent

Copy link
Copy Markdown
Collaborator Author

Codex finding PRRT_kwDOPxxmWM6ZkICc is already addressed on the current PR head 6eaa8236db458a746c50858b246305abe9512784.

TaskService.withWorkspaceOwnedWorkStartLock now contains an explicit missing-entry guard before the archived/status checks:

const entry = findWorkspaceEntry(this.config.loadConfigOrDefault(), workspaceId);
if (entry == null) {
  throw new Error("Cannot start workflow work from a missing workspace");
}

The same commit adds withWorkspaceOwnedWorkStartLock rejects missing workspaces, which verifies that a stale operation is rejected and never invoked. make static-check-full and the affected suites pass. The review comment appears to reference the pre-fix revision.

@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

The latest missing-workspace comment referenced the pre-fix code; the current head already has the explicit guard and regression test. The thread has been answered and resolved. Please review current head 6eaa8236db458a746c50858b246305abe9512784.

@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: 6eaa8236db

ℹ️ 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
Validate parent and descendant eligibility before deleting archived workflow workers so rejected task_remove calls have no destructive side effects.

---

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

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

Copy link
Copy Markdown
Collaborator Author

Addressed Codex finding PRRT_kwDOPxxmWM6ZkKMQ (Validate the parent before deleting archived workflow children):

  • Parent active-state validation now runs before any archived workflow descendant cleanup.
  • The full descendant set is preflighted; only an otherwise-eligible parent whose descendants are all inactive archived workflow-owned workers proceeds to cleanup.
  • User-owned, active, streaming, or non-archived descendants reject removal without deleting anything.
  • Added regression coverage for both active parents and inactive parents with user-owned descendants, verifying archived workflow workspaces remain intact and no remove call occurs.

Local make static-check-full, the focused parent-removal regression, and all affected suites pass.

@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

The rejected-removal side-effect finding has been addressed and its thread resolved. Please re-review the updated branch.

@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: 884c46ab6d

ℹ️ 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/workflows/WorkflowService.ts Outdated
Keep background workflow creation serialized until the run is durably running and the background runner has been scheduled.

---

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

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

Copy link
Copy Markdown
Collaborator Author

Addressed Codex finding PRRT_kwDOPxxmWM6ZkMuG (Hold the start lock through background dispatch):

  • startWorkflowInBackground now holds the workspace lifecycle lock through durable run creation, the running status write, status notifications, and background runner scheduling.
  • Extracted an unlocked run-creation helper so the background path avoids re-entering the non-reentrant lifecycle lock while foreground creation retains the existing guarded helper.
  • Added regression coverage asserting both pending and running callbacks execute while the lock is held and the lock releases only after the durable running state is established.

Local make static-check-full and all affected task/workflow/router/AI/TaskService suites pass.

@ammar-agent

Copy link
Copy Markdown
Collaborator Author

@codex review

The background workflow start-lock finding has been addressed and its thread resolved. Please re-review the updated branch.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: dcdb7a274b

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

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