Skip to content

perf(cli): skip absent gateway workspace dotenv - #119227

Merged
vincentkoc merged 5 commits into
mainfrom
fix/gateway-dotenv-no-file
Aug 4, 2026
Merged

vincentkoc merged 5 commits into
mainfrom
fix/gateway-dotenv-no-file

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

openclaw gateway run always imported and ran the CLI dotenv loader, even when
the workspace had no .env file. Gateway pre-bootstrap already owns
state/config dotenv selection, so the common path paid an unnecessary dynamic
import and filesystem/env parsing cost.

Root Cause And Owner

The CLI invocation boundary selected the command but delegated dotenv loading
without carrying that command fact forward. As a result, gateway startup could
not skip global/state dotenv work that its pre-bootstrap path already owns.

The CLI invocation owner now decides whether global/state dotenv loading is
allowed:

  • gateway startup checks only the workspace .env;
  • non-gateway commands retain workspace plus state dotenv behavior;
  • gateway pre-bootstrap remains the owner of state/config dotenv selection.

This is the best fix because it removes the work at the boundary that already
knows the command. Optimizing the dotenv module would still pay the dynamic
import, while skipping all gateway dotenv handling would break supported
workspace .env behavior.

User Impact

Typical gateway startup no longer imports the CLI dotenv loader when no
workspace .env exists. Workspace .env, state/config dotenv, CLI config, and
public API behavior are unchanged.

Production LOC: +10/-4. Tests: +88/-6. No config/default surface changes.

ClawSweeper Resolution

  • Refreshed onto exact current main
    52954a1fa8f4d63914967a87f56ada21f5a0252e.
  • Re-ran focused startup proof at exact head
    d0ce3f8e314df58a35202631a8b6cb6006c1dde0.
  • Re-ran exact-head autoreview: no findings, 0.94 correctness confidence.
  • Re-ran the Kova comparison against the same current-main baseline; evidence
    below replaces the earlier stale samples.

Verification

  • Focused Vitest: 205 tests passed across the affected CLI startup suites.
  • oxfmt --check: clean.
  • oxlint: clean.
  • git diff --check: clean.
  • trufflehog: clean.

Kova Evidence

Exact main run kova-260804-135713-433310:

  • six gateway process starts contained a cli.main.dotenv span;
  • direct span duration range: 104.083-1510.949 ms;
  • aggregate harness result: 1 pass / 2 threshold failures caused by unrelated
    readiness/health timing noise.

Exact PR-head run kova-260804-140445-8c1576:

  • zero of six gateway process starts contained a cli.main.dotenv span;
  • aggregate harness result: 1 pass / 2 threshold failures caused by unrelated
    post-ready health timing noise.

The claim is intentionally narrow: the gateway no-file path removes the exact
dotenv span in all observed starts. The noisy aggregate pass rate and wall time
are not used as performance claims.

No changelog entry: this is an internal startup optimization with no
user-facing contract change.

* origin/main:
  test(qa): cover Canvas agent and node controls (#119047)
  fix(cli): avoid repeated migration scans during local agent turns (#119051)
  fix(gateway): keep agents list on prepared model facts (#119208)
  fix(telegram): retry update offset persistence
  fix(ci): accept profiled partial Kova gates (#119121)
@vincentkoc vincentkoc self-assigned this Aug 4, 2026
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: S maintainer Maintainer-authored PR labels Aug 4, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Aug 4, 2026
@clawsweeper

clawsweeper Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 4, 2026, 10:33 AM ET / 14:33 UTC.

ClawSweeper review

What this changes

This PR avoids importing the CLI dotenv loader for gateway startup when the workspace has no .env, while retaining workspace dotenv and gateway pre-bootstrap behavior.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

No actionable correctness or security finding on the exact head. Keep this maintainer-authored, maintainer-labeled PR open for CLI/gateway owner approval and completion of its exact-head checks.

Priority: P3
Reviewed head: d0ce3f8e314df58a35202631a8b6cb6006c1dde0
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong exact-head source coverage and direct runtime-span evidence support a narrow, owner-boundary-correct optimization.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: This MEMBER-authored PR is not subject to the external-contributor proof gate; its body nevertheless documents exact-head Kova output showing zero CLI dotenv spans across six no-file gateway starts.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored PR is not subject to the external-contributor proof gate; its body nevertheless documents exact-head Kova output showing zero CLI dotenv spans across six no-file gateway starts.
Evidence reviewed 5 items Exact-head loader boundary: The new predicate retains a workspace .env check but avoids the state-dir probe when gateway pre-bootstrap owns global dotenv selection; the dynamic loader import is now skipped when no workspace file exists.
Gateway owner remains intact: Gateway invocations still call pre-bootstrap immediately after the CLI dotenv decision; that owner loads the selected state/config dotenv paths before guarded config selection.
Focused regression coverage: The added test covers bare gateway, gateway run, and the root-option Commander path with no workspace file; adjacent cases retain workspace dotenv and non-gateway state dotenv behavior.
Findings None None.
Security None None.

How this fits together

The CLI classifies an invocation and normally loads workspace and state environment files before dispatch. Gateway startup has a separate pre-bootstrap phase that selects trusted state/config environment files before it initializes the gateway.

flowchart LR
A[CLI arguments] --> B[Gateway invocation check]
B --> C[Workspace dotenv check]
C --> D[CLI dotenv loader]
B --> E[Gateway pre-bootstrap]
E --> F[State and config dotenv]
F --> G[Gateway startup]
Loading

Decision needed

Question Recommendation
Does the CLI/gateway owner approve skipping the absent-file CLI dotenv import while gateway pre-bootstrap remains the sole owner of state/config dotenv selection? Approve after green exact-head checks: Accept the existing owner-boundary optimization once the remaining checks complete for the reviewed head.

Why: The patch is source-consistent and well scoped, but this is a member-authored PR with the protected maintainer label, so automation must not make the final merge decision.

Before merge

None.

Agent review details

Security

None.

PR surface

Source +6, Tests +82. Total +88 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 10 4 +6
Tests 1 88 6 +82
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 98 10 +88

Review metrics

Metric Value Why it matters
Production vs test LOC production +6, tests +82 The small production increase carries the gateway invocation fact to the existing dotenv owner; the test increase covers no-file, workspace, and non-gateway behavior.
Config/default surfaces 0 added, 0 changed, 0 removed The patch changes only when an existing loader is imported and does not alter operator configuration or defaults.

Technical review

Best possible solution:

Retain this command-boundary optimization, then land it after a CLI/gateway owner approves the exact behavior and the exact-head checks complete successfully.

Do we have a high-confidence way to reproduce the issue?

Yes. The no-workspace gateway path is deterministically covered in the exact-head test, and the PR body supplies an exact-head six-start Kova comparison; this read-only review did not execute tests.

Is this the best way to solve the issue?

Yes. Carrying the already-known gateway invocation fact to the CLI boundary skips the unnecessary dynamic import without moving state/config dotenv ownership out of gateway pre-bootstrap.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1aedd8f37e0b.

Labels

Label justifications:

  • P3: This is a narrow startup-performance optimization with no reported user-facing regression or configuration change.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored PR is not subject to the external-contributor proof gate; its body nevertheless documents exact-head Kova output showing zero CLI dotenv spans across six no-file gateway starts.

Evidence

What I checked:

  • Exact-head loader boundary: The new predicate retains a workspace .env check but avoids the state-dir probe when gateway pre-bootstrap owns global dotenv selection; the dynamic loader import is now skipped when no workspace file exists. (src/cli/run-main.ts:722, d0ce3f8e314d)
  • Gateway owner remains intact: Gateway invocations still call pre-bootstrap immediately after the CLI dotenv decision; that owner loads the selected state/config dotenv paths before guarded config selection. (src/cli/run-main.ts:1185, d0ce3f8e314d)
  • Focused regression coverage: The added test covers bare gateway, gateway run, and the root-option Commander path with no workspace file; adjacent cases retain workspace dotenv and non-gateway state dotenv behavior. (src/cli/run-main.exit.test.ts:566, d0ce3f8e314d)
  • Current-main comparison: The current-main commit supplied for review changes CLI command and plugin-loading files, not either affected dotenv file; its current behavior therefore still contains the pre-PR loader condition. (src/cli/run-main.ts:722, 1aedd8f37e0b)
  • Feature provenance: Blame ties the existing gateway classification, dotenv predicate, and pre-bootstrap boundary to the same recent CLI/gateway implementation commit. (src/cli/run-main.ts:722, 1520b839f32d)

Likely related people:

  • vincentkoc: Current blame assigns the relevant CLI dotenv and gateway pre-bootstrap flow to Vincent Koc, who also authored the focused implementation and test commits on this PR. (role: recent CLI and gateway startup contributor; confidence: high; commits: 1520b839f32d, 2a2c07b99266, 2ebce9b201fc; files: src/cli/run-main.ts, src/cli/gateway-cli/pre-bootstrap.ts, src/cli/run-main.exit.test.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-08-04T13:02:36.095Z sha d6cf492 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-04T13:16:04.821Z sha 2ebce9b :: needs maintainer review before merge. :: none
  • reviewed 2026-08-04T14:03:46.686Z sha d0ce3f8 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-04T14:26:46.033Z sha d0ce3f8 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 4, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 4, 2026
* origin/main:
  chore(tui): add Gateway boundary PTY coverage (#119191)
  fix(telegram): route reactions to their originating forum topics
  test(gateway): isolate scheduled service timers (#119218)
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Refreshed onto exact current main and replaced the stale proof with exact-head
focused tests, autoreview, and Kova evidence. Please review
d0ce3f8e314df58a35202631a8b6cb6006c1dde0.

@clawsweeper

clawsweeper Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc
vincentkoc marked this pull request as ready for review August 4, 2026 14:28
@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer owner decision: approved.

I reviewed exact head d0ce3f8e314df58a35202631a8b6cb6006c1dde0.
ClawSweeper's latest exact-head review has no Before merge items, the
CLI/gateway ownership boundary is correct, and exact-head CI run
30919135676 is green after the isolated process-test retry.

Proceeding through the repository-native scripts/pr landing flow.

@vincentkoc
vincentkoc merged commit 29f3199 into main Aug 4, 2026
252 of 254 checks passed
@vincentkoc
vincentkoc deleted the fix/gateway-dotenv-no-file branch August 4, 2026 14:54
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 4, 2026
* origin/main:
  fix(agents): protect private memory in shared chats (#119198)
  perf(cli): skip absent gateway workspace dotenv (#119227)
  fix(agents): observe native provider prompt egress (#119219)
  fix(feishu): report bot identity retry failures (#102185)
  fix(memory): load configured providers for CLI search (#119186)
  fix(discord): count retained speech bytes
  test(discord): isolate exact speech overflow
  test(discord): cover exact speech overflow
  fix(discord): bound realtime exact speech
vincentkoc added a commit that referenced this pull request Aug 4, 2026
* origin/main:
  fix(agents): protect private memory in shared chats (#119198)
  perf(cli): skip absent gateway workspace dotenv (#119227)
  fix(agents): observe native provider prompt egress (#119219)
  fix(feishu): report bot identity retry failures (#102185)
  fix(memory): load configured providers for CLI search (#119186)
  fix(discord): count retained speech bytes
  test(discord): isolate exact speech overflow
  test(discord): cover exact speech overflow
  fix(discord): bound realtime exact speech
vincentkoc added a commit that referenced this pull request Aug 4, 2026
…licy-config-20260804

* origin/main:
  perf(cli): skip absent gateway workspace dotenv (#119227)
  fix(agents): observe native provider prompt egress (#119219)
  fix(feishu): report bot identity retry failures (#102185)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 5, 2026
* perf(cli): skip absent gateway workspace dotenv

* test(cli): cover gateway dotenv import boundary

* test(cli): prove gateway dotenv stays lazy
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
* origin/main:
  fix(agents): protect private memory in shared chats (openclaw#119198)
  perf(cli): skip absent gateway workspace dotenv (openclaw#119227)
  fix(agents): observe native provider prompt egress (openclaw#119219)
  fix(feishu): report bot identity retry failures (openclaw#102185)
  fix(memory): load configured providers for CLI search (openclaw#119186)
  fix(discord): count retained speech bytes
  test(discord): isolate exact speech overflow
  test(discord): cover exact speech overflow
  fix(discord): bound realtime exact speech
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant