Skip to content

feat(server): add fail-open turn-end output gate on agent wakes + silent_ack (CLO-1248 part 3) - #227

Merged
nullStack65 merged 2 commits into
release/native-0.1.10from
feat/clo-1248-output-gate
Nov 26, 2026
Merged

nullStack65 merged 2 commits into
release/native-0.1.10from
feat/clo-1248-output-gate

Conversation

@nullStack65

Copy link
Copy Markdown
Owner

Deploy: fleet

Problem

CLO-1248 Part 3 (built on Part 1 66f5c7d39865 and Part 2 51045b024c3d). On async origin: "agent" wakes (e.g., t3_thread_send, watch/event wakes, scheduled wakes), a model can finish with plain assistant text without explicitly routing it (send_to_user, t3_thread_send, ask_agent, or silent_ack), leaving the intent ambiguous between a founder-facing reply and an internal fold.

Fix

  • Explicit silent sink (silent_ack):
    • Add SILENT_ACK_TOOL_NAME ("silent_ack") in packages/shared/src/toolOutput.ts and register SilentAckTool (Tool.Readonly = true, Tool.Destructive = false, Tool.Idempotent = true, hidden from outside clients) alongside send_to_user in apps/server/src/mcp/toolkits/message/{tools,handlers}.ts.
    • Update apps/server/src/provider/agentContextBudget.json (mcpToolListJsonBytes: 75656).
  • Fail-open Turn-End Output Gate (AgentOutputGate.ts + AgentOutputGateReactor.ts, wired in server.ts):
    • Strictly scoped to completed async origin: "agent" wakes on active, non-retired, non-sideChat, non-subagent threads — origin: "user" turns, ask_agent side chats, and subagent child threads are never gated or bounced.
    • Allows turns that already completed an explicit channel tool (send_to_user, t3_thread_send, t3_thread_send_attachments, ask_agent, or silent_ack) or emitted no substantive plain assistant text.
    • On an unrouted plain-text origin: "agent" wake, dispatches at most 1 bounce (command: server:output-gate-bounce:<runId>, message: message:output-gate-bounce:<runId>) prompting the model to route explicitly or call silent_ack.
    • Fail-open fallback: If the 1-bounce run still ends unrouted (or on error/abort/timeout), keeps the output intact and stamps timelineVisibility: "agent_fold" on unstamped assistant items without looping >1 bounce or bumping founder unread/attention.
  • Carryover polish from Part 1 (#225 nits):
    • Add optional timelineVisibility to OrchestrationV2ConversationMessage in packages/contracts/src/orchestrationV2.ts.
    • Guard isUnseenCandidate in packages/client-runtime/src/seenMarker.ts with message.createdBy !== "user" so a human founder's own message is never treated as unseen even if stamped user_timeline.

Verification

  • effect-tsgo tsrs --noEmit: 0 errors across packages/contracts, packages/shared, packages/client-runtime, and apps/server.
  • packages/client-runtime seenMarker.test.ts: 13/13 passed (including human-user user_timeline guard).
  • apps/server AgentOutputGate.test.ts: 7/7 passed (policy matrix + reactor 1-bounce + fail-open agent_fold stamping).
  • apps/server AgentContextBudget.test.ts: 2/2 passed.
  • vp fmt on all touched files: clean.

Model: gemini-4-neon
Task: feat

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@nullStack65

Copy link
Copy Markdown
Owner Author
{
  "reviewed_base": "51045b024c3d192686b3e7abf159381694afc603",
  "reviewed_head": "6e2110aefd3b38a4753a7e733445c7e5f494c0cb",
  "reviewer": "Gemini 4 Neon, Antigravity",
  "author_session": "t3-thread:6a6b870263499e5c3c4ceec5efb20d31b46884a74e0c45beedb1a4cddb9ac991",
  "reviewer_session": "antigravity:7d2b601a-ba93-40ec-9da6-1bf09602424c",
  "fresh_context": true,
  "review_kind": "full",
  "round_id": "antigravity:7d2b601a-ba93-40ec-9da6-1bf09602424c",
  "prior_findings": [],
  "findings": [
    {
      "id": "F1",
      "severity": "important",
      "file": "apps/server/src/orchestration-v2/AgentOutputGate.ts",
      "line": 39,
      "summary": "isExplicitChannelToolName fails to match silent_ack and ask_agent for non-`__` provider prefixes (e.g. Antigravity mcp_t3-code_silent_ack, Codex/Cursor t3-code.silent_ack, OpenCode t3-code-<thread>_silent_ack) because neither tool is registered in T3_MCP_TOOLS (so resolveT3McpToolId returns null) and the fallback loop only checks endsWith(`__${id}`). Agents on those providers calling silent_ack or ask_agent will be falsely bounced.",
      "outcome": "open"
    },
    {
      "id": "F2",
      "severity": "important",
      "file": "apps/server/src/orchestration-v2/AgentOutputGate.ts",
      "line": 136,
      "summary": "evaluateAgentOutputGate counts any dynamic_tool item with status === \"completed\" as an explicit channel delivery without checking whether the tool returned an error (compactDynamicToolOutput(item.output)?.isError). Because send_to_user, silent_ack, t3_thread_send, t3_thread_send_attachments, and ask_agent all use failureMode: \"return\", a failed call still lands as status === \"completed\" and falsely bypasses the output gate.",
      "outcome": "open"
    },
    {
      "id": "F3",
      "severity": "important",
      "file": "apps/server/src/orchestration-v2/AgentOutputGateReactor.ts",
      "line": 110,
      "summary": "The bounce dispatch uses notification.source.kind === \"system\" with creationSource: \"server\", which Orchestrator.ts:8994 classifies as delegationReminder and promotes to steer_active into any currently running turn. If a new run (including a human origin: \"user\" turn) starts before the async queue processes the completed agent run, the output-gate bounce prompt is steered mid-turn into the unrelated active run.",
      "outcome": "open"
    },
    {
      "id": "F4",
      "severity": "nit",
      "file": "apps/server/src/orchestration-v2/AgentOutputGate.ts",
      "line": 118,
      "summary": "evaluateAgentOutputGate does not check thread.settledOverride === \"settled\"; if an agent self-settled the thread during the wake (or a founder settled it before the async bounce runs), Orchestrator.ts:8521 will emit thread.unsettled when the bounce message is dispatched.",
      "outcome": "open"
    }
  ]
}

Independent Review Summary (6e2110aefd3b38a4753a7e733445c7e5f494c0cb)

  • 1-Bounce Loop Prevention: Verified sound on the normal path (userMessageId = message:output-gate-bounce:<runId> is detected by isOutputGateBounceMessageId on the bounce run's completion, failing open to agent_fold with 0 additional bounces; failed/aborted/timed-out bounce runs are ignored because status !== "completed"). See F3 for the concurrent-run steering race.
  • Server Restart / Event Replay Safety: Verified safe — orchestrator.streamDomainEvents starts from eventSink.latestSequence(), matching sibling reactors (DelegationNudgeReactor, SessionSpendGuardReactor), so historical run.updated completions are never replayed on startup.
  • Tool Name Matching & Success Checking: Found F1 (missing silent_ack/ask_agent in T3_MCP_TOOLS breaks non-__ provider prefixes) and F2 (failed failureMode: "return" MCP calls with status === "completed" and isError: true bypass the gate).
  • Fail-Open agent_fold & Scope / silent_ack / Part 1 Carryover: Verified origin: "user", sideChat, subagent, and deleted/archived/retired threads are excluded; SilentAckTool annotations/visibility and agentContextBudget.json (75656) are accurate; OrchestrationV2ConversationMessage.timelineVisibility and isUnseenCandidate createdBy !== "user" guard are clean.
  • Verification (detached worktree at 6e2110aefd3b38a4753a7e733445c7e5f494c0cb):
    • effect-tsgo tsrs --noEmit: 0 errors across packages/contracts, packages/shared, packages/client-runtime, and apps/server.
    • vp test run: seenMarker.test.ts (13/13), AgentOutputGate.test.ts (7/7), AgentContextBudget.test.ts (2/2) all passed.

@nullStack65

Copy link
Copy Markdown
Owner Author
{
  "reviewed_base": "51045b024c3d192686b3e7abf159381694afc603",
  "reviewed_head": "ed6b822d3c3afdd7b3819684be9f4ba22f69400f",
  "reviewer": "Gemini 4 Neon, Antigravity",
  "author_session": "t3-thread:6a6b870263499e5c3c4ceec5efb20d31b46884a74e0c45beedb1a4cddb9ac991",
  "reviewer_session": "antigravity:0b287bfa-8cce-468b-ba9a-66ee00dd364b",
  "fresh_context": true,
  "review_kind": "focused_recheck",
  "round_id": "antigravity:7d2b601a-ba93-40ec-9da6-1bf09602424c",
  "prior_findings": [
    {
      "id": "F1",
      "severity": "important",
      "file": "apps/server/src/orchestration-v2/AgentOutputGate.ts",
      "line": 43,
      "summary": "ask_agent and silent_ack are now registered in T3_MCP_TOOLS (packages/shared/src/t3McpToolPresentation.ts), so isExplicitChannelToolName resolves Antigravity (mcp_t3-code_*), Codex/Cursor (t3-code.*), OpenCode (t3-code-<thread>_*), and Claude (mcp__t3-code__*) prefixes cleanly.",
      "outcome": "fixed",
      "rechecked_head": "ed6b822d3c3afdd7b3819684be9f4ba22f69400f"
    },
    {
      "id": "F2",
      "severity": "important",
      "file": "apps/server/src/orchestration-v2/AgentOutputGate.ts",
      "line": 150,
      "summary": "evaluateAgentOutputGate now requires compactDynamicToolOutput(item.output)?.isError !== true, preventing error-returning failureMode: \"return\" channel tools from bypassing the output gate.",
      "outcome": "fixed",
      "rechecked_head": "ed6b822d3c3afdd7b3819684be9f4ba22f69400f"
    },
    {
      "id": "F3",
      "severity": "important",
      "file": "apps/server/src/orchestration-v2/AgentOutputGateReactor.ts",
      "line": 99,
      "summary": "AgentOutputGateReactor now checks shell.activeRunId === null && (shell.latestRunId === null || shell.latestRunId === signal.runId) to fail open when superseded, and dispatches bounces with notification.source: { kind: \"monitor\" } so Orchestrator.ts:8994 never classifies them as delegationReminder or promotes them to steer_active into a racing turn. Verified no unintended side effects in Orchestrator.ts or UI unread/attention.",
      "outcome": "fixed",
      "rechecked_head": "ed6b822d3c3afdd7b3819684be9f4ba22f69400f"
    },
    {
      "id": "F4",
      "severity": "nit",
      "file": "apps/server/src/orchestration-v2/AgentOutputGate.ts",
      "line": 169,
      "summary": "evaluateAgentOutputGate now checks thread.settledOverride === \"settled\" and fails open to agent_fold without dispatching a bounce or unsettling the thread.",
      "outcome": "fixed",
      "rechecked_head": "ed6b822d3c3afdd7b3819684be9f4ba22f69400f"
    }
  ],
  "findings": []
}

Focused Re-Check Summary (6e2110aefd3b..ed6b822d3c3a)

All 4 prior findings (F1–F4) are confirmed fixed at head ed6b822d3c3afdd7b3819684be9f4ba22f69400f with no new regressions:

  • F1 (important, fixed): ask_agent (packages/shared/src/t3McpToolPresentation.ts:253) and silent_ack (packages/shared/src/t3McpToolPresentation.ts:464) are registered in T3_MCP_TOOLS. resolveT3McpToolId and isExplicitChannelToolName resolve Antigravity (mcp_t3-code_*), Codex/Cursor (t3-code.*, t3-code-direct.*), OpenCode (t3-code-<thread>_*), and Claude (mcp__t3-code__*) prefixes cleanly.
  • F2 (important, fixed): evaluateAgentOutputGate checks compactDynamicToolOutput(item.output)?.isError !== true (AgentOutputGate.ts:150), which handles isError, is_error, OrchestratorMcpFailure, and nested content/structuredContent envelopes so failed failureMode: "return" channel calls still trigger the gate.
  • F3 (important, fixed): AgentOutputGateReactor checks shell.activeRunId !== null || (shell.latestRunId !== null && shell.latestRunId !== signal.runId) and fails open to agent_fold (superseded_by_newer_run), and dispatches bounces with notification.source: { kind: "monitor" } (outcome: "updated"), preventing Orchestrator.ts:8994 from steering a bounce mid-turn into a racing run. Verified kind: "monitor" + outcome: "updated" has no unintended side effects in Orchestrator.ts (mayStartSubagentFollowup, followsCurrentConversation, monitorUpdateRunIds) or UI unread/attention (chatActivity.ts, seenMarker.ts, messageSender.ts).
  • F4 (nit, fixed): evaluateAgentOutputGate checks input.thread.settledOverride === "settled" (AgentOutputGate.ts:169) and fails open to agent_fold (thread_settled) without dispatching a bounce or unsettling the thread.
  • Verification (detached worktree at ed6b822d3c3afdd7b3819684be9f4ba22f69400f, cleaned up):
    • effect-tsgo tsrs --noEmit: 0 errors in packages/shared and apps/server.
    • vp test run: t3McpToolPresentation.test.ts (4/4), AgentOutputGate.test.ts (9/9), AgentContextBudget.test.ts (2/2) all passed.

@nullStack65
nullStack65 merged commit 6caa999 into release/native-0.1.10 Nov 26, 2026
6 checks passed
@nullStack65
nullStack65 deleted the feat/clo-1248-output-gate branch November 26, 2026 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant