Skip to content

fix: persist agent name on sub-session nodes across a delivery-order race (v6.7.4) - #83

Closed
Diego Colombo (colombod) wants to merge 1 commit into
stack/pr70-on-pr78from
fix/issue-484-agent-field-on-79
Closed

fix: persist agent name on sub-session nodes across a delivery-order race (v6.7.4)#83
Diego Colombo (colombod) wants to merge 1 commit into
stack/pr70-on-pr78from
fix/issue-484-agent-field-on-79

Conversation

@colombod

@colombod Diego Colombo (colombod) commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

What this fixes

A spawned sub-session's agent name was silently lost whenever the child's event landed before the parent's — leaving :Session.agent empty and undercounting every WHERE s.agent = ... query on the shared server. This restores correct per-agent attribution. Fixes microsoft-amplifier/amplifier-support#484. Bumps server version 6.7.3 → 6.7.4.

Root cause (verified against shipped source)

The agent name for a spawned sub-session arrives only on the parent's delegate:agent_spawned event (top-level agent); the child's own session:start carries none. Both flow through ensure_session_node (pipeline step 2). Its Tier-2 "node already exists" branch upserted only {labels, status, session_id}, so when the child's session:start created the node first, the parent's later agent value was dropped. (upsert_node uses key-present merge SET n += props, so it was never the culprit — the branch simply never included agent.)

The fix (surgical — one branch)

A populate-if-missing rule for agent, alongside the working_dir one #79 introduced:

if data.get("agent") and not existing.get("agent"):
    stub_data["agent"] = data["agent"]

Writes only when the event supplies agent and the node still lacks it, so an already-set value is never clobbered. No SessionHandler/bundle changes (out of scope).

Verification — RED before, GREEN after (real, no mocks at the gate)

  • Unit (tests/test_services.py::TestEnsureSessionNodeAgentField) — two writers sharing one GraphState reproduce the child-first ordering: RED without the fix, GREEN with it. Full file: 60 passed.
  • E2E, isolated Neo4j (tests/neo4j/test_agent_field_ordering_race.py) — a throwaway neo4j:5.26.22-community container drives the real SessionHandler + DelegationHandler across two stores sharing one Neo4j, child session:start before parent delegate:agent_spawned, and asserts :Session.agent persisted. RED without the fix (agent=None), GREEN with it (~24s).

SERVER_VERSION verified reporting 6.7.4 from package metadata.

Stack

#78 harden-durable-ingestion
  └─ #81 storage-api-on-78          (backend-neutral storage)
       └─ #79 stack/pr70-on-pr78    (operability & data-integrity, v6.7.3)   ← this PR's base
            └─ this PR              (agent-attribution fix, v6.7.4)

Base is #79's head, not main — merge after #79. The fix slots directly into the stub_data populate-if-missing block #79 introduced, so there is no conflict with #79 (an independent merge onto main would conflict on that same hunk).

🤖 Generated with Amplifier

Co-Authored-By: Amplifier 240397093+microsoft-amplifier@users.noreply.github.com

@colombod Diego Colombo (colombod) changed the title fix(#484): persist agent on sub-session nodes (delivery-order race) [stacked on #79, v6.7.4] fix: persist agent name on sub-session nodes across a delivery-order race (v6.7.4) Aug 24, 2026
…rder race (#484)

ensure_session_node's Tier-2 (node-already-exists) branch dropped the `agent`
value carried by the parent's delegate:agent_spawned event when the child's own
session:start created the node first. Apply the same populate-if-missing rule
already used for working_dir so the agent name is backfilled onto the existing
node without ever clobbering an already-set value. Fixes the empty
:Session.agent that silently undercounted `WHERE s.agent = ...` queries on the
shared server.

Also bump server version 6.7.3 -> 6.7.4.

Tests (RED before fix, GREEN after):
- unit: in-memory two-writer reproduction of the child-first ordering
- E2E: isolated throwaway Neo4j, real Session/Delegation handlers, child
  session:start before parent delegate:agent_spawned; asserts agent persisted

🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier)

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
@colombod
Diego Colombo (colombod) force-pushed the fix/issue-484-agent-field-on-79 branch from 5ab7ba8 to 943e87c Compare August 26, 2026 11:01
@colombod
Diego Colombo (colombod) marked this pull request as draft August 26, 2026 11:56
@colombod

Copy link
Copy Markdown
Collaborator Author

The agent-field session-node fix folds into PR2 (session-node data quality) of the #79 split; this PR will be closed when PR2 lands. See #85 (PR1: ingest correctness, now open) for the first layer of the split.

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