Repository navigation
fix(core): say why a refused machine is offline, as data - #66867
rekram1-node wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
The fix works. I copied the PR's updated protocol 2/4 refusal tests onto the base, where they fail because offlineReason is missing; with this PR they pass. The other core machine tests pass, apart from the 2 machine-path home-directory tests, which fail the same way on the base. tsc is clean in core and server.
Public API (additive, backwards compatible):
Machine.Info(fromGETmachine list,MachineInfoin the SDK/client types) gains an optionalofflineReason: string.- The
Machine.NotSenterror gains an optionalreason, and its message becomes<id> is offline, command not sent: <reason>when a refusal is recorded.
Existing callers are unaffected.
Needs fixing before merge: packages/protocol/openapi.json wasn't regenerated. bun run check:generated in packages/protocol reports it as stale (it passes on the base), so the "Check generated OpenAPI document" CI step will fail. Running bun run generate there adds the offlineReason property.
| }), | ||
| ), | ||
| /** Why the machine's last connection was refused, while it is offline since, such as a worker too old for this server. */ | ||
| offlineReason: Schema.optionalKey(Schema.String), |
There was a problem hiding this comment.
This new field isn't in packages/protocol/openapi.json yet. bun run check:generated here reports it as stale, which will fail the "Check generated OpenAPI document" CI step. Running bun run generate in packages/protocol fixes it.
There was a problem hiding this comment.
The OpenAPI document is now regenerated with offlineReason. check:generated in packages/protocol passes. The code is the same as my last review, so the earlier results still hold. No other concerns.
Public API (unchanged since last review, additive and backwards compatible):
Machine.Infogains an optionalofflineReason: string.- The
Machine.NotSenterror gains an optionalreason.
84e8073 to
89b6a4f
Compare
89b6a4f to
5c9f455
Compare
There was a problem hiding this comment.
The openapi thread is fixed: packages/protocol/openapi.json is regenerated and its check passes. I reviewed the reworked version (refusal stored as data, parseHello, the HTTP mapping) and found nothing blocking. Core machine tests pass, apart from the 2 machine-path home-directory tests that also fail on the base. tsc is clean in core and server, and the generated client check shows no diff. The 11 server test failures are the same on the base.
Public API (additive, backwards compatible):
- Experimental
Machine.Info(GET /api/experimental/machine,@opencode/clienttypes, Rustapi-types) gains an optionalrefused: { at: number (epoch ms), reason: { type: "protocol-mismatch", worker, home } | { type: "invalid-hello", issue } }. It replaces theofflineReasonstring from the earlier revision, which never shipped. Machine.NotSentgains an optionalrefused, and its message adds the reason when there is one.- The agent's
machine.listtool output includesrefused.
Existing callers are unaffected.
Issue for this PR
No issue. Found while testing protocol 3 (#66457) against a worker that still speaks protocol 2. First step of the machine API data model rework.
Type of change
What does this PR do?
When a paired worker speaks a different link protocol than the server, the server refuses it right after the handshake and only logs why. The worker redials every second, and everything the user or an agent sees says just "offline", which reads like a network problem. This PR keeps the refusal per machine as data and shows it in
machine.listand in the offline error.GET /api/experimental/machine { "id": "gpu", "online": false, "paired": true, + "refused": { "at": 1795800000000, "reason": { "type": "protocol-mismatch", "worker": 2, "home": 3 } } } shell / read / write on gpu:... -gpu is offline, command not sent +gpu is offline, command not sent: worker speaks protocol 2, this server needs 3; update opencode-worker on that machineA worker on a newer protocol than the server gets
…; update OpenCode on this server. A hello that passes the handshake but doesn't decode is recorded as{ "type": "invalid-hello", "issue": "…" }.How it works:
describeRefusalinpackages/core/src/machine/driver.tsis the only place a refusal becomes text, so the advice is computed when shown rather than frozen when the refusal is recorded.decodeHellois gone: the stdio worker client callsparseHellotoo, and both callers log throughLink.reject.Only refusals after the handshake are recorded: before it the server doesn't know which machine is calling, and nothing about the refusal is sent to the worker.
Link.serveDirect(pinned-key links withoutMachines) records nothing. A worker that proves its key but never sends a hello is still only a timeout, not recorded.The refusal stays until the machine next connects, so a machine that was refused and then switched off still shows it. That is still the last thing known about it.
API:
refusedis a new optional field on the experimentalMachine.Info; nothing else in the API changes. OpenAPI,@opencode/clientand the Rustapi-typesare regenerated.Overlap with #66483 (worker self-update on mismatch): both touch the hello line in
Link.serveWith. With this PR that becomes a match onparseHello'sProtocolMismatch, which is where the update request fits.How did you verify your code works?
packages/core/test/machine-frames.test.ts: the existing "refuses protocol 2/4" tests (a fake worker sends an old or new hello over a real handshake) check the log line,machine.list'srefused.reasonand theNotSentmessage.machine*,tool-machine*,worker*): 220 pass, 2 fail. The 2 failures (keeps expanding a home directory for a local command with the flag off/oninmachine-path.test.ts) fail the same way onorigin/dev.bun run cargo test -p opencode-cli --bin opencode-native machine): 7 pass.bunx tsc --noEmitin packages/core and packages/client;bunx tsc -p tsconfig.build.json --noEmitin packages/server, packages/sdk, packages/simulation: clean.Screenshots / recordings
Not a UI change.
Checklist
Added by the opencode bot (AI-generated).
Public API: adds optional
refused(timestamp + protocol-mismatch / invalid-hello reason) to experimental Machine.Info and Machine.NotSent (backwards compatible)