| Files | Last commit | Last update |
|---|---|---|
fix(token): stop backfilling bot-level tokens into agent session rows (echo loop) Root cause: repo binding / agent config save / scene apply all resolved the full token chain and wrote the resolved value (often level-2 bot token) into devops_agent_session.repo_gitcode_token. Level-1 (session) then always hit the bot token, and the self-loop guard treated the bot actor as a legit user -> bot comments triggered pipelines -> echo loop. Changes: - upsert_agent_session: repo_gitcode_token now None = keep existing value (aligned with enable/subscribe_events/im_* convention). INSERT falls back to empty string. No caller can clobber a user-configured session token with a lower-level value anymore. - ensure_default_agent_sessions: drop the resolve_config_level token read entirely; binding means the session row must stay token-empty. - agents.py update_agent_config: AgentConfig has no token field, so the read_stored_token value was always a lower-level backfill; both upsert call sites now pass None. - scenes.py apply_scene: same treatment, drop get_repo_token_with_refresh. Also removes now-dead github-token side write in ensure_default. SessionTokenHandler.is_self_loop_actor consumer-side guard is intentionally kept as defense-in-depth. scripts/sql/clean_session_bot_token_20261023.sql: one-shot cleanup for existing polluted rows (value == global/repo bot token), with backup table. | 1 month ago | |
fix(issue-343): dual-track OAuth token architecture + migration + deployment fixes Implement read/write separation for GitCode/GitHub API tokens and fix all related issues in migration, deployment flow, and JWT security. Token architecture (read/write separation): - Write operations (create/close/comment issues) use repo bot token via get_repo_bot_token(), skipping agent session token scope issues - Read operations use user OAuth token via with_oauth_token() wrapper with pre-refresh (10 min before expiry) and passive 401 retry - GitHub path symmetric with GitCode (get_user_github_token_with_refresh) - Wrapper calls _req directly to bypass get_user_gitcode_login / _check_collaborator_admin which swallow RuntimeError, letting original 401 with (NNN) format propagate to _is_token_error - sync_repos / list_member_repos use soft failure: single platform 401 does not abort loop, returns partial results + _reauth_provider marker Token lifecycle: - Store expires_in from OAuth callback through all paths (create_external_identity, update_external_identity_tokens, restore_binding_in_tx, restore_external_identity) - Pre-refresh threshold tightened from 60 to 30 min (measured min 15 min) - token_expires_at format normalized across external_identities (TEXT) and user_credentials (epoch int) via isinstance+strptime conversion - refresh_oauth_token creates user_credentials entry if missing (was dead path) Issue creation pipeline: - Assignee uses external_login from external_identities, not platform username - Pipeline payload creator uses assignee (external_login) - scene_user_id query uses assignee as issue_creator - Create issue API 403/422 caught and converted to friendly errors (not 500) - Idempotent dedup: state=open, paginated to 500, raises on failure (not silent) JWT security: - get_current_user adds username/id consistency check (prevent old JWT collision) - token_version+1 integrated into init_database() with meta table guard (idempotent, no manual SQL needed) Migration script: - Tables list expanded from 4 to 27+ (was missing issue/issue_state/agent_tasks) - Per-row UPDATE with try/except for UNIQUE key collisions - Phase 1 ID collision guard (_ensure_user_credentials checks username match) - Phase 3 orphan ID scan + collision detection - created_by_oauth (boolean flag) removed from migration list - _get_pk_columns adds MySQL SHOW KEYS fallback - _ensure_external_identity INSERT includes token_expires_at - _repair_missing_credentials passes source_username (collision guard) - D32 migration synchronous before lifespan yield (not async fire-and-forget) Other fixes: - _sync_send_async: add missing user_token assignment (baseline NameError) - Remove _migrate_create_personal_orgs / _migrate_data_to_personal_orgs calls - autopilot_subscriptions table DDL added - get_user_github_token_by_id alias to avoid name confusion - close_issue uses bot token + user token fallback via with_oauth_token - /readyz checks D32 migration status Design doc: docs/weekly-07/gitcode-dual-track-access-design.md (12 sections) Refs #343 Signed-off-by: yangaiwu <yangaiwu@nousresearch.com> Signed-off-by: grape <grape@local> | 1 month ago |
| Files | Last commit | Last update |
|---|---|---|
| 1 month ago | ||
| 1 month ago |