Skip to content

feat(approval): add tenant-aware guidance when approval scope is missing#241

Closed
zhangyiweneven wants to merge 2 commits intolarksuite:mainfrom
zhangyiweneven:feat/remind-lark-approval-bytedance-tenant
Closed

feat(approval): add tenant-aware guidance when approval scope is missing#241
zhangyiweneven wants to merge 2 commits intolarksuite:mainfrom
zhangyiweneven:feat/remind-lark-approval-bytedance-tenant

Conversation

@zhangyiweneven
Copy link
Copy Markdown

@zhangyiweneven zhangyiweneven commented Apr 3, 2026

Summary

  • When a user-identity approval API call fails due to a missing approval:* scope, the agent now checks the user's tenant_key via lark-cli contact +get-user before deciding how to guide the user.
  • For a specific tenant (736588c9260f175d): displays a friendly "not yet supported" message instead of the standard permission-fix flow.
  • For all other tenants: follows the existing lark-shared permission-handling logic as before.

Motivation

Certain tenants do not yet have the approval feature enabled on the platform side. Without this change, the agent would misleadingly guide users through the standard scope-authorization flow, which would still fail. This provides a clear, actionable message instead.

Test Plan

  • Trigger an approval:task:read permission error as a user with tenant_key=736588c9260f175d → should see the "not yet supported" message
  • Trigger the same error as a user with a different tenant_key → should see the standard permission-fix guidance
  • Bot identity calls are unaffected by this change

Summary by CodeRabbit

  • Documentation
    • Added step-by-step guidance for handling approval-API permission errors when requests use user identity, including running a user lookup and branching based on tenant support.
    • For tenants that do not support the approval skill, documentation explicitly forbids advising permission additions or bypasses.
    • For other tenants, directs users to the standard permission-scope remediation flow, with a fallback to that flow if user lookup fails.

When a user-identity approval API call fails due to missing `approval:*`
scopes, the agent now checks `tenant_key` before guiding the user:
- For tenant `736588c9260f175d`: shows a friendly "not yet supported" message
- For other tenants: follows the standard permission-fix flow in lark-shared
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions bot added the size/M Single-domain feat or fix with limited business impact label Apr 3, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 607d6a8a-c911-42f5-8569-4b9ec23bec22

📥 Commits

Reviewing files that changed from the base of the PR and between 125f326 and 63fe5ca.

📒 Files selected for processing (1)
  • skills/lark-approval/SKILL.md
✅ Files skipped from review due to trivial changes (1)
  • skills/lark-approval/SKILL.md

📝 Walkthrough

Walkthrough

Documentation update to the approval skill guidance that adds a specialized error-handling flow for user identity permission failures, branching remediation instructions based on tenant key to either indicate unsupported functionality or proceed with standard scope remediation.

Changes

Cohort / File(s) Summary
Approval Skill Documentation
skills/lark-approval/SKILL.md
Added guidance for handling approval API permission_violations when called with user identity and missing approval:-scoped permissions. Instructs running lark-cli contact +get-user, branching on data.user.tenant_key: treat 736588c9260f175d as unsupported (do not direct to add permissions or suggest bypasses), follow standard remediation from lark-shared/SKILL.md for other tenants, and fallback to standard flow if the call fails or tenant_key is absent.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested reviewers

  • liangshuo-1

Poem

🐰 I hopped through docs with a nibble and grin,
Tenant keys sorted — a careful, tidy spin,
Some say “not supported,” some follow the trail,
I left polite guidance along the approval trail. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding tenant-aware guidance for approval scope errors, which is the primary modification in the SKILL.md documentation.
Description check ✅ Passed The description covers all required template sections: Summary explains the change and motivation clearly, Changes are implicit through the summary, and Test Plan includes specific test scenarios with checkboxes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 3, 2026

Greptile Summary

This PR adds a tenant-aware branching section to skills/lark-approval/SKILL.md that guides the AI agent to check a user's tenant_key (via lark-cli contact +get-user) before deciding how to handle a missing approval:* scope error. For a specific tenant, the agent shows a "not yet supported" message instead of the standard permission-fix flow; all other tenants continue through the existing lark-shared logic.

Key changes:

  • New "审批权限不足时的租户兼容性分流" section inserted early in the skill file, triggered only for user-identity calls
  • Three-way branch: specific tenant → unsupported message; other tenants → standard flow; command failure → standard flow (fallback explicitly defined)
  • The fallback for a failed lark-cli contact +get-user call (previously flagged as missing) is now explicitly included in this revision

Confidence Score: 5/5

Safe to merge; the one previously open P1 (missing fallback) is now addressed, and no new blocking issues are introduced.

Both concerns raised in earlier review rounds have been resolved or are already tracked: the missing fallback for a failed lark-cli contact +get-user call is now explicitly covered in the third bullet, and the hardcoded tenant-key concern was already flagged in a previous thread. No new P0 or P1 findings emerged in this pass. All remaining considerations (long-term scalability of the hardcoded ID) are P2 and do not block merge.

No files require special attention beyond previously filed comments.

Important Files Changed

Filename Overview
skills/lark-approval/SKILL.md Adds tenant-aware branching logic for approval permission errors; fallback for failed contact lookup now explicitly included; hardcoded tenant ID remains a long-term maintainability and privacy concern (previously flagged).

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Approval API call fails] --> B{User identity?}
    B -- No / Bot identity --> Z[Unaffected — existing flow]
    B -- Yes --> C{permission_violations contains approval:* scope?}
    C -- No --> Z
    C -- Yes --> D[Call lark-cli contact +get-user]
    D --> E{Call succeeded & tenant_key present?}
    E -- No / error --> F[Standard lark-shared permission-fix flow]
    E -- Yes --> G{tenant_key == 736588c9260f175d?}
    G -- Yes --> H["⚠️ 当前租户暂不支持使用审批 skill,敬请期待"]
    G -- No --> F
Loading

Reviews (2): Last reviewed commit: "fix(approval): address review feedback o..." | Re-trigger Greptile


根据返回结果中 `data.user.tenant_key` 的值进行分流:

- **`tenant_key` 为 `736588c9260f175d`** → 直接告知用户:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Hardcoded tenant key in a public repository

The tenant key 736588c9260f175d is hardcoded directly in a versioned, (presumably) public skill file. This exposes a specific customer/tenant identifier to anyone who can read the repository, which is a privacy and security concern.

Beyond the sensitivity risk, this design is also fragile:

  • When more tenants need the same "not yet supported" treatment, each will require a new commit to this file.
  • When the feature is eventually enabled for this tenant, there will be no automated way to remove the exemption — it will silently keep showing the "not yet supported" message forever unless someone manually removes it.

Consider an alternative approach: have the lark-cli tool (or a dedicated endpoint) return a feature-flags/capability field in its response (e.g. data.user.features.approval_enabled: false) so the skill can branch on a boolean flag rather than a raw tenant ID. That way, tenant-specific rollout state lives in the platform, not in this file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the review. A few points:

  1. Privacy: tenant_key is not a secret — it's returned by a public API to any authenticated user within that tenant.

  2. Feature-flag approach: Agreed that a server-side feature flag would be ideal long-term. But that requires platform changes out of scope for this PR. This is a pragmatic stopgap that can be trivially removed once approval is rolled out to this tenant.

  3. Fragility: For a single known tenant, the cost of one hardcoded value is minimal. If more tenants need it, that would be the signal to invest in the flag approach.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@skills/lark-approval/SKILL.md`:
- Line 17: Update the guidance to specify how to detect the missing approval
scope by inspecting the API error object's permission_violations field and
checking whether any reported scope string starts with the prefix "approval:"
(e.g., "approval:task:read", "approval:instance:write"); if such a scope is
present treat it as the "缺少 `approval:` 开头的 scope" case, then follow the
existing flow that first checks the current user's tenant_key before deciding
how to prompt for permissions.
- Around line 19-23: The SKILL.md guidance incorrectly references
data.user.tenant_key which does not exist in the lark-cli contact +get-user
response; update the document to remove or replace that instruction and instead
explain a correct way to detect tenant context (for example, use the tenant
information from the app installation/authorization event or call the
appropriate tenant-info API), and reference the actual fields returned by
contact +get-user (open_id, union_id, email, mobile, enterprise_email) so users
won’t rely on a non-existent data.user.tenant_key; check cmd/auth/auth.go and
shortcuts/contact/contact_get_user.go to verify the real response fields and
link to or mention the correct endpoint/method to obtain tenant details.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2783d256-b1f7-4d7e-9954-a971e3c09167

📥 Commits

Reviewing files that changed from the base of the PR and between 51a6ada and 125f326.

📒 Files selected for processing (1)
  • skills/lark-approval/SKILL.md

- Reference `permission_violations` field explicitly instead of vague
  "错误原因" (coderabbit suggestion)
- Add fallback when `contact +get-user` fails: fall through to standard
  permission-fix flow (greptile suggestion)
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.

3 participants