ductor icon indicating copy to clipboard operation
ductor copied to clipboard

[Bug]: trace message on cron codex

Open attid opened this issue 9 months ago • 2 comments

What happened?

Title
Cron jobs with provider=codex leak raw JSONL event stream to Telegram when task should return empty output

Summary
In Ductor cron execution with provider=codex, tasks that should produce no output sometimes send raw Codex JSONL events (e.g. thread.started, item.started) to Telegram.
This breaks “notify only on non-empty result” behavior for silent-success cron tasks.

Environment
• Ductor running in Docker • Cron job provider: codex • Example job: docker-notifier-guard (hourly) • Job is designed to be silent when notifier is already running

Expected behavior
If a cron task has no user-facing result, Telegram should receive nothing (or status-only handling should still treat it as empty).

Actual behavior
Telegram receives a message like:

TASK: Docker Notifier Guard

{"type":"thread.started",...} {"type":"turn.started"} {"type":"item.started",...} ...

This appears even when the task should be silent.

How to reproduce

  1. Create a cron task with provider=codex.
  2. Task instruction should enforce a silent-success path (e.g. run a script that exits 0 with no stdout when everything is fine).
  3. Ensure script returns empty stdout in the common/success path.
  4. Let cron run.
  5. Observe that sometimes Telegram receives raw JSONL event stream instead of no message.

Likely root cause
In ductor_bot/cron/execution.py, parse_codex_result() does:

result_text, _thread_id, _usage = parse_codex_jsonl(raw) return result_text or raw[:2000]

When Codex produces no final assistant message (empty result_text), fallback returns raw JSONL stream, which is then treated as non-empty cron result and delivered.

Suggested fix
In parse_codex_result(): • If output is valid Codex JSONL events and parsed result_text is empty, return "" (not raw[:2000]). • Keep raw fallback only for truly non-JSON/unparseable output.

Possible logic:

  1. Detect that raw is JSONL event stream (parse_codex_jsonl can parse at least one event line).
  2. If parsed text is empty -> return empty string.
  3. Only use raw[:2000] when output is not recognizable Codex JSONL.

Additional hardening (optional)
In cron delivery/sanitization layer, ignore lines that are pure Codex event JSON ({"type":"thread.started"...} etc.) for status=success, unless explicitly requested for debug mode.

Impact
• Noisy false-positive Telegram alerts. • Breaks “silent on success” automations (especially guard/watchdog tasks). • Confusing operational signal for users.

Steps to Reproduce

How to reproduce

  1. Create a cron task with provider=codex.
  2. Task instruction should enforce a silent-success path (e.g. run a script that exits 0 with no stdout when everything is fine).
  3. Ensure script returns empty stdout in the common/success path.
  4. Let cron run.
  5. Observe that sometimes Telegram receives raw JSONL event stream instead of no message.

Expected Behavior

Suggested fix
In parse_codex_result(): • If output is valid Codex JSONL events and parsed result_text is empty, return "" (not raw[:2000]). • Keep raw fallback only for truly non-JSON/unparseable output.

Possible logic:

  1. Detect that raw is JSONL event stream (parse_codex_jsonl can parse at least one event line).
  2. If parsed text is empty -> return empty string.
  3. Only use raw[:2000] when output is not recognizable Codex JSONL.

Additional hardening (optional)
In cron delivery/sanitization layer, ignore lines that are pure Codex event JSON ({"type":"thread.started"...} etc.) for status=success, unless explicitly requested for debug mode.

Operating System

Linux

Environment

Local (pip install)

Which LLM provider?

Codex

ductor version

7

/diagnose output


Relevant log output


LLM self-diagnosis (optional)

No response

Additional context

No response

Before submitting

  • [x] I have searched existing issues for duplicates.
  • [x] I am running the latest version.

attid avatar Feb 27 '26 22:02 attid

Thanks for reporting this — your analysis was spot on.

parse_codex_result() was falling back to raw[:2000] when result_text was empty, which leaked the raw JSONL event stream to Telegram instead of treating it as no output.

This is fixed in v0.8.0. The raw fallback now only applies when the output is not recognizable as Codex JSONL. If the stream was successfully parsed but contains no assistant text, an empty string is returned.

ductor upgrade

PleasePrompto avatar Feb 28 '26 09:02 PleasePrompto

thanks

attid avatar Mar 03 '26 12:03 attid