Skip to content

Reload hand-off for exclusive extension resources so stateful sites hot-reload; contact-form signal docs and example version alignment (#777, #793, #795) - #798

Merged
jimhoyd merged 2 commits into
mainfrom
claude/sleepy-shannon-xvazgl
Sep 26, 2026
Merged

jimhoyd merged 2 commits into
mainfrom
claude/sleepy-shannon-xvazgl

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

Problem and change

#777 (reopened): a generic reload hand-off in the extension contract.

  • The bug: a generated init --with admin,form-records --example site could not hot-reload. reload() activates the replacement runtime before closing the serving one, so the last-good snapshot survives a failure, and the store's second activation in the same process failed with Store directory is already locked by this process.
  • Contract: the new pieces are additive and exported from @jimhoyd/urlcode/extensions.
    • ExtensionInstance.handoff?() is offered once per extension, in activation order, only during an in-process startServer reload, and only from the serving instance of the very same registration object. It is never offered on a first activation or to any other command.
    • A non-undefined result reaches the replacement's activation as context.handoff = {value}.
    • A throwing handoff() rejects the reload with extension-activation.
    • RuntimeOptions.replacing is set only by the server's reload; startServer refuses it from callers.
  • State machine: reference-counted, with the count held by the extension.
    • The replacement takes its own reference.
    • A failed reload closes only the replacement's references, so the serving instance keeps the resource and it stays usable.
    • A successful reload retires the old runtime, which drops only its own reference.
    • An activation that can't use the value opens fresh, which fails on the lock as before.
    • Cross-process and cross-registration exclusion are unchanged.
  • store adopts it:
    • It keeps a per-registration directory lease: one lock, a reference count, and a shared write path per data file. There is never a second writer, and no write is lost during the overlap.
    • A view that can't represent a committed state answers 503 rather than overwriting it.
    • The records export and the audit producer follow the newest live activation.
  • ui, auth and mail no longer lose their "current activation" when another one closes. With the lock fixed, every ui-rendered page returned 500 after a reload, because the retired runtime's close cleared ui's kit. auth and mail were likewise switched off by a failed reload's close. All three now keep the newest live activation.
  • Unchanged: audit, admin, forms, form-records and abuse needed no change.
  • Docs: new card RIM-EXT-HANDOFF-001; EXTENSIONS, LOCAL-DEVELOPMENT and STORE docs updated.

#793: the contact-form recipe no longer promises that test/audit won't fire its signal.

  • urlcode test/audit fixtures are ordinary requests, so a fixture that reaches /contact calls the granted destination. Only HEAD requests and the runtime's own health/readiness probes skip signals.
  • The recipe now tells you to declare a public HTTPS test endpoint you own while testing, because egress refuses loopback and private addresses and the policy can only grant the declared origin, pinned to the project revision.
  • EGRESS.md and examples/egress were corrected the same way.
  • A new check-agent-facts rule, derived from runtime.ts's emit condition, rejects the old claim.

#795: example runtime versions stay aligned.

  • examples/cloudflare and examples/vercel now pin the current core exactly.
  • scripts/release-bump.ts rewrites @jimhoyd/urlcode in every examples/*/package.json, and its --check step (run by npm run check) fails on a stale or ranged pin.
  • VERSION-ALIGNMENT and RELEASE-OPERATIONS docs are updated. The lockfile is unchanged; the examples are not workspaces.

Closes #777. Closes #793. Closes #795.

Verification

All runs used Node 26.10.0, on this exact head (main df0952d plus these two commits):

  • npm ci, build, workspace builds, npm run check, npm run audit:packages and npm run verify all passed (exit 0).
  • npm run test:package passed: 801780 packed / 3205208 unpacked bytes, 471 files; 39 packaged example commands ran from consumer copies.
  • New tests:
    • test/extension-handoff.test.ts: success, failure keeps the old runtime serving, the old close doesn't release, and exclusion holds;
    • packages/store/test/reload.test.ts;
    • packages/form-records/test/reload.test.ts, which runs the in-process composition;
    • a reload step in test/addons.integration.ts on the real packed site: change the contact title, the new title is served, earlier records are readable and new writes work.
  • Extended: the ui, mail and auth tests; release-bump and agent-facts tests with planted drift and stale wording.

Compatibility and security

  • Additive: extensions without handoff() behave exactly as before. Store single-writer safety is preserved, and the cross-process lock is unchanged.

  • Not covered by a reload: changes to host.mjs itself, such as the store directory option, still need a restart. Locking is still single-host.

  • Changed store declaration mid-reload: if the retiring runtime commits a record that the new declaration rejects, that collection answers 503 until a restart. It is refused rather than overwritten.

  • Test coverage: auth's failed-reload fix is covered by a unit test, not by a failed reload on the real composition. This is test evidence, not an independent security review.

  • Changes match the documented portable contract; docs/examples are updated where needed.

  • Relevant tests and package checks pass, or limitations are explained above.

  • No credentials, customer data or private project material are included.

  • Runtime/starter changes remain aligned where applicable.

🤖 Generated with Claude Code

https://claude.ai/code/session_014jmv9dMggduiprzSsNd7iP


Generated by Claude Code

…ources; store adopts it (#777)

An in-process reload activates the replacement runtime while the serving one
keeps serving, so the store's per-activation directory lock refused the
replacement ("Store directory is already locked by this process") and a
generated `init --with admin,form-records --example` site could not hot reload.

Core (RIM-EXT-HANDOFF-001): an optional, additive `ExtensionInstance.handoff()`
and `ExtensionActivation.handoff: ExtensionHandoff {value}`. Only
`startServer`'s reload (createRuntime `replacing`, refused from startServer
callers) asks the serving instance of the very same registration object for
its offer just before that registration activates in the replacement; a throw
rejects the reload ("failed to hand off for a reload"). Ownership is reference
counted by the extension: a failed replacement's close and the retired
runtime's close each drop only their own reference.

Store: a per-registration directory lease (one lock, refcount, one shared
write path per data file). The replacement joins the lease with a single-use
token instead of locking again; every commit is applied to every live view of
the file, so there is never a second writer; a changed declaration reloads,
and a view that cannot represent a committed state answers 503. The records
export and audit producer follow the newest live activation. Another
registration, server or process is still refused.

ui, auth (current activation and lifecycle hooks) and mail keep the newest
live activation current and fall back to the previous live one on close: ui
previously cleared its kit when the retired runtime closed, so every ui page
answered 500 after a successful reload, and a failed reload switched ui,
auth and mail off for the runtime still serving. Audit, admin, forms,
form-records and abuse hold no exclusive per-activation resource.

Tests: a synthetic exclusive extension in core, store reload/overlap tests,
an in-process generated-composition reload in form-records, ui/auth/mail
lifecycle tests, and a reload step in the packed add-on integration test.
Docs: RIM-EXT-HANDOFF-001 card, EXTENSIONS "Reload hand-off", LOCAL-DEVELOPMENT,
STORE "Single-writer lock and reload", store README, changelogs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014jmv9dMggduiprzSsNd7iP
@jimhoyd
jimhoyd merged commit 927e023 into main Sep 26, 2026
30 checks passed
@jimhoyd
jimhoyd deleted the claude/sleepy-shannon-xvazgl branch September 26, 2026 18:10
jimhoyd added a commit that referenced this pull request Sep 26, 2026
#798 fixed #777, #793 and #795 with its own design (an extension handoff()
hook with a reference-counted exclusive resource) and merged first. This
resolves the conflict by taking main for all of that, so this branch's own
reload-handoff, recipe-signal and example-pin changes are dropped. What remains
is the context/plan-feature/MCP fix for #791 and #790 on top of main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants