Skip to content

feat(mcp): defer thread organization safely - #8683

Closed
juliusmarminge wants to merge 10 commits into
agents/mcp-thread-state/organizationfrom
agents/mcp-thread-state/deferred
Closed

feat(mcp): defer thread organization safely#8683
juliusmarminge wants to merge 10 commits into
agents/mcp-thread-state/organizationfrom
agents/mcp-thread-state/deferred

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Aug 29, 2026

Copy link
Copy Markdown
Member

An active agent cannot safely settle or archive its own thread because ordinary organization commands correctly reject active work.

This dependent layer adds durable run-bound organization intents and t3_thread_defer_organization operations to schedule settlement or archival, inspect the current intent, and cancel it. The terminal path applies an intent only after its bound run finishes successfully and no newer, queued, active, pending-request, or title-regeneration work exists. Unsafe or stale intents clear without consuming an internal apply command receipt.

Stable receipts make retries deterministic. Projection rebuilds preserve intent state, terminal apply delegates to ordinary serialized settle/archive behavior, queued-run promotion survives typed apply failures, and startup recovery retries one transient typed plan failure while preserving interruption and isolating persistent failures.

Focused validation:

  • 76 focused tests across contracts, MCP registration/toolkit, runtime wiring, real deferred recovery, receipt replay, and settlement behavior
  • vp run --filter t3 typecheck
  • vp run --filter @t3tools/contracts typecheck
  • vp run --filter @t3tools/shared typecheck
  • Targeted vp lint, vp fmt --check, and git diff --check

Depends on #8676 for thread organization discovery and lifecycle mutations. Native stack: #8676#8683, rooted on t3code/codex-turn-mapping at 415ed0f73b97f1655b6282492f81d0b2bba3a9cc.

Implemented by GPT-5.6-Sol via Codex in T3 Code.

Note

Add t3_thread_defer_organization MCP tool and server-side apply recovery

  • Adds a new MCP tool that lets an agent schedule, read, or cancel a deferred settle/archive intent bound to its current run. The server applies the intent only after successful run completion, discarding it when newer, queued, approval-blocked, or unresolved-request work exists.
  • Introduces dispatchDeferredOrganization in Orchestrator.ts handling defer, cancel, and apply commands. Terminal run events now trigger locked deferred-organization application; startup recovery scans persisted thread shells and applies eligible intents whose bound run is missing, superseded, or terminal.
  • Adds contract schemas in orchestrationV2.ts and orchestratorMcp.ts for the deferred organization intent, commands, and MCP input/result. The server-only apply command is excluded from the client-dispatchable RPC schema via OrchestrationV2ClientCommand.
  • Wires recoverDeferredOrganization into the live orchestrator service and the server startup recovery phase in serverRuntimeStartup.ts, running it after provider runtime recovery succeeds.
  • Risk: thread mutations now accept a clearDeferredOrganization flag that nulls deferredOrganization on the committed thread payload; the emitted event uses the post-clear thread value, so any consumer reading the event payload for deferred state will see null after cleanup.

Macroscope summarized 6ff0395.

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 167dccd2-887e-4e48-91bb-7812cf6d2956

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Warning

Your free Security trial is over. An organization admin can activate Security or dismiss this notice.


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

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 29, 2026
Comment thread apps/server/src/orchestration-v2/Orchestrator.ts Outdated

@macroscopeapp macroscopeapp 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.

One finding on startup reconciliation isolation in apps/server/src/orchestration-v2/Orchestrator.ts.

Posted via Macroscope — Effect Service Conventions

Comment thread apps/server/src/orchestration-v2/Orchestrator.ts
@github-actions

github-actions Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Thread transfer impact

⚠️ The latest CI run did not produce a thread transfer result for 6ff0395.

This comment will update automatically after the next completed run.

@juliusmarminge
juliusmarminge force-pushed the agents/mcp-thread-state/deferred branch from 271e82b to 858c15a Compare August 29, 2026 21:59

@macroscopeapp macroscopeapp 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.

Effect service conventions review: one finding in apps/server/src/orchestration-v2/Orchestrator.ts (startup reconciliation isolation/retry). Everything else in the changed scope follows the surrounding service, layer, and import conventions.

Posted via Macroscope — Effect Service Conventions

Comment thread apps/server/src/orchestration-v2/Orchestrator.ts
@github-actions github-actions Bot added size:XL 500-999 changed lines (additions + deletions). size:L 100-499 changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). size:XL 500-999 changed lines (additions + deletions). labels Aug 29, 2026
@juliusmarminge
juliusmarminge marked this pull request as ready for review August 29, 2026 22:26
@macroscopeapp

macroscopeapp Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This change adds a durable MCP-driven workflow that can automatically settle or archive threads after run completion, with startup recovery and provider-session/cleanup side effects. The orchestration and lifecycle changes span multiple production layers and are broader than a small self-contained addition.

You can add or adjust custom eligibility rules. Learn more.

@macroscopeapp macroscopeapp 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.

One finding on the new deferred-organization startup recovery loop in apps/server/src/orchestration-v2/Orchestrator.ts. Per-thread isolation is now in place; the remaining gap is interruption handling and transient retry before readiness.

Posted via Macroscope — Effect Service Conventions

Comment thread apps/server/src/orchestration-v2/Orchestrator.ts Outdated
@github-actions github-actions Bot added size:XL 500-999 changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). labels Aug 30, 2026
@juliusmarminge
juliusmarminge force-pushed the agents/mcp-thread-state/deferred branch from afd33ef to a887160 Compare August 30, 2026 20:14
Comment thread apps/server/src/orchestration-v2/Orchestrator.ts
Comment thread docs/user/thread-sidebar.md Outdated
@juliusmarminge
juliusmarminge force-pushed the agents/mcp-thread-state/deferred branch from 284b9dc to cf20d21 Compare September 5, 2026 06:04
Comment thread packages/contracts/src/orchestrationV2.ts

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON, but a cloud agent failed to start.

Reviewed by Cursor Bugbot for commit cf20d21. Configure here.

Comment thread apps/server/src/orchestration-v2/Orchestrator.ts
@juliusmarminge
juliusmarminge force-pushed the agents/mcp-thread-state/deferred branch from cf20d21 to 71650ee Compare September 5, 2026 06:40
@juliusmarminge
juliusmarminge force-pushed the agents/mcp-thread-state/deferred branch from 71650ee to 6ff0395 Compare September 7, 2026 18:32
@cursor

cursor Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Bugbot is paused — on-demand spend limit reached

Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.

A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.

@juliusmarminge

Copy link
Copy Markdown
Member Author

Superseded as the active MCP proposal by #10554 for immediate organization only in the rebuilt MCP stack, following the maintainer request to review thin service wrappers separately from service hardening.

This is not a full feature-parity replacement. Durable deferred organization is parked as separate service/feature work. It is not included in the thin MCP wrapper.

Closing this mixed proposal without merging. The remote branch agents/mcp-thread-state/deferred and exact head 6ff0395a3cf73f8b756c352b492b3d5a205c0959 are retained so the service changes can be extracted for separate review later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant