Overview
Thecreate-handoff-marker worker creates a structured handoff record when an agent needs to escalate to another agent. It returns a pre-formatted Escalations block and optionally creates a tracking Task in Notion.
Key features:
- Generates pre-formatted handoff block for copy-paste into digest
- Creates tracking task in Tasks database with relations and due dates
- Circuit breaker: Prevents duplicate tasks within 7-day window
- Escalation cap: Blocks creation after 2 escalations in same direction
- Returns manual review flag when cap is hit
Input Parameters
Name of the agent initiating the escalation. Must be a valid agent name.
Name of the agent receiving the escalation. Must be a valid agent name.
Description of why escalation is needed. Example:
"Stale spike in CI failures; needs client repo audit"Notion URL of the source agent’s digest page. Used for traceability.
Whether to create a tracking task in Tasks database. Set to
false if you only need the handoff block text.Priority for created task. Required if
create_task: true.Array of Notion page IDs to link in Client relation property of created task
Array of Notion page IDs to link in Project relation property of created task
Output Format
All outputs include these fields:Whether the operation succeeded. False only on validation errors or API failures.
On Success (success: true)
Pre-formatted text block for copy-paste into source digest’s Escalations section:
Whether a task was created. False if:
create_task: false- Circuit breaker prevented duplicate
- Escalation cap reached
Notion URL of created task, or null if not created
Notion page ID of created task, or null if not created
Whether circuit breaker prevented duplicate task creation. True if an open handoff task for same direction exists within 7 days.
URL of existing task if duplicate was prevented, or null
Whether escalation cap blocked task creation. True if 2+ escalations in same direction within 7 days.
Whether item needs manual review. True when escalation cap is hit.
On Failure (success: false)
Error message describing validation failure:
"Invalid source_agent: ...""Invalid target_agent: ...""escalation_reason and source_digest_url are required""task_priority is required when create_task is true""[Notion API error message]"
Usage Examples
- Create Handoff Task
- Circuit Breaker
- Escalation Cap
- Text-Only Mode
Circuit Breaker Logic
The circuit breaker prevents duplicate handoff tasks within a 7-day rolling window for the same source → target direction.
- Worker queries Tasks database for handoff tasks matching
"Handoff: [source] → [target]" - Filters results to tasks created within last 7 days
- Checks if any matching tasks have open status (not “Done”, “Closed”, “Complete”)
- If open task found:
- Returns
duplicate_prevented: true - Returns
existing_task_urlfor reuse - Does NOT create new task
- Returns
- Any status except: “Done”, “Closed”, “Complete”
- Status property can be named “Status” or “status”
- Status can be select or status property type
Escalation Cap Logic
When escalation cap hits:- Worker counts ALL tasks (open + closed) matching
"Handoff: [source] → [target]"within 7 days - If count >= 2:
- Returns
escalation_capped: true - Returns
needs_manual_review: true - Does NOT create task
- Agent should move item to “Needs Manual Review” section
- Returns
HANDOFF_WINDOW_DAYS = 7(src/workers/create-handoff-marker.ts:10)ESCALATION_CAP = 2(src/workers/create-handoff-marker.ts:11)
Task Structure
Whencreate_task: true and no circuit breaker/cap triggers, the worker creates:
Task properties:
- Name:
"Handoff: [source_agent] → [target_agent] — [due_date]" - Priority: From
task_priorityinput - Due: Next business day (src/shared/date-utils.ts:nextBusinessDay)
- Client: Relations from
client_relation_ids - Project: Relations from
project_relation_ids
Due date is calculated as next business day (Monday–Friday). Weekends are skipped.
Handoff Block Format
Thehandoff_block output is designed for direct paste into source digest’s “Escalations / Hand-offs” section:
- Escalated To: Target agent name
- Escalation Reason: Why escalation is needed
- Escalation Owner: Who is responsible (usually target agent)
- Handoff Complete: Always “No” at creation time
- Source: URL back to originating digest for traceability
The handoff block matches the format expected by
write-agent-digest worker’s escalations section (src/workers/write-agent-digest.ts:103-113).Error Handling
Validation errors returnsuccess: false:
Implementation Details
Source Files
- Worker implementation:
src/workers/create-handoff-marker.ts:27-197 - Schema definition:
src/index.ts:65-85 - Type definitions:
src/shared/types.ts:101-125
Query Strategy
The worker uses a two-phase query: Phase 1: Find candidates- Filter results to
created_time >= (now - 7 days) - Separate open vs closed tasks
- Count total for cap check
Date Calculations
Window calculation:nextBusinessDay() skips Saturday/Sunday (src/shared/date-utils.ts).
Best Practices
- Always Check Flags
- Include Relations
- Text-Only for Light Escalations