Skip to content

Selective contribution to the built-in context target raises 'context' is undefined — dict form routes every target to the named-aggregator lookup #1687

Description

@Steve-Allison

Describe the bug

The schema allows a ContributeElement to be dict[str, ContributeValue], documented as
"Contribution of a specific value instead of the default one", and ContributeTarget includes
context. But contributing a specific value to the built-in context target fails at runtime:

text:
- def: STEP
  text: "FULL-RESULT-BODY"
  contribute:
    - result
    - context:
        value: "TINY-SUMMARY"
- "end"
PDLRuntimeError: Error during the evaluation of ${ context }: 'context' is undefined

The failure occurs during contribution processing itself — no downstream consumer of the context is
involved. The equivalent named-aggregator form (an aggregator: declared in defs, as in
examples/aggregators/contribute_in_file.pdl) works correctly.

Root cause (from reading the interpreter)

In process_contribution, the plain-string cases result / context return early, but the
dict() case has no special-casing for the built-in targets: after evaluating the value it falls
through to get_contribute_aggregator(block, target, scope, loc), whose str() branch does
get_var(target, scope, loc) and requires the result to be an Aggregator. context is not a
scope variable, so the lookup raises; if a variable named context did exist, it would then fail
"An aggregator was expected". The same applies to result as a dict target.

Expected behavior

contribute: [result, {context: {value: <expr>}}] contributes the evaluated value to the
background context in place of the block's result — the "small summary to context, full result
returned" pattern the schema description implies — mirroring how the plain context target and the
named-aggregator dict form already behave.

Versions / reproduction

Why it matters

This is the language's only mechanism for contributing a compressed representation to the
accumulated context while returning the full result — the natural tool for large-payload pipelines.
As it stands, the schema advertises the capability and the interpreter cannot execute it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions