agnes-the-ai-analyst/cli/commands
ZdenekSrotyr 8784f10a6b fix(devin-review): stale-token override + status sessions counter + lock comment
Three Devin Review findings on PR #173 addressed in one commit since
they're in adjacent code paths:

1. cli/commands/init.py:99 (\u{1F534}): `agnes init --token NEW` ran
   step 2 verify against the OLD on-disk token because `get_token()`
   read `~/.config/agnes/token.json` before the env var, and
   `_override_server_env` only set the env var. So `agnes init --force`
   on a machine with a stale token.json failed 401 with a confusing
   'token expired' even though the --token arg was valid.

   Fix: ContextVar-based override in `cli.config._token_override`
   checked by `get_token()` BEFORE the on-disk read.
   `_with_token_override` context manager scopes the override.
   `_override_server_env` now also sets the contextvar via
   `_with_token_override(token)`, so both env var and contextvar
   carry the override (env for back-compat with anything bypassing
   get_token; contextvar is the authoritative source).
   Async-safe (each task sees its own override) and leak-proof
   (resets on context exit).
   2 new tests: regression on stale-disk-token + scope leak guard.

2. cli/commands/status.py:43 (\u{1F7E1}): sessions_pending_upload only
   checked legacy `<workspace>/user/sessions/` and always reported 0
   in workspaces bootstrapped with `agnes init` (Claude Code writes
   to `~/.claude/projects/`, not the legacy path). Same bug we fixed
   for `agnes push` in 08e49591.

   Fix: route through `cli.lib.claude_sessions.list_session_files()`
   so status and push agree on what counts as a pending session.

3. connectors/bigquery/extractor.py:111 (\u{1F7E1}): docstring claimed
   "a live holder still wins the second flock attempt" — incorrect on
   Linux. After `unlink()` + `open()`, the new file is a new inode;
   fcntl.flock keys per-inode, so the old holder's lock does NOT block
   the new acquisition. In a genuine TTL-overrun scenario two writers
   CAN race the parquet.tmp.

   Fix: documentation only. Comment now honestly describes the
   inode-recreation behavior, names the threading.Lock as the actual
   in-process guard, and flags pid-gating as the next-iteration fix
   if real corruption surfaces. The 24h default TTL is well above
   typical COPY durations so the practical risk is low.

Tests: 17/17 across test_cli_init.py + test_lib_pull.py + the broader
regression set.
2026-05-04 21:26:30 +02:00
..
__init__.py feat: add Docker, CLI tool, scheduler, and agent skills 2026-03-27 15:30:03 +01:00
admin.py feat(cli): agnes admin metrics {import,export,validate} 2026-05-04 18:39:05 +02:00
admin_metrics.py feat(cli): agnes admin metrics {import,export,validate} 2026-05-04 18:39:05 +02:00
auth.py fix: address Devin Review findings — incomplete renames + estimate guard 2026-05-04 20:05:06 +02:00
catalog.py chore(cli-rename): replace stale da verbs in active code paths 2026-05-04 21:10:43 +02:00
describe.py refactor(cli): hard-cutover env vars + config dir to AGNES_* 2026-05-04 16:35:44 +02:00
diagnose.py feat(cli): agnes status = workspace state; old health check moves to agnes diagnose system 2026-05-04 18:29:15 +02:00
disk_info.py chore(cli-rename): replace stale da verbs in active code paths 2026-05-04 21:10:43 +02:00
explore.py fix(cli): hint text 'Run: da sync' → 'Run: agnes pull' 2026-05-04 18:42:21 +02:00
init.py fix(cli): Windows console crash on cs-CZ codepage (port + broaden #172) 2026-05-04 20:45:29 +02:00
memory_admin.py refactor(cli): hard-cutover env vars + config dir to AGNES_* 2026-05-04 16:35:44 +02:00
pull.py chore(cli-rename): replace stale da verbs in active code paths 2026-05-04 21:10:43 +02:00
push.py fix(push): read sessions from ~/.claude/projects/<encoded-cwd>/ 2026-05-04 20:29:59 +02:00
query.py fix(cli): hint text 'Run: da sync' → 'Run: agnes pull' 2026-05-04 18:42:21 +02:00
schema.py refactor(cli): hard-cutover env vars + config dir to AGNES_* 2026-05-04 16:35:44 +02:00
server.py refactor(cli): hard-cutover env vars + config dir to AGNES_* 2026-05-04 16:35:44 +02:00
setup.py fix(cli): Windows console crash on cs-CZ codepage (port + broaden #172) 2026-05-04 20:45:29 +02:00
skills.py fix(cli): Windows console crash on cs-CZ codepage (port + broaden #172) 2026-05-04 20:45:29 +02:00
snapshot.py fix(snapshot): catch httpx transport errors in --estimate path 2026-05-04 20:36:30 +02:00
status.py fix(devin-review): stale-token override + status sessions counter + lock comment 2026-05-04 21:26:30 +02:00
tokens.py fix: address Devin Review findings — incomplete renames + estimate guard 2026-05-04 20:05:06 +02:00