Qwen Portal Auth Helper
Battle-tested solution for qwen-portal OAuth automation
Solves the "interactive TTY required" problem, prevents cron task failures, and provides full monitoring.
🚨 The Problem
qwen-portal provides free models (2,000 requests/day) but OAuth expires every 1-2 weeks. When it expires:
- 1. Cron tasks fail with: INLINECODE0
- INLINECODE1 fails: INLINECODE2
- Manual intervention required, breaking automation
- Tasks remain in error state even after authentication fix
💡 The Solution
This skill provides a complete solution:
- - Automated OAuth link extraction using tmux (bypasses TTY requirement)
- Health monitoring for qwen-portal tasks
- Self-healing scripts to fix task states
- Documented best practices from real-world experience
📦 Installation
CODEBLOCK0
🛠️ Quick Start
Get OAuth Link (when authentication expired)
~/.openclaw/skills/qwen-portal-auth-helper/scripts/get-qwen-oauth-link.sh
Outputs:
CODEBLOCK2
Check Authentication Health
~/.openclaw/skills/qwen-portal-auth-helper/scripts/check-qwen-auth.sh
Checks all qwen-portal tasks, reports errors, generates actionable report.
Setup Weekly Monitoring
CODEBLOCK4
🔧 Core Features
1. OAuth Link Automation
CODEBLOCK5
How it works: Uses tmux to create virtual terminal, captures output before command hangs.
2. Health Monitoring
- - Scans all cron tasks using qwen-portal models
- Detects error states and consecutive failures
- Generates detailed reports with actionable advice
- Early warning before complete failure
3. Recovery Tools
- - Resets task error states after authentication fix
- Provides step-by-step recovery checklist
- Validates fixes actually work
4. Best Practices Documentation
- - Complete workflow from diagnosis to recovery
- Common pitfalls and how to avoid them
- Maintenance schedule recommendations
📋 Complete Workflow
When tasks start failing:
CODEBLOCK6
Weekly Maintenance:
CODEBLOCK7
🎯 Use Cases
1. AI Assistants & Automation
AI assistants can't provide interactive TTY. This skill enables them to:
- - Automatically detect qwen-portal auth issues
- Get OAuth links for user approval
- Complete the recovery process
2. Cron Task Reliability
Ensure scheduled tasks don't fail due to expired OAuth:
- - Weekly health checks
- Early detection of impending expiry
- Automated recovery procedures
3. Team Collaboration
Standardized approach for teams:
- - Everyone uses same proven method
- Documentation prevents repeated mistakes
- Shared monitoring and alerting
4. New User Onboarding
New OpenClaw users inevitably hit this issue. This skill provides:
- - Immediate solution without trial-and-error
- Complete documentation
- Community-validated approach
🔍 Technical Details
How OAuth Link Extraction Works
CODEBLOCK8
Key discoveries from real-world testing:
- - Link format is always: INLINECODE3
- Device code: 7 uppercase alphanumeric characters (e.g., M17WU0SC)
- Command hangs after showing link (
◑ Waiting for Qwen OAuth approval...) - Must capture output actively, not wait for completion
Task State Management
Even after successful authentication, cron tasks may remain in error state:
CODEBLOCK9
This skill includes scripts to reset these states automatically.
📊 Monitoring & Alerting
What We Monitor
- 1. Task Status: Error vs OK
- Consecutive Errors: >3 triggers warning
- Last Success Time: Tasks not running recently
- OAuth Expiry Estimate: Based on 1-2 week pattern
Alert Thresholds
- - Warning: 3+ consecutive errors
- Critical: Task in error state + OAuth-related error message
- Recovery Needed: Manual intervention required
Reports Generated
- - Weekly health report
- Error analysis with suggested fixes
- Maintenance checklist
- Historical trends
🚀 Advanced Usage
Integration with Other Skills
CODEBLOCK10
Custom Monitoring Schedule
CODEBLOCK11
Extending for Other OAuth Providers
The pattern works for other services with similar issues:
- 1. GitHub OAuth
- Google OAuth
- Other AI model providers with device-code flow
📝 Examples
Example 1: Quick Recovery
CODEBLOCK12
Example 2: Proactive Maintenance
CODEBLOCK13
Example 3: Integration with AI Assistant
CODEBLOCK14
⚠️ Common Pitfalls & Solutions
Pitfall 1: Command hangs indefinitely
Solution: Use timeout and active output capture (implemented in scripts)
Pitfall 2: ANSI escape codes break parsing
Solution: Robust regex that handles colored output (included)
Pitfall 3: Task state doesn't reset automatically
Solution: Manual state reset scripts (provided)
Pitfall 4: Multiple qwen-portal tasks failing
Solution: Batch processing in monitoring script
Pitfall 5: OAuth expires at inconvenient times
Solution: Weekly monitoring catches it early
🔄 Maintenance Schedule
Weekly (Essential)
- - Run health check script
- Review error reports
- Prepare for potential re-authentication
Monthly (Recommended)
- - Review OAuth expiry patterns
- Update scripts if qwen-portal changes
- Clean up old log files
Quarterly (Optional)
- - Test complete recovery workflow
- Update documentation
- Check for new best practices
🤝 Community & Support
Based on Real Experience
This skill was developed from solving actual production issues on 2026-03-09:
- - Two critical news collection tasks failing
- 9-10 consecutive errors before detection
- Multiple failed attempts before finding tmux solution
- Documented in
.learnings/ system
Contributing
Found a better way? Have another OAuth provider with similar issues?
- 1. Fork the repository
- Add your improvements
- Submit pull request
- Help others avoid the same pitfalls
Getting Help
- - Check
examples/ directory for common scenarios - Review
docs/troubleshooting.md for known issues - Open issue on repository for new problems
📈 Benefits
For Individual Users
- - No more manual OAuth link hunting
- Prevent task failures before they happen
- Standardized recovery process
- Less time spent on maintenance
For Teams
- - Shared knowledge and tools
- Consistent monitoring approach
- Reduced support requests
- Faster onboarding for new members
For Community
- - Open source solution to common problem
- Continuously improved by users
- Foundation for other OAuth automation
- Knowledge sharing prevents repeated mistakes
🎉 Getting Started
Installation
CODEBLOCK15
First-Time Setup
CODEBLOCK16
Verify It Works
# Simulate a failure scenario
openclaw cron run <your-qwen-portal-task-id>
# Check monitoring catches it
./scripts/check-qwen-auth.sh
# Practice recovery workflow
./scripts/get-qwen-oauth-link.sh --dry-run
Remember: qwen-portal OAuth expires every 1-2 weeks.
Solution: Weekly monitoring + this skill = no more surprises.
Skill version: 1.0.0 | Based on 2026-03-09 battle-tested experience
Qwen Portal 认证助手
经过实战检验的 qwen-portal OAuth 自动化解决方案
解决需要交互式 TTY问题,防止定时任务失败,并提供全面监控。
🚨 问题描述
qwen-portal 提供免费模型(每天 2000 次请求),但 OAuth 每 1-2 周过期一次。过期时:
- 1. 定时任务失败,错误信息:Qwen OAuth refresh token expired or invalid
- openclaw models auth login --provider qwen-portal 失败:requires an interactive TTY
- 需要人工干预,破坏自动化流程
- 即使修复认证,任务仍保持错误状态
💡 解决方案
本技能提供完整的解决方案:
- - 自动化 OAuth 链接提取,使用 tmux(绕过 TTY 要求)
- 健康监控,针对 qwen-portal 任务
- 自愈脚本,修复任务状态
- 记录最佳实践,基于真实经验
📦 安装
bash
通过 ClawHub(推荐)
clawhub install qwen-portal-auth-helper
或手动安装
cd ~/.openclaw/skills/
git clone
🛠️ 快速开始
获取 OAuth 链接(认证过期时)
bash
~/.openclaw/skills/qwen-portal-auth-helper/scripts/get-qwen-oauth-link.sh
输出:
🔗 OAuth 链接:https://chat.qwen.ai/authorize?user_code=M17WU0SC
📱 设备代码:M17WU0SC
检查认证健康状态
bash
~/.openclaw/skills/qwen-portal-auth-helper/scripts/check-qwen-auth.sh
检查所有 qwen-portal 任务,报告错误,生成可操作报告。
设置每周监控
bash
添加到 crontab(每周一上午 9 点运行)
0 9 1 ~/.openclaw/skills/qwen-portal-auth-helper/scripts/check-qwen-auth.sh
🔧 核心功能
1. OAuth 链接自动化
bash
传统方式(自动化中失败):
openclaw models auth login --provider qwen-portal # ❌ 错误:需要交互式 TTY
我们的解决方案:
./scripts/get-qwen-oauth-link.sh # ✅ 在 cron、AI 助手等环境中正常工作
工作原理:使用 tmux 创建虚拟终端,在命令挂起前捕获输出。
2. 健康监控
- - 扫描所有使用 qwen-portal 模型的定时任务
- 检测错误状态和连续失败
- 生成详细报告并提供可操作建议
- 在完全失败前发出早期警告
3. 恢复工具
- - 修复认证后重置任务错误状态
- 提供逐步恢复检查清单
- 验证修复是否实际生效
4. 最佳实践文档
- - 从诊断到恢复的完整工作流程
- 常见陷阱及避免方法
- 维护计划建议
📋 完整工作流程
当任务开始失败时:
- 1. 运行:check-qwen-auth.sh
→ 识别失败任务,显示错误详情
- 2. 运行:get-qwen-oauth-link.sh
→ 提供 OAuth 链接和设备代码
- 3. 用户:点击链接,在浏览器中认证
→ 授权自动完成
- 4. 测试:openclaw cron run
→ 验证认证是否生效
- 5. 重置:脚本帮助重置任务状态
→ 任务恢复正常运行
每周维护:
周一上午 9 点:check-qwen-auth.sh 自动运行
如果检测到问题:发送邮件/通知
预防措施:在过期前重新认证
🎯 使用场景
1. AI 助手与自动化
AI 助手无法提供交互式 TTY。本技能使它们能够:
- - 自动检测 qwen-portal 认证问题
- 获取 OAuth 链接供用户批准
- 完成恢复流程
2. 定时任务可靠性
确保计划任务不会因 OAuth 过期而失败:
3. 团队协作
为团队提供标准化方法:
- - 所有人使用相同的经过验证的方法
- 文档防止重复错误
- 共享监控和警报
4. 新用户入门
新的 OpenClaw 用户不可避免地会遇到此问题。本技能提供:
🔍 技术细节
OAuth 链接提取工作原理
bash
核心技术:
tmux new-session -d -s qwen-oauth openclaw models auth login --provider qwen-portal
sleep 5
tmux capture-pane -t qwen-oauth -p | grep -E (http|https)://
实际测试中的关键发现:
- - 链接格式始终为:https://chat.qwen.ai/authorize?user_code=XXXXXXX&client=qwen-code
- 设备代码:7 个大写字母数字字符(例如 M17WU0SC)
- 命令在显示链接后挂起(◑ Waiting for Qwen OAuth approval...)
- 必须主动捕获输出,而不是等待完成
任务状态管理
即使成功认证后,定时任务可能仍保持错误状态:
json
// 修复前:
state: {lastStatus: error, consecutiveErrors: 10}
// 修复后(需要手动重置):
state: {lastStatus: pending, consecutiveErrors: 0}
本技能包含自动重置这些状态的脚本。
📊 监控与警报
监控内容
- 1. 任务状态:错误 vs 正常
- 连续错误:>3 触发警告
- 最后成功时间:近期未运行的任务
- OAuth 过期估计:基于 1-2 周模式
警报阈值
- - 警告:3 次以上连续错误
- 严重:任务处于错误状态 + 与 OAuth 相关的错误消息
- 需要恢复:需要人工干预
生成的报告
- - 每周健康报告
- 错误分析及建议修复
- 维护检查清单
- 历史趋势
🚀 高级用法
与其他技能集成
bash
与系统维护技能结合
~/.openclaw/skills/system-maintenance/scripts/daily-maintenance.sh
~/.openclaw/skills/qwen-portal-auth-helper/scripts/check-qwen-auth.sh
与代理团队编排配合使用
将 OAuth 恢复分配为专门的团队任务
自定义监控计划
bash
每日快速检查(轻量级)
0 9 * ~/.openclaw/skills/qwen-portal-auth-helper/scripts/check-qwen-auth.sh --quick
每周全面检查
0 9 1 ~/.openclaw/skills/qwen-portal-auth-helper/scripts/check-qwen-auth.sh --full
立即警报关键问题
/30 * ~/.openclaw/skills/qwen-portal-auth-helper/scripts/check-qwen-auth.sh --alert-only
扩展到其他 OAuth 提供商
该模式适用于其他有类似问题的服务:
- 1. GitHub OAuth
- Google OAuth
- 其他具有设备代码流程的 AI 模型提供商
📝 示例
示例 1:快速恢复
bash
1. 检查问题
./check-qwen-auth.sh
2. 获取新的 OAuth 链接
./get-qwen-oauth-link.sh
输出:链接和代码,提供给用户
3. 用户认证后,验证
openclaw cron run 71628635-03e3-414b-865b-e427af4e804f
openclaw cron runs --id 71628635-03e3-414b-865b-e427af4e804f
4. 如果需要,重置任务状态
./scripts/reset-task-state.py 71628635-03e3-414b-865b-e427af4e804f
示例 2:主动维护
bash
添加到 crontab 进行周一早上检查
crontab -l | grep -q check-qwen-auth || echo 0 9 1 ~/.openclaw/skills/qwen-portal-auth-helper/scripts/check-qwen-auth.sh >> ~/.openclaw/logs/qwen-check.log | crontab -
查看每周报告
cat /tmp/qwen-auth-report-*.