Skip to content

feat(workflow): workflow summary <run_id> end-of-run message - #119

Merged
itaior merged 5 commits into
mainfrom
feat/66-workflow-summary
Nov 24, 2026
Merged

itaior merged 5 commits into
mainfrom
feat/66-workflow-summary

Conversation

@itaior

@itaior itaior commented Nov 23, 2026

Copy link
Copy Markdown
Member

Refs https://gitlab.tikalk.dev/tikalk/engineering/agentic-sdlc/adlc-workspace/-/issues/66

Why

When a run ends, nothing says how it ended or which MR/PR it opened. The Argo lane has no completion gate any more (ADR-531-amendment-1). So #151 run 1b997ae3 opened adlc-workspace!166, and its Slack thread never showed the link. The issue owner asked to see the opened MR/PR in Slack. As decided at triage, the engine builds the summary from run state, and the agentic-container runtime only forwards it in the run thread, in a follow-up there (ADR-414/416).

What changes

  • New adlc-cli workflow summary <run_id> [--json] in src/workflow/summary.mjs, wired in commands/workflow.mjs, dispatch.mjs and help.mjs. It builds one message from the run's own files: state.json, inputs.json, log.jsonl and the trace events. It makes no network calls. The message covers:
    • the outcome, the workflow, and the duration;
    • the issue and the dispatch;
    • the failing step and its error. That's the step with its own error, so not an if wrapper around a rejected gate.
    • every MR/PR link (mr_url, plus mr_urls split on spaces and commas), http(s) only, each listed once, at most 10;
    • the conclusion (execute's wins);
    • each gate's answer and who gave it, or (auto) for an auto-passed gate;
    • one line per step, in the order they ran;
    • the resume count.
  • Step text is redacted with redactSecrets, kept on one line and capped at 300 characters per field. The whole text is capped at 3000 characters, so it fits one Slack message. --json prints the same data plus text.
  • A gate that takes its verdict from an input now records answered_by from ADLC_ANSWERED_BY, plain ids only (^[A-Za-z0-9._@-]{1,64}$). The runtime already sets that variable for question answers, and the follow-up sets it for gate answers too.
  • The README gets a command-table row.

Example output for the #181 drill run:

*Run 56d27c13 failed* · factory-lane · 6m 10s
Issue g/adlc-workspace#181 · dispatch supervised
Failed at `plan`: Agent step 'plan': blocked: dependency-gate on #66
MR/PR: none
Conclusion: blocked: dependency-gate on #66
Steps:
• ✓ run-branch: completed
• ✗ plan: failed

Not in this PR

  • MR head and CI status (named in the issue's goal). They need a tracker API call, and ADR-416 keeps the engine off the network. The runtime could add them later.
  • Posting to Slack. That's the agentic-container follow-up: post workflow summary once, after the terminal status, in the run thread; set ADLC_ANSWERED_BY on gate resumes.

Tests

  • New tests/workflow-summary.test.mjs with 10 tests:
    • S1: golden texts for a completed, a failed and an aborted run, plus the CLI's text and --json output and exit 1 for a missing run;
    • S2: a gate records the approver on approve and on reject, and records nothing when the variable is unset or isn't a plain id;
    • S3: links are listed once and split, and non-links are dropped;
    • S4: redaction, one line per field, the caps, and the whole text at most 3000 characters.
  • The CLI test, the two gate tests and the aborted golden failed before the code they pin.
  • Full npm test: 1128 of 1132 pass. The 4 failures are the same target-branch tests that fail on a clean main here.

🤖 Generated with Claude Code

itaior and others added 2 commits November 23, 2026 16:16
adlc-workspace#66: a run that ended left no message saying how it ended
or which MR/PR it opened; since the lane has no completion gate, #151's
thread never showed adlc-workspace!166.

`adlc-cli workflow summary <run_id> [--json]` builds one message from
the run's own files (state.json, inputs.json, log.jsonl, trace events):
the outcome and duration, the failing step and its error (the step with
its own error, not an `if` around a rejected gate), every MR/PR link of
every step, the conclusion (execute's wins), each gate's answer and who
gave it, one line per step, and resumes. Step text is redacted, one
line and capped; the whole text fits one chat message. No network.

A gate that takes its verdict from an input now records `answered_by`
from ADLC_ANSWERED_BY (a plain id only), so the summary can name the
approver.

Refs adlc-workspace#66

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… per supplied verdict

Security review of a9f8541:
- a gate line comes only from a step the engine logged as `gate`; any
  other step can write choice/answered_by to its own output;
- the summary text escapes & < > and breaks @here/@channel/@everyone, so
  step text cannot become chat links, mentions or broadcasts (the JSON
  fields keep the cleaned values);
- a gate credits ADLC_ANSWERED_BY only when its verdict input was
  supplied in this run/resume call (StepContext.suppliedInputs), not for
  a verdict kept from an earlier call.

Refs adlc-workspace#66

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@itaior

itaior commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Pushed 55631f7 after an automated security review of a9f8541. All three findings were real, and each one has a test that failed before its fix:

  • Forged gate lines (S5). Any step could write choice and answered_by to its own output and show up as an approved gate. A gate line now comes only from a step the engine logged as gate in log.jsonl. A step with no logged type gets no gate line.
  • Chat markup and mentions (S6). The rendered text now escapes & < > and breaks @here, @channel and @everyone with a zero-width space, so step text can't become links, mentions or broadcasts. The --json fields keep the cleaned, unescaped values.
  • Approval credited to the wrong person (S2). A gate now records ADLC_ANSWERED_BY only when its own verdict input was supplied in the current run or resume call, through the new StepContext.suppliedInputs. A verdict kept from an earlier call is no longer credited to whoever resumed later.

tests/workflow-summary.test.mjs now has 13 tests. Full npm test: 1131 of 1135 pass, with the same 4 target-branch failures as on main.

…first logged type wins

Security review of 55631f7:
- a gate records ADLC_ANSWERED_BY only when it was paused before this
  call and its verdict input was supplied now: a verdict preset at the
  start, or one a second gate shares, is not credited;
- the answerer may not start with "@" (gate and summary) and is escaped
  in the summary text, so it can never render as a mention;
- the summary takes a step's first logged type; a later log line cannot
  turn a step into a gate.

Refs adlc-workspace#66

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@itaior

itaior commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Pushed 8ee4dd7 after a second automated security review, this time of 55631f7:

  • Attribution was per call, not per gate (fixed). A gate now credits ADLC_ANSWERED_BY only when it was paused before this call and its verdict input was supplied now. A verdict preset at the start, or one a second gate shares, is no longer credited to anyone. New tests cover a preset verdict and two gates sharing one verdict input.
  • The answerer could render as a mention (fixed). answered_by may no longer start with @, in both the gate and the summary, and it is escaped in the text. A new test checks this.
  • Gate lines came from a forgeable source (hardened, not fully fixable). The first logged type of a step now stands, so a later log.jsonl line can't turn a step into a gate. A step with no logged type still gets no gate line. state.json is no stronger as an anchor: it sits in the same agent-writable run directory as log.jsonl. The summary is a report, not an authorization record; gate decisions are enforced by the engine at run time. I didn't reserve choice and answered_by in step output, because that would reject whole output files and the type check already covers the case.

The summary tests now pass 17 of 17. Full npm test: 1135 of 1139, with the same 4 target-branch failures as on main.

…log.jsonl

Security review: log.jsonl is not a trust source (anything in the
workspace can append to it). Gate lines now come only from the run copy
of the definition (runs/<id>/workflow.yml), the file the engine executes
and resumes from, via the engine's own gateStepIds. No readable copy: no
gate lines. log.jsonl stays an ordering hint.

Also: resumes are counted from log.jsonl (a paused or interrupted end with
entries after it), not from trace events, which are sampled and were
absent on a real paused-and-resumed run. A test now runs a real pause and
resume and checks the summary.

Refs adlc-workspace#66

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@itaior

itaior commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Pushed 022a29e, covering a third automated security review plus a bug I found while checking it against a real run:

  • Gate lines came from the log (fixed). log.jsonl isn't a trust source, since anything in the workspace can append to it. Gate lines now come only from the run's copy of the definition (runs/<id>/workflow.yml), the file the engine itself executes and resumes from, through the engine's own gateStepIds. If that copy can't be read, there are no gate lines. log.jsonl is only used for ordering. There are new tests for a forged log line and for a missing definition.
  • Resume count (bug, fixed). The count came from trace events, which are sampled: a real paused-and-resumed run had none, and showed 0 resumes. It now comes from log.jsonl: a paused or interrupted end with entries after it counts as one resume. A new test runs a real pause and resume through the engine and checks that the summary credits the approver and shows one resume.

The summary tests pass 19 of 19. Full npm test: 1137 of 1141, with the same 4 target-branch failures as on main.

…e gate keys

Security review: the run copy of the definition is as writable as the log,
and walking it does not match runtime ids (fan-out, loops). The engine
already records each step's type in its result (state.json
step_results[<id>].type, keyed by the runtime id); a gate line now needs
`type === "gate"` there. The definition walker is gone; log.jsonl stays an
ordering hint. `choice`, `answered_by` and `auto_passed` are reserved in
step output, so no agent or shell step can supply a gate's fields.

Refs adlc-workspace#66

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@itaior

itaior commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Pushed e595627 after a fourth automated security review. Both findings were valid, and one change covers them:

  • The trust anchor and the runtime ids. The run's copy of the definition is as writable as the log, and walking it doesn't map runtime ids such as fan-out items and loop bodies. The engine already records each step's type in its result (state.json step_results[<id>].type, keyed by the exact runtime id, written by the engine itself). A gate line now requires type === "gate" there. The definition walker is gone, and log.jsonl is only used for ordering.
  • Gate fields in step output. choice, answered_by and auto_passed are now reserved in readStepOutput, so no agent or shell step can supply them. A file that tries is rejected whole, as with every other reserved key. A blocked: conclusion is still read from the raw file (fix(workflow): a step that concludes blocked: fails the run #118).

What's left to forge is the engine's own state.json. Anything that can rewrite that can also rewrite the run's outcome, so the summary can't add protection there. Gate decisions are enforced by the engine at run time; the summary is a report.

The summary tests pass 20 of 20, including a real pause and resume through the engine. Full npm test: 1138 of 1142, with the same 4 target-branch failures as on main.

@itaior itaior left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

factory-review verdict — PR #119 workflow summary <run_id>

Outcome: 🟢 merge-ready — no Important findings open. Nits below are advisory only.

Reviewed revision: head=e5956276df2211193b16a2e5292215af3c7e21ed · base b2f7db89b433447dc1cc593be40115de3a8dd06c · merge-base b2f7db89b433447dc1cc593be40115de3a8dd06c
Scope: 10 files, +742/−1. Read from detached checkout at exact head SHA, not the rendered diff.

Checked

  • bugs — cleanField guards non-strings, readJson/readLines fail-closed to null/[], formatDuration guards non-finite/negative, resume counting reads log.jsonl defensively, conclusion/failed_step selection logic matches PR description (execute-wins, own-error-first). No null-deref, off-by-one, or leak paths found.
  • security — Gate-line trust anchor is the engine-recorded step_results[<id>].type === "gate" (not log.jsonl, not the definition copy, not step output); choice/answered_by/auto_passed are reserved in readStepOutput so agent/shell steps cannot forge them; answered_by requires all of: verdict-from-input + supplied-now + gate-was-paused + plain-id regex that rejects a leading @; rendered text escapes &<> and breaks @here/@channel/@everyone; step text redacted via redactSecrets, one line, per-field + whole-text caps; links http(s)-only, deduped, max 10. Each hardening has a failing-before test (S2/S5/S6).
  • spec-compliance — Matches the issue goal as scoped by the PR body: outcome + duration + issue/dispatch + failing step + MR/PR links + conclusion + per-gate answers + per-step lines + resume count, no network calls (ADR-416 direction), caps fit one chat message. Explicitly out of scope (MR head/CI status, Slack posting) is declared, not silently dropped.
  • test-integrity — New tests/workflow-summary.test.mjs (20 tests) only adds assertions; no existing assertion weakened. agent.mjs reserved-key change rejects whole files that smuggle gate fields (fail-closed, consistent with existing reserved-key behaviour); blocked: conclusion still read from raw file so refusal paths are preserved.
  • ci-integrity — No workflow files touched. CI green on this head (all listed checks pass); full npm test in checkout: 1138/1142, the 4 failures are the same target-branch tests that fail on clean main.
  • quality (Nit) — naming/length/complexity within norms; see advisory nits.

Not checked

  • Live Slack rendering of the zero-width-space mention break (unit-tested, not rendered in a real client).
  • Performance of buildRunSummary on very large log.jsonl (linear scan; acceptable for a report path).

Nits (advisory, non-blocking)

  • 💬 summary.mjs: types[id] from log.jsonl still populates step.type for display while the gate decision correctly uses only r.type — consider not surfacing log-derived types at all so display and decision can never diverge.
  • 💬 summary.mjs: conclusion keeps the last non-execute conclusion — a run with several conclusion fields reports only the last; fine for the stated contract, worth one line in help text if multi-conclusion runs exist.

Evidence

  • Intent: PR body (Why/What/Not-in-this-PR) + linked issue adlc-workspace#66.
  • Execution: tests/workflow-summary.test.mjs 20/20 in checkout; full suite 1138/1142 with only the 4 pre-existing main failures; CI checks green on head e595627.

@itaior
itaior merged commit 3b998ae into main Nov 24, 2026
10 checks passed
@itaior itaior mentioned this pull request Nov 24, 2026
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