Skip to content

fix(runs): give each imported document a trial of its own, never renaming one already there - #404

Open
harenome wants to merge 2 commits into
ThinkFlowLab:mainfrom
harenome:fix/import-trial-names
Open

harenome wants to merge 2 commits into
ThinkFlowLab:mainfrom
harenome:fix/import-trial-names

Conversation

@harenome

Copy link
Copy Markdown
Collaborator

Closes #401

What

Two imported documents could land in one trial folder while the job counted both:

  • OpenTelemetry: traces with the same root span name and the same first 7 hex of the trace id.
  • ATIF: paths that flatten to one name, such as a/b.json and a__b.json.

Trial names are now decided before anything is written, with this rule:

  • First, each importer reads which document every existing trial folder in the output job holds. For OpenTelemetry that is the recorded trace id, or the trace in agent/trace.json. For ATIF it is the recorded source path.
  • A document whose trial already exists keeps that trial's name exactly. Judgements are keyed by it.
  • Any other document keeps today's name when no other document has it. A newcomer that would collide takes the longer name: the full trace id (OpenTelemetry) or an 8-hex digest of its path (ATIF).
  • A folder whose document cannot be told keeps its name for the first document that would take it under today's naming. The newcomer takes the longer name.
  • A folder an older conversion wrote two documents into (the job counts more trials than it has folders) is split: each of its documents takes the longer name.
  • If two documents would still share a name, the conversion is refused with a redacted error, before anything is written.

The OpenTelemetry trial's result.json now records the full trace id under source_document.trace_id. ATIF already recorded session_id and the source path there.

Touches

  • app/nullius/importers/__init__.py: existing_trials and unique_names, shared by both importers.
  • app/nullius/importers/otel.py, app/nullius/importers/atif.py: what an existing folder holds, names chosen before writing, the trace id recorded.
  • app/tests/harnesses/test_otel_import.py, app/tests/harnesses/test_atif.py: per importer, a collision in one conversion and a colliding document added later. For ATIF, also the old merged folder.

Verified

Importer CLI on crafted inputs. OpenTelemetry: trace abcdef1fff…, then abcdef1000… added, both with root span agent run. ATIF: a__b.json, then a/b.json added.

On upstream/main, the added documents overwrite the first trial:

== first conversion
atif__atif/a__b/result.json session-first
otel__otel/agent_run__abcdef1/result.json None
== colliding documents added, converted again
otel: wrote 1 trial(s) to /tmp/out/otel__otel (job id otel__otel)
atif: wrote 1 trial(s) to /tmp/out/atif__atif (job id atif__atif)
atif__atif/a__b/result.json session-later
otel__otel/agent_run__abcdef1/result.json None
atif__atif/result.json n_total_trials 2
otel__otel/result.json n_total_trials 2

With this branch, the first trial keeps its name and content, and the newcomer gets the longer name:

== first conversion
atif__atif/a__b/result.json session-first
otel__otel/agent_run__abcdef1/result.json abcdef1fffffffffffffffffffffffff
== colliding documents added, converted again
otel: wrote 2 trial(s) to /tmp/out/otel__otel (job id otel__otel)
atif: wrote 2 trial(s) to /tmp/out/atif__atif (job id atif__atif)
atif__atif/a__b/result.json session-first
atif__atif/a__b__6c45d4fe/result.json session-later
otel__otel/agent_run__abcdef1/result.json abcdef1fffffffffffffffffffffffff
otel__otel/agent_run__abcdef10000000000000000000000000/result.json abcdef10000000000000000000000000
atif__atif/result.json n_total_trials 2
otel__otel/result.json n_total_trials 2

Upgrade: the first conversion ran with upstream/main and the second with this branch. Same result: a__b and agent_run__abcdef1 kept, the newcomers at a__b__6c45d4fe and agent_run__abcdef1000….

  • Backend suite: 2866 tests in 173 modules, OK (on main as of today).
  • Route suite: 665 tests in 68 modules, OK.

Risk

  • A folder an older conversion wrote two documents into is split on the next convert. Both documents take longer names and the merged folder is removed as stale, along with any judgement keyed by its name. That folder only ever showed one of its two documents.
  • An ATIF trial is matched by its recorded source path. If the source tree moved, the folder counts as one whose document cannot be told. It keeps its name for the first document that would take it, which is today's order.
  • Output folders per source are not changed here.

…collide

OpenTelemetry traces sharing a root span name and the first 7 hex of their
trace id, and ATIF paths that flatten to one name (a/b.json, a__b.json), were
written into one trial folder while the job counted both. Names are now
decided before writing: an unshared name is kept as it is, a shared one takes
the full trace id (OpenTelemetry) or a digest of its path (ATIF), and a name
still shared is refused. The OpenTelemetry trial records its full trace id.
…es with it

Judgements are keyed by a trial's name, so a later conversion must not rename
a trial already in the output job. Each importer now reads which document each
existing trial folder holds (the recorded trace id or source path, or the
trace a folder carries) and keeps that name for it; only a newcomer that
collides takes the longer name. A folder an older conversion wrote two
documents into is split, and a folder whose document cannot be told keeps
its name for the first document that would take it.

This branch has not been deployed

No deployments
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.

Imports: two documents can land in one trial folder, when their trial names collide

1 participant