Skip to content

fix(quota-tracker): narrow bare except Exception to ImportError (closes #1062) - #1165

Closed
bassilkhilo-ag2 wants to merge 6 commits into
sonichi:mainfrom
bassilkhilo-ag2:fix/quota-bare-except-1062
Closed

bassilkhilo-ag2 wants to merge 6 commits into
sonichi:mainfrom
bassilkhilo-ag2:fix/quota-bare-except-1062

Conversation

@bassilkhilo-ag2

Copy link
Copy Markdown
Collaborator

Summary

One-line fix: narrow except Exception: to except ImportError: in skills/quota-tracker/scripts/read-quota.py around the workspace_default import block.

Why

The broad handler swallowed any non-ImportError exception raised by status_read_path(), silently setting _canonical = None and emitting the misleading "No quota-state.json found" fallback instead of surfacing the real error. The original #1055 bug was an ImportError — but if a future refactor makes status_read_path() raise something else (e.g. a config error, a permission issue), we want it to propagate to cron pass logs, not disappear.

Per Chi's issue #1062 and Lucy's original #1055 review comment.

Change

# Before
except Exception:
    _canonical = None

# After
except ImportError:
    _canonical = None

Test plan

  • python3 tests/quota-bare-except.test.py → All 5 tests passed
  • Confirms: no except Exception: present, except ImportError: present, import block structure intact, _canonical = None fallback preserved

Closes #1062.

🤖 Generated with Claude Code

bassilkhilo-ag2 and others added 6 commits May 25, 2026 05:41
Before: "multiple processes (2 PIDs: 25023,25065)" — no way to tell if
this is expected app-bundle + dev-repo coexistence or a zombie duplicate.

After: "multiple processes (2 PIDs: 25023:/Applications/Sutando.app/.../
discord-bridge.py, 25065:/Users/.../sutando/src/discord-bridge.py)" —
immediately actionable, confirms the two instances are different source
files running in parallel, not the same script spawned twice.

5 tests in tests/health-check-bridge-multi-pid.test.py.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…andoff.sh invariants (sonichi#1121)

17 checks: no e.message/String(e) in res.end() calls, static error strings
at the 3 scrubbed sites, ≥3 console.error('[web-client]') server-side logs,
no instanceof/e?.message patterns; session-handoff.sh: STATE_FILE→session-state.md,
SUTANDO_REPO_DIR for repo, SUTANDO_WORKSPACE for quota+sentinel, personal_path()
for pending-questions, TRANSCRIPT="$1" from PreCompact hook.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…reparent (closes sonichi#1088)

Mode A (EPIPE-on-dead-reader): replace `echo` with `printf || exit 0` in
the fswatch loop so a broken consumer pipe triggers an immediate exit on
the first failed write, not after ~100 buffered events (~hours of silence
on real DM traffic). Root cause of 2026-05-23 4h task-drop.

Mode B (PPID=1 reparent): add a PPID watchdog background subshell that
polls `kill -0 $_PARENT_PID` every 5s and SIGTERMs this script when the
parent (Monitor wrapper) is gone, so the watcher doesn't live indefinitely
under launchd. Stop hook + startup PID-file reaper cover clean exits;
this covers SIGKILL / Monitor teardown without signal delivery.

15 structural tests in tests/watch-tasks-stream-orphan.test.py.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
sonichi#1062)

The broad except Exception: around the workspace_default import swallowed
any non-ImportError raised by status_read_path(), silently falling through
to the misleading "No quota-state.json found" message instead of surfacing
the real error. Narrowed to ImportError so only the module-not-on-path case
is suppressed; all other exceptions propagate to cron pass logs.

5 structural tests in tests/quota-bare-except.test.py.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bassilkhilo-ag2

Copy link
Copy Markdown
Collaborator Author

Superseded by #1094 — VasiliyRad opened the same fix with more review activity. Recommend closing this one and merging #1094.

@VasiliyRad VasiliyRad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The one-line fix in skills/quota-tracker/scripts/read-quota.py is correct — except ImportError: is the right scope and the logic is preserved.

However, this PR bundles significant unrelated changes that should be separate PRs:

  • build_log.md (114 lines added) — workspace state file, should not be in a code PR
  • src/health-check.py (14 additions, 2 deletions) — multi-bridge source-path warn feature, unrelated to quota-tracker
  • src/watch-tasks-stream.sh (15 additions, 1 deletion) — unrelated
  • tests/health-check-bridge-multi-pid.test.py (88 lines, new file) — tests for the health-check change, not the quota fix
  • tests/watch-tasks-stream-orphan.test.py (201 lines, new file) — unrelated
  • tests/web-client-security-scrub.test.py (210 lines, new file) — unrelated

Only skills/quota-tracker/scripts/read-quota.py and tests/quota-bare-except.test.py belong here. Please strip the rest and resubmit.

bassilkhilo-ag2 added a commit to bassilkhilo-ag2/sutando that referenced this pull request May 26, 2026
…chi#1062)

5 structural tests verifying the `except ImportError` constraint in
skills/quota-tracker/scripts/read-quota.py. Companion tests to the
1-line fix in the same commit — extracted from the bundled PR sonichi#1165
(which mixed in unrelated changes).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bassilkhilo-ag2

Copy link
Copy Markdown
Collaborator Author

Closing — PR #1180 is the canonical fix for #1062: same 1-line change plus a regression test (tests/quota-bare-except.test.py), and has VasiliyRad's approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(quota-tracker): narrow read-quota.py:26 bare-except to ImportError

2 participants