# Error: failed to register new resource ... Resource monitor is terminating

## TL;DR
Your Automation API program exited (or moved on) while resource registrations were still in flight. Await the `up`/`preview` promise to completion and keep the process alive until it resolves; do not let the event loop drain early.

## The error

```
Unhandled Pulumi Rejection: failed to register new resource automation-bucket [aws:s3/bucket:Bucket]: Resource monitor is terminating
```

## Fix it

1. Find where your program stops awaiting: make sure `await stack.preview()` / `await stack.up()` is actually awaited all the way up the call chain to your entry point.
   - Success check: no floating promises; the process stays alive until the operation completes.
2. If you fire-and-forget the operation, keep a reference and await it before `process.exit` or function return.
   - Success check: the rejection disappears and you get a real result or a real error.
3. Attach a rejection handler while debugging so failures surface with context instead of as unhandled rejections.
   - Success check: errors name the failing resource and reason, not the monitor.
4. Confirm plugin and config setup happen before the operation: install the provider plugin and set config (region, etc.) prior to preview/up.
   - Success check: the operation starts cleanly instead of racing setup.

## When to use this
You hit this in Automation API code (Node.js, Python, Go, .NET) where resource registrations fail with the monitor terminating.

## When NOT to use this
Do not use this for the same text on the CLI (`pulumi up`). There the engine lifecycle is managed for you; look for provider crashes instead.

## Compatibility
Pulumi Automation API, all language SDKs. The monitor lifecycle rules are the same everywhere.

## Variants
- `failed to register new resource [name] [[type]]: Resource monitor is terminating` for any resource type
- The rejection repeating many times (once per resource the program tried to register)

## Root cause
The language host registers resources against the engine's resource monitor over RPC. If the program's main flow finishes and the runtime tears down while registrations are still queued, each one fails with "Resource monitor is terminating" because the other end is gone.

## Edge cases
- `stack.preview()` that throws synchronously (bad config) can look similar; check for an earlier real error first.
- In serverless handlers, the frozen event loop after return kills in-flight registrations. Await everything before returning the response.
