Skip to content

fix: support running a module in the parent namespace via an empty id#4394

Closed
cpsievert wants to merge 1 commit into
mainfrom
fix-empty-namespace-destroy
Closed

fix: support running a module in the parent namespace via an empty id#4394
cpsievert wants to merge 1 commit into
mainfrom
fix-empty-namespace-destroy

Conversation

@cpsievert

@cpsievert cpsievert commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

After the new session$destroy() work (#4372), the root-scope detection (if (!nzchar(namespace))) errors with "argument is of length zero" when a module is run with an empty id, e.g. callModule(server, character(0)).

That empty-id idiom is how packages such as teal run a module server in the parent namespace, and it is the documented behavior of NS():

Length 0 will cause the id to be returned without a namespace

This makes the new destroy machinery handle that case. A length-0 namespace is treated as the root scope in the destroy-callback bookkeeping only; the namespace itself is left untouched so NS(character(0)) keeps returning ids unchanged (normalizing to "" would instead prepend a stray - separator).

Caught by reverse-dependency checks against teal.

@cpsievert cpsievert force-pushed the fix-empty-namespace-destroy branch 2 times, most recently from d03c258 to fe28077 Compare June 1, 2026 18:27
callModule(server, character(0)) reaches makeScope(character(0)). #4372's
new destroy-callback code branched on if (!nzchar(namespace)) to detect the
root scope, but nzchar(character(0)) is logical(0), so the guard errored with
"argument is of length zero".

A length-0 namespace is documented NS() behavior meaning "no namespace"
(root) and worked before #4372 (makeScope had no nzchar guard). Treat a
length-0 namespace as root only in the destroy-key logic, leaving the
namespace itself untouched so NS(character(0)) keeps returning ids unchanged
(normalizing to "" would instead prefix ids with a stray separator).
@cpsievert cpsievert force-pushed the fix-empty-namespace-destroy branch from fe28077 to c0e76e9 Compare June 1, 2026 18:29
@cpsievert cpsievert changed the title Fix "argument is of length zero" error when a module is run with an empty namespace Support running a module in the parent namespace via an empty id Jun 1, 2026
@cpsievert cpsievert requested review from Copilot and schloerke June 1, 2026 18:37
@cpsievert cpsievert marked this pull request as ready for review June 1, 2026 18:37

This comment was marked as resolved.

@cpsievert cpsievert changed the title Support running a module in the parent namespace via an empty id fix: support running a module in the parent namespace via an empty id Jun 1, 2026
@cpsievert

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #4395

@cpsievert cpsievert closed this Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants