Decisions
Options considered and why they lost
Architecture
gaia.phoneis a plain Python package with no imports fromgaia.uior the daemon’s routes. The daemon hosts it and mounts its router.- One send path.
PhoneService._place_calland_send_textare the only code that reaches the provider. Each one re-reads the phone book from the store and refuses a number that isn’t verified. The rule engine, the routes and the agent tool all go throughraise_alert, never to the provider directly. - Escalation runs in the daemon as one asyncio task per open alert. Alert state lives in
SQLite (
~/.gaia/phone/phone.db), so a daemon restart resumes an open alert rather than losing or repeating it. - Outcome by polling. Calls are placed with answering-machine detection
(
MachineDetection=Enable). GAIA reads the call record every 3 s until it ends. Onlyanswered_by: humancounts as reached; voicemail,no-answer,busy,failedandcanceledall go on to the next step. A text is read the same way (delivered,undelivered,failed). - Reached stops the calls, not the alert. A call a person answered stops further calls and texts for that alert. The alert stays open in the apps until it is opened or marked handled.
- No double calls after a crash. Before calling, GAIA saves a
placingrow; it stores the provider’s call ID as soon as the provider returns it. On restart, aplacingrow with no ID is checked against the provider’s recent calls to that number before anything is redialed.
Alert sources
alert_owner’s reason is stored and shown in the apps. It is never spoken or texted.
A scheduled job alerts when its run raises. A job whose agent replies “I couldn’t do it” without
raising isn’t a failure to the scheduler and doesn’t alert.
Escalation
Each rule picks its steps:- Notify in the Agent UI and TUI.
- Text right away, or when nobody opens the alert within N minutes (default 5).
- Call after N more minutes (default 5), or right away for rules marked urgent.
- Call again once, two minutes later, to the same number. On iPhone, “Allow repeated calls” lets a second call within three minutes ring through Focus; setup tells you where to turn it on. If you have a second number, the next step calls it.
Phone book
- Adding a number: you enter it in Settings › Phone (Agent UI) or the phone panel (TUI). GAIA calls it, or texts it if you pick that, and says a 6-digit code. You type the code into the same screen within 10 minutes. Three wrong codes cancel the attempt.
- Who can add one: neither the agent nor a rule can. When the phone book already has a number, adding another also needs a code sent to an existing number, so someone who controls only the new phone can’t finish it.
- The phone book is never empty while phone is on. The keys and the first number are one setup step, so phone turns on only once a number is verified. Removing a number needs a code sent to that number. The last number can’t be removed while phone is on; turn phone off first.
- Changes are announced by a call to the numbers already there (texts may not be approved yet), and the apps show them.
- Accepted risk: any process running as you can read the daemon’s client token, including an agent’s shell tool once you approve it. The code checks above are what stop such a process from adding its own number; it can’t finish one without a code from a phone already in the book.
- Verification calls count against the daily limit, at most 3 attempts an hour. The code is sent by call by default, because texts are usually blocked until the number is registered.
- Format: numbers are stored in E.164 (
+15551234567). The phone book refuses short codes, premium-rate prefixes and emergency numbers, before any code is sent.
The call (phase A)
- Ring. Caller ID shows your Twilio number. Setup has you save it as a contact, with Emergency Bypass on iPhone, or as a starred contact allowed through Do Not Disturb on Android.
- Answer. GAIA says its fixed sentence twice and hangs up. On a trial account, Twilio first plays its own trial notice and asks you to press a key.
- Voicemail. The same sentence, which has nothing private in it.
Talking on the call (phase B)
- Host: the Agent UI server, which owns the chat pipeline and mobile access’s tunnel. The
daemon’s phone service places the call with a script that connects a live audio stream to
wss://<tunnel>/api/phone/stream. The UI server checks the call’s one-time token with the daemon, then runs the turns there. Needs mobile access to be on and the Agent UI server running; without them, a call is the fixed sentence only. - The stream carries 8 kHz µ-law audio both ways and the digits you press.
- PIN first. GAIA asks for your PIN on the keypad. Until you enter it, the call has only that alert’s own record: no files, web, memory, shell or email tools. Three wrong PINs end the call and alert you in the apps.
- After the PIN, it is voice mode over the phone with the same spoken-reply contract. Approvals aren’t taken on a call; GAIA says that you need to be at the PC.
- The stream is accepted only with the one-time token in that call’s script, and only while that call is live.
- Calls are saved to the call log with their transcript.
Calling GAIA (phase C)
You call GAIA’s number from a number in your phone book. Caller ID can be faked, so GAIA always asks for the PIN first. Three wrong PINs block that caller for an hour and alert you.Setup
Settings › Phone in the Agent UI, and/phone in the TUI. You never use a command line:
- Explain. What calls are for, the cost (about $1.15 a month for a US number and about 1.4¢ a minute, Twilio list price, November 2026), and that calls and texts cross the phone network.
- Account. Sign up at Twilio (linked). On a trial, verify your own number in the Twilio console too; a trial can call only numbers verified there.
- Keys. Paste the Account SID and Auth Token, then the Twilio number calls come from. GAIA checks them against the account at once and shows the provider’s own error if one fails.
- Phone book. Add your number with the code check.
- Rules. Turn each source on, choose its steps, quiet hours and limits.
- Test. A button sends a test alert through every step it would use.
Texts
- US: carriers block texts from numbers that aren’t registered. A toll-free number needs toll-free verification; a local number needs 10DLC registration as a sole proprietor. Twilio advises against starting toll-free verification on a trial, so texts may not work until the account is upgraded. Setup shows texts as “Not approved yet” until a test text is delivered.
- Canada and other countries follow the provider’s own rules; Canada has no 10DLC.
- Calls work while texts wait for approval.
Failure states
Every failure shows in the phone settings, and on the alert itself when it happens during one. No failure quietly becomes a different channel.Privacy
- What the provider sees: your number, GAIA’s number, the time, the call length, and the fixed sentence. For talking on a call (phase B), also the audio, which travels over the phone network unencrypted once it leaves the provider.
- What never leaves the PC: files, email, task output, agent text, the call log and the transcript.
- The apps say this on the setup’s first screen.
Test strategy
- Unit: the phone book (E.164 checks, refused prefixes, code expiry and attempts, the second-number rule), the send path refusing unverified numbers, limits and their reset, cooldown merging, quiet hours across midnight, escalation timing and stopping, restart resuming open alerts.
- Contract: Twilio request shapes (form fields,
Twiml, basic auth, the account path) against a fake Twilio HTTP server, and the status values GAIA maps from. - Security: an agent tool call with a phone number in its reason, a rule pointing at an unknown number, a code submitted through the agent’s token, a flood of alerts against the limits.
- Apps: Settings › Phone and
/phonescreens in every state with the Simulated provider, with screenshots. - Real: one real call and text with a Twilio account before each release candidate.
Delivery sequence
Out of scope and open questions
- Email-sender alerts wait for DKIM/DMARC checks on the sender.
- A PC that is off. An alert that the PC went offline has to come from somewhere else.
- Contacting anyone but you.
- Arabic. The fixed sentences are translated; Twilio’s voice for Arabic is checked before it ships.