Skip to content

feat(integrations): let agents discover company connections - #264

Merged
allisonmahmood merged 2 commits into
mainfrom
portal/251-connections-group
Sep 16, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
portal/251-connections-group

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

Agents need to discover company connections and inspect their schemas without going through the SDK catalog.

Adds member-readable connection routes with connection state, declaration hints, offered integrations and immutable snapshots. Missing snapshots return null. Removes the SDK catalog route and keeps the existing CLI catalog and add commands working against the replacement reads until the discovery CLI lands.

Stacked on portal/250-read-path (#263). This PR targets that branch, not main, and contains only the connections work for #251.

Closes #251.

Verification:

  • Typecheck and lint passed.
  • Full offline suite passed: 795 tests across 78 files. After review corrections, all 166 tests across the five affected suites passed.
  • Isolated runtime smoke checks covered member-token reads, catalog 404, and packed CLI shared-table and Postgres declarations.
  • Standards and spec re-reviews have no remaining findings.

Implemented with OpenAI GPT-6 Astra using Oh My Pi.

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area size:l 501-1,000 changed lines labels Sep 15, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Astra review

Reviewed 0a1b4c8292ac9b11bc2cc05af1414df85213ae8a against origin/portal/250-read-path at 1f5f321c7c375026776f9219a32efcd8c51c9524, using git diff origin/portal/250-read-path...HEAD. Spec: #251. One pass, no subagents; merge blockers only.

Standards

No merge-blocking method or YAGNI findings. The implementation uses the existing connection store and HttpApi patterns. I found no added abstraction or future feature that warrants blocking this change.

Spec

No merge-blocking intent findings. Both connection reads admit active members, remain company-scoped, and expose the required hints and snapshot metadata. Missing current snapshots return null. The SDK catalog route and Generation.catalog are removed. Retaining the connections-only CLI catalog is explicitly permitted by #251; migrating shared-table add keeps its existing behavior available after the route removal.

Verification

158 tests passed across ConnectionsApi.test.ts, cli.test.ts, SdkApi.test.ts, ApiGuard.test.ts, and api-md.test.ts. These cover the new routes, member access, disconnected hints, all, snapshot timestamps/null, catalog 404, CLI behavior, and generated API documentation.

An isolated CLI check also confirmed that a declared connection_storage_failed 503 produces exit 2 with kind: rejected, as ADR-0004 requires for decoded wire refusals.

Summary: Standards 0 blockers; Spec 0 blockers. No blocking issue in either axis.

@allisonmahmood allisonmahmood left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two-axis review of portal/251-connections-group vs portal/250-read-path (0a1b4c8), against issue #251. Extra passes on intent, the implementation method, and YAGNI.

Standards

Documented

  1. detail failures are labeled get. Effect service conventions ask for the operation as structured context. ConnectionStorageFailed.operation has no "detail" (ConnectionStore.ts). SqlConnectionStore.detail maps SQL/schema failures with safe("get") (SqlConnectionStore.ts:128). A failed handle read looks like get in diagnostics. Add "detail" and pass it, or keep get on purpose because this is the same storage read.

  2. Handle stuffed into ConnectionNotFound.id. Same rule, entity identifier. get/snapshot put a connection id in id. detail passes the handle (SqlConnectionStore.ts:119, ConnectionStoreDev.ts:39). Callers that read id get a handle. The HTTP 404 body still uses the generic message, so this is internal. Add a handle field, or a lookup error, rather than reusing id.

  3. ADR-0002's group list is stale. PatchyApi is still described as the auth, patches, sdk and runtime groups (docs/adr/ADR-0002-api-is-the-contract-package.md:31-33). This PR adds ConnectionsGroup. packages/api/src/api.ts:2 still omits connections. Issue #251 also says "ADR-0002 unchanged", so this is a standards/spec collision, not a silent miss.

Judgement

  1. takenAt clocks differ. SQL takes takenAt from connection_snapshots.created_at (SqlConnectionStore.ts:108-126). Dev uses lastDiscoveredAt (ConnectionStoreDev.ts:43-54). Production writes both from the same now, so live rows match. The API test seed sets them to different instants, and the in-memory fixture has no snapshot timestamp. Same wire field, two clocks in tests/dev.

  2. Wire assembly is duplicated in SQL and Dev ({ handle, description, status, snapshot: null | { ...snapshot, revision, takenAt } }). One helper on the port would stop them drifting.

  3. No 503 case. ConnectionsApi.test.ts covers 200/401/404. It does not inject ConnectionStorageFailed → 503. ConnectionStore tests never call detail.

  4. Project.add shared-table path smuggles HTTP status through a mutable observed box and HttpClient.tap (Project.ts:519-538) instead of responseMode: "response-only". Copied from Api.publish. Hidden side channel.

No Effect import/layer/runPromise breaches on the new group. Namespace imports and module-level Schema.encodeSync match the house style.

Spec

(a) Missing or partial. None of the ticket's required behaviour is missing. GET /api/connections and GET /api/connections/:handle, ConnectionSummary fields, connected hint patchy add postgres/<handle>, disconnected reason: not_connected with /company/connections in hint, all → offered, snapshot: null rather than an empty database, bearer / active member, catalog route and Generation.catalog gone, HttpApiTest.groups cases, catalog 404 in ApiGuard, Integrations glossary, CONTEXT-MAP.md, ADR-0002 left unchanged.

(b) Behaviour that was not asked for. Spec: "patchy catalog still compiles against the client until ticket 5 removes it: keep the CLI building by pointing catalog at the new connections route for one merge." The diff also rewrites patchy add shared-table onto GET /api/patches/:patchRef?state=all (declarable, 404 → patch_not_openable, null inventory → source_unavailable), plus ADR-0004, docs/product.md, README, and skills for that path. Ticket 3 owns the patch read path. This PR had to retarget add once the catalog no longer returned shared tables, or the CLI would stop building. Necessary follow-through, wider than the sentence about catalog.

(c) Implemented, but the two detail clocks disagree. Spec: "GET /api/connections/:handle → the connection with its current immutable snapshot and takenAt." SQL uses snapshot created_at. Dev uses lastDiscoveredAt. The connections seed sets those to different instants (2026-02-01 vs 2026-01-02), so the two implementations can disagree on takenAt.

Intent versus issue 251

Full match on the thing the ticket exists for.

#251 is ticket 4 of the portal build. Catalog mixed connections and shared tables. Ticket 3 moved shared tables onto the patches read path. This ticket owns the connections half as a first-class connections group, and deletes GET /api/sdk/catalog so nothing keeps serving the old combined shape.

That is what landed. List is summaries only. Drill-down is one handle's current immutable snapshot, or snapshot: null. Disconnected rows stay listed, and their current snapshot stays readable. No credentials, display host, or business rows. offered.connected means "any postgres is connected", which is what the old catalog did. Member machine token, not admin, not cookie.

The leftover patchy catalog command is the admitted one-merge bridge, not a second discovery product. Skills still teach pnpm patchy catalog. That is ticket 5 (#252). The wire is already list-then-detail. Ticket 5 can delete the command and grep for catalog.

Method

Sound, with nits.

The package cut is the same as PatchesApi / AuthApi / SdkApi. Schemas and ConnectionsGroup live in packages/api. ConnectionsApi is an HttpApiBuilder.group module in packages/integrations, not a second Context.Service. apps/server only mounts the layer. Extending ConnectionStore with detail is the right move. Composing list + snapshot at the handler cannot do this join: get is by id, snapshot() 404s a missing current revision, and takenAt belongs on the snapshot row.

Leaking the wire ConnectionDetail type into the store is the one shape I'd change later. list still returns domain rows and the handler adds hint / reason / offered. getConnection is a pass-through encode. A domain join { handle, description, status, snapshot, revision, takenAt } encoded in the handler would match list. Precedent exists (Patches already returns wire inventory). I would not rewrite this PR for it.

SQL LEFT JOIN ... AND s.revision = c.metadata_revision is the actual rule: current snapshot or null, never an older row pretending to be current. The pending fixture (revision 4, only snapshot 3) proves that. Catalog removal does not break generate or add. Auth is group-level bearer Authorization. No admin check. Cookie is 401, which matches this ticket. Parent #247's "portal reuses this read path with a browser session" is a later consumer of the store, not of cookie /api.

I would ship this shape.

YAGNI

This is the smallest honest 251.

Hardcoded offered: [{ integration: "postgres", connected: rows.some(...) }] is the same one-liner deleted from Generation.catalog. Postgres is the only integration. A registry would be for Gmail.

Hints stay in the HTTP handler. The store stays domain. Schema.encodeSync sits at module scope. Generation.catalog, the Catalog schema, the sdk handler, and the shared-table-list stage are gone. Guard treats /api/sdk/catalog as 404. No patchy list, no inspect command, no extra error class for a missing snapshot.

Dev detail is a second implementation because the in-memory fixture has no snapshot created_at, not because someone invented a port for fun.

The HttpClient.tap status box on shared-table add is the one piece that is not simple. responseMode: "response-only" is already used in the new tests.

README.md still says packages/sdk does "authenticated catalog and generation". CONTEXT-MAP's sdk line was updated. Small leftover, not new machinery.

Summary

Standards: 3 documented findings (worst: ConnectionNotFound.id holding a handle), 4 judgements (worst: takenAt clocks). Spec: 0 missing requirements, 1 follow-through wider than the catalog sentence (add shared-table), 1 wrong-looking takenAt split between SQL and Dev. Method is sound. YAGNI holds. I would merge this and leave the catalog command for #252.

Reviewed with Grok 4.6.

@allisonmahmood

allisonmahmood commented Sep 15, 2026 •

Copy link
Copy Markdown
Owner Author

Reviewed the Astra conversation comment and Grok's Reviews-tab review against the source. There were no inline review comments. Fixes are in 7e9fb39.

Fixed

  • Grok 1, operation context. SQL detail failures now carry operation: "detail", rather than looking like id-based get failures.
  • Grok 2, lookup identity. ConnectionNotFound.lookup distinguishes { id, revision? } from { handle }. Both store implementations and every constructor use it; handles no longer masquerade as ids. The HTTP 404 stays unchanged.
  • Grok 4 / spec timestamp finding. Dev metadata now stores takenAt with its immutable snapshot revision. detail never borrows lastDiscoveredAt; metadata without the snapshot timestamp returns snapshot: null. The regression deliberately makes those clocks disagree and checks the missing-timestamp case.
  • Grok 6, missing failure coverage. Added real-Postgres outage coverage for list and detail. Both return private, no-store 503 responses with connection_storage_failed, without exposing SQL diagnostics. The case also verifies detail's operation context. Existing dev-store coverage now exercises detail and missing lookup identities.
  • Stale documentation. Removed authenticated catalog from the root README's SDK description and added connections to the API header.

Kept as is

  • Grok 3, ADR-0002. feat(integrations): the connections group; the catalog route removed #251 explicitly requires it unchanged. The architectural rule still holds: the API package owns the contract and each capability implements its group. Current group discovery is documented in the context map and API docs.
  • Grok 5, response assembly in SQL and dev. Kept the small projections in each adapter. Their inputs differ; a shared helper would add indirection without owning meaningful logic. Both implement the same typed detail contract. Fixed the timestamp source rather than introducing another abstraction.
  • Grok 7, CLI status observer. Kept the existing Api.publish pattern. Effect's response-only mode skips generated success and refusal decoding. Switching would require manual decoding to retain the existing CLI contract. The observer only specializes 404; the existing 404/401/503 regressions pass.
  • Shared-table add migration. Necessary follow-through: removing the combined catalog otherwise breaks this command. It now consumes ticket 3's patch detail route and preserves canonical ids, refusal classification and repair guidance.
  • Temporary catalog command. Explicitly allowed by feat(integrations): the connections group; the catalog route removed #251; removal belongs to feat(patchy): patchy list replaces catalog; the skills teach the discovery chain #252. No second discovery command was added here.
  • Wire-shaped detail return from the store. No observed correctness issue, and existing patch inventory follows the same pattern. A domain/wire redesign is not needed for this ticket.

Astra reported no blockers. No review finding remains unresolved.

Verification

  • Before the fixes, regressions failed on the wrong dev timestamp and get operation label. Both now pass.
  • 168 tests passed across ConnectionsApi, ConnectionStore, CLI, SDK API, API guard and generated API documentation suites.
  • pnpm typecheck and pnpm lint passed.
  • The first CLI run overlapped typecheck's bundle rebuild and hit MODULE_NOT_FOUND. Rerunning after the build completed passed all six suites; no unrelated CLI change was needed.

Latest-commit CI is now green for 7e9fb39cd97dc53bcf78c5cfc0666e5a969a7ffc: CI run 34934160466. Both full test jobs, lint/format/typecheck, packed CLI smoke, live Clerk, Postgres concurrency and dependency review passed; labeling passed too. The stacked base has no required-check rule, but all seven checks required by the main-branch policy passed. GitHub reports CLEAN and MERGEABLE against portal/250-read-path. No new review findings arrived after the push. No unresolved blockers; ready to merge, not merged.

@allisonmahmood
allisonmahmood force-pushed the portal/251-connections-group branch from 7e9fb39 to aebcfa1 Compare September 16, 2026 16:00
Base automatically changed from portal/250-read-path to main September 16, 2026 16:34
Add member-readable connection discovery and immutable snapshot details. Keep catalog and declaration editing working against the replacement routes, and update API docs and agent guidance.

Closes #251
@allisonmahmood
allisonmahmood force-pushed the portal/251-connections-group branch from aebcfa1 to 986ea11 Compare September 16, 2026 16:34
@allisonmahmood
allisonmahmood merged commit 16c5b09 into main Sep 16, 2026
8 checks passed
@allisonmahmood
allisonmahmood deleted the portal/251-connections-group branch September 16, 2026 16:42
allisonmahmood added a commit that referenced this pull request Sep 16, 2026
Agents could list company connections, but finding an existing tool or a
usable shared table still required direct API calls.

`patchy list` now follows the discovery chain from company patches to a
patch's tables, stores and reads, then to individual schemas. It
replaces `catalog`, preserves wire JSON and lifecycle refusals, and
teaches the same chain in all six skills and the CLI docs.

Stacked on `portal/251-connections-group` (#264), which provides the
connections API. This PR targets that branch and contains only the CLI
discovery work.

Closes #252.

## Verification

- `pnpm typecheck` and `pnpm lint` passed.
- `pnpm test --maxWorkers=4`: 821 tests passed across 78 files.
- `pnpm test:packed-cli-e2e` passed, including discovery against two
seeded patches through the installed CLI.
- Standards and spec reviews completed; all three standards findings
addressed, no spec findings.

One default-concurrency rerun timed out in an unchanged server startup
test. That file passed in isolation, and the full suite passed with four
workers without changing any timeout.

Implemented with `openai-codex/gpt-6-astra` using Oh My Pi.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:cli Touches the cli area area:docs Touches the docs area area:server Touches the server area size:l 501-1,000 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(integrations): the connections group; the catalog route removed

1 participant