generated from alex/base-template
feat: tolerate network failures during IRC connection #8
No reviewers
Labels
No labels
dependencies
No milestone
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
alex/irc-greeter-bot!8
Loading…
Reference in a new issue
No description provided.
Delete branch "pi/issue7-1784383560700"
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
Fixes #7.
The bot previously crashed whenever the initial IRC connection failed (e.g.
ConnectionRefused, a dropped TLS handshake, or a temporarily unreachable server), becauseclient.connect()was awaited directly inmain()and any error propagated all the way up, killing the process.This wraps the connection in an infinite retry loop with a fixed 10-second backoff, so transient network issues no longer crash the bot.
Changes
retryForever(src/main.ts): a small, generic helper that calls an operation repeatedly until it succeeds, waiting a fixeddelayMsbetween failed attempts. It never rejects — failures are reported via an injectedonErrorcallback and the loop keeps going. The sleeper and error callback are injected dependencies so the behaviour is fully unit-testable without real timers.createClient(src/main.ts): the previous inline client construction + event-listener wiring was extracted into a helper. A fresh client is built on every connection attempt, so a half-open socket from a previous failed attempt can never leak into the next one.main()now resolves its client viaretryForever, with each attempt logging the connection target, and failures logging the error plus the attempt number and the upcoming backoff delay.src/main_test.ts): three new tests coveringretryForever— success on first try (no sleep / no error reported), retry-until-success (verifies backoff delay, attempt numbering, and error forwarding), and never-gives-up (verifies it keeps retrying indefinitely).Verification
deno task check✅deno lint✅deno task test→ 54 passed ✅deno fmt --check✅/pi fallow checks are failing, fix them in a new pr
Now let me experiment with the fallow
ignorePatternsto understand whyscripts/isn't being respected:scripts/(trailing slash) isn't matched, butscripts/**works. Let me verify the minimal fix with the full original config:Thetailmasked the real exit code. Let me capture fallow's actual exit code:The duplicateChattoConfigexport also fails the check. Let me examine the full picture before fixing — checking config_test.ts's chatto usage and confirming all references:Now I have the full picture. Let me restore the original config file (modified during testing) and apply both fixes:Working tree is clean. Now applying both fixes. Fix 1: correct thescripts/ignore pattern (trailing-slash form isn't matched by fallow;scripts/**is):Fix 2: resolve the duplicateChattoConfigexport.chatto.tsowns the API connection shape (baseUrl,token,roomId);config.tswill import it and define a richerChattoSettingsthat adds themessagetemplate. This removes the name collision while keeping the correct dependency direction (config → chatto).Now updatemain.tsto use the renamed type:Now let me verify all checks pass — fallow, type-check, lint, format, and tests:Fallow now passes, plus check/lint/fmt are green. Now the test suite:All 54 tests pass. Let me review the final diff before opening the PR:Both fixes are clean and minimal, and all checks pass (fallow ✓, check ✓, lint ✓, fmt ✓, 54 tests ✓). Let me create the PR:PR #9 created: #9The
deno task fallowcheck was failing onmasterdue to two issues, both now fixed:scripts/chatto-token.tsreported as an unused file —.fallowrc.jsonalready had"scripts/"inignorePatterns, but fallow's glob matcher doesn't match the bare trailing-slash directory form. Changed it to"scripts/**", which fallow honours (matching the author's clear intent that the standalone token helper isn't dead code).Duplicate export
ChattoConfig— it was exported from bothsrc/chatto.tsandsrc/config.ts. Madechatto.tsthe single canonical owner ofChattoConfig(the API connection shape), andconfig.tsnow imports it and definesChattoSettings extends ChattoConfigadding themessagetemplate. This keeps the correct dependency direction (config→chatto), leaveschatto.ts/its tests untouched, and stays structurally compatible.main.tswas updated to useChattoSettings.All checks pass: fallow ✓ No issues found,
check✅,lint✅,fmt --check✅,test→ 54 passed ✅.View action run | Model: zai/glm-5.2 (thinking: max) | Time: 6m 23s | Tokens: 404.7K | Pi SDK v0.80.10 | Action v2.26.0-develop (develop @ c0cad3d)