Repository navigation
feat(mcp): thread standing role and launch presets - #92
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. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Coordinator: removed the agent-context-increase label. It's the maintainer's decision after independent review, not the worker's (round-four rule). It'll be re-applied if the +1,287-byte growth survives review and trimming. |
chrisohearn
left a comment
There was a problem hiding this comment.
Independent Claude Opus review of 37f2244 (review of record)
Head 37f2244, base integration/mcp-events-20261109 at 7836910 (current), MERGEABLE. Only "Agent context budget" fails, and only because the label is missing (+1,287, ALLOW_INCREASE false). Read from the diff and source; no tests run.
Checked and OK: (a) the role is read at every turn start and sent once per turn through turnInput.message.text, which both ClaudeAdapterV2.ts:12446 and CodexAdapterV2.ts:3498 use. It is not repeated within a turn, because the delivery session is used once. (c) resolveRuntimeMode refuses (it does not clamp) a preset mode above the caller's on launch, or above the parent's on delegate. (d) t3_preset save and delete need writesEnvironment (full access). Sizes are enforced: role 4,000, done format 1,000, stored 5,200, name pattern. (e) Migration 013 is idempotent CREATE TABLE IF NOT EXISTS and registered correctly.
P1 apps/server/src/mcp/toolkits/thread/handlers.ts:252-266: setting another thread's standing role uses writesThreads. Any non-read-only caller (approval-required, auto-accept-edits or auto) can set, replace or clear the role of any thread at or below its own modes in the same link. Ownership, creator and full access are not checked. The role then outlives a later raise of that thread's mode, because nothing revalidates it. ADR 0018 gives exactly this reason for gating preset saves on full access, yet it is not applied here. Unlike t3_thread_send, a role write carries no ADR 0013 sender record, makes no thread event and does not appear in the UI. Its only audit is one updated_by row, overwritten on each change and deleted on clear (ThreadRoles.ts:45,58). Neither configure nor read shows who set it or when. An agent can also clear its own role, because authorize short-circuits for its own thread. Fix: require full access for cross-thread role writes, or limit them to the thread's launcher or parent. Store a sender record with updatedAt, show both in configure and read, and consider a visible thread activity.
P2 ProviderTurnStartService.ts:947,1832: the role is prefixed to every turn's user text, so each copy stays in native history. That is about 1,300 tokens per turn at the 5,200-character maximum, or about 65k tokens over 50 turns on a busy inbox thread, which brings compaction sooner. Fix: send it only when its hash changed since the last delivery to that native thread, or after a new session or compaction.
P2 preset/handlers.ts:13 with launchPresets.ts:36: updatedBy stores the full client sessionId, and t3_preset read returns it to read-only callers. ADR 0013 publishes only the first 8 characters. Truncate it, or store the sender record.
P3 launchPresets.ts:34 vs ADR 0018 line 8: the ADR says the done format is "required", but the schema makes it optional. A save with only a name passes. Enforce it on save or fix the ADR.
P3 OrchestratorMcpService.ts:2538: the preset loads before the retry check, so retrying an accepted delegation fails after its preset is deleted. Launch skips the preset when replaying. The delegate path also has no test for a preset above the parent's mode.
P3 ThreadLaunchMcpService.ts:373: any launch error clears the role, including an ambiguous failure after the thread committed. A failed delegate dispatch (OrchestratorMcpService.ts:2614) leaves an orphan row, and deleted threads keep their rows.
P3 ProviderTurnStartService.ts:154: NATIVE_COMMAND drops the role from any message that starts with /word , such as "/etc is full".
P3 FORK.md: migration id 13 is shared with r4/identity-events and r4/ledger-hygiene. Assign it at merge time from the tip and repeat the checks. ADR 0018 is also used by PR #90.
Budget (+1,287): cuts by exact JSON bytes. (1) Shorten t3_preset description (preset/tools.ts:15) to "Launch presets: list, read, save (omitted fields keep, null clears), delete.", -124. (2) Shorten launch preset (ThreadLaunchMcpService.ts:90) to "A t3_preset name; explicit fields win.", -108 (the error already explains a mode refusal). (3) Drop the launch standingRole description (ThreadLaunchMcpService.ts:94), -65. (4) End the configure text (thread/tools.ts:199) with "standingRole (alone; "" clears) is sent with every turn.", -30. Total -327. Estimated schema cuts: fold doneFormat into standingRole and make save replace the whole preset (no NullOr), about -200 to -250. Net growth would be about +960, or about +700 with the schema cuts. Run the evals first, as the budget test asks.
Verdict: blocking
9c7fb92 to
c9d4f6a
Compare
A thread carries a standing role that T3 sends with provider turns when it is new, changed, in a new session or after a compaction, and t3_preset stores named launch presets that t3_thread_launch and delegate_task accept as `preset`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
c9d4f6a to
71778e8
Compare
… into r4/role-docs-presets # Conflicts: # apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts # apps/server/src/orchestration-v2/runtimeLayer.ts # apps/server/src/provider/agentContextBudget.json
…integration tip Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
@codex review |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: afba139646
ℹ️ 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".
| const preset = yield* loadPreset(input.preset).pipe( | ||
| Effect.catchIf( | ||
| () => isRetryOfAcceptedDelegation, | ||
| () => Effect.undefined, | ||
| ), |
There was a problem hiding this comment.
Bypass mutable preset resolution on receipt replay
When an accepted delegation is retried after its preset was edited, this reloads the current preset and then revalidates its current model, runtime mode, and isolation before reaching the receipt-backed dispatch. A preset changed to an unavailable model, a mode above the parent, or worktree isolation that can no longer resolve a commit therefore makes an otherwise idempotent retry fail; only deletion is currently caught. Accepted retries should bypass preset resolution just as they bypass current project enablement and replay the original command.
Useful? React with 👍 / 👎.
| }), | ||
| runtimeMode: thread.runtimeMode, | ||
| interactionMode: thread.interactionMode, | ||
| ...configuration(thread, yield* (yield* ThreadRoles.ThreadRoles).get(thread.id)), |
There was a problem hiding this comment.
Preserve the standing role when forking a thread
When a thread with a standing role is forked through t3_thread_transfer, the thread.fork path around lines 275–288 creates the target thread but never copies its ThreadRoles row. Since the new role is stored outside the event-sourced thread projection, the fork silently loses this part of its configuration, reports no role through this configuration read, and stops receiving the instructions on future turns even though the tool promises a new thread with the same setup.
Useful? React with 👍 / 👎.
| userText: [standingRoleBlock, restartNote, userText] | ||
| .filter((part) => part !== "") | ||
| .join("\n\n"), |
There was a problem hiding this comment.
Reserve handoff budget only when the role is due
When a standing role was already delivered to this native session but a retry or side-chat handoff still invokes this budget, standingRoleSend is false and the role is omitted from the actual prompt, yet this calculation still subtracts the entire role from the handoff allowance. A maximum-length Unicode role can reserve roughly 16 KB under the byte-based budget and unnecessarily truncate or omit imported history on every such handoff; build userText from the role only when it will actually be included.
Useful? React with 👍 / 👎.
| if (input.standingRole !== undefined) { | ||
| if ( | ||
| input.modelSelection !== undefined || | ||
| input.runtimeMode !== undefined || | ||
| input.applyAt !== undefined |
There was a problem hiding this comment.
Reject acknowledge-only and role updates together
When a full-access caller supplies both acknowledgeOnly and standingRole, the earlier acknowledge-only branch returns before this role branch is reached, and configureAcknowledgeOnly does not include standingRole in its mixed-field validation. The call therefore succeeds while silently discarding the requested role update, despite both fields being documented as standalone operations; reject this combination instead of partially applying it.
Useful? React with 👍 / 👎.
| const NATIVE_COMMAND = | ||
| /^\s*\/(?!(?:etc|usr|var|home|tmp|opt|bin|sbin|dev|proc|root|srv|mnt|boot|lib|lib64|sys|run|Users|Library|Applications)(?:\s|\/|$))[A-Za-z][\w-]*(\s|$)/; |
There was a problem hiding this comment.
Recognize only actual native commands
When an ordinary prompt starts with an absolute path not in this hard-coded directory list, such as /workspace/t3code fails to build or /Volumes/repo is missing, this regex classifies the first path component as a native command. The role lookup is then skipped and the provider receives the prompt without its standing instructions; use the actual supported command set or command parser rather than trying to enumerate path roots.
Useful? React with 👍 / 👎.
| yield* sql`CREATE TRIGGER IF NOT EXISTS thread_standing_roles_thread_purged | ||
| AFTER DELETE ON orchestration_v2_projection_threads | ||
| BEGIN DELETE FROM thread_standing_roles WHERE thread_id = OLD.thread_id; END`; |
There was a problem hiding this comment.
Preserve roles across projection rebuilds
When ProjectionReplay.rebuild runs against a database containing standing roles, its DELETE FROM orchestration_v2_projection_threads statement activates this trigger for every live thread. The projection rows are recreated from events, but roles are deliberately stored outside the event stream, so every standing role is permanently lost after the rebuild; restrict cleanup to logical thread deletion or explicitly preserve these rows during projection replay.
Useful? React with 👍 / 👎.
8b3a0d1
into
integration/mcp-events-20261109
Ledger key: r4/w10-role-presets. Items C3 and C7 of round four.
C3: thread standing role
Evidence. The Jarvis inbox thread's Codex agent ignored its role file for hours: providers read
AGENTS.mdonly at session start, and the file was written after the session began. No existing feature covers this. ThestandingItemIdin the context handoff names the first user message in a provider-switch handoff and is unrelated and unchanged.Change.
standingRole(up to 4,000 characters) ont3_thread_configure(alone; empty text clears),t3_thread_launchanddelegate_task.t3_thread_configureand the first page oft3_thread_readshow it.ProviderTurnStartServicereads it at every turn start and sends it as an inline prefix, like the restart note and side-chat context. The turn input has no per-turn instruction field for every provider (appContextreaches only Codex; Claude takes a system prompt only at session start)./compact,/reviewand/goalgo verbatim; a path like/home/xis a message and gets the role.Tests.
ProviderTurnStartService.test.ts: a role stored after the session began reaches a plain turn; native commands go verbatim. The plain-turn cases fail without thedeliverySessionchange (checked).core.test.ts:t3_thread_configuresets, reads and refuses mixed role and mode writes.OrchestratorMcpToolkit.integration.test.ts:t3_thread_readshows it.C7: launch presets
Evidence. The coordinator launched nine workers with the same pasted rules, and one incident (a worker waking snoozed threads) came from a rule missing in one brief.
Change.
t3_preset(list,read,save,delete; omitted fields keep, null clears). A preset holds model, runtime mode, standing role, checkout kind (rootorworktree) and a done-message format, which is appended to the role as stored text.preset: "<name>"ont3_thread_launchanddelegate_task; explicit fields override.writesEnvironment); listing and reading are open. The writer is recorded (updatedBy).delegate_task. A linked build that predates this change ignores the two new fields.t3_presethas noenvironmentId.Tests.
handlers.test.ts: preset applied, explicit fields win, role stored before the launch reaches the orchestrator, above-ceiling preset refused, unknown preset refused.OrchestratorMcpService.test.ts: delegation applies a preset and stores the child's role before dispatch.core.test.ts: read-only andautocallers cannot save; full access can.LaunchPresets.test.ts: persistence round trip against SQLite.Notes for the coordinator
ThreadRolesAndPresets) is provisional. The tip is at 15 (ScheduledRunHistoryIndex);r4/identity-eventsmay also want 13 or 14.mcpToolListJsonBytesgrows 1,061 bytes over the tip (58,304 to 59,365) fort3_preset, three optional fields and the setter field. The label is the maintainer's call.docs/jarvis/decisions/0019-...(0018 is the freeze decision); the final number is assigned at merge.mcp-tool-useneeds paid API keys, and the resource rule limits local runs.--contextshows 74 tools. A run on the new tool text is worth doing after merge.Acceptance checks (read-only, after deploy)
sqlite3 -readonly ~/.t3/userdata/statev2.sqlite "select migration_id, name from t3_fork_migrations where name = 'ThreadRolesAndPresets'"returns one row.sqlite3 -readonly ~/.t3/userdata/statev2.sqlite "select count(*) from launch_presets; select count(*) from thread_standing_roles"runs without error (counts are 0 before first use).t3_preset {action: "list"}returns{presets: []}until the coordinator savesr4-fork-worker, then lists it;t3_preset {action: "read", name: "r4-fork-worker"}shows its fields andupdatedBy.t3_thread_configure {threadId}and the first page oft3_thread_readshowstandingRolefor a thread that has one.Standing role for this thread, set in T3 and sent with every turn. Codex keeps session files under~/.codex/sessions, Claude under~/.claude/projects.🤖 Generated with Claude Code
Review fixes (squashed, rebased on tip a59003e)
t3_thread_configureandt3_thread_read(standingRoleSetBy).updatedByis the 8-character session prefix and label, or a thread id./etc is fullgets the role.doneFormatseparate because the task names it as a preset field.standingRoleDelivery.test.ts,ProviderTurnStartService.test.ts), full-access gate and note (core.test.ts), delegate preset above the parent's mode, retry after preset deletion, failed dispatch cleanup (OrchestratorMcpService.test.ts), launch failure cleanup (handlers.test.ts), revision, delivery and thread-delete trigger (LaunchPresets.test.ts).