Skip to content

Stop a stone the previous engine started with that engine, and ask before forcing it for an upgrade - #195

Open
srbaker wants to merge 3 commits into
mainfrom
fix/upgrade-stop-old-stone
Open

srbaker wants to merge 3 commits into
mainfrom
fix/upgrade-stop-old-stone

Conversation

@srbaker

@srbaker srbaker commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

@MatiasFernandez, could you review this?

The report

Updating 1.9.0 → 1.10.0 with several VS Code windows open, and no notebook or GemDB Shell in any of them:

  1. The engine-upgrade question appeared and was approved. The upgrade then failed: stopping the database ended with an error, and the message said to close notebooks and GemDB Shells. None were open.
  2. Stop GemDB (still enabled) failed with "The Gem and Stone versions are incompatible", and the status view showed engine 4.0.0.a8 installed. That looked like a partial upgrade.
  3. Reinstalling 1.9.0 stopped the server. Updating to 1.10.0 again then upgraded cleanly.

What was going on

Two bugs, and no partial upgrade. The upgrade checks that the stone is down before it runs the script, so the extent was never touched. The status view showed a8 because a8 is the engine now installed.

  • The upgrade only tried a normal stop. upgradeEngine logged out this window's sessions, then ran a5's stopstone without -i. Every VS Code window running GemDB keeps a session (GemDB Code) even with no notebook open. A window not reloaded since the update is still 1.9.0, logged in to the a5 stone. So stopstone refused, and the upgrade ended with advice nothing in this window could follow. It also never stopped the MCP server, which holds a session too.
  • Stop GemDB used the new engine on the old stone. runStop → stopStone() resolved enginePath(), which is a8, and a8's stopstone cannot log in to an a5 stone (4044). That left no way out short of reinstalling 1.9.0.

The fix

  • stopStone / stopNetldi stop each process with the engine that started it (engineThatStarted, from the version gslist reports). A prefix of the pin counts as the pin, because gslist can truncate the version. If that engine is no longer installed, they log it and fall back to the pinned engine.
  • ensureListener (the listener a declined "Stop Anyway" puts back) will not start this engine's listener beside a stone another engine started.
  • The upgrade stops the database through runStop: this window's sessions, the MCP server, the listener, then the stone. When the normal stop is refused it asks Stop Anyway, exactly as Stop does. If the answer is no, nothing is changed, and the error names other VS Code windows as the likely holders.
  • The force-stop question now says every window running GemDB holds a session, including one not reloaded since the update.
  • CHANGELOG (Unreleased → Fixed) and docs/automation-boundary.md updated.

Testing

  • npm test: 1326 passing.

    • New engineThatStarted.test.ts covers which engine is used.
    • The upgradeEngine tests now cover a refused stop the user won't override.
    • startProcesses.test.ts fixture rows now carry the pinned version, plus a case for the listener refusal.
  • npm run lint, format:check, typecheck and typecheck:strict are clean.

  • src/__integration__/engineUpgrade.test.ts: 5 passing on arm64 macOS, with the a8 engine, Grail built at the pinned 4d57909, and a5's stock extent0.rowan3.dbf as the old database. Before, the test stopped the a5 stone before upgrading, so the stop this PR changes never ran. Two cases now start from a5's stone and listener with an RPC session logged in, standing for a window still on 1.9.0:

    • Declining Stop Anyway asks the question, then changes nothing: the extent is untouched and there is no backup.
    • Answering Stop Anyway force-stops with a5's tools and upgrades to a8.

    Running it found a further problem, now fixed. The fixture kept a5 outside the root path, so the stop could not find a5's stopstone. The pre-PR code had the same check and would have refused the same way. The fixture now puts a5 under the root path, where 1.9.0 installs it.

  • Worth trying by hand: with a5 running, open two windows (one still on 1.9.0) and start the upgrade from the other. Expect the Stop Anyway question, then a clean upgrade. Separately, decline the upgrade and press Stop: it should stop the a5 stone.

🤖 Generated with Claude Code

…fore forcing it for an upgrade

After updating to 1.10.0 with another VS Code window open, the engine upgrade
could not stop the a5 stone: every window running GemDB keeps a session on it,
and a window not reloaded since the update is still 1.9.0. The upgrade gave up
with "close the notebooks and GemDB Shells", which nothing in this window
could do. Stop GemDB then used a8's stopstone on the a5 stone, which cannot log
in to it ("The Gem and Stone versions are incompatible"), so the only way out
was reinstalling 1.9.0.

- stopStone and stopNetldi pick the engine that started the process they stop
  (engineThatStarted), so Stop works on a stone the previous engine started.
- ensureListener will not start this engine's listener beside such a stone.
- The upgrade stops the database through runStop: the MCP server goes too, and
  a refused stop asks Stop Anyway rather than failing.
- The force-stop question and the upgrade's failure name other editor windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s engine left running

The test stopped the a5 stone before upgrading, so it never reached the stop
the upgrade does. Two cases now start from a5's stone and listener with an RPC
session in them, standing for another window still on 1.9.0: declining Stop
Anyway changes nothing, and answering it upgrades. The previous engine sits
beside the pinned one under the root path, where the previous GemDB put it;
without that the stop could not find a5's stopstone, which the old check
would also have refused on.

The upgrade's failure names other windows only when the stop was refused; a
stop that errored says so and points at the log instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@MatiasFernandez MatiasFernandez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments worth reviewing

Comment thread src/lifecycle.ts
Comment on lines +856 to +862
const stone = findStone();
if (startedByAnotherEngine(stone) && !engineThatStarted(stone)) {
throw new Error(
`the running database was started by GemStone ${stone?.version ?? from}, ` +
'which is no longer installed',
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 What happens here when the previous engine has been uninstalled? runStop wraps stopStone(false) in a try/catch and sends any error to confirmForce. So this error doesn't fail the upgrade. The user gets the Stop Anyway modal with "the running database was started by GemStone 4.0.0.a5, which is no longer installed" as the reason, followed by "This is usually a session that is still logged in…". If they choose Stop Anyway, stopStone(true) throws the same error and the upgrade fails anyway. So we ask a question whose answer can't change anything.

By that point runStop has also logged out this window's sessions, stopped the MCP server and stopped the listener, using a8's stopnetldi because engineThatStarted(findNetldi()) falls back. engineThatStarted has also logged "trying GemStone 4.0.0.a8's tools instead", right before we throw instead of trying.

Should this check run in stopDatabase before runStop, so the upgrade fails before it touches anything? Something like:

stopDatabase: async () => {
  const stone = findStone();
  if (startedByAnotherEngine(stone) && !enginePath(stone!.version)) throw new Error(...);
  await runStop({ ..., stopStone, ... });
},

Calling enginePath directly would also avoid the misleading fallback log line.

Comment thread src/processes.ts
*/
export function startedByAnotherEngine(process: EngineProcess | undefined): boolean {
if (!process || externalDatabase()) return false;
return !engineVersion().startsWith(process.version);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 Is the prefix match broader than the truncation needs? Per parseGslist, the cut comes from the lock file's char version[12], so only an 11-character version can come back short. With a plain startsWith, a stone reporting 3.7.1 counts as the same engine under a 3.7.1.4 pin, and 4.0.1 counts as 4.0.10. GemStone uses both patterns. In that case we'd stop the old stone with the new engine's tools, which is the 4044 this PR fixes, and ensureListener would start a mismatched listener beside it.

What if we only allowed the prefix when the reported version is at the truncation width?

const reported = process.version;
const pin = engineVersion();
return reported.length >= GSLIST_VERSION_WIDTH ? !pin.startsWith(reported) : reported !== pin;

We could also add a case to engineThatStarted.test.ts with a short version that is a prefix of the pin but a different engine.

Comment thread src/lifecycle.ts Outdated
Comment on lines +866 to +870
// A declined force-stop leaves the database to the windows still using
// it. Not put back: this engine's listener cannot serve the previous
// engine's stone, and the stone lock this runs under is the one
// `ensureListener` would wait on.
startNetldi: () => Promise.resolve(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 When the user declines, the old stone stays up with no listener. The sessions we chose to protect survive, but the 1.9.0 window can't open anything new: a notebook it hasn't run yet, or a new GemDB Shell, fails to log in until something restarts the listener. This also hits plain Stop GemDB: its startNetldi is ensureListener, which now refuses beside another engine's stone (processes.ts:463).

Now that stopNetldi picks the engine that started the process, could startNetldi do the same, and start the previous engine's listener when the stone is the previous engine's? ensureListener could then put the right listener back instead of refusing. Here, since we already hold the stone lock, we could call the inner start directly rather than going through ensureListener. The integration test's netldi toBeUndefined() assertion would flip to checking that the listener's version is from.

startPreviousDatabase();
await holdPreviousSession();
const before = fs.statSync(extentPath()).mtimeMs;
const warning = vi.spyOn(vscode.window, 'showWarningMessage');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The "declined" answer here comes from the vscode mock's default showWarningMessage (which resolves undefined), so a reader can't see from the test itself that the user said no. Would .mockResolvedValue(undefined) be clearer? It would match the explicit 'Stop Anyway' in the next test and keep this test correct if the mock's default ever changes.

Setup stages this release's Grail before the upgrade is asked about, so a
listener put back on the previous engine's stone would hand every new session
a shim built for the other engine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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