Skip to content

fix(apps): friendly-ize "Container not exists" for observability commands - #2302

Merged
zhmushan merged 4 commits into
mainfrom
fix/apps-metric-container-friendly
Aug 12, 2026
Merged

fix(apps): friendly-ize "Container not exists" for observability commands#2302
zhmushan merged 4 commits into
mainfrom
fix/apps-metric-container-friendly

Conversation

@zhmushan

@zhmushan zhmushan commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

apps +metric-list and +analytics-list passed the upstream business code 400002655 ("Container not exists") through verbatim. The message reads like an infrastructure fault and misleads callers (including AI agents) into retrying a non-retryable, expected business state: an app with no running container simply has no metrics/analytics to query until it is deployed and serving traffic.

Changes

  • Add a scoped withObservabilityHint helper in shortcuts/apps/common.go that rewrites the "no running container" business state (code 400002655, or a container not exist message fallback) into a user-facing explanation plus a deploy-then-retry hint, mirroring the existing isAppNoDatabaseError override.
  • Route the two observability callers (apps_metrics.go, apps_analytics.go) through it instead of the raw withAppsHint(err, appIDListHint).
  • Detection is code-OR-message so a server renumber alone cannot silently drop the rewrite; classification, code, and the wrapped cause are preserved, and unrelated failures still fall through to the shared app-id recovery hint (which retains its own no-database override).
  • Scoped to the two observability commands (not the global withAppsHint chokepoint) because 400002655 is not known to be observability-exclusive and the message-marker fallback must not reach unrelated commands.

Test Plan

  • Unit tests pass — go test ./shortcuts/apps/ (full package) and ./internal/errclass/...
  • New TestWithObservabilityHint (8 subcases: code hit, message fallback, case-insensitivity, cause preservation, overrides upstream hint, unrelated failure falls through, no-database still applies) + TestIsAppNoContainerError_NilProblem
  • go build ./... and go vet ./shortcuts/apps/... clean
  • Live E2E intentionally omitted: reproducing 400002655 needs a permissioned app with no running container and no deterministic, cleanable live flow; substitute evidence is the unit tests that construct the typed 400002655 error directly (classification layer verified to place the code in Problem.Code).

Summary by CodeRabbit

  • Bug Fixes
    • Improved error guidance for analytics and metrics listing failures.
    • Added clear messaging and deployment guidance when an app has no running container.
    • Improved recovery hints for other observability-related errors.
    • Preserved underlying error details while making failures easier to understand and resolve.
    • Improved classification of app observability errors for more accurate handling.

…ands

+metric-list and +analytics-list passed the upstream business code 400002655
("Container not exists") through verbatim. The message reads like an
infrastructure fault and misleads callers (including AI agents) into retrying a
non-retryable, expected business state: an app with no running container simply
has no metrics/analytics to query yet.

Rewrite it at a scoped observability helper (withObservabilityHint) into a
user-facing explanation plus a deploy-then-retry next step, mirroring the
existing isAppNoDatabaseError override. Detection is code-OR-message so a server
renumber alone does not silently drop the rewrite. Classification, code, and the
wrapped cause are preserved; unrelated failures still fall through to the shared
app-id recovery hint (and its own no-database override).
@github-actions github-actions Bot added the size/M Single-domain feat or fix with limited business impact label Aug 11, 2026
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8e4316fa-c3a7-4739-a5e5-317196c69e7b

📥 Commits

Reviewing files that changed from the base of the PR and between 13d9a89 and 9dcd750.

📒 Files selected for processing (1)
  • shortcuts/apps/common.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • shortcuts/apps/common.go

📝 Walkthrough

Walkthrough

Apps analytics and metric-list requests now use observability-specific error hints. Missing-container failures are detected by code or message, rewritten with deployment guidance, and tested while preserving error classification and causes.

Changes

Observability error hints

Layer / File(s) Summary
Error classification and hint rewriting
shortcuts/apps/common.go, shortcuts/apps/common_test.go, internal/errclass/codemeta_spark.go, internal/errclass/codemeta_spark_test.go
Missing-container detection uses a business code or message markers. The handler adds deployment guidance and preserves error classification and causes. Spark code 400002655 is classified as a non-retryable validation failed-precondition error. Tests cover these behaviors and fallback hints.
Observability request wiring
shortcuts/apps/apps_analytics.go, shortcuts/apps/apps_metrics.go
Analytics and metric-list API errors now use withObservabilityHint.
Execute-path validation
shortcuts/apps/apps_observability_execute_test.go
Command-level tests verify missing-container error codes, rewritten messages, and deployment hints for metric-list and analytics-list requests.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • larksuite/cli#2162: Adds specialized app error rewriting and hints for database-related failures.
  • larksuite/cli#2217: Adds app-specific failure detection, hint handling, and Spark error metadata.
  • larksuite/cli#2251: Updates Spark error metadata and app shortcut error-hint handling.

Suggested labels: domain/task

Suggested reviewers: liangshuo-1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the apps observability error-handling fix and describes the primary change.
Description check ✅ Passed The description includes a clear summary, detailed changes, and test plan; the optional Related Issues section is omitted.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/apps-metric-container-friendly

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 `@shortcuts/apps/apps_analytics.go`:
- Line 66: Add HTTP-mocked command-level regression tests for both wrapper
changes: in shortcuts/apps/apps_analytics.go lines 66-66, cover +analytics-list,
and in shortcuts/apps/apps_metrics.go lines 71-71, cover +metric-list. Execute
each command against a typed no-container failure and assert the rewritten
message, hint, category, subtype, code, and wrapped cause so the tests fail if
either call site reverts to withAppsHint.
🪄 Autofix

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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4c3dc112-29aa-448b-9189-81ab92834728

📥 Commits

Reviewing files that changed from the base of the PR and between 7436a53 and 6ca6e8e.

📒 Files selected for processing (4)
  • shortcuts/apps/apps_analytics.go
  • shortcuts/apps/apps_metrics.go
  • shortcuts/apps/common.go
  • shortcuts/apps/common_test.go

Comment thread shortcuts/apps/apps_analytics.go
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@9dcd750d572620806e12a71713b8af27e55f2a00

🧩 Skill update

npx skills add larksuite/cli#fix/apps-metric-container-friendly -y -g

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.44%. Comparing base (115357d) to head (9dcd750).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2302      +/-   ##
==========================================
- Coverage   76.51%   76.44%   -0.08%     
==========================================
  Files        1019     1025       +6     
  Lines      112614   113679    +1065     
==========================================
+ Hits        86172    86898     +726     
- Misses      19873    20109     +236     
- Partials     6569     6672     +103     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…tainer hint

common_test.go proves withObservabilityHint in isolation but stays green if a
call site reverts to withAppsHint. Drive +metric-list and +analytics-list
Execute with a mocked 400002655 "Container not exists" envelope and assert the
container-specific message/hint/code, so a revert fails the build. Also closes
the two uncovered call-site lines flagged by coverage.
…dition

Register 400002655 in sparkCodeMeta mirroring its no-database twin
(400002465) so both "expected precondition not met" business states expose
the same validation/failed_precondition classification to machine consumers,
instead of falling back to api/unknown. The shortcut-layer message rewrite
already keyed off the raw code, so this only aligns the typed envelope's
category/subtype; update the execution-path tests to pin the new
classification.
@zhmushan
zhmushan requested a review from liangshuo-1 as a code owner August 12, 2026 03:06
…tion

The no-container hint told a harness to deploy via +release-create, a "write"
that takes the whole app live and can affect existing production traffic —
without the user-confirmation gate its no-database twin deliberately carries.
Since the hint's audience is an AI agent that acts on it, a failed metrics read
could trigger an unconfirmed go-live. Lead with a read-only +release-list
status check and gate +release-create behind an explicit user confirmation,
mirroring appNoDatabaseHint.
@zhmushan
zhmushan merged commit 1e87f67 into main Aug 12, 2026
41 of 55 checks passed
@zhmushan
zhmushan deleted the fix/apps-metric-container-friendly branch August 12, 2026 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants