Skip to content

fix(client): とまり comes back by itself when its role was not read at startup - #1151

Open
eichann wants to merge 2 commits into
mainfrom
fix/tomari-gate-retry
Open

eichann wants to merge 2 commits into
mainfrom
fix/tomari-gate-retry

Conversation

@eichann

@eichann eichann commented Dec 5, 2026 •

Copy link
Copy Markdown
Owner

概要(オーナー向け)

  • 直ること: 0.7.10 で起動直後に「とまり」が消える件(「AIへの相談」の上のとまりの行も、受け箱の「とまりに話しかける」も出ない。設定を開いて閉じると戻る)。これからは、起動直後にサーバーへの確認が間に合わなくても、数秒〜最大2分ほどのうちに自分でとまりが出ます。設定を触る必要はありません。
  • 原因: 起動直後はサーバーへの問い合わせが混み合い、1件に6秒以上かかっていました(この PC の起動記録 startup-timeline.log の 0.7.10 の行:会社一覧の取得が最大 6.3 秒)。とまりを出してよいかの確認(会社での役割の読み取り)は5秒で打ち切るため、「分からない」が「出さない」と同じ扱いになり、そのあと誰も聞き直していませんでした。サーバーの記録で 200 が返っているのは、アプリ側が待つのをやめた後にサーバーが答えたためです。
  • 変わらないこと: とまりを出してよいかの判断(関所)は弱めていません。会社の人でない・「とまりを使う」がオフ・この AI では使えない、というはっきりした「いいえ」には聞き直しません。オフにすれば今までどおりすぐ全部消えます。分からない間は今までどおり何も出ません。
  • サーバーへの負担: 聞き直すのは「分からない」ときだけ、2・5・15・30・60 秒後の最大5回で終わり(その後は設定を閉じたとき・とまりが変わったときだけ)。1回につき会社一覧の取得は多くて1件です。

Details (English)

Confirmed cause. tomari:open (→ session.open → gate.shown) is asked once when the company comes on screen. The gate reads the role with GET /api/companies cut at ROLE_READ_TIMEOUT_MS (5 s). The owner's startup-timeline.log for 0.7.10 shows every server call in that window taking ~6.3 s (api:getCompanies=3x…/max 6274 ms, writeAccess:get max 6379, api:getDepartments 6301, …; the company opened at 8.1 s, the shell at 8.2 s), so the role read aborted → null → { offered: false, reason: 'not-shown' }, which the slot never asked again (only keyEpoch — the settings closing — or tomari:changed did). The server logged 200 because it answered after the client had aborted. The sign-in race (gate.forget() in onSignedIn) is not the trigger at startup: onSignedIn runs inside auth:getSession, before the renderer has a user and so before the slot's first open; it is still covered (a dropped read is now 'unknown').

Change.

  • electron/features/tomari/gate.ts: new answer(companyId): Promise<boolean | 'unknown'> (shown = answer === true, so every other caller is unchanged). 'unknown' = switch on, signed in, and the role read failed / timed out / was refused / was dropped by a sign-in change. A definite no = switch off (also turned off during the read), nobody signed in, or the server answered without this company. companyRoleFromServer now throws on a non-OK response instead of returning null (a 503 or 401 is "not read", not "not in the company"). An unknown role is still never kept.
  • electron/features/tomari/session.ts: open returns reason: 'unknown' for the gate's 'unknown' (still no id); main passes tomariGate.answer.
  • shared/tomari-screen.ts: tomariOpenMayAskAgain (only 'unknown', 'signed-out', 'unreachable') and TOMARI_OPEN_ASK_AGAIN_MS = 2, 5, 15, 30, 60 s.
  • src/features/tomari/hooks/useTomariSlot.tsx: after such a no, one timer at a time re-runs the same open path; reset on a definite answer or an offer, cleared on the subscription's cleanup (company / account / settings change, unmount).
  • Rule file chat-and-agents.md ("Who sees とまり: one gate") updated.

Checklist 1 — invariants. (a) No id from tomari:open unless the gate answers true now — unchanged; the retry only re-asks the same gate. (b) 「とまりを使う」 off is a definite no (also when turned off during the read) and closes everything at once as before. (c) Re-asking is bounded (≤ 5 per subscription, ~2 min) and never follows a definite no or 'agent'. (d) An unknown role is never kept. Guarded by tests/tomari-gate.test.ts (new: 'unknown' vs definite no as open's reason; dropped-by-sign-in → 'unknown'; switched off during a failed read → false; refused → throws) and tests/ui/tomari-talk.spec.ts (new, Playwright clock: a role not read at startup → the box and pinned row come by themselves; never read → exactly 1 + 5 asks then nothing until the settings close; a definite no → asked once). Mutation-checked: disabling the slot's timer, retrying on any no, unbounded retries, open mapping 'unknown' to 'not-shown', the gate returning null for a dropped read, the switch re-check, and !response.ok → null each fail a test.

Checklist 6 — what cannot be undone. IPC contract: TomariOpenResult.reason was already a free-form string (log only); a new value 'unknown' is additive and older screens treat it as before (not offered). No DB, wire format or push-marker change. Permission boundary unchanged (main decides; the renderer only asks again).

Checklist 7 — failure, time, concurrency. Stops halfway / runs twice: a retry is just another tomari:open; concurrent asks share the gate's one in-flight read (reading). Company or account switch during a wait: the subscription cleanup clears the timer, and a late answer for another key is ignored (onScreen.current !== k). Server down for long: 5 extra asks then quiet. Clock: browser timers only; the gate's kept-role clock is unchanged (performance.now()).

Reviews. codex review --base origin/main: no actionable findings. Second opinion (agy, read-only): (1)(2) an older tomari:open answering after a newer one (settings closed meanwhile, A→B→A) could overwrite what is held and arm retries on the new subscription — fixed: only the latest open's answer applies (opens counter), test 「an older ask answering late changes nothing」, mutation-checked; (4) the subscription did not re-run when only the account changed — fixed (userId in its deps). (3) a tomari:changed during a settings reopen can reuse the previous id from the closure — pre-existing and unchanged by this PR; main closes every id at switch-off (session.closeAll), so such an id runs no turn, read or save; left as is.

Decisions for the owner

  • Ask again from the screen with a fixed, short schedule (2/5/15/30/60 s) rather than main announcing tomari:changed after sign-in: the cause was a timeout, not a missing sign-in signal, and a signal-only fix would not help. Safe side: bounded, at most 5 extra GET /api/companies per app start in the bad case.
  • A refused / server-error answer for the role counts as "not read" (asked again, still not shown), not as "not in the company". Shown nothing meanwhile, as before.
  • 5 s role timeout kept (not raised): the retry covers slow startups without making every gate question wait longer.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HCZRwqpGXuZgGQRpurpGKB

eichann and others added 2 commits December 5, 2026 09:08
…tartup

The gate now tells a role it could not read (timeout, offline, refused, a
sign-in under the read) from a definite no; tomari:open answers
reason 'unknown' for the former, and the slot asks again a few times
(2, 5, 15, 30, 60 s) — never after a definite no.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HCZRwqpGXuZgGQRpurpGKB
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.

1 participant