Skip to content

feat(workflow): per-step transcript producer (M25 G1 #175) - #123

Merged
kanfil merged 5 commits into
mainfrom
factory/m25-g1-transcripts
Dec 2, 2026
Merged

kanfil merged 5 commits into
mainfrom
factory/m25-g1-transcripts

Conversation

@motizamir-beep

Copy link
Copy Markdown

M25 G1 transcript producer. Ref-first per-step stdout + session dump, redacted at capture. Fail-soft producer, fail-hard caps 5MB/file 20MB/ref with trimmed. Retention fail-closed. Bot review fixes in: real-store extractor shapes, pause/budget capture, trimmed guard. Tests 33 green. AC-T1..T6 + G1 contract.

moti.zamir and others added 3 commits November 26, 2026 11:07
- recordStepTranscript: stdout + session dump, redacted at capture
- 5MB/file + 20MB/ref caps with trimmed retention class
- fail-soft: producer never fails the step
- 6 new contract tests, 17/17 green
@motizamir-beep motizamir-beep self-assigned this Nov 30, 2026

@kanfil kanfil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verdict

Outcome: not-merge-ready

Reviewed revision: head 39782305714bb818d64fb4c45ac450f828c9775e · base 58c9f889ad874e3c458d462353e6463084ad1a34 (target main) · merge mergeable. Read from a detached checkout at the exact head SHA (.adlc/worktrees/factory-review-3978230/), not the rendered diff. Scope: 5 files, +375/−13.

One-paragraph summary: The producer skeleton is right — redaction before write, fail-soft capture, fail-hard caps with a trimmed signal, deduped index, contract tests all green, CI green. But the session leg — the headline half of the producer — can never fire: nothing in the repo ever sets ADLC_AGENT_SESSION_ID, and even if it were set, nothing ties it to the step's own agent session. Each step will write an empty session.jsonl and index it as if a transcript existed. A second real bug: the full-sampled finalize branch overwrites a cap-hit trimmed record, erasing the terminal signal. A third: when the session leg trips a cap, the already-written (and larger, more valuable) stdout leg is left on disk but never indexed, so artifacts.json consumers cannot see it. Unverified-but-fair items (run-ref drill, secrets scan, release/pin/image rollout) sit with the human owner — see the merge-risk table — and are disclosed, not counted, in keeping with the local-session preview rule.

issue-conformance (governing brief: adlc-workspace#175, M25 G1)

Resolved to adlc-workspace#175 from the PR title/body reference (no closes/linked-issue syntax in the PR, hence no auto-close; the issue itself is cancelled/closed as of 2026-11-30 while #177 — which depends on this producer working — is spec-gated/InProgress). Criterion accounting against the issue's Success Criteria:

# Criterion Verdict Evidence
1 Trace + transcript suite green on main met (on this head; main runs post-merge) CI green on head 3978230 (10/10: e2e + mac/ubuntu/windows × node 18/20/22); node --test tests/workflow-trace.test.mjs tests/format-audit.test.mjs → 24/24 in the exact-head checkout
2 Released and pinned unverified — owned by human/code-owner No release tag and no agentic-container pin in this diff; handled as rollout evidence, not a counted finding (see merge-risk table)
3 Bundle + transcripts produced by the image not-met (counted: I1) The producer's session leg is unwired, so a run in the image records an empty steps/<step>.session.jsonl (see I1)
4 No secrets in run ref unverified — evidence available on request No gitleaks/trufflehog scan of an actual run ref exists; redaction-at-capture is unit-covered (glpat-SEEDgabriel0011223344 seeded-secret test) but an end-to-end ref scan is human-side evidence

Scope fencing: no Non-Goal overreach — all changes are inside producer/caps/tests; the S3 overlay (G2) and drill matrix (G5) are untouched.

visual-evidence

Scored not-applicable (no runnable producer evidence from a real run) for this iteration: the checked-out tree builds and its contract tests pass, but there is no transcript-producing run in this environment to screenshot or diagram beyond the flow already stated in ADR-548, and the governing issue is closed. Re-review on a fix push can re-score this pass against real steps/*.stdout.log / steps/*.session.jsonl output.

Merge risk

Row Rating Evidence
Verification poor Unit/integration coverage proves the producer given a session dump (trace.mjs G1 block, tests/workflow-trace.test.mjs:456–552, 24/24 green), but nothing proves the live path yields one: no producer sets the env, no step ties it to its own agent session (unverified: live session leg — I1); no run-ref secrets scan (unverified: ref scan, human-side)
Alignment decent Every hunk maps to the brief's item 1–3 text; no drive-by files (5 files: trace.mjs, agent.mjs, audit.mjs + 2 test files). Criterion 2/3 rollout pieces (release, image pin) live outside this diff and are disclosed, not smuggled
Impact decent Paths are telemetry-only (src/workflow/); not in sensitive-paths: (auth/, billing/, migrations/). Worst case is a misleadingly empty transcript file on the run ref, never a run failure (fail-soft everywhere)
Rollback cost good Pure additive telemetry; revert is one PR touching the same 3 source files; no migrations, no schema, no cross-service change
Error detection poor The failure mode is silence — empty session files that still get indexed as git-ref:// artifacts (trace.mjs:477–480) look healthy to ref consumers; nothing in the producer or the tests flags the empty case

Merge risk: high (driven by undetectable silent emptiness + unverified live path; rollout evidence sits with the human owner)

Suggested mitigations (advisory): fix I1 so the session leg is content-bearing; assert non-trivial session content in at least one test; run the run-ref secrets scan before merge; keep the release/pin/image drill (#177 path) as the follow-up gate. codeowners: none configured.

Important findings

I1: Session leg is structurally empty — nothing produces the session id it is scoped to

Nothing in the repository (or in the sibling runtime repos) ever sets ADLC_AGENT_SESSION_ID (repo-wide search: the only hits are the two consumers and the tests). runTask (src/run.mjs:53–72) spawns the agent with no session id (opencode run supports --session to create/continue one, verified against opencode v2.2.6), and runContextEnv (src/workflow/steps/agent.mjs:443–469) passes ADLC_RUN_ID / ADLC_STEP_* but never a session id. So emitStepTranscript → captureStepTranscript → dumpAgentSession(process.env.ADLC_AGENT_SESSION_ID ?? null) (agent.mjs:17–28, 474–486; trace.mjs:354–364) always resolves to [], writes an empty steps/<step>.session.jsonl, and then recordStepTranscript indexes the empty file as a real artifact (trace.mjs:477–480). Even if the env were set externally, it would name the caller's session, not the step's own freshly-spawned agent session — the producer has no mechanism (pre-created --session id, id emitted by the run, or newest-session lookup) to tie the dump to the step that ran. Repro: set any temp run dir, call the wired path without the env var, get {ok:true} plus a 0-byte indexed session file. Impact: criterion 3 of the governing brief ("run writes steps/<step>.session.jsonl") is met in letters only — the file exists but carries nothing, and #177's recovery proof depends on its content. Required correction: give the step agent a knowable session id (e.g. generate one per step and pass --session for opencode, with the equivalent for other agents) and read dumpAgentSession back with that id; add a regression test asserting the session file from the wired path is non-trivial, not just that the pure producer redacts. (Also note: dumpAgentSession only knows opencode SQLite — the brief's "opencode SQLite / Claude JSONL" includes a Claude path that has no implementation here; acceptable only if G1's lanes are opencode-only, otherwise the Claude leg is still missing.)

I2: full-sampled finalize overwrites a cap-hit trimmed record

markTrimmed sets manifest.retention_class = "trimmed" as the terminal signal (trace.mjs:326–345), and the unsampled-complete branch correctly preserves it (trace.mjs:288–296). But the sampled-complete branch unconditionally sets retention_class = "full-sampled", trace_pruned = false (trace.mjs:283–287). On any deployment with ADLC_TRACE_SUCCESS_SAMPLE_RATE > 0 (or an explicit sampleRate), a run whose transcript capture was stopped by the 5MB/20MB caps is reported as "full-sampled" — the cap-hit signal ADR-548 requires survive finalize is erased exactly where sampling is on. Required correction: guard the sampled branch the same way (if (manifest.retention_class !== "trimmed")), with a test that finalize-after-trim keeps trimmed under sampling.

I3: A cap tripped by the session leg leaves the on-disk stdout leg unindexed

recordStepTranscript writes steps/<step>.stdout.log first (trace.mjs:434), then builds the session text. If the session text exceeds TRANSCRIPT_MAX_FILE_BYTES, or pushes the projected total past TRANSCRIPT_MAX_REF_BYTES, the function marks trimmed and returns capped before the recordArtifact() calls (trace.mjs:464–480). The stdout file — the leg the brief explicitly keeps ("per-step stdout log ... survives per-step even when events.jsonl is success-pruned") and the more valuable debug half — exists on disk and will ship in the ref, but trace/artifacts.json has no entry for it, so index-driven consumers (dashboard, G5 drill scripts reading the index) cannot see it. Only the both-legs-fit path indexes both files. Required correction: index the stdout leg before the session-leg cap check (or run the artifact indexing per leg as each write completes), with a test asserting the stdout entry survives a session-leg cap.

Nits

N1: Step-scoped transcript uses the first 4000 rows, not the newest

defaultSessionQuery orders ORDER BY seq ASC LIMIT 4000 (trace.mjs:369–371), while the sibling audit query uses ORDER BY time_created DESC LIMIT 4000 (src/format/audit.mjs:125). Under the current 5MB-per-file cap this is cosmetic — a >4000-message step session is trimmed by bytes anyway — so consider DESC (or cap-then-index) for consistency so the retained slice is the most recent.

N2: No provenance of why capture was skipped

Every skip/cap path returns {ok:true, skipped:true} (trace.mjs:410–419, 466–474), indistinguishable from a real write except capped. An operator triaging an empty session.jsonl cannot tell "no env set" from "db missing" from "over cap" without reading code. Consider a small reason string (never failing, never logged with secrets).

N3: runId/stepId are joined into runDir without the SAFE_ID check the same file applies to env paths

captureStepTranscript builds the run dir from raw ids (agent.mjs:19–22) while runContextEnv gates the identical join on SAFE_ID (agent.mjs:450). Today context.runId/config.id come from the engine, but the exported helper is one careless caller away from a path escape. Cheap hardening: apply the same SAFE_ID guard in captureStepTranscript.

Pass notes

  • bugs — stdout legs survive every exit point the producer was placed at (7 emitStepTranscript calls incl. SIGINT/timeout/blocked/question-budget paths); per-file and projected per-ref caps are both byte-measured via Buffer.byteLength (not char length); resume-overwrite dedups artifacts by path (trace.mjs:534–537). The 4 full-suite failures (679/682/685/690) are pre-existing single-branch-clone environment failures, identical on main per the #119 precedent; not regressions.
  • security — redaction happens before every write (redactDeep on stdout at trace.mjs:427, per-string session redaction at trace.mjs:453, plus redactRunDir before ref push); agent-writable step output cannot smuggle stdout in (reserved in RESERVED_OUTPUT_KEYS, agent.mjs:390–391); session-id → SQL interpolation is quote-doubling with no shell in the path (execFileSync("sqlite3", …), trace.mjs:369–378). Extractor fallback record.parts (audit.mjs:24) only reshapes store-native opencode parts, still gated on the row not being user.
  • spec-compliance — matches ADR-548's producer shape (post-step files + git-ref:// scheme + 5MB/20MB + fail-soft/fail-hard split + retention on failure) modulo the gaps in I1–I3; no S3/Argo-chart changes (brief Non-Goals respected).
  • test/ci-integrity — 6 new tests assert the contract (redaction, fail-soft, caps, retention, extractor, dedup); existing suites unaffected; CI green on the head.
  • quality — additive, small helpers, comments cite the ADR at each decision point; no dead code introduced.

@kanfil kanfil added the validation Passed automated factory-review validation; awaiting human approval label Nov 30, 2026
…n session cap

I1: mint per-step session id (runId-stepId) for opencode --session, dump that
session post-step; other agents stay stdout-only. Skip indexing empty
session files. N3: SAFE_ID guard on capture ids.
I2: sampled finalize no longer overwrites terminal trimmed.
I3: index stdout leg at write so a session-leg cap can't leave it unindexed.
N1: session query newest-first (DESC). N2: reason on every skip/cap return.
@motizamir-beep

Copy link
Copy Markdown
Author

Review fixes pushed as 54debc5 — all 6 findings addressed, mapped to kanfil's verdict on 3978230:

I1 — session leg unwired (blocker). Nothing set ADLC_AGENT_SESSION_ID, so every step wrote an empty session.jsonl indexed as a real artifact. Fix (opencode-only, per your scoping call): runAgentStep mints a per-step id runId-stepId (stepSessionId()), passes it as opencode run --session via new sessionFlag profile field threaded through buildRunCommand/runTask, sets ADLC_AGENT_SESSION_ID for the agent env, and emitStepTranscript passes the same id back so the post-step dump reads this step's own session. Other agents have no session flag — stdout-only, never fails. Empty session files stay on disk but are no longer indexed (reason: empty-session). Files: src/registry.mjs, src/run.mjs, src/workflow/steps/agent.mjs, src/workflow/trace.mjs.

I2 — sampled finalize overwrote trimmed (blocker). Cap-hit runs reported full-sampled under sampling, erasing the terminal signal. Fix: sampled branch now guards if (retention_class !== trimmed) before setting full-sampled (unsampled branch already did). Test: finalize-after-trim keeps trimmed under sampleRate: 1 — verified PASS. File: src/workflow/trace.mjs finalizeTrace.

I3 — session cap left stdout unindexed (blocker). Session-leg cap returned before recordArtifact(), so the on-disk stdout leg shipped in the ref invisible to index consumers. Fix: stdout leg is written + indexed immediately at write; session-leg cap paths return after, stdout already indexed. Empty session legs skip indexing. File: src/workflow/trace.mjs recordStepTranscript.

N1 — ASC vs DESC. Step query took oldest 4000 rows, audit takes newest. Fix: defaultSessionQuery now ORDER BY seq DESC LIMIT 4000 to match. File: src/workflow/trace.mjs.

N2 — no provenance on skip. Every skip/cap path returned bare {skipped: true}. Fix: all paths now carry reason (trimmed, ref-cap, stdout-cap, session-cap, empty-session, redact-failed, bad-ids, etc.) — never logged secrets, fail-soft preserved. New test pins stdout-cap + reason type. Files: src/workflow/trace.mjs, src/workflow/steps/agent.mjs, tests/workflow-trace.test.mjs.

N3 — SAFE_ID guard. captureStepTranscript joined raw ids into runDir while runContextEnv gates on SAFE_ID. Fix: capture now returns reason: bad-ids unless both ids pass SAFE_ID. File: src/workflow/steps/agent.mjs.

Verification: I2 trim-survives-sampling PASS, empty-session skip + stdout-indexed PASS, --session wiring + no-session unchanged PASS, stdout-cap reason PASS, transcript dedup PASS (isolated scripts; full-file node --test hangs in this sandbox on git-dependent setup, unrelated to the diff). Requesting fresh verdict.

Hang: recordStepTranscript now totals raw session text before redacting;
over TRANSCRIPT_MAX_FILE_BYTES trims immediately (8ms vs hours). URL
credentials regex scheme bounded {0,31} — 2MB single-letter redacts in ~150ms.
O1: expected ADLC_AGENT_SESSION_ID r26-intent. emitStepTranscript passes
sessionId only for sessionFlag agents. Guard test pins redact linearity.
@motizamir-beep

Copy link
Copy Markdown
Author

CI cause confirmed — ours, not infra. Fixed in 750f677:

Hang: I3 test fed 6MB of y through redactSecrets before the size check; the URL-credentials regex scheme [a-z0-9+.-]* rescanned from every position (80KB took ~3s, 6MB took hours), so every test job sat in Run tests to the limit. Two-part fix: recordStepTranscript now totals raw session text first and trims with reason: session-cap before any redaction (6MB path now 8ms); regex scheme bounded to {0,31\} (2MB redacts in ~150ms, URL masking unchanged). Guard test pins 2MB under 1s.

O1 failure: agent spawn now sets ADLC_AGENT_SESSION_ID; exact-env assertion updated to expect r26-intent.

Step 6: emitStepTranscript passes sessionId only when the step's agent profile has sessionFlag — other agents skip the sqlite lookup.

Local: step-output 32/32 green, workflow-trace 24/24 green, npm test E2E passed. Head 750f677 pushed — watch for 9 green jobs (~6 min).

@motizamir-beep
motizamir-beep requested a review from kanfil December 1, 2026 12:16

@kanfil kanfil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verdict

Outcome: merge-ready

Reviewed revision: head 750f6771c5eea2fb2b4866c6acc47737c9b4c737 · base 58c9f889ad874e3c458d462353e6463084ad1a34 (target main) · merge MERGEABLE. Read from a detached checkout at the exact head SHA (.adlc/worktrees/factory-review-750f677/), not the rendered diff. Scope: 9 files, +556/−18.

One-paragraph summary: The M25 G1 per-step transcript producer is complete and correct on this head. I1 (unwired session leg — the prior blocker) is resolved: runAgentStep mints a per-step runId-stepId id, passes it via opencode --session (sessionFlag profile + buildRunCommand/runTask threading, verified --session exists in installed opencode run --help), sets ADLC_AGENT_SESSION_ID for that step's agent env, and captureStepTranscript/emitStepTranscript dump that same session post-step — other agents skip the sqlite lookup by design (stdout-only, never fails). I2 (sampling overwrote trimmed) and I3 (session-cap left stdout unindexed) are fixed with passing guards; N1/N2/N3 addressed. CI is 10/10 green on this head; workflow-trace 24/24 and workflow-step-output + format-audit 39/39 pass in the exact-head checkout. Redaction precedes every write, fail-soft holds, caps are byte-measured with a terminal trimmed signal. No new Important findings.

Important findings

None.

Nits

N1 — Early-exit paths skip transcript capture without marking

Two runAgentStep failure exits return before any emitStepTranscript: unknown agent/integration (agent.mjs:108) and spawn/start failure (agent.mjs:151). Every post-spawn exit (SIGINT, timeout, fast-failure, blocked, question-budget, pause, completion) captures correctly, but a spawn failure leaves no steps/<id>.stdout.log for that step — the absence is silent in the index. Fail-soft is preserved either way; consider a best-effort emitStepTranscript with the (possibly empty) stdout on these two paths, or a reason: spawn-failed skip entry, so ref consumers can distinguish "step never spawned" from "producer missed a step".

N2 — Session leg is empty for command steps by design, undisclosed in docs

CommandStep.execute (agent.mjs:600+) has no transcript hook — only runAgentStep emits. That matches the M25 G1 agent-transcript scope, but a run mixing command: and agent: steps will have transcript gaps with no per-step reason. Consider documenting that steps/*.stdout.log coverage is agent-steps-only, or adding the same fail-soft emit to the command path.

Merge risk

Row Rating Evidence
Verification good trace.mjs G1 block + 13 contract/guard tests (workflow-trace.test.mjs:456–652, 24/24 in exact-head checkout); I1/I2/I3 guards assert session wiring, trimmed persistence, stdout-index-on-session-cap; CI 10/10 green on 750f677
Alignment good Every hunk maps to the brief (post-step redacted files + git-ref:// index + 5MB/20MB fail-hard + fail-soft + retention); no drive-by files (9 files: producer + wiring + 3 test files)
Impact decent Telemetry-only (src/workflow/); worst case is a misleadingly empty/skipped transcript file, never a run failure
Rollback cost good Pure additive telemetry; revert is one PR touching the same sources; no migrations, no schema, no cross-service change
Error detection good Failure mode is now visible: every skip/cap path carries reason (trimmed, ref-cap, stdout-cap, session-cap, empty-session, bad-ids, redact-failed); caps mark trimmed on the manifest

Merge risk: low

@kanfil
kanfil merged commit 5ae23e0 into main Dec 2, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

validation Passed automated factory-review validation; awaiting human approval

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants