Files
Numman AliandHanzo Dev fe29b2110d feat: Add comprehensive compliance documentation and fix critical bugs (v2.1.2)
This release includes comprehensive OpenAI ToS compliance updates and fixes
4 critical bugs that prevented per-model options and multi-turn conversations
from working correctly.

## ๐Ÿ”’ Compliance & Legal Updates

### Terms of Service & Usage Guidelines
- Added comprehensive ToS & Usage Notice to README emphasizing personal use only
- Added Rate Limits & Responsible Use section with best practices
- Added extensive FAQ section addressing TOS compliance questions
- Updated LICENSE with MIT + Usage Disclaimer for personal development use
- Added compliance header to index.ts documenting intended use cases

### New Documentation
- **CONTRIBUTING.md**: Complete contribution guidelines with compliance requirements
- **SECURITY.md**: Security policy, vulnerability reporting, best practices
- **docs/privacy.md**: Comprehensive privacy & data handling documentation
- **Issue Templates**: Bug reports & feature requests with compliance checklists

### Documentation Updates
- Updated docs/index.md with usage notice and trademark disclaimers
- Updated docs/getting-started.md with "Before You Begin" compliance notice
- Updated docs/troubleshooting.md with subscription & compliance sections
- All references updated to "Plus/Pro" (removed Team/Enterprise mentions)

### Key Compliance Principles
- โœ… Emphasizes personal development use with own ChatGPT Plus/Pro subscription
- โœ… Uses OpenAI's official OAuth authentication (same as Codex CLI)
- โœ… Clear prohibition of commercial resale, multi-user services
- โœ… Not a "free API alternative" - uses existing ChatGPT subscription
- โœ… Proper trademark notices and attribution to OpenAI
- โœ… Transparent about data handling and privacy

## ๐Ÿ› Critical Bug Fixes

### Bug #1: Per-Model Options Ignored (Config Lookup Mismatch)
**Severity:** ๐Ÿ”ด HIGH

Users configured different reasoning levels for each model variant, but all
variants behaved identically because the plugin was looking up normalized
model names instead of the original config keys.

**Fix:** lib/request/request-transformer.ts:277
- Use original model name for config lookup before normalization
- Allows per-model options to work correctly
- Impact: Different reasoning levels now properly applied per variant

### Bug #2: Multi-Turn Conversations Fail (AI SDK Compatibility)
**Severity:** ๐Ÿ”ด CRITICAL

Multi-turn conversations failed with "Item not found" errors because:
1. AI SDK sends `item_reference` (not in Codex API spec)
2. IDs weren't completely stripped for stateless mode (store: false)

**Fix:** lib/request/request-transformer.ts:114-135
- Filter out AI SDK `item_reference` items
- Strip ALL IDs from remaining items (not just rs_* prefix)
- Confirmed ChatGPT backend requires store: false via testing
- Full message history preserved for LLM context

### Bug #3: Case-Sensitive Normalization
**Severity:** ๐ŸŸก MEDIUM

**Fix:** lib/request/request-transformer.ts:22-27
- Added toLowerCase() for case-insensitive matching
- Backwards compatible with old verbose config names
- Handles uppercase/mixed case user input

### Bug #4: GitHub API Rate Limiting
**Severity:** ๐ŸŸก MEDIUM

Plugin checked GitHub on every request, exhausting 60 req/hour limit.
15-minute cache timestamp was stored but never checked.

**Fix:** lib/prompts/codex.ts:50-53, lib/prompts/opencode-codex.ts:47-50
- Check cache TTL before GitHub API call
- Only fetch if cache >15min old
- Prevents rate limit exhaustion during testing

## โœจ Enhancements

### Debug Logging System
- New environment variable: `DEBUG_CODEX_PLUGIN=1`
- Added logDebug() and logWarn() functions
- Shows config lookups, ID filtering, options resolution
- File: lib/logger.ts

### Optimized Config Structure
- Changed to Codex CLI preset names (gpt-5-codex-low, etc.)
- Removed redundant `id` field (not used by OpenAI provider)
- Added `name` field for friendly TUI display
- File: config/full-opencode.json

### GitHub Pages Documentation
- Complete documentation restructure for GitHub Pages
- User guides: getting-started.md, configuration.md, troubleshooting.md
- Developer guides: ARCHITECTURE.md, CONFIG_FLOW.md, CONFIG_FIELDS.md, TESTING.md
- Privacy policy, security policy, contribution guidelines

## ๐Ÿงช Testing

### Test Coverage
- โœ… 159 unit tests passing (30+ new tests)
- โœ… 14 integration tests passing (actual API verification)
- โœ… All documented scenarios have test coverage

### Integration Tests (scripts/test-all-models.sh)
- Tests all 9 custom model configurations
- Tests all 4 default OpenCode models
- Verifies backwards compatibility with old config format
- Uses ENABLE_PLUGIN_REQUEST_LOGGING to verify actual API requests

### Test Results
- 14/14 model configuration tests passing
- All per-model options verified correct
- Multi-turn conversations work without errors
- Backwards compatibility confirmed

## ๐Ÿ“ Files Changed

### Modified (7 files)
- lib/request/request-transformer.ts: Config lookup & ID filtering fixes
- lib/prompts/codex.ts: 15-minute cache TTL
- lib/prompts/opencode-codex.ts: 15-minute cache TTL
- lib/logger.ts: Debug logging system
- config/full-opencode.json: Optimized structure
- test/request-transformer.test.ts: 30+ new tests
- LICENSE: Added usage disclaimer
- index.ts: Added compliance header
- README.md: Added ToS, Rate Limits, FAQ sections

### Created (20+ files)
- CONTRIBUTING.md: Contribution guidelines
- SECURITY.md: Security policy
- docs/index.md: GitHub Pages landing
- docs/getting-started.md: Installation guide
- docs/configuration.md: Advanced config
- docs/troubleshooting.md: Debug guide
- docs/privacy.md: Privacy policy
- docs/development/ARCHITECTURE.md: Technical architecture
- docs/development/CONFIG_FLOW.md: Config system internals
- docs/development/CONFIG_FIELDS.md: Field usage guide
- docs/development/TESTING.md: Testing guide
- .github/ISSUE_TEMPLATE/bug_report.md
- .github/ISSUE_TEMPLATE/feature_request.md
- .github/ISSUE_TEMPLATE/config.yml
- scripts/test-all-models.sh: Automated testing

## ๐ŸŽฏ Verification

All scenarios tested and verified:
- โœ… Default models work without config
- โœ… Custom models with per-variant options
- โœ… Old config format (backwards compatible)
- โœ… Mixed default + custom models
- โœ… Multi-turn conversations (no "item not found" errors)
- โœ… Model switching with different options
- โœ… All normalization patterns
- โœ… Complete ID filtering

## ๐Ÿ“š Documentation

Complete documentation suite (100+ KB):
- User guides for installation, configuration, troubleshooting
- Developer guides for architecture, config system, testing
- Privacy policy and security policy
- Compliance guidelines and contribution requirements
- Release notes in tmp/release-notes/

## ๐Ÿ”— References

- OpenAI Terms of Use: https://openai.com/policies/terms-of-use/
- OpenAI Usage Policies: https://openai.com/policies/usage-policies/
- OpenAI Platform API: https://platform.openai.com/
- OpenAI Codex CLI: https://github.com/openai/codex

Co-authored-by: Hanzo Dev <[email protected]>
2025-10-12 21:25:43 +01:00

9.2 KiB

Troubleshooting Guide

Common issues and debugging techniques for the OpenCode OpenAI Codex Auth Plugin.

Authentication Issues

"401 Unauthorized" Error

Symptoms:

Error: 401 Unauthorized
Failed to access Codex API

Causes:

  1. Token expired
  2. Not authenticated yet
  3. Invalid credentials

Solutions:

1. Re-authenticate:

opencode auth login

2. Check auth file exists:

cat ~/.opencode/auth/openai.json
# Should show OAuth credentials

3. Check token expiration:

# Token has "expires" timestamp
cat ~/.opencode/auth/openai.json | jq '.expires'

# Compare to current time
date +%s000  # Current timestamp in milliseconds

Browser Doesn't Open for OAuth

Symptoms:

  • opencode auth login succeeds but no browser window
  • OAuth callback times out

Solutions:

1. Manual browser open:

# The auth URL is shown in console - copy and paste to browser manually

2. Check port 1455 availability:

# See if something is using the OAuth callback port
lsof -i :1455

3. Official Codex CLI conflict:

  • Stop Codex CLI if running
  • Both use port 1455 for OAuth

"403 Forbidden" Error

Cause: ChatGPT subscription issue

Check:

  1. Active ChatGPT Plus or Pro subscription
  2. Subscription not expired
  3. Billing is current

Solution: Visit ChatGPT and verify subscription status


Model Issues

"Model not found"

Error: Model 'openai/gpt-5-codex-low' not found

Cause 1: Config key mismatch

Check your config:

{
  "models": {
    "gpt-5-codex-low": { ... }  // โ† This is the key
  }
}

CLI must match exactly:

opencode run "test" --model=openai/gpt-5-codex-low  # Must match config key

Cause 2: Missing provider prefix

โŒ Wrong:

model: gpt-5-codex-low

โœ… Correct:

model: openai/gpt-5-codex-low

Per-Model Options Not Applied

Symptom: All models behave the same despite different reasoningEffort

Debug:

DEBUG_CODEX_PLUGIN=1 opencode run "test" --model=openai/your-model

Look for:

hasModelSpecificConfig: true  โ† Should be true
resolvedConfig: { reasoningEffort: 'low', ... }  โ† Should show your options

If false: Config lookup failed

Common causes:

  1. Model name in CLI doesn't match config key
  2. Typo in config file
  3. Wrong config file location

Multi-Turn Issues

"Item not found" Errors

Error:

AI_APICallError: Item with id 'msg_abc123' not found.
Items are not persisted when `store` is set to false.

Cause: Old plugin version (fixed in v2.1.2+)

Solution:

# Update plugin
(cd ~ && sed -i.bak '/"opencode-openai-codex-auth"/d' .cache/opencode/package.json && rm -rf .cache/opencode/node_modules/opencode-openai-codex-auth)

# Restart OpenCode
opencode

Verify fix:

DEBUG_CODEX_PLUGIN=1 opencode
> write test.txt
> read test.txt
> what did you write?

Should see: Successfully removed all X message IDs

Context Not Preserved

Symptom: Model doesn't remember previous turns

Check logs:

ENABLE_PLUGIN_REQUEST_LOGGING=1 opencode
> first message
> second message

Verify:

# Turn 2 should have full history
cat ~/.opencode/logs/codex-plugin/request-*-after-transform.json | jq '.body.input | length'
# Should show increasing count (3, 5, 7, 9, ...)

What to check:

  1. Full message history present (not just current turn)
  2. No item_reference items (filtered out)
  3. All IDs stripped (jq '.body.input[].id' should all be null)

Request Errors

"400 Bad Request"

Check error details:

ENABLE_PLUGIN_REQUEST_LOGGING=1 opencode run "test"

# Read error
cat ~/.opencode/logs/codex-plugin/request-*-error-response.json

Common causes:

  1. Invalid options for model (e.g., minimal for gpt-5-codex)
  2. Malformed request body
  3. Unsupported parameter

"Rate Limit Exceeded"

Error:

Rate limit reached for gpt-5-codex

Solutions:

1. Wait for reset: Check headers in response logs:

cat ~/.opencode/logs/codex-plugin/request-*-response.json | jq '.headers["x-codex-primary-reset-after-seconds"]'

2. Switch to different model:

# If codex is rate limited, try gpt-5
opencode run "task" --model=openai/gpt-5

"Context Window Exceeded"

Error:

Your input exceeds the context window

Cause: Too much conversation history

Solutions:

1. Start new conversation:

# Exit and restart OpenCode (clears history)

2. Use compact mode (if OpenCode supports it)

3. Switch to model with larger context:

  • gpt-5-codex has larger context than gpt-5-nano

GitHub API Issues

Rate Limit Exhausted

Error:

Failed to fetch instructions from GitHub: Failed to fetch latest release: 403
Using cached instructions

Cause: GitHub API rate limit (60 req/hour for unauthenticated)

Status: Fixed in v2.1.2 with 15-minute caching

Verify fix:

# Should only check GitHub once per 15 minutes
ls -lt ~/.opencode/cache/codex-instructions-meta.json

# Check lastChecked timestamp
cat ~/.opencode/cache/codex-instructions-meta.json | jq '.lastChecked'

Manual workaround (if on old version):

  • Wait 1 hour for rate limit to reset
  • Or use cached instructions (automatic fallback)

Debug Techniques

Enable Full Logging

# Both debug and request logging
DEBUG_CODEX_PLUGIN=1 ENABLE_PLUGIN_REQUEST_LOGGING=1 opencode run "test"

What you get:

  • Console: Debug messages showing config resolution
  • Files: Complete request/response logs

Log locations:

  • ~/.opencode/logs/codex-plugin/request-*-before-transform.json
  • ~/.opencode/logs/codex-plugin/request-*-after-transform.json
  • ~/.opencode/logs/codex-plugin/request-*-response.json

Inspect Actual API Requests

# Run command with logging
ENABLE_PLUGIN_REQUEST_LOGGING=1 opencode run "test" --model=openai/gpt-5-codex-low

# Check what was sent to API
cat ~/.opencode/logs/codex-plugin/request-*-after-transform.json | jq '{
  model: .body.model,
  reasoning: .body.reasoning,
  text: .body.text,
  store: .body.store,
  include: .body.include
}'

Verify:

  • model: Normalized correctly?
  • reasoning.effort: Matches your config?
  • text.verbosity: Matches your config?
  • store: Should be false
  • include: Should have reasoning.encrypted_content

Compare with Expected

See development/TESTING.md for expected values matrix.


Performance Issues

Slow Responses

Possible causes:

  1. reasoningEffort: "high" - Uses more computation
  2. textVerbosity: "high" - Generates longer outputs
  3. Network latency

Solutions:

  • Use lower reasoning effort for faster responses
  • Check network connection
  • Try different time of day (server load varies)

High Token Usage

Monitor usage:

# Tokens shown in logs
cat ~/.opencode/logs/codex-plugin/request-*-stream-full.json | grep -o '"total_tokens":[0-9]*'

Reduce tokens:

  1. Lower textVerbosity
  2. Lower reasoningEffort
  3. Shorter system prompts (disable CODEX_MODE if needed)

Getting Help

Before Opening an Issue

  1. Enable logging:

    DEBUG_CODEX_PLUGIN=1 ENABLE_PLUGIN_REQUEST_LOGGING=1 opencode run "your command"
    
  2. Collect info:

    • OpenCode version: opencode --version
    • Plugin version: Check package.json or npm
    • Error logs from ~/.opencode/logs/codex-plugin/
    • Config file (redact sensitive info)
  3. Check existing issues:

Reporting Bugs

Include:

  • โœ… Error message
  • โœ… Steps to reproduce
  • โœ… Config file (redacted)
  • โœ… Log files
  • โœ… OpenCode version
  • โœ… Plugin version

Account or Subscription Issues

If you're experiencing authentication problems:

  • Ensure active subscription: Verify your ChatGPT Plus/Pro subscription is active at ChatGPT Settings
  • Check subscription type: This plugin requires Plus or Pro (Free tier is not supported)
  • Review usage limits: Check if you've exceeded your subscription's usage limits
  • Revoke and re-authorize:
    1. Revoke access: ChatGPT Settings โ†’ Authorized Apps
    2. Remove local tokens: opencode auth logout
    3. Re-authenticate: opencode auth login

Note: If OpenAI has flagged your account for unusual usage patterns, you may experience authentication issues. Contact OpenAI support if you believe your account has been incorrectly restricted.

If you receive errors related to terms of service violations:

  • Review your usage: Ensure you're using the plugin for personal development only
  • Check rate limits: Verify you haven't exceeded usage limits
  • Avoid automation: Do not use for high-volume automated requests
  • Commercial use: Switch to OpenAI Platform API for commercial applications

This plugin cannot help with TOS violations or account restrictions. Contact OpenAI support for account-specific issues.


Next: Configuration Guide | Developer Docs | Back to Home