# feat\(mcp\): defer thread organization safely · PR \#8683 · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/pull/8683)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

State: closed

Source repository: pingdotgg/t3code

Source branch: agents/mcp-thread-state/deferred

Target branch: agents/mcp-thread-state/organization

Head commit: 6ff0395a3cf73f8b756c352b492b3d5a205c0959

[Discussion and reviews](https://git.cafe/pingdotgg/t3code/pull/8683)

[Commits](https://git.cafe/pingdotgg/t3code/pull/8683/commits?format=markdown)

[Files changed](https://git.cafe/pingdotgg/t3code/pull/8683/diffs?format=markdown)

## Description

---

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](https://github.com/pingdotgg/t3code/pull/8676) for thread organization discovery and lifecycle mutations. Native stack: [#8676](https://github.com/pingdotgg/t3code/pull/8676) → [#8683](https://github.com/pingdotgg/t3code/pull/8683), rooted on `t3code/codex-turn-mapping` at `415ed0f73b97f1655b6282492f81d0b2bba3a9cc`.

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


<!-- Macroscope's pull request summary starts here -->
<!-- Macroscope will only edit the content between these invisible markers, and the markers themselves will not be visible in the GitHub rendered markdown. -->
<!-- If you delete either of the start / end markers from your PR's description, Macroscope will append its summary at the bottom of the description. -->
> [!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](https://github.com/pingdotgg/t3code/pull/8683/files#diff-8747d8bd671948fc866dd5d05e74fa07e196b1f397fa7895aa5095e3186cd570) 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](https://github.com/pingdotgg/t3code/pull/8683/files#diff-b32ccdacc28721bf0de57f1d053cd6e766d7d6119475e59292cb21d9f30ba984) and [orchestratorMcp.ts](https://github.com/pingdotgg/t3code/pull/8683/files#diff-30fbd4867ef75aeb0387d7659bcc37b66ae287fb1356db374bd78ac363599dd3) 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](https://github.com/pingdotgg/t3code/pull/8683/files#diff-1930335d6e319fc5766e0578303e19f9d788e9990f87604b77f9f768e61d7118), 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's review summary starts here -->
>
> <sup><a href="https://app.macroscope.com">Macroscope</a> summarized 6ff0395.</sup>
> <!-- Macroscope's review summary ends here -->
>
<!-- Macroscope's pull request summary ends here -->
