Repository navigation
Conversation
ymichael
force-pushed
the
bb/class-fix-cli-commands-reporting-false-success-thr_2ptrjaw73f
branch
2 times, most recently
from
November 18, 2026 05:38
ab9e8cc to
4e69d45
Compare
The server answered machine removal, cleanup retry, and thread stop with a
plain {ok: true} even when the provider teardown failed or the thread was
still running, and several CLI commands printed --json results before their
failure check, so they exited 0. Failed operations now surface as errors or
as an explicit status, and the CLI reports results through one
reportCommandResult owner that exits non-zero on a reported failure.
Guards: outputJson rejects payloads that carry an ok/success failure flag at
compile time, and every registered command is run against a failing server
and must exit non-zero without success output.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…no server bb status now exits non-zero when the server does not answer, so the wrapper test runs bb guide --json instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Mutating routes now answer a shared { ok, progress } outcome instead of a
bare { ok: true }, and fail with an error status when the work failed. A
type-level contract test over publicApiRoutes forbids bare acknowledgements
and unlisted failure-shaped 2xx bodies. The SDK reads every body instead of
fabricating { ok: true }, and readVoid is gone.
On the CLI, command-result.ts owns all JSON output and exit codes: a source
guard forbids direct JSON writes and process.exit elsewhere, outputJson
rejects untyped and failure-shaped results, and the every-command guard now
fails each recorded request in turn with route-keyed failure bodies and
rejects commands that never reach the server.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… reload outcome Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
force-pushed
the
bb/class-fix-cli-commands-reporting-false-success-thr_2ptrjaw73f
branch
from
November 18, 2026 21:50
4e69d45 to
f174e23
Compare
ymichael
deleted the
bb/class-fix-cli-commands-reporting-false-success-thr_2ptrjaw73f
branch
November 18, 2026 21:58
ymichael
added a commit
that referenced
this pull request
Nov 18, 2026
…eeds-recovery state Rebased onto origin/main as one commit. The drop of hosts.suspend_retry_at is regenerated as migration 0159, the plugin SDK moves to 0.6.162, and the retry-cleanup guard test expects the 502 machine_teardown_failed answer that #7748 added. The bb-app launcher restart budget (#3340) is left out of this PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Human comments
What was wrong
Two halves of one bug let a command report success for work that failed or never finished.
Server: mutating routes answered a bare
{ok: true}whatever happened. Examples:DELETE /hosts/:id,?force=trueandPOST /hosts/:id/retry-cleanupreturned 200 after provider teardown failed (host leftremoving,teardownStatus: "failed").POST /environments/:id/cleanup?recover=trueawaited a sweep that recorded the failure, then returned{ok: true}.POST /threads/:id/stopreturned{ok: true}after swallowing a failed interrupt.{ok: true}for work that was only queued.The SDK then fabricated
{ok: true}itself (readVoidfollowed byreturn { ok: true }), so callers could not tell even when the body had more to say.CLI: commands printed results before deciding whether they failed.
if (outputJson(opts, result)) return;came before the failure check, so--jsonexited 0. Other commands never checked failure fields.status.get'sfetchSilentandthread show's pending-todos lookup swallowed every error. Each command used its own exit mechanism.Reproduced live on
origin/main(3678415),pnpm start:worktreeplus a local machine-provider plugin whose removal always fails:What changed
Server: one outcome shape, one owner, one guard
OperationResponse = { ok: true, progress: "complete" | "in-progress" }(packages/server-contract/src/api/operation.ts).apps/server/src/services/lib/operation-response.ts(operationComplete()/operationInProgress()).{ok: true}now return it.502 machine_teardown_failed(readMachineRemovalOutcome);cleanup --recover→502 environment_teardown_failed(readEnvironmentRecoveryOutcome);thread stopleaving the threadstarting/active→409 thread_stop_unfinished.packages/server-contract/test/operation-responses.test.ts. A type-level contract test overpublicApiRoutes:{ok: true}.ok/successcan befalse,outcome/state/resultcan be a failure value, anerrorfield is present, or aresultsbatch contains any of these.import-cookies(typed per-reason outcome the desktop dialog renders),server/moveandserver/move/cancel(state-machine snapshots),ai-services/test(diagnostic probe),cli-skills/install(batch).origin/main'spublic-api.ts,api/hosts.tsandapi/system.ts, it fails and names all 25 routes, includingdelete /hosts/:id,post /hosts/:id/retry-cleanup,post /environments/:id/cleanupandpost /threads/:id/stop.app.postplugin routes (apps/server/src/routes/plugins.ts,plugin-catalog.ts) are not inpublicApiRoutes, so the type guard can't see them. They already answer failures with non-2xx, except outcomes the CLI checks (plugin enable/installload errors, marketplace refresh batches). The every-command CLI guard below covers those.SDK
readVoidnow returns the route's typed body.readVoidis deleted from the transport, so a discarded body can no longer be fabricated into{ok: true}.status.getmaps only a 404 tonull(a missing thread or project); any other failure propagates.CLI: one owner for result output and exit codes (
apps/cli/src/command-result.ts)outputJson,printJsonResult,printJsonLine,reportCommandResult,reportOperationandpassThroughExitCodeall live there.outputJson's parameter rejects, at compile time, untyped payloads (unknown,any, and index signatures ofunknown) and failure-shaped payloads (same rule as the server guard). Those must go throughreportCommandResult, which requires an explicit failure decision.apps/cli/src/__tests__/command-result-owner.test.ts. An AST scan ofcommands/that fails on any directJSON.stringifywritten to stdout (including through a conditional, like the oldbrowser.tsprint), anyprocess.exit, and anyprocess.exitCode. The only allowlisted exceptions are the two passthroughs of a plugin command's exit code (plugin run, retiredenvironmentgit aliases).console.error+process.exit(1)pairs inplugin.ts;browser import-cookies,plugin safe-mode off,server move(recovery keeps its own exit code),server move cancel;terminal run/wait(viapassThroughExitCode, output unchanged);One rule for in-progress results
progress: "in-progress"means the server accepted the work and is still carrying it out. It exits 0, and the text says it is still in progress. A failed operation exits non-zero.reportOperationapplies the rule everywhere:The first version of this PR exited 1 for a stopping thread; it now follows this rule.
Class members
bb machine remove(machine.ts:486;routes/hosts.ts:319-323; SDKhosts.ts:301)in-progresswhile removingbb machine remove --forcebb machine retry-cleanupbb machine removeof a bb connect machine (routes/hosts.ts:110-139)warningsin the success body; CLI prints it to stderr, exit 0 (the host is removed)bb environment cleanup --recover(routes/environments.ts:99;environment.ts:185)environment_teardown_failedbb thread stop(routes/threads/actions.ts:443; SDKthreads.ts:1609)in-progresswhile stopping; 409 if still activebb statusagainst a dead server (status.ts:71-81, #2382)server_unreachable, exit 1bb statuswith a context thread/project the server lacks (SDKstatus.ts:48fetchSilent)context_not_found, exit 1; other errors propagatebb thread showswallowing head-state failures (thread/pending-todos.ts)bb terminal close --if-cleanexitedbb machine provider-cli installproviderCliInstallFailure, shared withupdates applybb updates apply --json, and "Everything is up to date" when a status check failedbb skill install-cli-skills --jsonbb settings ai-services test --jsonbb marketplace refresh --jsonbb plugin update(rolled-back)bb plugin install(plugin loads inerror)plugin enable){ok: true}fabricationsOperationResponseandreadJsonLeft out, with reasons:
bb thread open/paneprintDelivered: falsetruthfully.tell --compact-first,updates app cancelandserver move canceldon't report success for a failure.plugin new's npm warning andmachine enroll's launcher symlink are side effects. #2382's stalled-daemon hang (no timeouts) is a different failure mode. #6912 happens below the server, in the ACP bridge.The every-command guard, v2 (
apps/cli/src/__tests__/failing-server-guard.test.ts)CORE_COMMAND_GROUPS, text and--json, 452 invocations, about 2 s.error, terminal close left running).updates apply(partial batch),status(local context).guide,plugin build,server unlock).origin/main'sapps/cli/src/commands, it fails 16 invocations across every CLI-side member: provider-cli install, marketplace refresh, plugin install, plugin update, ai-services test, install-cli-skills, status, terminal close, thread show, updates apply. Members 1–6 are server-side; the contract guard and route tests catch those.Decisions for review
502 machine_teardown_failed(machine remove/retry-cleanup) and502 environment_teardown_failed(cleanup --recover) replace 200 for failed teardown. The app's remove dialog now stays open with the error instead of closing, and plugins callinghosts.deleteget a rejection.Warning: ….thread stop→ 409 only when the thread is still active or starting.bb statusexits non-zero when the server is unreachable or its context is unknown.bb thread showfails when head-state fails for any reason other than 404.Error: …, includingplugin.tsusage errors (previously unprefixed).--jsonfailures include the payload or the envelope.{ ok: true }→{ ok: true; progress; ... },HostActionResultkept, SDK 0.6.159 as assigned. A plugin built against 0.6.156 still compiles. A plugin test double typed as one of these methods must addprogress; the one bundled case,provider-codex/goal-card.test.tsx, is updated.Docs: guide chapters
json,machines,environments,thread-lifecycle,terminalsandoverview, plus the plugin-authoringbackend-machinesreference.How you verified
pnpm start:worktree, real CLI):machine remove→Error: HTTP 502: QA: provider removal failed, exit 1.--json→machine_teardown_failedenvelope, exit 1.retry-cleanup --json→{"ok": true, "progress": "complete", "warnings": []}, exit 0.thread stopon a pending thread →progress: "complete", exit 0.BB_THREAD_ID=thr_doesnotexist bb status→ context, thenError: The context thread thr_doesnotexist was not found on the server, exit 1.bb statuson a closed port → exit 1.terminal close --if-cleanafter input → exit 1.cleanup --recover502, stopin-progressbody;turbo run typecheck lintfor cli, server, sdk, app, server-contract, plugin-sdk, templates and all plugins: pass.turbo run testfor cli (1401), sdk, server-contract, templates, scripts, provider-codex, workflows, side-chat and storage-retention: pass. Fullapps/servervitest: 4244 passed. App machine/project/thread suites: 124 passed.Part of #2382: fixes the unreachable-server case only; the stalled-daemon hang is not addressed.
🤖 Generated with Claude Code