You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 27, 2026. It is now read-only.
The two context tables (agent_turn_context and agent_bootstrap_context) evolved separately and have inconsistent column naming and constraints. This creates confusion and maintenance overhead.
Current state
agent_turn_context:
context_type (UNIVERSAL/GLOBAL/DOMAIN/AGENT)
context_key — scope identifier (domain name, agent name, or *)
document_name — redundant with context_key since there's only one row per scope
Unique: (context_type, document_name)
agent_bootstrap_context:
context_type (UNIVERSAL/GLOBAL/DOMAIN/AGENT)
domain_name — set for DOMAIN type
agent_name — set for AGENT type
document_name — distinguishes multiple documents within a scope
context_key vs domain_name/agent_name — same concept, different names
document_name is redundant in turn context (one row per scope)
No enforcement that UNIVERSAL and GLOBAL have only one row each
COALESCE in unique index is ugly — separate columns for the same logical field
Changes
1. agent_turn_context
Dropdocument_name column
Renamecontext_key → context_name
New unique constraint: (context_type, context_name)
context_name values: '*' for UNIVERSAL/GLOBAL, domain name for DOMAIN, agent name for AGENT
2. agent_bootstrap_context
Dropdomain_name and agent_name columns
Addcontext_name column (replaces both)
Keepdocument_name (bootstrap has multiple documents per scope)
New unique constraint: (context_type, context_name, document_name)
context_name values: '*' for UNIVERSAL/GLOBAL, domain name for DOMAIN, agent name for AGENT
3. Shared pattern
Both tables use context_type + context_name as the scope identifier. Bootstrap adds document_name as a third dimension for multiple documents per scope.
4. Enforce UNIVERSAL/GLOBAL uniqueness
agent_turn_context: Add partial unique index — only ONE row where context_type = 'UNIVERSAL', only ONE row where context_type = 'GLOBAL'
agent_bootstrap_context: UNIVERSAL/GLOBAL can have multiple rows (multiple documents), but all share context_name = '*'. Uniqueness is already handled by (context_type, context_name, document_name)
5. Update dependent code
get_agent_turn_context() function — query uses context_name instead of context_key
get_agent_bootstrap() function — query uses context_name instead of domain_name/agent_name
Background
The two context tables (
agent_turn_contextandagent_bootstrap_context) evolved separately and have inconsistent column naming and constraints. This creates confusion and maintenance overhead.Current state
agent_turn_context:context_type(UNIVERSAL/GLOBAL/DOMAIN/AGENT)context_key— scope identifier (domain name, agent name, or*)document_name— redundant withcontext_keysince there's only one row per scope(context_type, document_name)agent_bootstrap_context:context_type(UNIVERSAL/GLOBAL/DOMAIN/AGENT)domain_name— set for DOMAIN typeagent_name— set for AGENT typedocument_name— distinguishes multiple documents within a scope(context_type, COALESCE(agent_name, ''), COALESCE(domain_name, ''), document_name)Problems
context_keyvsdomain_name/agent_name— same concept, different namesdocument_nameis redundant in turn context (one row per scope)COALESCEin unique index is ugly — separate columns for the same logical fieldChanges
1.
agent_turn_contextdocument_namecolumncontext_key→context_name(context_type, context_name)context_namevalues:'*'for UNIVERSAL/GLOBAL, domain name for DOMAIN, agent name for AGENT2.
agent_bootstrap_contextdomain_nameandagent_namecolumnscontext_namecolumn (replaces both)document_name(bootstrap has multiple documents per scope)(context_type, context_name, document_name)context_namevalues:'*'for UNIVERSAL/GLOBAL, domain name for DOMAIN, agent name for AGENT3. Shared pattern
Both tables use
context_type+context_nameas the scope identifier. Bootstrap addsdocument_nameas a third dimension for multiple documents per scope.4. Enforce UNIVERSAL/GLOBAL uniqueness
agent_turn_context: Add partial unique index — only ONE row wherecontext_type = 'UNIVERSAL', only ONE row wherecontext_type = 'GLOBAL'agent_bootstrap_context: UNIVERSAL/GLOBAL can have multiple rows (multiple documents), but all sharecontext_name = '*'. Uniqueness is already handled by(context_type, context_name, document_name)5. Update dependent code
get_agent_turn_context()function — query usescontext_nameinstead ofcontext_keyget_agent_bootstrap()function — query usescontext_nameinstead ofdomain_name/agent_nameprotect_bootstrap_context_writes()trigger — references column namesagent-turn-contexthook (handler.ts) — if it references column namesdb-bootstrap-contexthook (handler.ts) — column name referencesgraybeard_sync_pub) — WHERE clauses reference column namesMigration strategy
context_namefrom existingdomain_name/agent_name/context_keyConstraints
agent_turn_context, one GLOBAL rowagent_turn_contextagent_turn_contextdocument_name)