Skip to content

Propagate runtime approval policy and sandbox mode to thread turn startup - #100

Merged
juliusmarminge merged 10 commits into
mainfrom
codething/2c75aea7
Feb 27, 2026
Merged

juliusmarminge merged 10 commits into
mainfrom
codething/2c75aea7

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Feb 27, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add approvalPolicy and sandboxMode to thread.turn.start command and thread.turn-start-requested payload contracts.
  • Forward runtime approval/sandbox settings through decider and provider command reactor when creating/starting provider sessions.
  • Update ChatView to derive runtime settings from runtimeMode (full-access => never + danger-full-access, otherwise on-request + workspace-write).
  • Extend server orchestration tests to verify approval/sandbox fields are emitted and passed into session startup.

Testing

  • apps/server/src/orchestration/decider.projectScripts.test.ts: verifies thread.turn-start-requested includes approvalPolicy and sandboxMode.
  • apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts: verifies startSession receives approvalPolicy and sandboxMode.
  • Project lint scripts: Not run.

Note

Medium Risk
Touches turn-start/session lifecycle and persistence (contracts, provider session management, projections, and a DB migration), so regressions could break turn dispatch or session reuse/restart behavior; changes are scoped and covered by updated tests.

Overview
Propagates runtime controls by making approvalPolicy and sandboxMode required on thread.turn.start and carrying them into thread.turn-start-requested and OrchestrationSession so the values are visible end-to-end.

Updates ProviderCommandReactor to pass these settings into providerService.startSession, persist them onto the thread session, and restart the provider session when either setting changes (otherwise reuse the existing session).

Persists the new fields in projection_thread_sessions (adds columns via a new migration, projects them in ProjectionPipeline, and hydrates them in ProjectionSnapshotQuery). The web ChatView now derives the two fields from runtimeMode when dispatching turn start, and tests are updated/expanded to assert propagation and session restart behavior.

Written by Cursor Bugbot for commit 7d0226c. This will update automatically on new commits. Configure here.

Note

Propagate approvalPolicy and sandboxMode through thread.turn.start and persist them in projection-backed session reads across server and web dispatch paths

Add required approvalPolicy and sandboxMode to ThreadTurnStartCommand, forward them via decider into thread.turn-start-requested, ensure ProviderCommandReactor.make starts/restarts sessions based on these fields, and persist them via projection repositories and migration. Update UI dispatch to include these fields based on runtime mode.

📍Where to Start

Start with processTurnStartRequested and session handling in ProviderCommandReactor.ts, then review event emission in decider.ts and projection persistence in ProjectionThreadSessions.ts.

Macroscope summarized 7d0226c.

Summary by CodeRabbit

  • New Features
    • Provider sessions now include configurable approvalPolicy and sandboxMode that flow from runtime mode into session start and events.
    • Settings persist in session state and read models so UI and tooling observe policy and sandbox values.
  • Bug Fixes
    • Sessions will restart and rebind when approvalPolicy or sandboxMode change, preventing mismatched runtime behavior.

@coderabbitai

coderabbitai Bot commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds optional approvalPolicy and sandboxMode fields across the orchestration stack: contract schemas, client dispatch, event payloads, provider session lifecycle (start/stop/rebind), runtime ingestion, projection/store mappings, and tests. Session restart occurs when policy or sandbox mode changes.

Changes

Cohort / File(s) Summary
Contract Definitions
packages/contracts/src/orchestration.ts
Added optional approvalPolicy and sandboxMode to OrchestrationSession, ThreadTurnStartCommand, and ThreadTurnStartRequestedPayload.
Provider Session Core
apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
Extended ensureSessionForThread and sendTurnForThread signatures to accept approvalPolicy and sandboxMode; include them in start payloads; restart sessions when policy/mode change; propagate fields into provider events.
Runtime Ingestion
apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts
Include approvalPolicy and sandboxMode in thread.session.set and error paths; added default constants for both.
Persistence & Projections
apps/server/src/persistence/Migrations/005_Projections.ts, apps/server/src/persistence/Services/ProjectionThreadSessions.ts, apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts, apps/server/src/orchestration/Layers/ProjectionPipeline.ts
DB migration adds approval_policy and sandbox_mode columns; persistence layer upsert/select updated; projection snapshot and pipeline map new fields into read model session objects.
Event Routing / Decider / Client
apps/server/src/orchestration/decider.ts, apps/server/src/orchestration/decider.projectScripts.test.ts, apps/web/src/components/ChatView.tsx
thread.turn.start/thread.turn-start-requested payloads extended with approvalPolicy and sandboxMode; ChatView derives and sets these based on runtimeMode.
Tests & Integration
apps/server/.../*.test.ts, apps/server/integration/orchestrationEngine.integration.test.ts, apps/server/src/wsServer.test.ts, apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts
Numerous tests and integration specs updated to include approvalPolicy and sandboxMode in fixtures and assertions; added session reuse/restart scenarios for mode changes.

Sequence Diagram(s)

sequenceDiagram
    participant Client as ChatView
    participant Decider as Decider
    participant Reactor as ProviderCommandReactor
    participant Provider as Provider Session
    participant Ingest as ProviderRuntimeIngestion

    Client->>Decider: dispatch thread.turn.start(approvalPolicy, sandboxMode)
    Decider->>Reactor: sendTurnForThread(..., approvalPolicy, sandboxMode)
    Reactor->>Provider: ensureSessionForThread -> check existing session
    alt session exists & policy/mode unchanged
        Reactor->>Provider: reuse session
    else session exists & policy/mode changed
        Reactor->>Provider: stop session
        Reactor->>Provider: start session(approvalPolicy, sandboxMode)
    else no session
        Reactor->>Provider: start session(approvalPolicy, sandboxMode)
    end
    Provider-->>Reactor: session details
    Reactor->>Ingest: emit thread.session.set(..., approvalPolicy, sandboxMode)
    Ingest->>Ingest: update projections / persistence with new fields
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and accurately describes the main change: adding approvalPolicy and sandboxMode propagation through the thread turn startup flow, which is the core objective of this PR.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codething/2c75aea7

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

@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 and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Existing session ignores runtime mode changes
    • Added in-memory tracking of per-thread session runtime settings (approvalPolicy/sandboxMode) so that when ensureSessionForThread detects the requested settings differ from the stored ones, it stops the old session and creates a new one with the updated configuration.

Create PR

Or push these changes by commenting:

@cursor push 9ee36a6e77
Preview (9ee36a6e77)
diff --git a/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts b/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
--- a/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
+++ b/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
@@ -127,6 +127,11 @@
     return readModel.threads.find((entry) => entry.id === threadId);
   });
 
+  const sessionRuntimeSettings = new Map<
+    string,
+    { approvalPolicy?: ProviderApprovalPolicy; sandboxMode?: ProviderSandboxMode }
+  >();
+
   const ensureSessionForThread = Effect.fnUntraced(function* (
     threadId: ThreadId,
     createdAt: string,
@@ -143,7 +148,15 @@
 
     const existingSessionId = thread.session?.providerSessionId;
     if (existingSessionId) {
-      return existingSessionId;
+      const stored = sessionRuntimeSettings.get(threadId);
+      const runtimeModeChanged =
+        (options?.approvalPolicy !== undefined &&
+          options.approvalPolicy !== stored?.approvalPolicy) ||
+        (options?.sandboxMode !== undefined && options.sandboxMode !== stored?.sandboxMode);
+      if (!runtimeModeChanged) {
+        return existingSessionId;
+      }
+      yield* providerService.stopSession({ sessionId: existingSessionId });
     }
 
     const preferredProvider: ProviderKind | undefined =
@@ -163,6 +176,11 @@
       ...(options?.sandboxMode !== undefined ? { sandboxMode: options.sandboxMode } : {}),
     });
 
+    sessionRuntimeSettings.set(threadId, {
+      approvalPolicy: options?.approvalPolicy,
+      sandboxMode: options?.sandboxMode,
+    });
+
     yield* setThreadSession({
       threadId,
       session: {
@@ -314,6 +332,8 @@
       yield* providerService.stopSession({ sessionId });
     }
 
+    sessionRuntimeSettings.delete(thread.id);
+
     yield* setThreadSession({
       threadId: thread.id,
       session: {

@juliusmarminge
juliusmarminge force-pushed the codething/2c75aea7 branch 2 times, most recently from aedb803 to 5fdf30b Compare February 27, 2026 03:31

@cursor cursor Bot left a comment •

Copy link