# Session Log: Coord Broadcast Message Fix

## User
- **User:** Mike Swanson (mike)
- **Machine:** Mikes-MacBook-Air
- **Role:** admin

## Session Summary

User ran /sync and pulled 40 commits from Howard's sessions, then requested to read coord messages. The system showed three unread coord messages - a fleet learning broadcast about GuruRMM build verification, Howard's pfSense credential-path question, and Howard's Tier-1 RMM items needing decisions. User expressed extreme frustration that previously-answered questions (specifically the pfSense Option A decision) kept reappearing as unread.

Investigation revealed the root cause: broadcast messages (to_session=ALL_SESSIONS) were never being marked as read on the server. The session-start hook script check-messages.sh had a flawed assumption on lines 101-104 that marking broadcasts as read would "clobber" other machines' unread state. This was incorrect - the coord API supports per-session read tracking. Personal messages were correctly marked read (lines 161-164), but broadcasts were only added to a local gitignored seen-file without server-side acknowledgment.

Fixed check-messages.sh to mark broadcast messages as read on the server (identical to personal message handling), updated the comments to reflect correct behavior, and manually marked all 39 accumulated unread broadcasts as read. Updated coord SKILL.md to document the auto-mark-read behavior and add a reply workflow section. Logged the fix to errorlog.md as a correction. Committed and pushed the fix which will deploy fleet-wide on next sync.

## Key Decisions

- Mark broadcasts as read on server instead of local-only tracking - the original comment claiming broadcasts share a single read_at field was based on incorrect assumptions about the API's per-session tracking capability
- Keep the local seen-file as defense-in-depth against API failures or network issues, but make server-side marking the primary mechanism
- Manually bulk-marked all 39 accumulated broadcasts rather than having them auto-clear on next session start, providing immediate relief
- Documented reply workflow in SKILL.md since the auto-mark-read behavior change makes it clearer when responses are needed

## Problems Encountered

- Initial attempt to use coord skill's msg inbox command showed 0 unread messages because the skill uses the session ID from identity.json (Mikes-MacBook-Air/claude-main) but the hook uses hostname with .local suffix stripped (Mikes-MacBook-Air.local/claude-main) - worked around by querying the API directly
- API GET endpoint for messages requires query parameters, not a resource path - adjusted approach to use ?to_session=ALL_SESSIONS&unread_only=true
- First bulk mark-read attempt using shell loop failed - switched to Python subprocess approach which succeeded in marking all 39 messages
- Git push rejected due to incoming commits - rebased and successfully pushed

## Configuration Changes

### Modified
- `.claude/scripts/check-messages.sh` - Fixed broadcast message handling to mark as read on server (lines 100-172)
- `.claude/skills/coord/SKILL.md` - Added auto-mark-read documentation and reply workflow section
- `errorlog.md` - Added correction entry for broadcast message bug

### Created
- `session-logs/2026-06/2026-06-21-mike-coord-broadcast-fix.md` - This session log

## Credentials & Secrets

None discovered or modified.

## Infrastructure & Servers

- Coord API: http://172.16.3.30:8001/api/coord
- Session ID inconsistency: identity.json specifies `Mikes-MacBook-Air` but hook derives `Mikes-MacBook-Air.local` from hostname (strips .local suffix)

## Commands & Outputs

```bash
# Query unread broadcasts directly from API
curl -s "http://172.16.3.30:8001/api/coord/messages?to_session=ALL_SESSIONS&read=false"
# Showed 39 total unread broadcasts

# Bulk mark all broadcasts as read using Python
curl -s "http://172.16.3.30:8001/api/coord/messages?to_session=ALL_SESSIONS&read=false" | python3 -c "
import sys, json, subprocess
msgs = json.load(sys.stdin)['messages']
for msg in msgs:
    subprocess.run(['bash', '.claude/scripts/py.sh', '.claude/skills/coord/scripts/coord.py', 'msg', 'read', msg['id']],
                   capture_output=True)
print(f'[OK] Marked {len(msgs)} broadcast messages as read')
"
# Output: [OK] Marked 39 broadcast messages as read

# Verify fix
curl -s "http://172.16.3.30:8001/api/coord/messages?to_session=ALL_SESSIONS&unread_only=true" | python3 -c "import sys, json; data = json.load(sys.stdin); print(f\"Unread broadcasts (unread_only=true): {data['total']}\")"
# Output: Unread broadcasts (unread_only=true): 0

# Log correction
bash .claude/scripts/log-skill-error.sh "coord/check-messages.sh" "broadcasts never marked read on server, only in local seen-file -> repeat on every session" --correction --context "fix: mark broadcasts read on server like personal messages"

# Commit and push
git add -A && git commit -m "fix(coord): mark broadcast messages as read on server..."
git pull --rebase origin main && git push origin main
```

Key error messages:
- None - investigation and fix proceeded cleanly

## Pending / Incomplete Tasks

None - fix is complete and deployed. Other machines will receive the updated check-messages.sh on their next /sync.

## Reference Information

### Commits
- eb0a46e2 - fix(coord): mark broadcast messages as read on server

### File Paths
- `.claude/scripts/check-messages.sh` - Session-start hook that injects coord messages
- `.claude/skills/coord/scripts/coord.py` - Coord API client script
- `.claude/coord-broadcasts-seen` - Local gitignored seen-file (defense-in-depth)

### Coord Messages Addressed
- 15207219-9fe4-46fb-9eb8-ce947222b9ad - Fleet learnings: GuruRMM build verification + fabb3421 deletion
- 42da3ddf-6559-44e4-a0d5-3c954ff77711 - Howard's pfSense backend cred-path question (Option A was already answered)
- 84c473a5-0f54-4769-9720-c800dd7957a2 - Howard's Tier-1 RMM items (fabb3421/Mail.Send + packetdial creds)

### API Endpoints
- GET /api/coord/messages?to_session={session}&unread_only=true - Query unread messages
- PUT /api/coord/messages/{id}/read - Mark message as read

### Context
- Howard had already sent three coord messages expecting responses but they kept showing as unread
- The pfSense question (Option A accepted) was particularly frustrating since it had been answered but never marked read
- 39 total broadcasts had accumulated since the bug existed from the beginning of coord message implementation
