Overview
Notion Workers are deployed to Notion’s infrastructure via thentn CLI. Workers:
- Run on Node.js ≥ 22 (managed by Notion)
- Execute on-demand (not long-running servers)
- Receive JSON input and return JSON output
- Have access to a pre-authenticated Notion client
Notion Workers is currently in alpha. APIs and deployment behavior may change. Check makenotion/workers-template for the latest updates.
Prerequisites
Install ntn CLI
Follow the installation guide at makenotion/workers-template.
Deployment Process
Quick Deploy
The fastest way to deploy:npm run build && ntn workers deploy automatically.
Manual Deploy
Deploy
Deploy workers to production:The CLI will:
- Package your workers
- Upload to Notion’s infrastructure
- Register the tools
- Confirm deployment success
Setting Production Secrets
Before first deployment, configure production secrets:List Configured Secrets
Update a Secret
Updating a secret requires redeployment for the change to take effect.
Testing Deployed Workers
Invoke a Worker
Test a deployed worker with sample input:View Logs
Monitor worker execution:Log Retention
Log Retention
Check the makenotion/workers-template documentation for current log retention policies.
Deployment Checklist
Before deploying to production:Secrets Configured
NOTION_TOKENDOCS_DATABASE_IDHOME_DOCS_DATABASE_IDTASKS_DATABASE_ID
Worker Platform Constraints
Runtime Environment
Node.js ≥ 22
Managed by Notion’s infrastructure
No Bun APIs
Bun.file(), Bun.serve(), etc. won’t existESM Only
"type": "module" in package.jsonTypeScript
Compiled to JavaScript before deployment
Execution Limits
Design for Timeout Constraints
Design for Timeout Constraints
- Break large operations into smaller chunks
- Return progress indicators if needed
- Consider pagination for database queries
- Use early returns for validation failures
Input/Output Constraints
- JSON only — No
Dateobjects,Map,Set, etc. - Structured responses — Always return
{ success, ... }shape - No throwing — Return
{ success: false, error }instead - No raw Notion objects — Map to your own types
Worker Design Rules
1. Atomic Operations Only
One tool = one concern. Good:write-agent-digest— Creates one digest pagecheck-upstream-status— Checks one agent’s statuscreate-handoff-marker— Creates one handoff record
- A single worker that writes digests AND creates handoffs
2. Idempotent by Default
Same input twice should produce the same result or safely skip. Example:create-handoff-marker has a circuit breaker — no duplicate handoff within 7 days.
3. No Side Effects on Dry Run
If a future worker supportsdryRun: true, it must not write to Notion.
4. Structured Return Values
Always return typed objects:5. Timeout-Aware Processing
For large datasets:- Process in batches
- Return progress indicators
- Consider pagination
Common Issues
Build fails with type errors
Build fails with type errors
Solution:
- Run
npm run checklocally - Fix all TypeScript errors
- Ensure
strict: trueis maintained - Rebuild with
npm run build
Worker times out in production
Worker times out in production
Solutions:
- Profile execution time locally
- Break operations into smaller batches
- Optimize Notion API calls (fewer queries)
- Check for infinite loops or blocking operations
Secrets not found at runtime
Secrets not found at runtime
Solutions:
- Verify secrets are set:
ntn workers secrets list - Check secret names match exactly (case-sensitive)
- Redeploy after updating secrets
- Use
src/shared/notion-client.tsto read fromprocess.env
Worker invocation fails with schema error
Worker invocation fails with schema error
Solutions:
- Validate input matches the tool’s JSON schema
- Check for invalid types (Date objects, etc.)
- Review input in
.examples/directory - Test locally with the exact input first
Monitoring & Debugging
View Recent Logs
Debug a Specific Invocation
Error Handling Pattern
Workers return errors in the response:Rollback & Recovery
Rollback to Previous Version
Rollback to Previous Version
The ntn CLI may support version history. Check current documentation:Verify in makenotion/workers-template.
Emergency Shutdown
Emergency Shutdown
If a worker is causing issues:
- Quick fix: Deploy a version that returns early with a maintenance message
- Long-term: Fix the issue, test thoroughly, redeploy
- Monitor: Watch logs after redeployment
CI/CD Integration
For automated deployments:Store
NTN_TOKEN and other credentials in your CI secrets, never in code.Next Steps
Architecture
Understand the worker system design
Worker Reference
Detailed API documentation for each worker
Testing Guide
Test before deploying
Credentials
Manage production secrets