Skip to content

fix(trace): compiled PASS traces omit persisted session steps #203

Open

Description

@coygeek

Summary

A completed recorded task can have steps in the session database while its compiled PASS-folder steps.json is []. artemis trace view consequently renders an empty step table. This report concerns step metadata only; it makes no claim about missing videos or other artifact types.

Steps to reproduce

From the main source checkout with its Python dependencies installed, run the following focused offline fixture with PYTHONPATH=.. It uses the real DataEngine step writer, SDK finalizer, and CLI trace viewer. It replaces IPC publication/connection and device-lock annotation with no-ops, supplies synthetic task/context objects instead of launching a task, waits for step writes to finish before finalization, and cleans up its temporary directory. No model, phone, host daemon, or screenshots are needed.

import asyncio
import json
import os
import tempfile
from datetime import datetime
from pathlib import Path
from types import SimpleNamespace
from unittest.mock import patch

root = Path(tempfile.mkdtemp(prefix='artemis-trace-probe-'))
os.environ['ARTEMIS_APP_DIR'] = str(root / 'app-state')
os.environ['ARTEMIS_TRACES_DIR'] = str(root / 'fixture' / 'traces')
os.environ['ARTEMIS_CONFIG_PATH'] = str(root / 'no-config.json')
import artemis.data_engine.engine as engine_module
from artemis.data_engine.engine import DataEngine
from third_party.mobile_use.sdk.agent import AgentBase
from third_party.mobile_use.utils.media import create_steps_json_from_trace_folder
from artemis.interfaces.cli.commands.trace import view_trace

class OfflineEngine(DataEngine):
    def _connect_ipc_locked(self):
        return None
    def _publish(self, *args, **kwargs):
        return None

traces = root / 'fixture' / 'traces'
output = root / 'fixture' / 'output'
output.mkdir(parents=True, exist_ok=True)
name = 'synthetic-task'
(traces / name).mkdir(parents=True, exist_ok=True)
context = SimpleNamespace(execution_setup=SimpleNamespace(traces_path=traces, trace_name=name), device=None, run_outcome=None)
context.data_engine = OfflineEngine(context)
with patch('artemis.runtime.DeviceExecutionLock.annotate_active_owner'):
    context.data_engine.start_session('Synthetic trace compilation fixture', session_id='synthetic-session')
for action in ['click', 'click', 'report_task_status']:
    context.data_engine.record_step(action_taken={'action': action})
for thread in list(context.data_engine._pending_threads):
    thread.join()
# Disable log-to-DB capture before the finalizer; step storage is already complete.
engine_module._CURRENT_DATA_ENGINE = None
assert len(context.data_engine.storage.get_steps('synthetic-session')) == 3

task = SimpleNamespace(status='completed', created_at=datetime.now(), request=SimpleNamespace(record_trace=True, trace_path=output), get_name=lambda: name)
asyncio.run(AgentBase._finalize_tracing(SimpleNamespace(_tmp_traces_dir=traces), task, context))
compiled = next(output.glob('synthetic-task_PASS_*'))
result = {
    'db_steps': len(context.data_engine.storage.get_steps('synthetic-session')),
    'session_status': context.data_engine.storage.get_session('synthetic-session').status,
    'compiled_steps': json.loads((compiled / 'steps.json').read_text()),
}
print('PROBE_RESULT', json.dumps(result, sort_keys=True))
print('TRACE_VIEW_BEGIN')
view_trace(compiled.name, output)
print('TRACE_VIEW_END')
control = root / 'fixture' / 'legacy-control'
control.mkdir(parents=True, exist_ok=True)
(control / '123.json').write_text('{"action":"click"}')
create_steps_json_from_trace_folder(control)
print('LEGACY_CONTROL', json.dumps(json.loads((control / 'steps.json').read_text())))

import shutil
shutil.rmtree(root)

The fixture is a reproduction of the DB-to-compiled-artifact boundary, rather than a new end-to-end task run. Separately, supplied evidence from a completed Flash task on the same source baseline showed three session-API step records and an empty compiled PASS steps.json. That live task was not rerun for this report.

Expected behavior

For a recorded task whose session steps are already persisted, trace finalization and artemis trace view should preserve and display those steps. The CLI describes view as a step-by-step summary of a recorded trace session; a successfully compiled trace should not silently represent three persisted steps as an empty sequence.

Actual behavior

The focused fixture exited successfully and produced the following discriminating output:

Found 0 steps to compile
PROBE_RESULT {"compiled_steps": [], "db_steps": 3, "session_status": "completed"}

Between TRACE_VIEW_BEGIN and TRACE_VIEW_END, the CLI displayed only the step/action/reasoning column headers and no rows. The legacy-file control produced one compiled entry:

Found 1 steps to compile
LEGACY_CONTROL [{"timestamp": 123, "data": "{\"action\":\"click\"}"}]

Evidence

  • Expected source: artemis/interfaces/cli/commands/trace.py:72-104 documents and implements the recorded trace's step-by-step summary; TaskRequestBase.record_trace in third_party/mobile_use/sdk/types/task.py enables recording, and artemis/sdk/agent.py:282-340 prepares the task trace and starts its DataEngine session.
  • Failure source: The executed fixture above calls DataEngine.record_step() and AgentBase._finalize_tracing() and compares persisted steps with the generated JSON and CLI output. artemis/data_engine/engine.py:852-952 writes StepRecord objects to SQLite; third_party/mobile_use/sdk/agent.py:885-928 calls the folder compiler; third_party/mobile_use/utils/media.py:192-206 reads only numeric-basename JSON files and writes the collected list to steps.json.
  • Evidence provenance: observed
  • Local verification: reproduced
  • Reproduction completeness: complete

The focused synthetic fixture and its legacy-file control were executed; the additional live Flash-task observation is supplied evidence. Reproduction is complete for the offline persistence/finalization/view path; a new end-to-end phone/model task was not executed.

The existing media unit test exercises a timestamp-named JSON file, which the control confirms still compiles. The failing fixture instead uses the current DB-backed step writer. This source evidence identifies the disconnected boundary without prescribing how to reconcile the storage and artifact formats.

Runtime or environment

Fresh google/artemis default-branch checkout at 351ca8422f7b5b54e80a9c1ce03a222e02415b6b (main), project metadata version 1.0, CPython 3.12.15, macOS. No published GitHub releases or tags were available when checked. The installed dependency environment was reused read-only only after confirming the fresh checkout's uv.lock matched; module import identity pointed at the fresh checkout. The supplied live observation used this same source baseline.

Restoration check

With the same three already-persisted synthetic steps, finalization must retain a nonempty, faithful step history and the recorded-trace viewer must show those steps. Verify the session still has all three rows and the legacy-file control still preserves its step, so a passing result cannot come from dropping DB rows, suppressing recording, or discarding existing trace inputs. Choose the implementation and test design freely.

Triage assessment

  • Impact level: P2
  • Assessment status: supported
  • Impact basis: Recorded tasks can finish correctly while their compiled step artifact and CLI step summary omit the persisted action history, reducing trace inspection and debugging reliability. One supplied completed Flash task and the focused offline fixture support this scope; other profiles and population frequency were not measured.
  • Workaround status: available
  • Workaround basis: The session database retains the step rows; the supplied live observation obtained all three steps through the session API, and the focused fixture read all three through StorageManager. Preserve the database and inspect that retained history instead of relying on the compiled JSON.

Activity

  1. aron-intframe commented on Oct 25, 2026

    @aron-intframe

    Reproduced your fixture verbatim on Linux at the same baseline (351ca8422f7b5b54e80a9c1ce03a222e02415b6b), CPython 3.12.3, and got the discriminating lines unchanged:

    ℹ Found 0 images to compile
    ℹ Found 0 steps to compile
    PROBE_RESULT {"compiled_steps": [], "db_steps": 3, "session_status": "completed"}
    

    Cause in one line: nothing in the tree writes the inputs the folder compiler reads. create_steps_json_from_trace_folder collects only digit-named .json files (third_party/mobile_use/utils/media.py:196) and create_gif_from_trace_folder only *.jpeg (media.py:171), while step metadata now goes to SQLite via DataEngine.record_step (artemis/data_engine/engine.py:853) and screenshots into a content-addressed store at <traces>/images/<sha256>.jpg (engine.py:832-834). The only .jpeg filename references left in the tree are the two consumers, with no producer:

    $ grep -rn --include='*.py' -e '.jpeg"' artemis third_party | grep -v image/jpeg
    third_party/mobile_use/utils/media.py:171:        if file.suffix == ".jpeg":
    third_party/mobile_use/utils/media.py:188:        if file.suffix == ".jpeg":
    

    and no module builds a digit-named .json path anywhere, so _finalize_tracing (third_party/mobile_use/sdk/agent.py:920-921) compiles a folder that nothing populates. Found 0 images to compile in your own run is the same defect on the GIF path.

    Three things I ran that the report does not cover.

    1. Restoring the legacy writer alone would not fix artemis trace view. The compiler emits {"timestamp": int, "data": "<raw json string>"}, but the viewer reads step, action and motivation/thought (artemis/interfaces/cli/commands/trace.py:99-101). I compiled a legacy 123.json whose contents already carry exactly those keys, then viewed it:

    A_COMPILED [{"timestamp": 123, "data": "{\"step\": 1, \"action\": \"click\", \"motivation\": \"tap the Search field\"}"}]
    ┃ Step ┃ Action ┃ Reasoning / Motivation ┃
    │    - │ -      │ -                      │
    

    One row, every cell a dash. The compiler and the viewer never agreed on a schema, so your legacy control is green at the file level only. Any fix that re-populates per-step files has to change the shape too.

    2. artemis trace list presents the broken trace as having steps. It tests existence, not content (trace.py:59-60), and the compiler always writes the file, so a zero-step trace is indistinguishable from a good one in the inventory view:

    │ empty_PASS_2026-01-01T00-00-00  │ 2026-10-25 10:51:42 │ 📋 Steps  │
    │ legacy_PASS_2026-01-01T00-00-00 │ 2026-10-25 10:51:42 │ 📋 Steps  │
    

    empty there holds steps.json containing [], which is exactly what a finished task now produces.

    3. A restoration check that passes. Emitting the viewer's own schema from StepRecord rows (step_number, action_taken["action"], summary) renders all three steps:

    │    1 │ click              │ tap the Search field   │
    │    2 │ click              │ tap the first result   │
    │    3 │ report_task_status │ done                   │
    

    That points at the finalizer rather than media.py as the place to source from: read storage.get_steps(session_id) while the session id is still in hand and write that, and resolve images for the GIF through DataEngine.get_image_path() or drop the GIF stage.

    One note on test design. tests/unit/utils/test_media.py passes today (1 passed in 0.02s) and will keep passing under any fix, because it hand-writes the 123.json input that no production path produces. It pins the compiler's file format, not the property that persisted steps survive finalization. A regression test that would have caught this has to start at record_step and assert on the compiled steps.json or on the view_trace rows.

    A writer that finds nothing, logs the zero and reports success is a failure shape we keep hitting ourselves; the catalog entry and the self-test we use against it are in our repo (ours): https://github.com/aron-intframe/agent-guards

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