Skip to content

feat(sources): materialize Hermes subagent-delegation topology (fs1.14/fs1.2.1) - #3231

Merged
Sinity merged 6 commits into
masterfrom
feature/hermes/subagent-topology-and-fidelity-proof
Jul 20, 2026
Merged

Sinity merged 6 commits into
masterfrom
feature/hermes/subagent-topology-and-fidelity-proof

Conversation

@Sinity

@Sinity Sinity commented Jul 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes fs1.14's last remaining scope item (subagent-delegation topology
materialization from Hermes ATIF subagent_trajectories and ATOF
hermes.subagent.* marks) and fs1.2.1's residual detector-tightness and
fidelity-honesty ACs, all against the two real redacted producer fixtures
already checked into the repo.

Problem

hermes_spans.py already parsed ATIF subagent_trajectories entries and
ATOF hermes.subagent.* marks into hermes_subagent_span summary events,
and hermes_topology_projection.py already surfaced them read-side as
subagent_evidence -- but both explicitly declared topology_edges as
permanently absent: the delegation evidence never became a real
session_links graph edge. Separately, fs1.2.1 had residual ACs (detector
tightness proof, fidelity-band honesty) that were unaddressed after the
merged unpaired-scope-debt and shared-file/single-session fixes (#3103,
#3113).

Solution

Materialization (polylogue/sources/parsers/hermes_spans.py):
parse_atof_stream and parse_atif_document now materialize a real
session_links parent edge (branch_type=subagent) for a subagent
reference when the child session id is producer-positive, non-self-
referential, unambiguous (no two different parents claiming the same
child), and a profile root is known -- the same fail-closed pattern fs1.14's
profile-qualification fix already established. On the ATOF route, when the
child's own trace records aren't present in the same batch, a minimal
delegation-evidence-only session is materialized so the edge still lands in
the archive (content-hash full-replace later reconciles it if the child's
real trace is separately ingested). On the ATIF route, subagent_trajectories
entries carry their own steps, so the child gets real parsed content, not
a stub. parse_atif_document's return type changed from ParsedSession to
list[ParsedSession] (parent + any materialized children); dispatch.py's
lowering was updated accordingly (one call site).

Each observing session's own hermes_subagent_span event now carries a
delegation_edge_asserted flag recording whether materialization actually
happened, so import_fidelity_declaration's topology_edges capability
(and hermes_topology_projection.HermesSubagentEvidenceRef. delegation_edge_materialized) can report it without cross-session lookups.
ATOF's mapping is proven end-to-end against the real NeMo Relay ATOF
fixture's hermes.subagent.start mark (topology_edges: exact); ATIF's
subagent_trajectories mapping has no real-fixture evidence yet (every real
ATIF export sampled so far carries an empty/absent list), so it stays
inferred, never exact.

Detector tightness (fs1.2.1 AC2): added a negative test proving the
ATOF structural detector (looks_like_atof_payload) rejects a
repository-invented marker-only payload -- ATOF never had an invented
marker historically (unlike ATIF's pre-fix polylogue_artifact: "hermes_atif_trace"), so this closes the "reject the marker" half of AC2
for both artifact families. Also added a detect_provider-level assertion
on the existing ATIF marker-rejection test, proving rejection through the
real dispatch entrypoint, not just the low-level predicate.

Fidelity honesty (fs1.2.1 AC5): audited every status="exact" /
verified_by_real_fixture site in hermes_spans.py. The pre-existing
llm_request_spans/tool_execution_spans (ATIF) and
llm_request_spans/tool_execution_spans/decision_points/
error_taxonomy/subagent_delegation/context_events (ATOF) capabilities
were already correctly gated (real-fixture-proven mapping, "exact" means the
mapping is proven, matching the precedent already established and tested
elsewhere in this file for exactly this reason) -- no downgrade needed. The
new topology_edges capability is gated the same way: exact only when the
real ATOF fixture proves both the field mapping and the edge materialization
end-to-end; inferred on the ATIF route since no real fixture proves that
mapping yet.

Docs: docs/hermes-operators.md had several claims that
subagent_delegation "never reaches topology_edges/session_links" --
narrowed to describe exactly when an edge is and isn't materialized, and
updated the ATIF/ATOF capability example blocks to current observed values.

Per-bead AC matrix

polylogue-fs1.14 (residual scope: subagent-delegation topology
materialization):

  • Materialize parent/child delegation evidence as session_links parent
    references from producer-positive ids + profile qualification, fail
    closed otherwise: satisfied -- hermes_spans.py
    (_mark_delegation_edges_on_subagent_events, _atif_subagent_child_session,
    _atof_subagent_delegation_stub_session); see
    test_real_atof_fixture_subagent_mark_materializes_delegation_edge,
    test_atof_subagent_mark_fails_closed_without_profile_root,
    test_atof_subagent_mark_fails_closed_on_self_reference,
    test_atif_subagent_trajectory_materializes_delegation_edge_with_known_profile,
    test_atif_subagent_trajectory_fails_closed_without_profile_root,
    test_atif_subagent_trajectory_fails_closed_on_self_reference.
  • Extend hermes_topology_projection.py to surface the edges: satisfied
    -- HermesSubagentEvidenceRef.delegation_edge_materialized, read straight
    from the underlying event's delegation_edge_asserted payload flag; kept
    shape-agnostic (no new coupling to hermes_spans internals).
  • Anti-vacuity real-fixture test + fail-closed test: satisfied -- see
    above.
  • Where the real fixture lacks subagent evidence (ATIF), keep the capability
    declared absent/inferred: satisfied -- ATIF topology_edges stays
    inferred even when materialized (never exact, no real fixture proof).

polylogue-fs1.2.1 (residual ACs 2 and 5):

Verification

devtools test tests/unit/sources/parsers/test_hermes_spans.py tests/unit/sources/test_dispatch_payloads.py tests/unit/insights/test_hermes_topology_projection.py
# 56 passed in 3.89s

mypy --strict polylogue/sources/parsers/hermes_spans.py polylogue/insights/hermes_topology_projection.py polylogue/sources/dispatch.py tests/unit/sources/parsers/test_hermes_spans.py tests/unit/sources/test_dispatch_payloads.py
# Success: no issues found in 5 source files

devtools verify --quick
# exit_code 0 (format, lint, mypy, render all --check, topology/layering/
# closure-matrix/schema-roundtrip/manifests/ci-workflows/doc-commands/
# docs-coverage/test-infra-currency/test-clock-hygiene/pytest-timeout-
# overrides/degrade-loudly all pass)

Not run: full devtools verify/--all (testmon unseeded in this worktree;
out of the requested synchronous-foreground scope) and integration tests.

Residual risk

  • topology_edges materialization only handles the case observed in the
    real fixture (one mark, one child, single batch). Two different parents
    claiming the same child id in one batch is fail-closed (no edge) but not
    independently unit-tested beyond code review -- low risk, same pattern as
    the already-tested self-referential guard.
  • ATIF child sessions reuse _events_for_step, so any future step-shape
    addition to that function automatically applies to subagent children too
    (intentional, not drift).
  • parse_atif_document's return-type change (ParsedSession ->
    list[ParsedSession]) is a public-ish API change within
    polylogue.sources.parsers.hermes_spans; the only production call site
    (dispatch.py) was updated, and a repo-wide grep confirmed no other
    caller exists.

Ref polylogue-fs1.14
Ref polylogue-fs1.2.1

Summary by CodeRabbit

  • New Features

    • Hermes imports now recognize real ATIF documents and can represent delegated subagent sessions.
    • Subagent evidence now indicates when a concrete parent-child session link was materialized.
    • Delegated sessions can be created from available trajectory or stream evidence, including minimal evidence-only sessions.
  • Bug Fixes

    • Improved session identity handling to prevent collisions between parent and delegated sessions.
    • Unsupported or ambiguous delegation references now fail closed without creating topology links.
  • Documentation

    • Updated Hermes fidelity, topology, and session-correlation guidance to reflect delegation behavior.

Sinity added 4 commits July 20, 2026 23:08
Problem: hermes_spans.py already parsed ATIF subagent_trajectories entries
and ATOF hermes.subagent.* marks into hermes_subagent_span summary events,
but explicitly declared topology_edges "absent" -- the delegation evidence
was surfaced read-side (hermes_topology_projection.subagent_evidence) but
never materialized as a real session_links parent edge, per fs1.14's last
remaining scope item.

What changed: parse_atof_stream and parse_atif_document now materialize a
real session_links parent edge (branch_type=subagent) for a subagent
reference when the child session id is producer-positive, non-self-
referential, unambiguous (no two different parents claiming the same child),
and a profile root is known -- the same fail-closed pattern fs1.14's
profile-qualification fix already uses. ATOF: when the child's own trace
records are not present in the same batch, a minimal delegation-evidence-
only session is materialized so the edge still lands in the archive
(content-hash full-replace later reconciles it if the child's real trace is
separately ingested). ATIF: subagent_trajectories entries carry their own
steps, so the child session gets real parsed content, not a stub.
parse_atif_document's return type changed from ParsedSession to
list[ParsedSession] (parent + any materialized children); dispatch.py's
lowering updated accordingly.

Each observing session's own hermes_subagent_span event now carries a
delegation_edge_asserted flag recording whether materialization actually
happened, so import_fidelity_declaration's topology_edges capability (and
hermes_topology_projection's new HermesSubagentEvidenceRef.
delegation_edge_materialized field) can report it without cross-session
lookups. ATOF's mapping is proven end-to-end against the real NeMo Relay
ATOF fixture's hermes.subagent.start mark (topology_edges: exact); ATIF's
subagent_trajectories mapping has no real-fixture evidence yet (every real
ATIF export sampled carries an empty/absent list), so it stays inferred.

Verification: devtools test tests/unit/sources/parsers/test_hermes_spans.py
(32 passed), tests/unit/insights/test_hermes_topology_projection.py
(13 passed); mypy --strict on the three touched modules (no issues).

Ref polylogue-fs1.14
…ures (fs1.2.1)

Problem: fs1.2.1 AC2 requires the ATIF/ATOF structural detectors to admit
both real producer fixtures at the correct tightness AND reject a payload
containing only the repository-invented marker; only the ATIF side had an
explicit negative marker test. Separately, materializing subagent-delegation
sessions from the real ATOF fixture (this branch's fs1.14 work) changed the
real fixture's produced-session count from 1 to 2, which two pre-existing
tests asserted exactly.

What changed: added test_looks_like_atof_payload_rejects_a_repository_
invented_marker_only_shape (ATOF never had an invented marker historically,
so this proves a marker-only payload was never, and is still not,
sufficient) and a detect_provider-level assertion on the existing ATIF
marker-rejection test, closing AC2 through both the structural predicate and
the real dispatch entrypoint. Updated
test_real_nemo_relay_atof_fixture_reaches_the_stream_parser_without_copying_content,
test_import_explain_uses_atof_stream_fidelity_for_a_real_fixture, and
test_source_parser_groups_real_shaped_hermes_atof_jsonl_as_one_retained_stream
to the new 2-session count and added topology_edges="exact" assertions.

Verification: devtools test tests/unit/sources/parsers/test_hermes_spans.py
(33 passed), tests/unit/sources/test_dispatch_payloads.py (10 passed).

Ref polylogue-fs1.2.1
devtools verify --quick's mypy step flagged the untyped dict literal added in
the previous commit's detect_provider-level marker-rejection assertion
(dict[str, Sequence[str]] inferred instead of JSONDocument). Annotate it
explicitly; no behavior change.

Verification: mypy --strict tests/unit/sources/parsers/test_hermes_spans.py
tests/unit/sources/test_dispatch_payloads.py (no issues);
devtools verify --quick (exit 0).

Ref polylogue-fs1.2.1
…14/fs1.2.1)

Problem: docs/hermes-operators.md's "What Polylogue cannot claim" section
and the ATIF/ATOF fidelity examples asserted subagent_delegation "never
reaches topology_edges/session_links" and showed topology_edges as
permanently absent -- both now false for the case where the evidence is
unambiguous and profile-qualified (this branch's fs1.14 work).

What changed: updated the ATIF/ATOF capability example blocks with current
observed values (topology_edges: exact/1/1 for the real ATOF fixture,
parent_session_link added to both), narrowed cannot-claim item 5 to describe
exactly when an edge is and isn't materialized, and added a "Subagent
delegation is the one exception" paragraph to the Session identity section
explaining this is the only case where the archive stores a real graph edge
rather than a read-time lookup.

Verification: devtools verify --quick (exit 0, render all/docs-coverage/
doc-commands all pass).

Ref polylogue-fs1.14
Ref polylogue-fs1.2.1
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f7e342bc-453b-400e-822e-be8c4fe565d6

📥 Commits

Reviewing files that changed from the base of the PR and between f54eab5 and 46047f2.

📒 Files selected for processing (2)
  • polylogue/sources/parsers/hermes_spans.py
  • tests/unit/sources/parsers/test_hermes_spans.py
📝 Walkthrough

Walkthrough

Hermes ATIF and ATOF parsing now materializes qualified subagent sessions and delegation edges, reports edge provenance, updates fidelity calculations, and validates fail-closed behavior for ambiguous or self-referential delegation.

Changes

Hermes topology and delegation

Layer / File(s) Summary
Parser detection and return contracts
polylogue/sources/dispatch.py, polylogue/sources/parsers/hermes_spans.py, tests/unit/sources/parsers/test_hermes_spans.py
Hermes detection validates real ATIF payload structure, and ATIF parsing returns multiple sessions directly through dispatch.
ATOF delegation session materialization
polylogue/sources/parsers/hermes_spans.py, tests/unit/sources/parsers/test_hermes_spans.py, tests/unit/sources/test_dispatch_payloads.py
ATOF delegation claims create qualified child sessions or minimal evidence stubs, assert parent edges only when unambiguous, and update session-count and fidelity expectations.
ATIF child sessions and fidelity
polylogue/sources/parsers/hermes_spans.py, tests/unit/sources/parsers/test_hermes_spans.py
ATIF subagent trajectories produce child sessions with delegation metadata, while topology and parent-link fidelity distinguish materialized, inferred, and absent edges.
Projection provenance and operator documentation
polylogue/insights/hermes_topology_projection.py, docs/hermes-operators.md
Subagent evidence exposes whether parser-time delegation edges were materialized, and documentation describes the updated topology and correlation rules.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant HermesPayload
  participant HermesParser
  participant ParsedSession
  participant TopologyProjection
  HermesPayload->>HermesParser: provide ATIF or ATOF delegation evidence
  HermesParser->>ParsedSession: create parent and qualified child sessions
  HermesParser->>ParsedSession: assert delegation_edge_asserted when valid
  ParsedSession->>TopologyProjection: expose delegation event payload
  TopologyProjection-->>HermesPayload: report delegation_edge_materialized
Loading

Possibly related issues

Possibly related PRs

  • Sinity/polylogue#3225 — Introduces the topology projection and subagent delegation handling extended by this PR.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: Hermes subagent-delegation topology materialization.
Description check ✅ Passed The PR description covers Summary, Problem, Solution, Verification, and Risks, but it omits the template's Changelog section.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/hermes/subagent-topology-and-fidelity-proof

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…1.14)

Problem: parse_atof_stream's delegation_targets computation excludes any
child_session_id claimed by more than one distinct parent in a batch
(len(parents) == 1 guard), but this fail-closed conflict path had no
dedicated unit test -- only the simpler unknown-profile and self-reference
fail-closed cases were covered.

What changed: added
test_atof_subagent_mark_fails_closed_when_two_parents_claim_the_same_child,
two hermes.subagent.start marks from different parent sessions both naming
"contested-child" as their child. Asserts no third (stub or overridden)
session is materialized, both parents' hermes_subagent_span events keep
delegation_edge_asserted=False, and topology_edges stays absent/0 on both
sides while subagent_delegation (the underlying mark-shape mapping) stays
exact -- the evidence is retained, only the graph edge is withheld.
Verified the mutation this test targets (relaxing the len(parents) == 1
guard to admit every claimed child) makes it fail with a 3-session,
spuriously-materialized-edge result, then reverted that mutation.

Verification: devtools test tests/unit/sources/parsers/test_hermes_spans.py
(34 passed); devtools verify --quick (exit 0).

Ref polylogue-fs1.14

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@polylogue/sources/parsers/hermes_spans.py`:
- Around line 422-441: Update _mark_delegation_edges_on_subagent_events to
retain each grouped session’s parent/session ID while iterating, and mark
delegation_edge_asserted true only when delegation_targets[child_session_id]
matches that actual parent identity. Keep invalid, missing, and self-referential
child IDs false so materialized delegation fidelity remains fail-closed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8b310d9f-e226-4af7-8f9d-678c3e23ab19

📥 Commits

Reviewing files that changed from the base of the PR and between c6a01b2 and f54eab5.

📒 Files selected for processing (6)
  • docs/hermes-operators.md
  • polylogue/insights/hermes_topology_projection.py
  • polylogue/sources/dispatch.py
  • polylogue/sources/parsers/hermes_spans.py
  • tests/unit/sources/parsers/test_hermes_spans.py
  • tests/unit/sources/test_dispatch_payloads.py

Problem: CodeRabbit inline review on PR #3231 (hermes_spans.py:441) found
_mark_delegation_edges_on_subagent_events iterated grouped.values() without
the owning session id, so it set delegation_edge_asserted=True whenever a
mark's child_session_id was ANY key in delegation_targets -- not only when
THIS session was the recorded parent for that specific child. Concrete
failure: session S emits a self-referential mark (child==S, correctly
excluded from delegation_claims by the child_session_id != session_id
check), while an unrelated session P legitimately claims S as its own child
(delegation_targets["S"] == "P"). Membership alone made S's own
self-referential span read delegation_edge_asserted=True merely because "S"
is a key in the map, contradicting the fail-closed self-reference guarantee
test_atof_subagent_mark_fails_closed_on_self_reference already asserts.

What changed: iterate grouped.items() to carry the owning session id, and
require delegation_targets.get(child_session_id) == owning_session_id
before setting the flag -- not just truthy membership. P's own claim on S
is unaffected (P *is* the owning session for that resolved target) and
still materializes S's real session_links edge to P.

Added test_atof_self_referential_mark_stays_unasserted_when_another_session_
legitimately_claims_the_same_id reproducing the exact S/P scenario: asserts
S's own span stays delegation_edge_asserted=False while P's edge to S still
materializes (parent_session_provider_id, branch_type=subagent). Verified
the mutation this test targets (reverting to membership-only:
bool(delegation_targets.get(child_session_id))) makes it fail (True is
False), then reverted that mutation.

Verification: devtools test tests/unit/sources/parsers/test_hermes_spans.py
(35 passed); mypy --strict polylogue/sources/parsers/hermes_spans.py
tests/unit/sources/parsers/test_hermes_spans.py (no issues);
devtools verify --quick (exit 0).

Ref polylogue-fs1.14
@Sinity

Sinity commented Jul 20, 2026

Copy link
Copy Markdown
Owner Author

Coordinator merge note: CodeRabbit's single Major finding (delegation_edge_asserted marked by global membership instead of parent identity — self-referential mark misattribution) fixed in 46047f2 with a mutation-proven regression test; reply posted on the inline thread. Conflict-guard (two parents claiming one child → no edge, visible debt) also gained its dedicated test earlier at coordinator request. Delegation edges materialize fail-closed from the real ATOF fixture (stub child sessions carry the edge under the same computed id, so later real ingest full-replaces in place); fs1.2.1 AC2 negative-marker tests + AC5 fidelity audit complete. 35+56 focused tests, mypy --strict, quick verify green ×3. Merging.

@Sinity
Sinity merged commit c928f0e into master Jul 20, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/hermes/subagent-topology-and-fidelity-proof branch July 20, 2026 21:33
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.

1 participant