Skip to content

fix(graphile-llm): add {col}Text only to inputs that carry {col} - #2006

Open
theothersideofgod wants to merge 2 commits into
mainfrom
feat/llm-companion-needs-vector-field
Open

theothersideofgod wants to merge 2 commits into
mainfrom
feat/llm-companion-needs-vector-field

Conversation

@theothersideofgod

Copy link
Copy Markdown
Contributor

Why

The schema must not offer an input that writes nothing. Text sent in {col}Text either reaches the vector column or is refused.

LlmTextMutationPlugin added {col}Text to a create input or patch for every vector column of the table. It did not check whether the input type has {col} at all. A patch omits {col} when the role cannot update that column (PostGraphile turns the missing column UPDATE grant into -attribute:update). The companion was still added, with the description "Natural language text to embed server-side into the embedding vector column". At plan time applyRule embeds the text and sets embedding on the input value (embed-inputs.ts:218). No field applies it, so the vector is dropped. The update succeeds without it, or, when {col}Text was the only field sent, fails with "no new values".

Rules touched: R9

Before / after

Live, on a local fun up (GraphQL image constructive:9b764d6, whose graphile-llm source is identical to main). The tenant's files table: the request role has SELECT but no UPDATE on embedding. The caller is the owner.

step before (9b764d6) after (9b764d6 + this file)
AppFilePatch input fields matching embedding* embeddingText (no embedding) none
updateAppFile(patch: { filename, embeddingText }) succeeds; filename changes; the vector's md5 and embedding_updated_at do not BAD_USER_INPUT: Field "embeddingText" is not defined by type "AppFilePatch"
updateAppFile(patch: { embeddingText }) "Attempted to update a record, but no new values were specified." BAD_USER_INPUT, same message
patches whose vector column is writable (docEmbedding/docEmbeddingText, embedding/embeddingText on a chunks table) both fields both fields

For "after", only the built dist/plugins/text-mutation-plugin.js (CJS and ESM) was layered onto the pinned image. graphql-public was pointed at that image and then set back to the pinned one.

Unit (embed-inputs.test.ts, fake embedder, a table whose embedding carries @behavior -attribute:update, the behavior PgRBACPlugin derives from a missing column grant):

cd graphile/graphile-llm
npx jest src/__tests__/embed-inputs.test.ts -t offers     # test commit only
  ✕ offers {col}Text only on inputs that can write {col}
    FrozenDocPatch: expected [], received ["embeddingText"]
npx jest                                                  # this branch
  Test Suites: 6 passed, 6 total
  Tests: 103 passed, 103 total   (rebased on 1dceb60e5)

The new test also asserts that sending embeddingText to that patch is a validation error and that the embedder is never called.

The change

if (!vectorField) continue; before required is computed. The companion follows the vector field. Where the input can write {col}, nothing changes, including the NOT NULL create path that makes {col} optional. The plugin's doc comment now says "inputs that carry the vector column's own field" instead of "every vector column".

The lookup is right: the plugin names the field with inflection.attribute({ codec, attributeName }), the same call PgAttributesPlugin uses, and runs after it (after: ['PgAttributesPlugin', …]).

Is this how it was meant to work

No. The field's own description says the text is embedded into the column. The plugin header says the plugin "injects the resulting vector into the actual column". #1956 made sending both {col} and {col}Text an error: either input must land or fail loudly.

How it came about:

The suites run as the root role (useRoot: true, authRole: 'postgres'), where every column is writable. No test had a table with a column the role cannot update.

Behavior changes

was now why
{col}Text on an input with no {col} present; text embedded, then dropped absent; sending it is a GraphQL validation error the field could never write
GraphQL schema {X}Patch.{col}Text with the description "embed server-side into the {col} vector column" field removed from those types only

Clients that send {col}Text on such a patch now get a validation error instead of a silent no-op. The committed generated schemas in constructive-db, constructive (sdk/) and dashboard contain no input type with {col}Text and no {col}, so no SDK regeneration follows from this change. I scanned 30 .graphql files.

Relation to planning#2293

planning#2293 (open) proposes removing {col} and {col}Text from mutation inputs entirely (D2: backend-managed vectors). This PR does not anticipate that decision. It only stops offering the companion where it cannot write. If D2 lands, this line goes with the rest of the plugin.

Considered: removing companions from all mutation inputs now (D2). Rejected here, because that is planning#2293's decision to make, and it changes writable inputs too.

Generated with Devin

theothersideofgods and others added 2 commits November 16, 2026 18:16
A patch type without the vector field (the role may not update the column)
still gets the text companion, so the text is embedded and then dropped.
Fails until the companion follows the vector field.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The companion was added for every vector column of the codec, including
patches that omit the column because the role cannot update it. The text
was accepted, embedded, and written into a field nothing applies, while the
field's description says it lands in the column.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@luxor-code-review

luxor-code-review Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR adjusts the graphile-llm embedding input plugin and its tests so the schema plugin skips injecting embed-vector handling where it does not apply, while keeping the server-side embedding generation path intact.

Files Change
graphile/graphile-llm/src/plugins/text-mutation-plugin.ts Tightens the guard logic that decides when embedding companion fields and vector inputs are added to Create/Patch input types.
graphile/graphile-llm/src/__tests__/embed-inputs.test.ts Updates the embed-inputs test suite to match the new gating behavior, including the case where the embedder is not called.

Reviewed commit: d9e213b

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.

2 participants