feat: atomization pipeline with job queue, atomizer client, WS hub, and board UI (phase 7)
- internal/extsvc: circuit breaker (§11.16) + retrying bearer JSON client - atomizer client: §5.1 contract incl. defensive coefficient normalization and extension coefficient range (0,2] - persisted jobs collection: atomic claim, panic recovery, exponential backoff (max 3), stale-running requeue, shutdown-safe bookkeeping - subdivide (async 202, atomizing status, re-run replaces unpublished children after confirm) and extend (sibling task, source budget) - failure path reverts status and notifies the consultant on final attempt - PATCH task editing with bounty recompute, budget cascade to descendants - publish single + bulk; task detail endpoint role-scoped - coder/websocket hub: multiplexed channels, origin check, 30s heartbeats; client ws.js with reconnect + 15s polling fallback - consultant atomization board: tree by root, coefficient sliders with live per-parent sum indicator, bounty preview, modals, shimmer, atomizer-down gating via /api/v1/service-health - fix: tasks external-ref unique index is partial, not sparse (compound sparse indexed every task through customerId and broke child inserts) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,8 +33,13 @@ func EnsureIndexes(ctx context.Context, db *mongo.Database) error {
|
||||
{Keys: bson.D{{Key: "assignee.userId", Value: 1}, {Key: "status", Value: 1}}},
|
||||
{Keys: bson.D{{Key: "rootId", Value: 1}}},
|
||||
{Keys: bson.D{{Key: "parentId", Value: 1}}},
|
||||
// The spec calls this "unique sparse", but a compound sparse index
|
||||
// matches any doc where customerId exists (i.e. every task), which
|
||||
// breaks subdivided children. A partial index expresses the intent:
|
||||
// uniqueness only for tasks that actually have an external ref.
|
||||
{Keys: bson.D{{Key: "external.system", Value: 1}, {Key: "external.key", Value: 1}, {Key: "customerId", Value: 1}},
|
||||
Options: options.Index().SetUnique(true).SetSparse(true)},
|
||||
Options: options.Index().SetUnique(true).SetName("uniq_external_ref").
|
||||
SetPartialFilterExpression(bson.M{"external.key": bson.M{"$exists": true}})},
|
||||
{Keys: bson.D{{Key: "title", Value: "text"}, {Key: "description", Value: "text"}}},
|
||||
},
|
||||
"bountyAwards": {
|
||||
@@ -63,6 +68,10 @@ func EnsureIndexes(ctx context.Context, db *mongo.Database) error {
|
||||
},
|
||||
}
|
||||
|
||||
// migration: an earlier build created the external-ref index as sparse
|
||||
// under the auto-generated name; drop it so the partial variant applies
|
||||
_ = db.Collection("tasks").Indexes().DropOne(ctx, "external.system_1_external.key_1_customerId_1")
|
||||
|
||||
for coll, models := range plan {
|
||||
if _, err := db.Collection(coll).Indexes().CreateMany(ctx, models); err != nil {
|
||||
return fmt.Errorf("create indexes for %s: %w", coll, err)
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestEnsureIndexesIsIdempotent(t *testing.T) {
|
||||
// Spot-check a few critical indexes actually exist.
|
||||
checks := map[string]string{
|
||||
"users": "email_1",
|
||||
"tasks": "external.system_1_external.key_1_customerId_1",
|
||||
"tasks": "uniq_external_ref",
|
||||
"sessions": "expiresAt_1",
|
||||
}
|
||||
for coll, wantName := range checks {
|
||||
@@ -44,10 +44,10 @@ func TestEnsureIndexesIsIdempotent(t *testing.T) {
|
||||
for _, s := range specs {
|
||||
if s["name"] == wantName {
|
||||
found = true
|
||||
// the unique upsert key must really be unique+sparse
|
||||
// the upsert key must be unique and partial (external-only)
|
||||
if coll == "tasks" {
|
||||
if s["unique"] != true || s["sparse"] != true {
|
||||
t.Errorf("%s/%s: want unique sparse, got %v", coll, wantName, s)
|
||||
if s["unique"] != true || s["partialFilterExpression"] == nil {
|
||||
t.Errorf("%s/%s: want unique partial, got %v", coll, wantName, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user