Skip to content

Fix children_count_worker crash on empty DataFrame groupby - #167

Merged
arjunrajlab merged 2 commits into
masterfrom
claude/docker-network-resolution-im1i6g
Aug 7, 2026
Merged

Fix children_count_worker crash on empty DataFrame groupby#167
arjunrajlab merged 2 commits into
masterfrom
claude/docker-network-resolution-im1i6g

Conversation

@arjunrajlab

Copy link
Copy Markdown
Collaborator

Summary

Fixes a production crash in children_count_worker where an empty 'Child Tags' selection caused pd.DataFrame([]).groupby('parentId') to raise KeyError: 'parentId'. The worker now validates required inputs early and handles zero-match scenarios gracefully with appropriate error/warning messages.

Changes

entrypoint.py:

  • Added validation to reject empty child_tags with a clear sendError message asking the user to select at least one child tag
  • Fixed unsafe dictionary access: workerInterface['Child Tags Exclusive'].get('Child Tags Exclusive', 'No')
  • Added guards before pandas operations to handle empty result sets:
    • Skip groupby entirely when filtered_connections is empty (legitimate outcome: no connections exist)
    • Return empty dict and send sendWarning instead of crashing
  • Added warnings for other zero-match scenarios:
    • No parent annotations found (parent tags don't match anything)
    • No child annotations found (child tags don't match anything)
    • No connections between matching parents and children (suggests running a connection tool first)

test_children_count.py:

  • Replaced the old test_empty_tag_filters test (which mocked pandas and missed the crash) with three focused regression tests:
    • test_empty_child_tags_sends_error: Verifies empty tag list triggers sendError and prevents upload
    • test_missing_child_tags_field_sends_error: Verifies missing 'Child Tags' key also triggers error
    • test_no_connections_uploads_zero_counts: Real pandas path with zero connections → warns and uploads zeros
    • test_no_matching_child_annotations_warns_and_uploads_zeros: Valid tags but zero matches → warns and uploads zeros
  • All new tests use real (unmocked) pandas to catch DataFrame edge cases

CHILDREN_COUNT.md:

  • Added "Error Handling" section documenting the three error/warning scenarios and their user-facing messages

Implementation Details

The fix follows the pattern from the nimbus-worker-hardening skill (catalog #6 and #7):

  1. Validate required selections early — empty tag sets are misconfiguration, not valid data
  2. Guard pandas operationspd.DataFrame([]) has no columns, so groupby fails; check for empty input before calling it
  3. Distinguish misconfiguration from valid zero-matchsendError for missing required input, sendWarning for legitimate zero results

The old tests mocked pandas.DataFrame entirely, which is why the crash survived code review. New tests use real pandas with empty inputs to catch this class of bug.

https://claude.ai/code/session_01Mbm8CVwCNx2kdcPLadmsLA

A production job run with 'Child Tags': [] crashed with
KeyError: 'parentId': an empty tag set matches no annotations, so the
filtered connection list was empty and pd.DataFrame([]) — which has no
columns — raised inside groupby('parentId').

- sendError with a clear message when no child tag is selected, instead
  of crashing (an empty required tag selection is a misconfiguration)
- Skip the pandas groupby when zero connections match: upload counts of
  0 for every parent and sendWarning explaining why (zero children is
  valid data, e.g. before a connection tool has been run)
- sendWarning when the parent or child tags match no annotations
- Defensive .get() for 'Child Tags Exclusive'

The old tests mocked pandas.DataFrame entirely, so this path was never
exercised; the rewritten empty-tags test and the three new tests run the
real code (test_empty_tag_filters had asserted a count-all-children
behavior that never existed). All four new tests reproduce the crash on
the previous code and pass on the fix.

Also documents the failure mode in CHILDREN_COUNT.md and adds it to the
nimbus-worker-hardening catalog (sweep found no other worker feeding a
possibly-empty list into groupby; connect_* workers pre-declare columns).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mbm8CVwCNx2kdcPLadmsLA

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b3393ce352

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .claude/skills/nimbus-worker-hardening/SKILL.md
The new failure-mode entry was added only to the Claude copy of the
nimbus-worker-hardening skill; Codex loads .agents/skills/, which still
ended at catalog entry 6. The new section has no Claude-specific
references, so it mirrors verbatim.

Addresses PR #167 review comment.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mbm8CVwCNx2kdcPLadmsLA
@arjunrajlab
arjunrajlab merged commit 3f8f2b5 into master Aug 7, 2026
1 check passed
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.

2 participants