Skip to content

fix(connectors): derive the flagship's mail scopes for --grant-agent - #4533

Closed
github-actions[bot] wants to merge 1 commit into
mainfrom
autofix/issue-4531
Closed

github-actions[bot] wants to merge 1 commit into
mainfrom
autofix/issue-4531

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Connecting a mailbox to the flagship agent with gaia connectors connect google --grant-agent installed:gaia failed with exit 5 and no sign-in link. The shipped flagship is a frozen binary, so the CLI couldn't read its mail requirement, and the daemon's copy of the flagship's details never listed one. Now the command prints the sign-in link, asks Google for read-only Gmail access (gmail.readonly) and nothing else, and grants that access to installed:gaia. The daemon still sends no OAuth tokens to the flagship.

Closes #4531

Test plan

  • python -m pytest tests/unit/connectors/test_grant_agent_scope_derivation.py -rs passes (the new CLI test fails on main with the exact exit-5 error from the issue)
  • python util/lint.py --all — black, isort and flake8 pass; the one pylint error is already on main, in files this PR doesn't touch
  • Manual, from a cold connector state (move ~/.gaia/connectors aside) with the flagship binary installed and a Google OAuth client configured: gaia connectors connect google --grant-agent installed:gaia prints a sign-in URL, and the consent screen asks only for read-only Gmail access
  • After consent, gaia connectors grants list google shows installed:gaia: https://www.googleapis.com/auth/gmail.readonly
  • gaia connectors connect google --scopes https://www.googleapis.com/auth/gmail.readonly still works as before

⚠️ Needs manual validation — the automated tests cover everything up to the OAuth call. A maintainer should run the steps above with a real Google account to confirm the consent screen and the stored grant.

🔍 Technical details
  • Root cause: register_installed_sidecars registers a binary-installed agent using AgentSidecarSpec.required_connections. The "gaia" spec left that field empty, so resolve_declared_scopes raised NoDeclaredScopesError. GaiaAgent.REQUIRED_CONNECTORS is only read when the gaia_agent wheel can be imported, and the shipped frozen binary doesn't provide it.
  • Fix: src/gaia/daemon/sidecars/spec.py adds _GAIA_REQUIRED_CONNECTIONS, written out as literals the same way _EMAIL_REQUIRED_CONNECTIONS is, so core never imports the hub wheel. It matches gaia_agent.connectors.MAILBOX_REQUIREMENTS: Google gmail.readonly, Microsoft Mail.ReadWrite, and the same reason strings.
  • forward_providers stays empty, so forward.py still refuses to send any token to the flagship. A test checks this.
  • Drift guards in tests/unit/connectors/test_grant_agent_scope_derivation.py:
    • The spec must match core's DECLARED_SCOPES. This runs everywhere.
    • The spec must equal MAILBOX_REQUIREMENTS. This is skipped when gaia_agent isn't importable; it passed locally with the hub source on PYTHONPATH.
  • End-to-end CLI test: runs the real AgentRegistry and register_installed_sidecars with list_installed faked to report the flagship binary. It asserts grant_agents == {"installed:gaia": [gmail.readonly]}.
  • Validation: full tests/unit/ run: 17,376 passed. The 32 failures and 8 collection errors are all environmental on this runner (missing cvss, responses, dateutil, sherpa_onnx, fitz, matplotlib, or a read-only site-packages / step-summary file). None touch connectors or sidecars.

…installed:gaia

`gaia connectors connect google --grant-agent installed:gaia` exited 5
because the flagship's sidecar spec declared no connector requirements,
and a binary install has no importable gaia_agent to read them from.

The spec now carries the flagship's mailbox requirement (gmail.readonly /
Mail.ReadWrite) for scope derivation only; forward_providers stays empty,
so the daemon still forwards no tokens to the flagship. Tests pin the spec
to DECLARED_SCOPES and to gaia_agent.connectors.MAILBOX_REQUIREMENTS.

Closes #4531
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Superseded by #4859 (same fix, rebased onto current main, with the CLI test running from the frozen-binary state).

kovtcharov-amd pushed a commit to aksh8b/gaia that referenced this pull request Oct 6, 2026
…installed:gaia (amd#4859)

`gaia connectors connect google --grant-agent installed:gaia` — the
documented way to connect a mailbox to the flagship — failed with exit 5
and no sign-in link for anyone running the shipped flagship. The
flagship ships as a frozen binary, so its declared mail requirement
can't be imported, and the daemon's own record of the flagship listed
none. That record now carries the same read-only requirement, so the
command prints the sign-in link, asks Google for `gmail.readonly` only,
and grants exactly that. No tokens are forwarded to the flagship.

Supersedes amd#4533 (same fix, rebased onto current main). Its command-line
test passed without the fix on any machine that has the flagship wheel
installed, so it now runs from the frozen-binary state.

Closes amd#4531

## Test plan
- [x] `pytest
tests/unit/connectors/test_grant_agent_scope_derivation.py` — 18 passed;
without the fix 3 fail, one with the exact exit-5 message from the issue
- [x] `pytest tests/unit/connectors` — 907 passed
- [ ] From a cold connector state (move `~/.gaia/connectors` aside) with
the flagship binary installed and a Google OAuth client configured: the
command prints a sign-in URL and the consent screen asks only for
read-only Gmail
- [ ] After consent, `gaia connectors grants list google` shows
`installed:gaia` with `gmail.readonly`
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.

fix(connectors): --grant-agent installed:gaia exits 5 — the flagship's mail scopes are never derived

1 participant