Tolerate a stale Notion database ID and title property - #12
Draft
dplakon wants to merge 1 commit into
Draft
Conversation
`find_company_page()` failed outright in the deployed environment: the
configured GRAINIAC_NOTION_DATABASE_ID answers Notion 404 because that
database is not shared with the integration, and the configured
GRAINIAC_NOTION_TITLE_PROPERTY was not a property of the database that
is shared. Either misconfiguration silently breaks the create-vs-update
decision, and the "no page found" path would create duplicate company
pages next to the real ones.
- Resolve the database once via `resolve_database()`: use the configured
ID when the integration can read it, otherwise discover the shared
database with /search (disambiguated by GRAINIAC_NOTION_DATABASE_NAME).
- Read the title property from the database schema instead of trusting
config, warning when the configured name does not exist.
- Match company names case-insensitively after the exact-title query, so
a name inferred from an email domain ("Chargepoint") finds the
existing page ("ChargePoint") instead of creating a duplicate.
- Fall back to a /search title lookup if the database is unreachable
entirely, since page and block writes do not need database access.
Every fallback logs to stderr so the underlying misconfiguration stays
visible rather than being papered over.
Co-Authored-By: Oz <oz-agent@warp.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Found while running the daily pipeline:
find_company_page()fails outright in the deployedgrainiacenvironment.GRAINIAC_NOTION_DATABASE_ID(3a043263616d803d98de000c5b916204) returns Notion 404 onGET /databases/{id},POST /databases/{id}/query,GET /pages/{id}andGET /blocks/{id}— that database is not shared with the integration.3a043263-616d-80bd-a6da-f099fa90796a), and its title property isAccount name— notCompany(the code default) and notName(the value configured in the environment).Both failure modes are worse than a crash. A wrong title property makes the title-equals query return zero rows, and a "no page found" result sends the meeting processor down the create path — writing duplicate company pages alongside the real ones. The name inferred from email domains (
Chargepoint,Imc) also never title-matches the real page names (ChargePoint,IMC), so even a correctly configured database would produce duplicates.Both meeting-processor agents had to independently hand-roll a
/search-based workaround to get their work done.Change
resolve_database()resolves(database_id, title_property)once and caches it. It uses the configured ID when the integration can actually read it, and otherwise discovers the shared database viaPOST /search, disambiguated by the new optionalGRAINIAC_NOTION_DATABASE_NAME.GRAINIAC_NOTION_TITLE_PROPERTYis honored only if it actually exists on the database; otherwise the real title property is used and a warning is logged.find_company_page()tries the exact title query, then falls back to a case-insensitive scan of the database (paginated), soChargepointresolves to the existingChargePointpage.find_company_page()falls back to aPOST /searchtitle lookup. Page and block writes need no database access, so the rest of the processor works unchanged._database_id()/_title_property()keep their signatures, and explicitdatabase_id/title_propertyarguments still win, so existing callers are unaffected.Verification
Against the live workspace, with the stale ID and wrong title property still set in the environment:
The two resolved page IDs match the pages the meeting-processor agents updated by hand.
Note for maintainers
This makes the code resilient, but the environment config is still wrong and should be corrected independently:
GRAINIAC_NOTION_DATABASE_IDshould point at3a043263-616d-80bd-a6da-f099fa90796a(or that database should be shared with the integration), andGRAINIAC_NOTION_TITLE_PROPERTYcan simply be unset.Conversation: https://app.warp.dev/conversation/f92e17e1-1b36-44b0-bfd9-41425daff5c8
Run: https://oz.warp.dev/runs/019fcb24-a1bf-7109-9854-cab556a23ecc
This PR was generated with Oz.