Skip to content

feat(desktop): expose bot onboarding retry health - #4746

Merged
me2seeks merged 20 commits into
apache:mainfrom
testikun:codex/issue-4745-bot-onboarding-health
Sep 18, 2026
Merged

me2seeks merged 20 commits into
apache:mainfrom
testikun:codex/issue-4745-bot-onboarding-health

Conversation

@testikun

@testikun testikun commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Expose finite, redacted timeout/network/rate-limit/server retry health from the existing main-process Bot onboarding poll owner.
  • Clear the projection on recovery, cancellation, expiry, denial, terminal failure, and supersession. Provider-poll retry thresholds and intervals remain unchanged; failures after a successful poll, including credential persistence and connection warnings, are terminal and are not retried.
  • Show concise localized backoff status in the existing QR onboarding modal while preserving the QR and secret-free IPC boundary.

Fixes #4745

Verification

  • Core and Desktop focused onboarding tests: 22 passed.
  • Redaction regressions: 27 passed.
  • Electron retry-health E2E: 1 passed.
  • Desktop build and typecheck.
  • Core typecheck.
  • Renderer architecture check.
  • npm run lint.
  • npm run format:check.
  • npx knip --workspace apps/desktop.
  • npm run check:asf-headers.
  • git diff --check.

Visual evidence

Earlier visual verification built and launched 3a37a66f3 (the screenshot predates current head 685d85250) in a visible local Electron App. The real QR onboarding modal kept the QR available while showing only the bounded retry category, consecutive count, and retry delay. This is a direct App capture, not a mockup or generated image.

Real Maka bot onboarding retry health with the QR preserved

The Electron test also asserts that fixture provider details do not appear in the renderer.

Review focus

The existing poll loop remains the only retry authority. retryHealth contains only a finite category, consecutive count, and retry timing; raw provider errors and credentials remain main-process-only.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: OpenAI Codex implemented the bounded Core/Desktop contract, main-process projection, localized UI state, deterministic lifecycle/redaction coverage, and E2E visual fixture. The human contributor remains responsible for review and submission.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

@github-actions github-actions Bot added the effort/M Under 500 readable lines label Sep 4, 2026
@testikun
testikun force-pushed the codex/issue-4745-bot-onboarding-health branch 2 times, most recently from 3a37a66 to 20a2442 Compare September 5, 2026 02:06

@hqhq1025 hqhq1025 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.

I reviewed exact head 0c2008256f8dcf94a26435e951610f0c0898d481.

This change adds a finite, redacted retry-health projection and localized onboarding status, with focused lifecycle and Electron coverage. I found one P2 state-machine issue in the post-confirmation error path, so I do not recommend merging this head yet.

Validation included a clean install, build:test, Desktop typecheck/build, Core (825/825) and Desktop (2165/2165) dist suites, focused onboarding/redaction tests, renderer architecture (98/98), both affected Electron journeys, lint, format, Biome, ASF headers, diff check, hosted test, and a clean patch-preserving merge onto current main (7743890729b26a7e95f653af8b93ccbe42ad480f). I did not exercise live provider APIs or native macOS/Windows UI behavior.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

@testikun
testikun force-pushed the codex/issue-4745-bot-onboarding-health branch from 0c20082 to 8cbdb12 Compare September 6, 2026 06:32
@testikun

testikun commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor Author

@hqhq1025 Addressed the P2 from your review comment in commit 8cbdb12e.

The retry classifier is now enabled only after the provider poll promise rejects. Once the provider returns confirmed, failures from credential persistence or runtime effects are terminal error snapshots with no retryHealth, so the renderer cannot promise another provider poll for a non-pollable connecting session. Added a regression test covering a timeout-shaped post-confirmation runtime-effects failure.

Targeted diff check passed; the branch was rebased onto current apache/main and pushed to codex/issue-4745-bot-onboarding-health.

@testikun
testikun force-pushed the codex/issue-4745-bot-onboarding-health branch from 5990e5b to 8f43713 Compare September 6, 2026 06:56
@testikun
testikun force-pushed the codex/issue-4745-bot-onboarding-health branch from ebe9abe to 6ea4b5b Compare September 7, 2026 02:34

@hqhq1025 hqhq1025 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.

Reviewed exact head 6ae4b58667e82c373950e61a77bcb83582bc83bc.

The previous P2 is fixed: retry classification is now limited to failures thrown by the provider poll itself. Once poll() returns confirmed, persistence or runtime-effect failures are terminal and no longer publish retry health that the renderer cannot act on. I found no remaining P0-P3 issues in the current diff.

The change exposes only a finite, redacted retry category plus bounded retry timing/count data, clears that projection on recovery, terminal outcomes, cancellation, expiry, and supersession, and keeps the renderer polling only while the session remains waiting or scanned. The Electron regression traverses the real main-process fixture, IPC, and renderer path; its captured window showed the localized retry status with the QR still visible and no raw provider detail.

Validation passed: build:test; full Core (832/832) and Desktop (2256/2256) suites; focused onboarding tests (25/25); full typecheck; lint, format, ASF headers, E2E budget, renderer architecture (101/101), renderer production build, and the targeted Electron test (1/1). Hosted test is green, and the head merges cleanly with current main (42fa4d070504e672173c46dd75f7fcabb88789f5). I did not exercise live provider APIs or native macOS/Windows UI behavior.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

Verified full build and typecheck, 25 focused tests, and Electron retry-health E2E. Removing the post-confirmation guard reproduces the regression.

Generated-by: OpenAI Codex
@testikun

Copy link
Copy Markdown
Contributor Author

Automated follow-up by OpenAI Codex on behalf of testikun (not an independent human review). Merged current main. Full build:test and full typecheck passed, along with 25 focused Core/Desktop tests, Electron bot-onboarding-retry-health E2E (1/1), and the E2E budget check. Ablation of the provider-poll-settled guard reproduced the post-confirmation connecting-state regression; restoring it passed. Existing fix retained without additional abstraction. Please review the latest head.

@me2seeks me2seeks 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.

Automated review (Command Code) — not an approval

P2 (Should-Fix) — the test that covers the one renderer behavior this PR changes does not execute it.

// apps/desktop/src/main/__tests__/bot-onboarding-status-copy.test.ts:38-46
test('the existing onboarding status surface prefers retry health while present', async () => {
  const source = await readFile(
    new URL('../../../src/renderer/settings/bot-onboarding-modal.tsx', import.meta.url),
    'utf8',
  );
  assert.match(source, /if \(snapshot\?\.retryHealth\)/);
  assert.match(source, /shared\.retrying\(/);
  assert.match(source, /case 'waiting': return copy\.waiting/);
});

This reads the component as text and greps it. It never calls the status function, so it passes if the branch is unreachable, returns the wrong string, or if the precedence it claims to test is reordered; the third pattern matches an unrelated pre-existing line; and any reformat breaks it. The retry-health precedence is the only renderer behavior this PR changes, so it is currently unprotected — the end-to-end spec is the real check. Replace it with a behavioral assertion, or drop it in favour of the e2e.

P3 (Nice-to-have) — the retry copy overrides the "scanned" instruction. The retry-health branch is evaluated before the state switch, so once the user has scanned, a single transient blip replaces "Scanned. Complete confirmation in …" with the retry message for the whole backoff window — removing the action the user needs. Show retry health only while the state is still waiting, or append it to the state copy.

P3 (Nice-to-have) — the shared waiting fixture was repurposed. The onboarding e2e fixture now makes every poll fail, so it no longer holds the modal in the waiting state after the retry threshold, while its own doc comment still says that is what it does. A dedicated scenario would be clearer than overloading the shared one.

P3 (Nice-to-have) — a tautological test and runtime-dead constants. One core test asserts an exported constant deep-equals an identical literal, and that array is consumed by nothing at runtime (only its type is used) — keep the type and drop the array. A second exported field is an absolute timestamp read by no consumer over IPC. Also, the new copy function types its category as string, so a typo compiles and silently falls through to the default.

P3 (Nice-to-have) — classifier coverage gaps. No test produces the network category and none covers a failed authentication asserting it clears retry health and goes terminal, so a regression in either boundary would be invisible.

Checked and clean (recorded because this was the main risk): no secret crosses the new surface — every IPC field is an enum or a number, the raw error text is never placed on the snapshot, retryHealth is cleared on success, expiry, terminal failure and cancel, and a new onboarding session allocates fresh state, so no previous account's health can persist. The retry thresholds and intervals are unchanged.

Review-relevant risks. No security, licensing or release effect identified in the diff. Automated review is not the independent human review CONTRIBUTING.md requires.

Required conclusion.

  1. Optimal for the actual problem? Essentially yes — it extends the existing retry owner with a redacted projection and does not add a second retry loop.
  2. Production code that can be deleted? The runtime-dead category array (keep the derived type) and the unconsumed absolute timestamp.
  3. Low-quality tests to delete or replace? The source-text-grep test above; the tautological constant test goes with the constant.
  4. Deeper refactor required? No. Do not add a second health layer; tighten the copy function's parameter type and add the missing classifier cases.
  5. Ready to merge? Mergeable after the P2 test replacement and the two coverage additions; no correctness or secret-exposure defect found.
  6. Residual risks / verification gaps: I did not run the suite, so the fixture-repurposing consequence for the audit script is unverified.

Approval boundary. This is automated review; it is not an approval. Per CONTRIBUTING.md, the merge decision requires an independent human review. No approve was submitted.

@hqhq1025 hqhq1025 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.

Re-reviewed the full change at c52616d08ad7aae3e5f1e05b49ecef841c52b0f8. I found no remaining P0-P3 issue and no technical blocker.

The previous post-confirmation retry-state bug remains fixed: once poll() returns confirmed, persistence or runtime-effect failures terminate as errors instead of publishing retry health that the renderer cannot fulfill. The exposed snapshot is still limited to a finite error class, attempt count, and timestamps; raw provider errors do not cross the main/renderer boundary.

I also checked the renderer regression evidence directly. The source-text assertion is weak in isolation: a mutation that preserved its shared.retrying(...) match while returning the waiting copy still passed that test. However, after rebuilding the renderer, the production Electron onboarding test failed on the same mutation and passed again on the restored exact-head code. Therefore the user-visible retry-copy selection is covered by the actual main-to-renderer path, despite the redundant source assertion.

Validation completed on this head: build test compilation; 25 focused Core/Desktop tests; Desktop renderer build; renderer architecture checks (103 tests); E2E budget; changed-file Biome and diff checks; and the Electron retry-health scenario under Xvfb. Hosted test is green, and the head cleanly merges with current main at b37eb96398ace9a9935dbfd87999b12d0af865b8.

I did not connect to a live provider or run the UI on native macOS/Windows.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

Keep scanned instructions alongside retry health. Replace source assertions with production presenter tests, cover network-to-auth failure, remove unused retry metadata and restore the waiting fixture. Sync current main.

Generated-by: OpenAI Codex

@hqhq1025 hqhq1025 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.

Reviewed exact head 0262ccd396a394a80d1246536631171b004cd00e.

I found no P0-P3 issue in the current six-file change. The previous post-confirmation retry-state bug remains fixed: only failures thrown by the provider poll can produce retry health; once a provider response has settled, persistence or runtime-effect failures terminate without advertising a retry the renderer cannot perform. The main process exposes only a finite category and consecutive-failure count, clears them on recovery and every terminal/cancel/supersession path, and the renderer preserves scanned instructions while scheduling the next poll from the existing bounded delay.

I exercised the compiled production service and presenter together: a secret-bearing HTTP 503 became { category: "server", consecutiveFailures: 1 }, rendered a localized seven-second retry notice, exposed none of the provider detail, and cleared after the next successful pending response. A separate post-confirmation timeout ended in error with no retry projection.

Validation passed: build:test; Core 837/837; Desktop 2466/2466; focused onboarding 27/27; full typecheck, lint, format, ASF headers, locale hygiene, renderer architecture 112/112, E2E budget, renderer production build, all hosted test steps including Desktop E2E, and a clean merge with current main (f109ccde910dd8a42d35c6a72e60cef91815819f). I did not connect to a live provider or run native macOS/Windows UI.

One non-behavioral cleanup remains before merge: git diff --check origin/main...HEAD reports apps/desktop/src/renderer/settings/bot-onboarding-modal.tsx:248: new blank line at EOF. Biome formatting and hosted CI do not flag it, but the repository diff check is not clean.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

@testikun

Copy link
Copy Markdown
Contributor Author

Addressed the remaining cleanup in 529e875: removed the EOF blank line from bot-onboarding-modal.tsx. git diff --check upstream/main...HEAD is clean. Verification: npm run build:test, 27 focused onboarding/status-copy tests, and the strict renderer architecture check against upstream/main pass. Full Desktop typecheck remains blocked by current upstream/main errors in runtime-host-session-catalog.ts (DesktopSessionSummary.id), outside this PR.

@hqhq1025 hqhq1025 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.

Reviewed exact head 6d5f374032f653cebf33fe89f11044b689dde9f7.

I found no P0-P3 issue in the current six-file change. The main process remains the only retry authority: only failures thrown by the provider poll produce retry health, while post-confirmation persistence/runtime-effect failures stay terminal. The snapshot exposes only a finite category and consecutive-failure count, clears that state on recovery, terminal outcomes, cancellation, expiry, and supersession, and the renderer preserves the scanned instruction while showing the bounded retry delay.

The latest commit is an empty CI-rerun commit and has the same tree as 529e8756; the preceding code change only removed the previously reported EOF blank line. The branch merges cleanly with current main (1ae4d5b899db66511322876d9df44295eb49eb70).

Validation on this exact head passed: clean install, build:test, full workspace typecheck, Core 842/842, focused onboarding 27/27, renderer architecture 112/112, E2E budget, production renderer build, changed-file Biome, ASF headers, diff check, and the previously failing CLI clean-EOF test 10/10. Hosted test is green. I did not connect to live providers or exercise native macOS/Windows UI; the current tree no longer contains the earlier dedicated onboarding Electron E2E.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

@testikun

Copy link
Copy Markdown
Contributor Author

Automated follow-up by OpenAI Codex on behalf of testikun (not an independent human review).

Merged current upstream/main (4410c3a2d) without conflicts and pushed 21c199e6f. The final PR diff remains limited to the same six onboarding files; GitHub reports the new head mergeable.

Validation on Node 24.20.0:

  • clean npm ci with all repository dependency patches applied and 0 audit vulnerabilities
  • npm run build:test and full workspace typecheck
  • focused onboarding/presenter tests: 27/27
  • full Desktop suite: 2667/2667
  • repository lint and git diff --check
  • renderer architecture: 112/112; E2E budget: 38 tests in 21 files
  • production Desktop build, renderer entry attestation, and third-party notice check

The current tree no longer contains the earlier dedicated onboarding Electron spec, consistent with the latest review note, so this update does not claim a fresh Electron E2E run. New CI and independent human review remain required.

@me2seeks me2seeks 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.

One expiry-boundary issue found on the current head; details are inline.

@Astro-Han Astro-Han 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.

Approved at 21c199e. Verified: the projected retry health is enum + count only — no error text, URL, or token can cross the IPC boundary; all six claimed clear paths (recovery, cancellation, expiry, denial, terminal failure, supersession) actually clear; the field rides the existing snapshot contract with no new channel; the transient classification set is union-equivalent to the old predicate; three locales complete. Two non-blocking notes: (1) errors thrown after the provider poll resolves — credential persist, connection warning — are now unconditionally terminal rather than retried, which is deliberate and tested but contradicts the body's "without changing retry thresholds" claim and deserves a line in the description; (2) in waiting state the retry line replaces the scan instruction rather than appending it. Also note the visual evidence in the body predates this head — worth one re-run of the modal on 21c199e before merge.

@me2seeks me2seeks 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.

P3 — Defensive malformed provider expiry response can poison the new retry schedule.

The DingTalk/Feishu adapters coerce expires_in/expire_in with Number(...) without checking finiteness. If a provider returns a truly malformed nonnumeric value, session.expiresAt becomes NaN; this new Math.min(retryAt, session.expiresAt ?? retryAt) then stores nextPollAt = NaN, and the snapshot's nextPollAfterMs is also NaN. The renderer's timer receives a non-finite delay, so the expiry/retry projection no longer has a bounded schedule. This is a defensive malformed-response edge rather than a normal OAuth response, so it is non-blocking.

/** Return true only when the next provider poll can run before QR expiry. */
private scheduleNextPoll(session: BotOnboardingSession): boolean {
const retryAt = this.now() + session.pollIntervalMs;
session.nextPollAt = Math.min(retryAt, session.expiresAt ?? retryAt);

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.

P3 — Defensive malformed provider expiry response can poison the new retry schedule. The DingTalk/Feishu adapters coerce expires_in/expire_in with Number(...) without checking finiteness. If a provider returns a truly malformed nonnumeric value, session.expiresAt becomes NaN; this new Math.min(retryAt, session.expiresAt ?? retryAt) then stores nextPollAt = NaN, and the snapshot's nextPollAfterMs is also NaN. The renderer's timer receives a non-finite delay, so the expiry/retry projection no longer has a bounded schedule. This is a defensive malformed-response edge rather than a normal OAuth response, so it is non-blocking.

@me2seeks me2seeks 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.

Reviewed current head 685d852. The only remaining observation is the published non-blocking P3 inline note about malformed provider expiry values; no blocking P0-P2 issue remains.

@me2seeks
me2seeks merged commit 5e58c20 into apache:main Sep 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/M Under 500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(bots): expose bounded redacted onboarding retry health

4 participants