Fix CLI domain failures exiting with code 0#993
Open
Nih1tGupta wants to merge 1 commit into
Open
Conversation
Contributor
📝 WalkthroughWalkthroughThe CLI's graph command now raises a validation exit code when the result payload indicates failure. The host CLI now captures the Typer app's invocation return value and propagates it as a non-zero exit code when truthy. ChangesCLI Exit Code Propagation
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Contributor
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@potpie/context-engine/adapters/inbound/cli/commands/graph.py`:
- Around line 396-398: The downstream ok re-checks are dead code because
_emit_graph_result already raises typer.Exit when payload.get("ok", True) is
False. Remove the redundant post-call checks in _emit_inbox_result,
_emit_quality_result, and _emit_graph_read so those callers just rely on
_emit_graph_result’s exit behavior and no longer repeat unreachable validation
logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: ASSERTIVE
Plan: Pro
Run ID: 2aa8b21a-dd58-423b-8d78-ab3a1b930c76
📒 Files selected for processing (2)
potpie/context-engine/adapters/inbound/cli/commands/graph.pypotpie/context-engine/adapters/inbound/cli/host_cli.py
3 tasks
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.
Closes #992
Summary
run_cli()usesstandalone_mode=False, socontract()/fail()outcomes (e.g.CapabilityNotImplemented,ambiguous_pot, validation errors) reach the OS process instead of always exiting 0.1when graph workbench results emit"ok": falsevia_emit_graph_result(), closing the gap for in-band failures that never raised an exception (e.g. invalidgraph nudgeevents).Problem
The CLI printed correct structured errors (JSON or human) but often returned exit code
0, so scripts, CI, andcmd && next_steptreated failed commands as successful. Parser/usage errors already exited non-zero; many runtime/domain failures did not.Root causes:
host_cli.run_cli()discarded the return value fromapp(..., standalone_mode=False). Click returns command exit codes instead of propagatingtyper.Exitto the process in that mode._emit_graph_result()printed graph envelopes with"ok": falsewithout raising, so some graph commands exited0despite failure payloads.Solution
adapters/inbound/cli/host_cli.pyexit_code = app(...)andraise typer.Exit(code)when non-zeroadapters/inbound/cli/commands/graph.pyraise typer.Exit(EXIT_VALIDATION)whenokis falseDocumented exit contract (unchanged):
0ok /1validation /2unavailable /3degraded /4auth.Test plan
potpie --json cloud status→ exit2,code: not_implementedpotpie --json graph status(ambiguous pot repo) → exit1,ok: falsepotpie --json graph nudge --event bogus --session s1 --pot <id>→ exit1,ok: falsepotpie pot create(missing name) → exit2(parser error, unchanged)potpie --json graph catalog --pot <id>→ exit0,ok: truepotpie --json cloud status && echo fail→ chain stops (does not print)test_graph_cli_contract,test_cli_usage_errors,test_sentry_daemon,test_cli_ergonomics,test_cli_bootstrap_status(145 tests)Manual verification tip: check Potpie’s exit code without piping (
cmd; echo $?), since$?after| jqreflectsjq, notpotpie.