Repository navigation
Record owners when agents launch threads - #753
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5636a80cfc
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Agent-created threads could appear as independent roots because launch provenance and ownership were missing. Store the exact creator and an opt-out for explicitly requested roots, and record schedule provenance at creation. Carry-Group: incubator Carry-Fix: #751 Carry-Observation: Keep launch ownership with the cross-environment creation and lifecycle contracts. Implemented by GPT-6.2 Sol in Codex through T3 Code.
Regenerate the agent-context budget for the launch tool guidance and use a typed schema decoder in the compatibility test. Carry-Group: incubator Carry-Fix: #751 Implemented by GPT-6.2 Sol in Codex through T3 Code.
Keep the owner and placement rules in the launch tools while shortening their descriptions enough to fit the current context budget. Carry-Group: incubator Carry-Fix: #751 Implemented by GPT-6.2 Sol in Codex through T3 Code.
Record false for new independent launches so worktree suspension can classify them as other threads. Keep historical provenance without an ownership decision and accept explicit false in the ownership eval. Carry-Group: incubator Carry-Fix: #751 Implemented by GPT-6.2 Sol in Codex through T3 Code.
Hoist the compatibility test decoder to satisfy the schema lint rule. Carry-Group: incubator Carry-Fix: #751 Implemented by GPT-6.2 Sol in Codex through T3 Code.
Keep the launch and batch handlers thin by resolving ownership and placement in a fork-owned module. Restore the existing launch guidance alongside the new ownership rule. Carry-Group: incubator Carry-Fix: #751 Implemented by GPT-6.2 Sol in Codex through T3 Code.
f78a4f3 to
8047b29
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Part of #751 ## Problem Agents launch threads in other projects, and #753 now records who owns them. Archiving the parent at wrap-up still left that owned work open, so it had to be archived thread by thread. This PR makes wrap-up follow ownership across projects, and keeps threads the user has written in open by default. ## What gets archived Within the **current environment**, archiving uses the existing placement and delegated family and follows `getThreadOwner` transitively across projects. **Historical threads** whose creator record has no ownership keep their existing archive behavior. **Threads released from ownership** stay outside the added cascade. **Unarchive** uses the persisted `archivedWith` cohort. An already-archived intermediate keeps its prior restore cohort for legacy placement and lineage. A descendant reached only through recorded ownership restores with the operation that archived it. ## Human-message rule A child stays open by default when its stored shell records a message with **user role and user authorship**. The `latestUserAuthoredMessageAt` signal excludes agent relays and idle compaction. Renames and other actions that adopt the workspace do not set this message signal. The child and its downstream family stay owned. If the child is already archived, its messages still protect the live branch. Web and desktop can include the branch with separate confirmation. Mobile previews the default selection and offers Review so the user can open and archive a conversation directly. ## Preview and protections - **Preview first.** Web, desktop, mobile, and the tool show the family before the wider selection applies. Clients list titles and projects, what stays open, and active, unread, or protected state. The tool returns the environment ID and project IDs. - **Server re-check.** The server validates the exact selection again under its locks. - **Saved workspaces.** Each archive selection shows its own discardable and retained copies. The server binds disposal consent to the confirmed thread IDs. A copy shared with a thread that stays open remains available. - **Bulk.** An explicitly selected child still gets its own archive when the parent's default keeps it open. When two operations share a thread, the later one refreshes and can proceed only when its confirmed selection still matches after removing threads the batch already archived. - Existing activity, permission, shutdown, and retry protections apply to the selected family. ## Groups In an archive that uses the new ownership preview, a marked group is eligible when it has no conversations, runs, recorded Project Actions, user adoption, or protection, and every live member is in the same confirmed archive. It then archives with the family and can be restored from the archive. ## Scope and follow-ups - **Current environment only.** Linked environments can already preview or archive a known thread ID with the peer's authorization. They cannot enumerate a remote part of a family by owner, or record an offline destination as pending. - **Cross-environment follow-up.** Use an owner-qualified inventory and a durable operation record. Review the exact selection per reachable peer, use that peer’s authorization, and record its receipt. Show offline or denied peers as pending or blocked and retry idempotently. Restore the cohorts that actually committed. - **Temporary projects.** PR #761 landed the project listing service. The orchestrator is scheduling removal at wrap-up separately. Promotion landed in #763 and is included through the base. ## Archive performance Measured on the same 4,866 real thread projections. The dev migration preserved complete histories for 191 visible, stopped threads. The benchmark added the remaining projection rows from a read-only snapshot and archived only the migrated threads. | Median wall time | Original main | Original PR | Current main | Guarded indexed PR | | --- | ---: | ---: | ---: | ---: | | Candidate query | 0.08 ms | 33.85 ms | 0.09 ms | 0.43 ms | | Family preview | 12.76 ms | 48.19 ms | 13.47 ms | 14.48 ms | | Archive one 11-thread family | 176 ms | 425 ms | 183 ms | 178 ms | | Archive 50 threads, including previews | 654 ms | 11.44 s | 671 ms | 778 ms | Across five alternating pairs per comparison, the original query added a median 10.70 seconds to the 50-thread batch. The guarded indexed query added 108 ms (range +66 to +139 ms). The traced statements account for a median 76 ms of this difference. The 11-thread command runs the candidate query three times at dispatch and four times at completion. Preview adds one. The bulk ran 284 statements, including 50 previews. SQLite's original plan materialized `recorded_owner_candidates` and scanned the thread table twice. The new plan seeks both partial expression indexes from the recursive family and group lookups. The expressions guard malformed JSON so legacy recovery can keep running. The recorded restore-cohort lookup runs only when the root has both cohort fields. Ownership qualification stays in `getThreadOwner`. ## Verification - **Seeded parity.** On a LastCode database seed, current main and the indexed head selected and archived the same 27 threads across three real historical families. Archive events and exact restore cohorts matched. Each case used its own disposable copy, production dispatch, and the production archive runner, with the background worker disabled. The seed stayed byte-for-byte identical. - **Tests.** Archive and promotion server tests, the saved-workspace regression, Chromium confirmation tests, compiled web tests, and mobile and shared unit tests passed. Quick CI passed on the current head. Three bulk-archive regressions cover shared members in both orders and a refresh that finds new work. The database recovery, migration, and archive suites verify guarded lookups on legacy data and index selection. - **Browser.** The isolated browser applied the default cascade across two projects, and the user-authored conversation stayed open. - **Evals.** The new tool eval passed 0/4 on the baseline and 4/4 after the first tool change. The idle control passed 3/3 on both. The rebased tool text passed all 12 scored samples, including 3/3 for the typed-in branch and 2/2 for the idle control. The provider stream ended early on three samples, which remained unscored. - **Context growth.** The measured agent tool list grew by 314 bytes (85,690 → 86,004). The budget changes by one line. <details><summary>Browser evidence</summary> The existing archive menu on the synthetic fixture. <img width="840" alt="Archive option in the existing thread menu" src="https://github.com/user-attachments/assets/87994587-c683-4fd7-9b1a-3e2cb0353b39" /> The cross-project preview with the typed-in conversation kept open. <img width="840" alt="Archive preview with projects, selection, and a keep-open conversation" src="https://github.com/user-attachments/assets/da231c65-2c75-49c1-b7f8-00bb46c4e810" /> Opting in to archive the typed-in child now updates the saved-copy list to match the selection. Both captures use the same Chromium fixture. | Before | After | | --- | --- | | <img width="414" alt="After opt-in, the saved copy still appears under retained copies" src="https://github.com/user-attachments/assets/71bd3d69-c49e-43a1-be6f-24559f768658" /> | <img width="414" alt="After opt-in, the shared saved copy appears in the list to discard" src="https://github.com/user-attachments/assets/3176ef20-d563-4775-bf04-b3adeac23810" /> | </details> ## Upstream-owned files | File | Added | Removed | | --- | ---: | ---: | | `apps/mobile/src/features/home/useThreadListActions.test.ts` | 4 | 0 | | `apps/server/src/mcp/toolkits/thread/handlers.ts` | 6 | 0 | | `apps/server/src/mcp/toolkits/thread/tools.ts` | 4 | 2 | | `apps/server/src/orchestration-v2/Orchestrator.ts` | 6 | 35 | | `apps/server/src/orchestration-v2/ProjectionStore.ts` | 3 | 1 | | `apps/server/src/orchestration-v2/ThreadManagementService.ts` | 2 | 1 | | `apps/server/src/provider/agentContextBudget.json` | 1 | 1 | | `packages/client-runtime/src/operations/commands.ts` | 8 | 0 | | `packages/contracts/src/orchestrationV2.ts` | 4 | 0 | | Each of `apps/mobile/src/i18n/translations/{de,en,es,fr,ja,ko,pt-BR,ru,sv,zh}.json` | 3 | 0 | | Each of `apps/web/src/i18n/translations/{de,en,es,fr,ja,ko,pt-BR,ru,sv,zh}.json` | 5 | 0 | 🤖 Generated with [Claude Code](https://claude.com/claude-code) Local review: 4 rounds with GPT-6.1 Terra (xhigh), approved. The fourth round reviewed the final safety changes after churn-gate. A separate scoped source review approved the archive query and index migration. Carry-Source-Ref: refs/lastcode/carry-sources/pr-764/51687d0e8003745ca2058df231e4d0fcf7e87310 Carry-Source-Base: afdac03 Carry-Source-Head: 51687d0
Part of #751
Sidebar placement (
groupedUnderThreadId) can't say which thread owns a launched thread. Agent launches now record that owner when the thread is created, so the sidebar and archive work can read it directly. A user-requested top-level thread keeps its creator and starts with no owner.Storage
New launches store:
owned: truerecords a new owned launch.owned: falserecords a new explicitly top-level launch.owned.lineage.independentand keep the original creator.creatorOriginand strips it from clientthread.createcommands.Reading the owner
getThreadOwner(thread, environmentId)inpackages/shared/src/threadOwnership.tsreturns the environment-qualified owner. First match wins:lineage.independentis true.delegatedFrom.creatorOriginwithkind: "thread_launch"andowned: true.It ignores placement and historical creator fields.
Launch paths
topLevel: true(either tool)owned: falsedelegatedFromfor delegated execution. It must match the linked sender when one is provided, or the call fails withinvalid_request.topLevel: truefails withinvalid_requestif combined with a non-nullgroupedUnderThreadId. On the project launch tool it also fails withremotePreparationor a linked caller'sdelegatedFrom.scheduledTaskOrigin. The scheduled task record gives that ID and may have no creator thread. Keeping the field optional preserves the existing creator-origin wire shape for older clients.Worktree suspension
Proof
The 405-test local run passed. After the suspension repair, the four classification cases and 22 launch, ownership, and context-budget tests passed. The explicit top-level model eval went 0/3 to 3/3, with 3/3 each on the default-ownership and thread-organization cases. The refactor passed 54 focused tests, including the existing handler tests, plus server typecheck, format, and scoped lint. Existing launch guidance was restored because there was no matched base sweep for the earlier cuts. The tool list is 85,056 bytes, up 396 from
lastcode/main.Local review: 4 rounds with GPT-6.1 Terra (xhigh), approved.
Upstream-owned files
The single and batch handlers call the fork-owned
apps/server/src/mcp/threadLaunchOwnership.tsfor ownership, placement and validation. The following files exist onorigin/main. Counts are for the full PR diff againstlastcode/main.apps/server/src/mcp/OrchestratorMcpService.tsapps/server/src/mcp/linkOrigin.test.tsapps/server/src/mcp/toolkits/orchestrator/tools.tsapps/server/src/mcp/toolkits/project/handlers.test.tsapps/server/src/mcp/toolkits/project/handlers.tsapps/server/src/mcp/toolkits/project/tools.tsapps/server/src/mcp/toolkits/thread/tools.tsapps/server/src/orchestration-v2/Orchestrator.tsapps/server/src/orchestration-v2/ProjectionStore.tsapps/server/src/orchestration-v2/ThreadForkService.tsapps/server/src/orchestration-v2/ThreadLaunchService.test.tsapps/server/src/orchestration-v2/ThreadLaunchService.tsapps/server/src/orchestration-v2/ThreadManagementService.test.tsapps/server/src/orchestration-v2/ThreadManagementService.tsapps/server/src/provider/agentContextBudget.jsonapps/server/src/storageCleanup.test.tspackages/contracts/src/orchestrationV2.tspackages/contracts/src/orchestratorMcp.tspackages/provider-core/src/server/subagentProjection.tspackages/shared/package.json