Skip to content

Document app shutdown cleanup (scope 'close') — currently a bare event-list line in plugin-api.md #604

Description

@heskew

Summary

An app developer asked how to run custom cleanup before Harper shuts down and guessed it might involve the status API. The actual answer — a 'close' listener on the plugin-API Scope — is technically documented, but not in a way anyone would find:

export function handleApplication(scope) {
	const service = startService();
	scope.once('close', async () => {
		await service.close();
	});
}

Current state

The entire coverage is one line in the Scope events list in reference/components/plugin-api.md:

'close' — Emitted after scope.close() is called

Gaps

  1. No connection to shutdown. The line reads as if it's about the plugin author calling scope.close() themselves. Nothing says the component loader calls scope.close() when Harper shuts down or restarts — which is the whole reason an app would listen for it.
  2. Wrong doc for the audience. Someone building an application looks in applications.md; it (along with extension-api.md, overview.md, and javascript-environment.md) has zero occurrences of "cleanup", "shutdown", or "teardown". There is no lifecycle / graceful-shutdown section anywhere in the component docs, so searching the docs for the words in the question finds nothing.

Proposal

  • Add a "Cleanup on shutdown" subsection to plugin-api.md with the snippet above, stating explicitly that Harper calls scope.close() (emitting 'close') on shutdown and on graceful restart.
  • Cross-link it from applications.md (short "Lifecycle" or "Shutdown cleanup" pointer).
  • Caveat async cleanup: the shutdown path does not currently await async 'close' listeners, so long-running cleanup can be cut off — tracked in Graceful shutdown doesn't await scope 'close' cleanup — app teardown races process.exit harper#1912. Word the docs so they can be simplified once that lands.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions