Repository navigation
Stop a stone the previous engine started with that engine, and ask before forcing it for an upgrade - #195
Stop a stone the previous engine started with that engine, and ask before forcing it for an upgrade#195srbaker wants to merge 3 commits into
Conversation
…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
left a comment
There was a problem hiding this comment.
I left some comments worth reviewing
| 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', | ||
| ); | ||
| } |
There was a problem hiding this comment.
💭 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.
| */ | ||
| export function startedByAnotherEngine(process: EngineProcess | undefined): boolean { | ||
| if (!process || externalDatabase()) return false; | ||
| return !engineVersion().startsWith(process.version); |
There was a problem hiding this comment.
💭 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.
| // 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(), |
There was a problem hiding this comment.
💭 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'); |
There was a problem hiding this comment.
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>
@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:
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.
upgradeEnginelogged out this window's sessions, then ran a5'sstopstonewithout-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. Sostopstonerefused, and the upgrade ended with advice nothing in this window could follow. It also never stopped the MCP server, which holds a session too.runStop→stopStone()resolvedenginePath(), which is a8, and a8'sstopstonecannot log in to an a5 stone (4044). That left no way out short of reinstalling 1.9.0.The fix
stopStone/stopNetldistop each process with the engine that started it (engineThatStarted, from the versiongslistreports). A prefix of the pin counts as the pin, becausegslistcan 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.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.docs/automation-boundary.mdupdated.Testing
npm test: 1326 passing.engineThatStarted.test.tscovers which engine is used.upgradeEnginetests now cover a refused stop the user won't override.startProcesses.test.tsfixture rows now carry the pinned version, plus a case for the listener refusal.npm run lint,format:check,typecheckandtypecheck:strictare clean.src/__integration__/engineUpgrade.test.ts: 5 passing on arm64 macOS, with the a8 engine, Grail built at the pinned4d57909, and a5's stockextent0.rowan3.dbfas 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: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