Skip to content

fix: context button for an LLM node cannot be interacted with within an agent workflow - #8216

Merged
peslyn merged 1 commit into
v3from
pr@v3@fix_context_button_for_an_llm_node_cannot_be_interacted_with_within_an_agent_workflow
Nov 30, 2026
Merged

peslyn merged 1 commit into
v3from
pr@v3@fix_context_button_for_an_llm_node_cannot_be_interacted_with_within_an_agent_workflow

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

fix: context button for an LLM node cannot be interacted with within an agent workflow

enableException: typeof args.enable_exception === 'boolean' ? args.enable_exception : Boolean(node.properties.enableException),
})
if (defaultMissing) {
return new ErrorResult(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review

1. Bugs / correctness

a) Hard failure on unrelated updates (regression risk)

if (enableContext && !contextVariable.length) {
  return new ErrorResult('开启「上下文」需要先绑定入参 materials ...')
}

enableContext falls back to Boolean(nodeData.enable_context). For any node that already has enable_context === true but no materials binding (legacy nodes, or nodes configured before this change), every update call now fails — including updates to prompt, tools, is_result, etc. — until the user either binds materials or explicitly passes enable_context: false. That breaks the documented contract of update ("只传要设置的字段,其余保持不变") and is a silent behavior break for existing workflows.

Fix: only validate when the user is changing context state, e.g.

const contextExplicit = typeof args.enable_context === 'boolean' || materialRefs.length > 0
if (contextExplicit && enableContext && !contextVariable.length) { ... }

or auto-disable instead of erroring:

const enableContext = materialRefs.length ? (args.enable_context ?? true) : false

b) Silent data loss with multiple materials refs

const contextVariable = materialRefs.length ? [...materialRefs[0]!] : ...

context_variable is a single [nodeId, field] reference, but materialRefs is a list. If the parent binds more than one, all but the first are dropped without warning. Either:

  • error/warn when materialRefs.length > 1, or
  • change context_variable to an array and store all refs.

c) Silent clearing of an existing context_variable

: Array.isArray(nodeData.context_variable) ? [...nodeData.context_variable] : []

If context_variable is currently a non-array shape (legacy/object/string), Array.isArray is false → it becomes [], i.e. the value is wiped on an unrelated update. Safer: only write the key when you actually have something to write:

const patch: Record<string, unknown> = {}
if (materialRefs.length) patch.context_variable = [...materialRefs[0]!]
// otherwise leave the existing value untouched

d) materials type changed to an invalid JSON Schema type

- type: 'array', items: {}, description: '...'
+ type: 'any',

"any" is not a valid JSON Schema type. With Ajv (or any spec-compliant validator) this throws schema is invalid: data/properties/materials/type must be equal to one of the allowed values at compile time — the whole update tool would break. Use one of:

materials: { description: '...', 'x-bind': 'context_variable' }                 // untyped
materials: { type: ['string', 'array', 'object'], description: '...' }          // draft-07 style
materials: { anyOf: [{ type: 'string' }, { type: 'array' }, { type: 'object' }] }

If your validator is custom and accepts 'any', at least document that — it's non-standard and will confuse anyone reading it as JSON Schema.

e) Schema/doc contradiction
materials now says "可为字符串、数组或对象 … 绑定后写到 context_variable", but the comment says context_variable is a single [节点ID, 字段] reference. The description implies the caller can pass a literal value or multiple entries, which the implementation cannot honor. Align the wording with the actual constraint (a single bound upstream variable).

2. Type-safety / robustness

  • [...materialRefs[0]!] — the non-null assertion is required by noUncheckedIndexedAccess, but note the spread produces string[], not a tuple. If the backend expects exactly [nodeId, field], a ref like [nodeId, 'a', 'b'] will produce an invalid 3-element value. Destructure explicitly and validate length.
  • node.properties.enableException — will throw if properties is ever undefined. Use node.properties?.enableException. Also verify the field really lives under node.properties (camelCase) rather than node_data: everything else is node_data + snake_case, and this asymmetry is a likely source of a "setting silently doesn't persist" bug. Consider a helper (readExceptionFlag(node) / writeExceptionFlag(node, v)) so read and write locations can't drift.
  • Boolean(nodeData.enable_context) vs the previous (nodeData.enable_context ?? false) is equivalent — no issue, just noise in the diff.
  • Nested ternary:
typeof args.enable_context === 'boolean' ? args.enable_context : materialRefs.length ? true : Boolean(...)

Correct but trips no-nested-ternary; prefer:

const enableContext =
  typeof args.enable_context === 'boolean' ? args.enable_context
  : materialRefs.length ? true
  : Boolean(nodeData.enable_context)
  • context_variable is written even when enable_context is false. Decide whether that's intentional (keeps binding for a later toggle) or should be cleared; document it either way.

3. Prompt / tool-description consistency

  • The condensed system prompt drops guidance for model_params_setting, tools_location, and enable_context. The model now has no instruction on those fields beyond the schema descriptions — acceptable, but for tools_location ("customize" vs "reference") and model_params_setting the schema text is terse; consider keeping a one-line hint or the model will guess.
  • The prompt references get_field_options, and the update description promises auto-validation — make sure get_field_options is actually registered in this agent's tools array (the diff only shows update). If it isn't, the model will call a non-existent tool.
  • enable_exception is added to the schema and to the update description, but the system prompt never mentions exception handling. Minor, but worth a clause so the model knows when to enable it.

4. Optimization suggestions

  1. Replace the ad-hoc boolean/normalization logic with small helpers, e.g. pickBoolean(args.x, fallback) and toContextRef(materialRefs).
  2. Build a single patch object and write once, so you can omit keys you don't intend to change (context_variable, model_params_setting) instead of always writing defaults — reduces accidental overwrites and diff noise.
  3. Add a console.warn/telemetry when materialRefs.length > 1 and only the first is used, so the truncation is observable.
  4. For enable_exception, prefer reading the same source you write to, and add a unit test asserting update({prompt}) does not mutate enableException or context_variable.
  5. Add tests for the four cases: (i) materials bound + no enable_context arg → on; (ii) materials unbound + enable_context: true → error; (iii) legacy node with enable_context: true, no materials, unrelated update → should succeed; (iv) multiple materials → defined behavior (error or all stored).
  6. Error message could include the concrete remedy ("bind materials or pass enable_context: false") — it partially does; make it explicit that false is allowed.

@peslyn
peslyn merged commit f3a161d into v3 Nov 30, 2026
3 of 4 checks passed
@peslyn
peslyn deleted the pr@v3@fix_context_button_for_an_llm_node_cannot_be_interacted_with_within_an_agent_workflow branch November 30, 2026 06:12
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