Skip to content

[US-737] feat: on-demand workflow supervisor - #767

Merged
rucka merged 67 commits into
mainfrom
feature/US-737-workflows-supervisor-on-demand-first-escalation
Nov 29, 2026
Merged

rucka merged 67 commits into
mainfrom
feature/US-737-workflows-supervisor-on-demand-first-escalation

Conversation

@rucka

@rucka rucka commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

PR Information

Type: Feature
Story: #737
Merge strategy: squash

Refs #737

The live GitHub maintainer handoff remains open on #737. The maintainer authorized merging the implementation after all other review findings are resolved.

Summary

Adds an on-demand supervisor that diagnoses blocked workflow steps and directs the host through bounded recovery or a human decision.

Classification

risk:red · cost:yellow

Matrix — per dimension
Dimension Tier Source Note
Service/domain criticality green Criticality Table Changed workspaces are Low
Change/diff risk red Diff and refinement floor Supervisor protocol, engine transitions and persisted state
Business impact red Subdomain class Collaborative Workflow is core
Security relevance red Security assessment IPC authorization, external answer parsing and agent permissions
Coupling balance green Coupling assessment One team owns the CLI and interpreter, joined by a typed host contract

Confidence: high. Cost reflects bounded retries per trigger and on-demand model use.

Changes Made

  • Adds supervisor grammar, configuration, validation and ADR-038.
  • Adds the host MCP directive bridge, guardrails, event history, retry budgets, polling and telemetry.
  • Ships the default supervisor workflow, documentation and changeset.

Services to Release

  • @pair/pair-cli and @pair/workflows: supervisor host and protocol support.

Testing

  • pnpm quality-gate and pnpm build: pass. Mutation: not measured.
  • Supervisor grammar, MCP, engine, host, telemetry and dataset tests cover the specified behaviors.
  • Real dirty-worktree run used Claude agents, local PM/worktree adapters, a scripted fixture step and a fixture-only prompt addition. The unmodified prompt asked a human.
  • A real tracker question was posted on Workflows · Supervisor (on-demand): first escalation level over the host's MCP #737; no answer was fabricated. Human-answer completion remains unverified in a real run.

Reviewer Guide

Review directive guardrails, crash recovery, history replay, human polling and prompt safety. Inspect real-run limitations above. T-1 through T-8 follow the story's technical analysis and AC coverage; implementation approaches are captured in ADR-038 and the changed code.

T added 16 commits November 28, 2026 13:03
Add supervisor grammar, validation and protocol ADR.\n\nTask: T-1\nRefs: #737
Record supervisor events and restore history before escalation.

Task: T-2

Refs: #737
Restore the workflow core boundary and refresh generated artifacts.

Refs: #737
…ows-supervisor-on-demand-first-escalation

# Conflicts:
#	.claude/skills/pair-capability-workflow/scripts/workflow.mjs
#	apps/pair-cli/src/commands/run/workflow-host.ts
#	packages/knowledge-hub/dataset/.skills/capability/workflow/scripts/workflow.mjs
#	packages/workflows/src/engine/index.ts
@rucka rucka self-assigned this Nov 28, 2026
@rucka rucka added the pr-state:to-be-reviewed PR state: awaiting review / gate label Nov 28, 2026
@rucka rucka added the risk:red Classification: high risk tier label Nov 28, 2026

@rucka rucka left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict

risk:red · cost:yellow — CHANGES-REQUESTED — Supervisor guardrails, recovery and human handoff fail the story requirements.

Open findings: 10. First review. All findings are new.

PR: #767 · Story: #737 · Type: feature · Author / session identity: rucka · Reviewer: Codex · Date: 2026-11-28
Reviewed head: c96edab4657f913b67602364773f80b9530c5e82

Red tier calls for one reviewer, a two-working-day SLA and explicit human approval. No qualifying approval was present. This repository uses advisory enforcement.

Light row: n-a — no identity (session mode)

Classification matrix — per dimension
Service Diff Business Security Coupling
green red red red green

Assessments

Security — Input validation

Verdict: yellow — Directive fields and reply schema are checked.

Details

The host refuses invalid durations, unexpected fields and malformed decisions.

Security — Output handling

Verdict: yellow — Events are serialized and identified as untrusted.

Details

Context grows recursively. See F-737-08.

Security — Authentication

Verdict: green — IPC uses a scoped capability, with maintainer identity checked on card replies.

Details

The socket sits in an owner-only directory. Polling checks the original human author, question marker and timestamps.

Security — Authorization

Verdict: red — Supervisor privileges exceed the host directive boundary.

Details

Hard restrictions at the directive endpoint need corresponding restrictions on agent and nested workflow capabilities. See F-737-01.

Security — Introduced vulnerabilities

Verdict: red — One introduced authorization finding.

Details

F-737-01 concerns the new supervisor launch path.

Cost

Verdict: cost:yellow — On-demand model launches and bounded retries per trigger.

Details

Metering is present. Recursive history raises input costs as interventions accumulate.

Architecture (Coupling)

Verdict: green — The CLI, interpreter and MCP bridge share one owning context.

Details

The typed host interface keeps the engine independent of process and tracker I/O. The bridge communicates over local IPC.

Bug fix — Red test before fix

Verdict: not applicable — Feature PR.

Details

Card #737 introduces on-demand supervision.

Details

Findings by severity

Critical

  • F-737-01 · apps/pair-cli/src/commands/run/workflow-host.ts:841 · The supervisor inherits delivery-agent autonomy and host operations. ADR-038 needs enforced restrictions. Isolate external access while preserving local repair.

Major

  • F-737-02 · packages/workflows/src/engine/index.ts:1843 · AC-2. Idle-fault and single-round exhaustion replays made zero supervisor calls. Route both events through supervision before fallback escalation.
  • F-737-03 · packages/workflows/src/engine/index.ts:2036 · AC-3. A retry advanced the round at max: 2 and parked at max: 1. Apply directives before loop advancement.
  • F-737-04 · apps/pair-cli/src/commands/run/supervisor-question.ts:184 · AC-4/6. Three polls spaced one second apart give maintainers roughly two seconds. Persist a meaningful deadline and use it across restarts.
  • F-737-05 · apps/pair-cli/src/commands/run/workflow-host.ts:1005 · AC-5. Initial and resumed dispatch put the answer in history only. Supply the ADR-038 answer field and assert the actual event envelope.
  • F-737-06 · apps/pair-cli/src/commands/run/workflow-host.ts:1013 · AC-7. Exhausted retries or budget report no answer after a valid reply, including on resume. Apply the original escalation.
  • F-737-07 · apps/pair-cli/src/commands/run/workflow-host.ts:794 · AC-3. The handler exposes wait before its timer completes. If the agent exits first, the engine treats it as immediate retry. Let the host own the deadline and completion.
  • F-737-08 · packages/workflows/src/engine/index.ts:1864 · AC-8. Persisting events with prior history embeds the log recursively. Eight retries grew it from 212 to 53,933 bytes. Store flat rows and reconstruct history on read.
  • F-737-09 · packages/workflows/src/cli/supervisor/mcp.ts:111 · AC-3/8. MCP acknowledges before engine state commits. Resume reads question and wait markers, so interruption can lose an acknowledged kill. Replay directives idempotently.
  • F-737-10 · .pair/adoption/tech/workflows/supervisor.yaml:16 · Recovery required a fixture-only prompt. The shipped prompt asked a human. The tracker run showed question posting. Supply both #737 real-run traces.

Minor: none. Questions: none.

Positive feedback

MCP tests exercise real stdio and local IPC.

Functionality & requirements (AC coverage)

AC-1, AC-9 and AC-10 supported. AC-2 through AC-8 have findings. Real-run DoD remains open.

Testing & quality gates

Build, review gate and 41 website E2E tests passed. Full quality gate failed twice in packages/workflows/test/session-command.test.ts under Node 26. Three focused cases passed on Node 20. Mutation not measured.

Adoption compliance

Level 1. The SDK is adopted and pinned. ADR-038 covers the architecture. F-737-01 and F-737-09 record runtime deviations.

Tech debt

Supervisor orchestration enlarges the existing CLI host module (DR-1).

Documentation

Grammar, schema, ADR, mirrors and changeset present. Glossary entry absent.

Performance & deployment

Opt-in deployment. F-737-08 tracks history growth.

@rucka rucka added pr-state:not-approved PR state: changes requested and removed pr-state:to-be-reviewed PR state: awaiting review / gate labels Nov 28, 2026
@rucka

rucka commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

First-round root cause: the supervisor is a separate authority and lifecycle, but the implementation inherits the delivery launcher and records supervision as transient side effects. Fix capability isolation before enabling any triggers. Then exercise stall, exhaustion, question, timeout and restart through one durable event/directive lifecycle. Persist flat events and ensure accepted directives survive interruption and are applied at most once. Cover fallback escalation and wait behavior at the engine boundary. Close with both real-run traces using the shipped workflow.

@rucka

rucka commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Integration candidate is available locally in the sibling worktree 737-integration at 8b415264, based on the reviewed head 47e182a and main 4f7d8ff. It combines classification persistence with supervisor outcomes in the engine, keeps the new dependency, and regenerates both workflow bundles. TypeScript, the 15 engine supervisor tests, the bundle test and pre-commit passed. If your branch still has that head and your tree is clean, you can fast-forward to this candidate. Otherwise, use the tested resolution as reference when integrating your current changes.

@rucka rucka left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict

APPROVED for integration on addcf70. The maintainer deferred #737's live GitHub question-and-answer trace to after integration. Keep #737 open for that acceptance check.

  • F-737-01: restricted engine launch, scoped MCP tools and isolated local gates. The actual sandbox gate check passed on Ubuntu and macOS.
  • F-737-02: watchdog stalling and loop exhaustion reach the supervisor before fallback. The regression tests pass.
  • F-737-09: recovery tests cover interruption after acknowledgment for step and loop kills and human-answer directives.
  • F-737-10: real Claude recovered a dirty disposable worktree through the shipped supervisor and preserved its untracked file. A separate real-engine run drafted a valid maintainer question and parked. The live GitHub round trip remains open.
  • F-737-14: integrated main, regenerated both bundles, and verified a clean merge simulation.

The 246 focused tests and all GitHub checks passed. Prior resolved findings remain green. Mutation was not measured.

@rucka
rucka merged commit 8b1cdd0 into main Nov 29, 2026
8 checks passed

This branch was successfully deployed

1 active deployment
Website Preview — addcf70c Deployed Nov 29, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-state:not-approved PR state: changes requested risk:red Classification: high risk tier

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant