Skip to content

fix(worker): attribute learning to project/team/role and commit the prompt snapshot - #32

Merged
GQAdonis merged 1 commit into
mainfrom
fix/worker-attribution-snapshot
Oct 4, 2026
Merged

GQAdonis merged 1 commit into
mainfrom
fix/worker-attribution-snapshot

Conversation

@GQAdonis

@GQAdonis GQAdonis commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Plan PR A2 of the team-aware learning work (design §6, §8 U2).

  • Attribution. LearningJob gains optional projectId, teamId and roleId, all serde(default), so jobs queued by older hooks still parse. enqueue_memory now derives the scope keys from them:

    • user_id is the project id, falling back to project_scope();
    • agent_id is <team>/<role> when both are set, otherwise @project;
    • shared-scope learning uses @global for both.

    Previously agent_id was always null, which is the source of the unattributed records.

  • Legacy task steps. The legacy add_task_step form ({stream, description}) now gets non-null agent_id and user_id keys (PROMETHEUS_PROJECT_ID, or an explicit project:unknown that the surreal-memory re-key can repair).

  • Hashed payloads are untouched on purpose. Already-normalized payloads (add_memory, stream_name task steps) are bound by their stored payloadHash and any server receipt, so rewriting them would break reconciliation. New operations get correct keys at the source, the skill-pack memory bridge.

  • Prompt snapshot. process_job now commits it after the upsert. Without that, session records were written to disk but were invisible to pk context.

Test plan

  • cargo test -p pk-learning-worker --test attribution, 2 tests:
    • attributed and unattributed jobs produce tlm-fixture/api-dev and @project keys, no queued operation has a null key, and both session entries are in the committed project snapshot;
    • a legacy task step is submitted with agent_id=@project and user_id=$PROMETHEUS_PROJECT_ID, captured at a fake ledger.
  • cargo test -p pk-learning-worker --test worker: 5/5 still pass.

🤖 Generated with Claude Code

…rompt snapshot

LearningJob gains optional projectId/teamId/roleId. enqueue_memory now
derives surreal-memory scope keys from them (user_id = project id;
agent_id = <team>/<role>, else @project; shared scope = @global) instead
of always sending agent_id null, which left every record unattributed.
Legacy add_task_step operations get non-null keys too. Already-hashed
payloads are left untouched so stored payload hashes and receipts stay
valid. process_job commits the prompt snapshot after upsert so session
records become visible to pk context.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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, add credits to your account and enable them for code reviews in your settings.

@GQAdonis
GQAdonis merged commit 4b85e6c into main Oct 4, 2026
0 of 3 checks passed
@GQAdonis
GQAdonis deleted the fix/worker-attribution-snapshot branch October 4, 2026 10:42
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