UAT: yaml format output keys not sorted — spec requires sorted keys for deterministic output #4503

Open
opened 2026-04-08 13:54:25 +00:00 by HAL9000 · 0 comments
Owner

Bug Report

Feature Area: Output Rendering Framework — YAML Format
Severity: Low
Discovered by: UAT tester (uat-worker-output-rendering-001)


Summary

The yaml format output from OutputSession.YamlMaterializer does not sort top-level envelope keys. The spec requires sorted keys for deterministic output.

Expected Behavior (per spec)

The spec defines the yaml format as:

Sorted keys for deterministic output.

The top-level envelope keys should be sorted alphabetically: command, data, exit_code, messages, status, timing.

Actual Behavior

from cleveragents.cli.output import OutputSession, YamlMaterializer
import yaml

strategy = YamlMaterializer()
with OutputSession(format='yaml', command='test', strategy=strategy) as session:
    panel = session.panel('Test')
    panel.set_entry('Key', 'Value')

output = strategy.get_output()
data = yaml.safe_load(output)
print(list(data.keys()))
# Output: ['command', 'status', 'exit_code', 'data', 'timing', 'messages']
# Expected: ['command', 'data', 'exit_code', 'messages', 'status', 'timing']

The keys are in insertion order, not sorted alphabetically.

Root Cause

In src/cleveragents/cli/output/materializers.py, the YamlMaterializer._serialise method uses sort_keys=False:

class YamlMaterializer(_AccumulateStrategy):
    def _serialise(self, snapshot: StructuredOutput) -> str:
        return yaml.safe_dump(
            _snapshot_to_dict(snapshot),
            default_flow_style=False,
            sort_keys=False,  # ← Should be True for spec compliance
            allow_unicode=True,
        ).rstrip("\n")

Fix Required

Change sort_keys=False to sort_keys=True in YamlMaterializer._serialise and YamlMaterializer._serialise_dict:

class YamlMaterializer(_AccumulateStrategy):
    def _serialise(self, snapshot: StructuredOutput) -> str:
        return yaml.safe_dump(
            _snapshot_to_dict(snapshot),
            default_flow_style=False,
            sort_keys=True,  # ← Changed to True
            allow_unicode=True,
        ).rstrip("\n")

    def _serialise_dict(self, data: dict[str, Any]) -> str:
        return yaml.safe_dump(
            data,
            default_flow_style=False,
            sort_keys=True,  # ← Changed to True
            allow_unicode=True,
        ).rstrip("\n")

Note: The format_output() function in formatting.py also uses sort_keys=False for YAML, so both paths need to be fixed for consistency.


Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: uat-tester

## Bug Report **Feature Area:** Output Rendering Framework — YAML Format **Severity:** Low **Discovered by:** UAT tester (uat-worker-output-rendering-001) --- ## Summary The `yaml` format output from `OutputSession.YamlMaterializer` does not sort top-level envelope keys. The spec requires sorted keys for deterministic output. ## Expected Behavior (per spec) The spec defines the `yaml` format as: > **Sorted keys** for deterministic output. The top-level envelope keys should be sorted alphabetically: `command`, `data`, `exit_code`, `messages`, `status`, `timing`. ## Actual Behavior ```python from cleveragents.cli.output import OutputSession, YamlMaterializer import yaml strategy = YamlMaterializer() with OutputSession(format='yaml', command='test', strategy=strategy) as session: panel = session.panel('Test') panel.set_entry('Key', 'Value') output = strategy.get_output() data = yaml.safe_load(output) print(list(data.keys())) # Output: ['command', 'status', 'exit_code', 'data', 'timing', 'messages'] # Expected: ['command', 'data', 'exit_code', 'messages', 'status', 'timing'] ``` The keys are in insertion order, not sorted alphabetically. ## Root Cause In `src/cleveragents/cli/output/materializers.py`, the `YamlMaterializer._serialise` method uses `sort_keys=False`: ```python class YamlMaterializer(_AccumulateStrategy): def _serialise(self, snapshot: StructuredOutput) -> str: return yaml.safe_dump( _snapshot_to_dict(snapshot), default_flow_style=False, sort_keys=False, # ← Should be True for spec compliance allow_unicode=True, ).rstrip("\n") ``` ## Fix Required Change `sort_keys=False` to `sort_keys=True` in `YamlMaterializer._serialise` and `YamlMaterializer._serialise_dict`: ```python class YamlMaterializer(_AccumulateStrategy): def _serialise(self, snapshot: StructuredOutput) -> str: return yaml.safe_dump( _snapshot_to_dict(snapshot), default_flow_style=False, sort_keys=True, # ← Changed to True allow_unicode=True, ).rstrip("\n") def _serialise_dict(self, data: dict[str, Any]) -> str: return yaml.safe_dump( data, default_flow_style=False, sort_keys=True, # ← Changed to True allow_unicode=True, ).rstrip("\n") ``` Note: The `format_output()` function in `formatting.py` also uses `sort_keys=False` for YAML, so both paths need to be fixed for consistency. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
HAL9000 added this to the v3.5.0 milestone 2026-04-08 17:42:07 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#4503
No description provided.