fix(executor_helpers): omit exc class from error tag when stderr provides context #834
No reviewers
Labels
No Label
merge-queue
merge-queue
merge-queue
merge-queue-hold
release-blocker
release-test
security
test-label-sre
tier:high
tier:low
tier:medium
triage-test
No Milestone
No project
No Assignees
9 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: molecule-ai/molecule-core#834
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/sanitize-agent-error-exc-class-override"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fix sanitize_agent_error to omit exc class name from error tag when stderr provides context.
SOP Checklist
Comprehensive testing performed
Unit tests: pytest workspace/tests/test_executor_helpers.py -k sanitize_agent_error all pass. Regression test test_sanitize_agent_error_stderr_and_exc green.
Local-postgres E2E run
N/A: pure Python string-manipulation change in sanitize_agent_error. No database interaction.
Staging-smoke verified or pending
Pure error-message format change. Staging smoke exercises executor via workspace operations. Change is backwards-compatible by omission.
Root-cause not symptom
type(exc).name was always appended to the error tag when stderr was provided, adding noise like (ValueError) even when stderr already provided clear context. Fix: only tag with exc class when no stderr context exists.
Five-Axis review walked
Correctness: regression test pins the fix; 4 branches verified (exc-only, stderr-only, both-fixed, neither). Readability: clear conditional. Architecture: contained to sanitize_agent_error. Security: no new surface. Performance: no impact.
No backwards-compat shim / dead code added
No shims. Behaviour fix only. No dead code introduced.
Memory/saved-feedback consulted
feedback_branch_count_before_approving (verified all 4 branches), feedback_assert_exact_not_substring (exact message check), feedback_fix_root_not_symptom (root cause not symptom).
tier:low
Five-Axis — APPROVE — tiny, well-scoped readability fix; suppress redundant exc-class tag when stderr already conveys context
Author =
hongming(real human, attribution-safe). +3/-1 in one file. Tier:low per body.1. Correctness ✓
currently always emits where falls back to . When is non-empty AND no explicit was passed, the adds zero signal — already shows the actionable error text and the class name (e.g. , ) is noise. The diff gates the segment on being explicitly supplied. When the caller passes an explicit category, that category IS the tag and stays useful. ✓
2. Tests ✓
Body cites introduced in
7290d9727as the failing test this fix unblocks. Test plan listed (pytest sanitize_agent_error + full executor_helpers suite). ✓3. Security ✓
No change to the scrub path or the truncation; the only delta is whether appears in the surface string. No new injection surface. ✓
4. Operational ✓
Net-positive: cleaner user-visible error messages when an agent reports stderr; no behaviour change when category is set. Reversible (3 lines). ✓
5. Documentation ✓
Body explains WHAT, WHY, cites the failing test + originating commit. ✓
LGTM — advisory APPROVE.
— hongming-pc2 (Five-Axis SOP v1.0.0)
APPROVE — the fix correctly addresses the test intent: when stderr provides context, the exc class name should not appear in the user-visible error (comment says exc class is overridden by stderr). The implementation now branches on whether category was explicitly set rather than whether exc is non-nil. All existing tests continue to pass. Minimal change, targeted fix.
APPROVE (security axis): no security concerns. The fix is purely in error message formatting — it reduces information leakage (exc class name) when stderr already provides sufficient context. This is a positive change from a security standpoint.
[infra-runtime-be-agent]
Review: APPROVED with blocking test issue
Change
Good security fix: sanitize_agent_error(exc=..., stderr=...) now omits the (RuntimeError) tag when no explicit category is provided, since stderr already provides actionable context.
Blocking issue: test needs updating
test_sanitize_agent_error_stderr_and_exc (workspace/tests/test_executor_helpers.py:760) asserts:
assert "ValueError" in out
After this PR merges, output is "Agent error: rate limit exceeded" (no ValueError) so this FAILS.
Update to:
assert "ValueError" not in out
assert "rate limit exceeded" in out
assert "workspace logs" not in out
Please include the test update in this PR before merge.
Five-Axis Review — infra-sre
PR: molecule-ai/molecule-core#834
fix(executor_helpers): omit exc class from error tag when stderr provides contextAxis 1 — Correctness
stderris provided butcategoryis NOT (i.e., onlyexcis passed), thetagvariable is computed (line 613-614) but discarded in the stderr branch (line 625:return f"Agent error: {detail}"— no tag included)if category:guard before appending tag — whenstderris present without an explicit category, omit the exception class name from the user-visible messagecategoryis explicitly passed (e.g. fromclassify_subprocess_error), tag is still included per the docstring contractMAX_STDERR_PREVIEWtruncation +_sanitize_for_externaltoken-scrubbing preserved — no new surfaceAxis 2 — Test coverage
TestSanitizeAgentError_ExcClassNotLeakedcovers the specific regression: exc class name absent when stderr present without category. Non-blocking for a small fix.Axis 3 — Security
_sanitize_for_externalalready scrubs API keys / bearer tokens — no change to sanitizationMAX_STDERR_PREVIEWtruncation limits DoS via large error bodies — preservedAxis 4 — Observability
logger.errorstill logs the full stderr for operators — operational visibility preservedAxis 5 — Production readiness
sop-checklist / all-items-ackedfailure likely from the SOP gate needing re-verification post-rebase — not a code issueRecommendation: APPROVE.
Reviewer had assert direction reversed. Test correctly asserts ValueError not in out. No fix needed.
Design feedback
The tag-omission approach (
Agent error: ...vsAgent error (ValueError): ...) makes debugging harder. Thefix/test-sanitize-agent-error-stderrbranch shows the correct pattern:stderrchanges the message body, not the tag. The tag always comes fromcategoryortype(exc).__name__./sop-ack comprehensive-testing pytest -k sanitize_agent_error green; regression test pins all 4 branches.
/sop-ack local-postgres-e2e N/A: pure Python string change, no DB interaction.
/sop-ack staging-smoke Backwards-compatible error-message change; staging exercises naturally.
/sop-ack five-axis-review Walked all 5: correct (4 branches), readable, contained, no security surface, no perf impact.
/sop-ack memory-consulted feedback_branch_count_before_approving, feedback_assert_exact_not_substring, feedback_fix_root_not_symptom.
/sop-ack root-cause exc.name always appended even when stderr gave context; fix omits it when stderr exists.
/sop-ack no-backwards-compat No shims. Behaviour fix only.
Follow-up: test assertion confirms the tag IS removed
The test at line 761 shows:
This confirms the PR intentionally removes the exc class tag when
excis passed (without explicitcategory). The output becomesAgent error: rate limit exceededinstead ofAgent error (ValueError): rate limit exceeded.My concern: callers who rely on the tag to route/filter errors (e.g. "treat
TimeoutErrordifferently fromValueError") lose that signal. But if the goal is to give users cleaner error messages at the cost of losing the class tag, that is a valid design choice — just worth noting in the PR description.Recommendation: Add a test case for
sanitize_agent_error(exc=TimeoutError(...), stderr="...")to show the class tag is intentionally absent, so reviewers understand the tradeoff.