Skip to content

fix(create): exit 5 on InitTask insufficient_credits (0.5.1)#4

Merged
voidkey merged 1 commit into
mainfrom
fix/credits-exit-code
May 14, 2026
Merged

fix(create): exit 5 on InitTask insufficient_credits (0.5.1)#4
voidkey merged 1 commit into
mainfrom
fix/credits-exit-code

Conversation

@voidkey
Copy link
Copy Markdown
Collaborator

@voidkey voidkey commented May 14, 2026

Summary

A 0.5.1 patch that fixes an exit-code inconsistency surfaced during 0.5.0 real-backend validation.

Before: vk create exited 1 when POST /v1/tasks/init returned insufficient_credits (envelope code 100001), via cobra's generic error handler.
After: exits 5 (business failure), matching:

  • the same condition surfacing later in the SSE stream path (cmd/create.go:259 — already os.Exit(5))
  • the documented exit-code contract in AGENTS.md / README (5 = business failure)

Agents branching on exit codes no longer need to know about two different paths for the same condition.

Diff

  • cmd/create.go: replace return fmt.Errorf(...) with fmt.Fprintln(os.Stderr, ...); os.Exit(5) — verbatim mirror of the stream-side handler 4 lines below.
  • tests/integration/create_credits_test.go (new): mocks /v1/tasks/init returning envelope code 100001, asserts binary exits 5 and stderr carries the message.
  • CHANGELOG.md: 0.5.1 entry under Fixed.
  • package.json + 3 SKILL.md: 0.5.0 → 0.5.1.

Test plan

  • go test ./... passes including new integration test
  • go build ./... clean
  • CI three-platform green (will appear after push)
  • Manual smoke against real backend with depleted credits — not retested (already established symptom during 0.5.0 validation; mock test is equivalent shape)

Out of scope

  • auth status showing valid but token refresh actually failing — was also observed during 0.5.0 validation but the root cause is non-obvious; needs middleware-level diagnostics before fix. Tracked separately.

InitTask's insufficient_credits handler returned a plain fmt.Errorf
which cobra mapped to its default exit 1, while the same condition
surfacing later in the stream path explicitly os.Exit(5). The
documented contract (AGENTS.md, README) is 5 = business failure;
agents branching on exit codes had to know about two paths.

Caught during real-backend smoke for 0.5.0 (depleted credits during
testing made the inconsistency observable).

Match the stream-side pattern verbatim: print the i18n message to
stderr, os.Exit(5). Add an integration test that mocks /v1/tasks/init
returning envelope code 100001 and asserts the binary exits 5.
@voidkey voidkey merged commit e95cdc0 into main May 14, 2026
3 checks passed
@voidkey voidkey deleted the fix/credits-exit-code branch May 14, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant