Repository navigation
fix(hosts): leave a legacy host's recovery channel alone #528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andrebrait
wants to merge
2
commits into
main
Choose a base branch
from
fix/legacy-recovery-delivery
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { mkdtempSync, rmSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { setTimeout as sleep } from "node:timers/promises"; | ||
| import test from "node:test"; | ||
| import { mock } from "bun:test"; | ||
|
|
||
| const root = mkdtempSync(join(tmpdir(), "legacy-recovery-channel-")); | ||
| const previous = process.env.PI_CODING_AGENT_DIR; | ||
| process.env.PI_CODING_AGENT_DIR = root; | ||
| const { releaseRepo } = await import("../release-repo.ts"); | ||
| const realRecoveryRelease = await import("../recovery-release.ts"); | ||
| mock.module("../recovery-release.ts", () => ({ ...realRecoveryRelease, | ||
| recoveryHelperRelease: async () => ({ version: "0.7.2", repo: releaseRepo(), assets: [{ name: "ompweb-linux-x64.tar.gz", digest: `sha256:${"c".repeat(64)}` }] }), | ||
| })); | ||
| const hub = await import("./hub.ts"); | ||
| const { readLegacyUpgrade } = await import("./legacy-upgrades.ts"); | ||
| const { linkHost, until } = await import("./link-driver.test-helper.mjs"); | ||
| const { LINK_PROTOCOL_VERSION } = await import("./link-protocol.ts"); | ||
| const operationId = "12345678-1234-4234-8234-123456789012"; | ||
| const recoverySession = "01a1eed6-de03-7591-84fb-20c20bb3ecca"; | ||
| test.after(() => { | ||
| hub.flushLinkSamples(); | ||
| if (previous === undefined) delete process.env.PI_CODING_AGENT_DIR; | ||
| else process.env.PI_CODING_AGENT_DIR = previous; | ||
| rmSync(root, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| // A 0.7.1 daemon lists the recovery omp it opened as a channel with that omp's own session id (creationId = the operation). | ||
| // The server must not adopt it as a session: the adoption's get_state is `id: 1` like the bootstrap's bash, and its reply | ||
| // was taken for the bootstrap's, which closed the channel seconds in and lost the real result (ai-worker-2, 2026-11-18). | ||
| test("a legacy host's recovery channel is never adopted, so the bootstrap's own result is the one that is read", async (t) => { | ||
| const link = await linkHost("Legacy recovery channel", { hello: { v: LINK_PROTOCOL_VERSION, platform: "linux", home: "/tmp" } }); | ||
| const opens = []; | ||
| const commands = []; | ||
| let closes = 0; | ||
| const serving = link.serve({ | ||
| checkUpdates: () => ({ ompweb: { currentVersion: "0.7.1", availableVersion: "0.7.2", updateAvailable: true, canUpdate: false, | ||
| blockedReason: null, updateCommand: "", installMethod: "binary", protocolVersion: LINK_PROTOCOL_VERSION }, omp: { currentVersion: null }, operation: null }), | ||
| open: (args) => { | ||
| opens.push(args); | ||
| return { ch: "recovery", joined: true, pending: [], streaming: null, cwd: "/tmp", fellBack: false, launchAdvisor: false, advisorSpawned: false, autoApproveExtension: false }; | ||
| }, | ||
| close: () => { closes++; return {}; }, | ||
| }, async (message) => { | ||
| if (message.type !== "stdin") return; | ||
| const command = JSON.parse(message.line); | ||
| commands.push(command); | ||
| // The runner answers any command with its own id, as the daemon maps it back to the sender's. | ||
| if (command.op === "get_state") await link.post({ type: "stdout", ch: message.ch, line: JSON.stringify({ t: "res", id: command.id, ok: true, data: { sessionId: recoverySession, sessionFile: "", isStreaming: false, isCompacting: false } }) }); | ||
| }); | ||
| t.after(async () => { hub.closeHostLink(link.id); await serving; }); | ||
|
|
||
| await hub.updateHostSoftware(link.id, "ompweb", "0.7.2", { force: true, operationId }); | ||
| await until(() => commands.length === 2, "both recovery lines"); | ||
| await link.post({ type: "channels_changed", channels: [{ ch: "recovery", sessionId: recoverySession, cwd: "/tmp", pending: [], creationId: operationId }] }); | ||
| await sleep(100); | ||
| assert.equal(opens.length, 1, "only the recovery's own open: no join of the channel as a session"); | ||
| assert.deepEqual(commands.map((command) => command.op ?? command.type), ["bash", "bash"], "nothing but the bootstrap is sent to its channel"); | ||
| assert.equal(closes, 0); | ||
| assert.equal(readLegacyUpgrade(link.id)?.operation.state, "running"); | ||
|
|
||
| // The bootstrap fails after the channel was listed: that exit code is what reaches the operation. | ||
| await link.post({ type: "stdout", ch: "recovery", line: JSON.stringify({ t: "res", id: 1, ok: true, data: { exitCode: 1 } }) }); | ||
| await until(() => closes === 1, "the recovery channel's close after the bootstrap's result"); | ||
| const state = readLegacyUpgrade(link.id)?.operation; | ||
| assert.equal(state?.state, "failed"); | ||
| assert.match(state?.error ?? "", /exited with code 1/); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Limit the reattachment guarantee to active recovery.
reattachskips a listed channel with no existing transport when itscreationIdmatches the activelink.recovery.id. This sentence implies that the channel is excluded from reattachment for its entire lifetime. State the active-operation condition here and in the changelog.