Skip to content

feat(kiloclaw) improve openclaw test harness - #4877

Open
St0rmz1 wants to merge 2 commits into
mainfrom
fix/kiloclaw-smoke-gateway-readiness
Open

feat(kiloclaw) improve openclaw test harness#4877
St0rmz1 wants to merge 2 commits into
mainfrom
fix/kiloclaw-smoke-gateway-readiness

Conversation

@St0rmz1

@St0rmz1 St0rmz1 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

The credentialed live smoke (smoke-live-provider.sh) could fail for reasons
that had nothing to do with the image under test, and it suppressed the error
text, so those failures were hard to tell apart from real ones. This fixes three
causes and makes the remaining failures name themselves.

Organization scope was silently dropped on the documented path. The org id
was only read from the Kilo CLI config when the token also came from that config.
Exporting KILOCODE_API_KEY, which is what the README, the validator, and the
image checks all tell you to do, skipped org discovery entirely and ran with no
org scope. A personal token in an organization then spends personal credits
rather than org credits, and the live turn fails inside the gateway as
402 add credits, a websocket 1008 close, or "provider rejected the request
schema". None of those name the real cause, and all of them read as a broken
image.

The readiness check gated on the wrong thing. wait_for_ready polls the
controller's /_kilo/health, which reports ready as soon as the controller is
up. The gateway is still loading provider plugins and running model discovery for
several seconds after that, and a call landing in that window dies with a
websocket 1006 abnormal closure.

Failures were unattributable. On error the smoke printed command failed and
suppressed the whole body, so a startup race and a real provider rejection looked
identical.

Changes:

  • Read the org id from the Kilo CLI config regardless of where the token came
    from, and report which source it came from.
  • Add a credential preflight that runs before any image is built or booted. An
    invalid token exits immediately by name. A token belonging to an organization
    with no KILOCODE_ORGANIZATION_ID set stops the run, lists the org names and
    ids from the profile, and prints the export line to fix it. ALLOW_NO_ORG_SCOPE=true
    overrides it for the case where the token genuinely has personal credits.
  • Add wait_for_gateway_serving(), which polls openclaw gateway call status
    until the gateway actually answers. It runs after first boot and again after
    assert_hook_config_self_heal, whose own wait also only returns the controller
    to ready.
  • Retry the live agent turn only on the 1006 warm-up signature, never on other
    closes such as 1008 policy violations and never on provider errors, so real
    incompatibilities still fail on the first attempt.
  • Report the structured error identity (type, kind, code) on failure while
    keeping the message body suppressed, since provider errors can carry live
    credentials.
  • Document the org id requirement in the tests README, the validator's guidance,
    and the image checks footer.

Verification

Run against prebuilt OpenClaw images on a local machine. Nothing here runs in CI.

  • Live smoke against the 2026.7.1 image, fresh mode, with no artificial delay:
    28 passed, 0 failed, repeated three times. Both readiness gates fired
    (gateway serving after 1s and after 2s) and no retries were needed.
  • Confirmed the race is real before fixing it: the same image and mode failed
    at the live turn with gateway_transport_error closed 1006, and passed when
    a 45 second delay was inserted before the turn.
  • Measured the gap directly: controller reported ready at 3s while the
    gateway did not answer a status call until several seconds later.
  • Confirmed the retry does not mask real failures. A failing image still fails
    on the first attempt and now reports
    error: gateway_transport_error closed 1008 instead of command failed.
  • Invalid token preflight: exits in about a second with the token rejection
    message instead of building an image and failing later.
  • Organization preflight against a token that belongs to an org. Not run, see
    Reviewer Notes.

Visual Changes

N/A

Reviewer Notes

Two things I did not verify and would flag:

  1. The org membership branch of the preflight (the one that lists org ids and
    stops the run) has not been exercised against a real org token. Only the
    invalid token branch and the syntax were tested.
  2. The retry on 1006 is defense in depth and was not exercised by any passing
    run. The readiness gate alone closed the window in every case, so retry never
    triggered. If reviewers would rather not carry untested retry logic, dropping
    it and keeping only the readiness gate is reasonable, and the smoke would still
    pass the runs above.

The preflight adds a network call to https://api.kilocode.ai/api/profile before
the smoke starts. It is overridable with KILOCODE_API_BASE, and an unreachable
endpoint warns and continues rather than blocking the run.

@kilo-code-bot

kilo-code-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Reviewed the incremental changes (surfacing the websocket close reason for gateway transport errors and clarifying the org-credit/1008 documentation) and found no high-confidence bugs, security issues, or logic errors in the changed lines.

Files Reviewed (4 files)
  • services/kiloclaw/scripts/tests/README.md
  • services/kiloclaw/scripts/tests/openclaw-upgrade-image-checks.sh
  • services/kiloclaw/scripts/tests/openclaw-upgrade-validate.sh
  • services/kiloclaw/scripts/tests/smoke-live-provider.sh
Previous Review Summary (commit 04dbbb0)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 04dbbb0)

Status: No Issues Found | Recommendation: Merge

Executive Summary

Reviewed the OpenClaw smoke-test harness changes (org-credit preflight, gateway warm-up gating, transport-error retry, and docs) and found no high-confidence bugs, security issues, or logic errors in the changed lines.

Files Reviewed (4 files)
  • services/kiloclaw/scripts/tests/README.md
  • services/kiloclaw/scripts/tests/openclaw-upgrade-image-checks.sh
  • services/kiloclaw/scripts/tests/openclaw-upgrade-validate.sh
  • services/kiloclaw/scripts/tests/smoke-live-provider.sh

Reviewed by claude-sonnet-5 · Input: 26 · Output: 6.8K · Cached: 747.1K

Review guidance: REVIEW.md from base branch main

…guidance

  The live smoke discarded the websocket close reason on a failed agent turn, so
  the string that names the cause never reached the operator. Print it for
  transport errors: it is generated by OpenClaw's own loopback gateway inside the
  container, not by the model provider, so it carries no credentials. Provider
  error bodies stay suppressed.

  This surfaced the real cause of a failing turn: 'pairing required: device is
  asking for more scopes than currently approved'. OpenClaw's in-container gateway
  auto-approves the CLI device at operator.read, then refuses its upgrade to
  operator.write and closes with 1008.

  That also disproves the guidance added earlier in this branch, which told the
  reader a 1008 meant a missing organization id. It does not; a 1008 reproduces
  with the org id correctly set, and the credential symptom is a 402. Correct the
  preflight message and the README to describe the two separately, and stop
  printing the 'message suppressed' caveat when a reason was in fact shown.
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