Skip to content

Commit 9430465

Browse files
Revert "Read workflow visibility metadata from typed tables"
This reverts commit 7382e32.
1 parent 4b1519e commit 9430465

8 files changed

Lines changed: 42 additions & 517 deletions

src/V2/Models/WorkflowRun.php

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -146,24 +146,6 @@ public function summary(): HasOne
146146
);
147147
}
148148

149-
public function searchAttributes(): HasMany
150-
{
151-
return $this->hasMany(
152-
ConfiguredV2Models::resolve('search_attribute_model', WorkflowSearchAttribute::class),
153-
'workflow_run_id',
154-
'id',
155-
);
156-
}
157-
158-
public function memos(): HasMany
159-
{
160-
return $this->hasMany(
161-
ConfiguredV2Models::resolve('memo_model', WorkflowMemo::class),
162-
'workflow_run_id',
163-
'id',
164-
);
165-
}
166-
167149
public function waits(): HasMany
168150
{
169151
return $this->hasMany(
@@ -277,86 +259,6 @@ public function outputEnvelope(): ?array
277259
];
278260
}
279261

280-
/**
281-
* @return array<string, mixed>
282-
*/
283-
public function typedSearchAttributes(): array
284-
{
285-
if (! $this->exists) {
286-
return $this->decodeVisibilityArrayAttribute($this->attributes['search_attributes'] ?? null);
287-
}
288-
289-
$this->loadMissing('searchAttributes');
290-
291-
/** @var \Illuminate\Database\Eloquent\Collection<int, WorkflowSearchAttribute> $searchAttributes */
292-
$searchAttributes = $this->getRelation('searchAttributes');
293-
294-
return $searchAttributes
295-
->mapWithKeys(static function (WorkflowSearchAttribute $attribute): array {
296-
return [
297-
$attribute->key => $attribute->getValue(),
298-
];
299-
})
300-
->toArray();
301-
}
302-
303-
/**
304-
* @return array<string, mixed>
305-
*/
306-
public function typedMemos(): array
307-
{
308-
if (! $this->exists) {
309-
return $this->decodeVisibilityArrayAttribute($this->attributes['memo'] ?? null);
310-
}
311-
312-
$this->loadMissing('memos');
313-
314-
/** @var \Illuminate\Database\Eloquent\Collection<int, WorkflowMemo> $memos */
315-
$memos = $this->getRelation('memos');
316-
317-
return $memos
318-
->mapWithKeys(static function (WorkflowMemo $memo): array {
319-
return [
320-
$memo->key => $memo->getValue(),
321-
];
322-
})
323-
->toArray();
324-
}
325-
326-
/**
327-
* @return array<string, mixed>
328-
*/
329-
public function getSearchAttributesAttribute(mixed $value): array
330-
{
331-
return $this->typedSearchAttributes();
332-
}
333-
334-
/**
335-
* @return array<string, mixed>
336-
*/
337-
public function getMemoAttribute(mixed $value): array
338-
{
339-
return $this->typedMemos();
340-
}
341-
342-
/**
343-
* @return array<string, mixed>
344-
*/
345-
private function decodeVisibilityArrayAttribute(mixed $value): array
346-
{
347-
if (is_array($value)) {
348-
return $value;
349-
}
350-
351-
if (! is_string($value) || $value === '') {
352-
return [];
353-
}
354-
355-
$decoded = json_decode($value, true);
356-
357-
return is_array($decoded) ? $decoded : [];
358-
}
359-
360262
/**
361263
* Decode a payload (arguments or output) with the run's pinned codec
362264
* when available. Falls back to the legacy codec-blind sniffer so rows

src/V2/Models/WorkflowRunSummary.php

Lines changed: 30 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class WorkflowRunSummary extends Model
3939
'repair_attention' => 'bool',
4040
'task_problem' => 'bool',
4141
'visibility_labels' => 'array',
42-
'memo' => 'array',
4342
'search_attributes' => 'array',
4443
'projection_schema_version' => 'integer',
4544
'history_event_count' => 'integer',
@@ -152,69 +151,57 @@ public function getTaskProblemBadgeAttribute(): ?array
152151
}
153152

154153
/**
155-
* Get search attributes from the authoritative typed table.
154+
* Get search attributes with dual-read fallback.
155+
*
156+
* Phase 1 dual-read: prefer typed table when available, fall back to JSON blob.
157+
* This enables gradual migration without breaking existing Waterline queries.
156158
*
157159
* @return array<string, mixed> Key-value pairs
158160
*/
159161
public function getTypedSearchAttributes(): array
160162
{
161-
if (! $this->exists) {
162-
return $this->decodeVisibilityArrayAttribute($this->attributes['search_attributes'] ?? null);
163-
}
164-
165-
$this->loadMissing('searchAttributes');
166-
167-
/** @var \Illuminate\Database\Eloquent\Collection<int, WorkflowSearchAttribute> $searchAttributes */
168-
$searchAttributes = $this->getRelation('searchAttributes');
169-
170-
return $searchAttributes
171-
->mapWithKeys(static function (WorkflowSearchAttribute $attr): array {
163+
// Try typed table first (optimal for new runs)
164+
if ($this->relationLoaded('searchAttributes')) {
165+
$typed = $this->searchAttributes->mapWithKeys(static function (WorkflowSearchAttribute $attr) {
172166
return [
173167
$attr->key => $attr->getValue(),
174168
];
175-
})
176-
->toArray();
169+
})->toArray();
170+
171+
if (! empty($typed)) {
172+
return $typed;
173+
}
174+
}
175+
176+
// Fallback to JSON blob (for old runs or if typed storage failed)
177+
return is_array($this->search_attributes) ? $this->search_attributes : [];
177178
}
178179

179180
/**
180-
* Get memos from the authoritative typed table.
181+
* Get memos with dual-read fallback.
182+
*
183+
* Phase 1 dual-read: prefer typed table when available, fall back to JSON blob.
184+
* Memos are returned-only metadata, excluded from filtering by contract.
181185
*
182186
* @return array<string, mixed> Key-value pairs
183187
*/
184188
public function getMemos(): array
185189
{
186-
if (! $this->exists) {
187-
return $this->decodeVisibilityArrayAttribute($this->attributes['memo'] ?? null);
188-
}
189-
190-
$this->loadMissing('memos');
191-
192-
/** @var \Illuminate\Database\Eloquent\Collection<int, WorkflowMemo> $memos */
193-
$memos = $this->getRelation('memos');
194-
195-
return $memos
196-
->mapWithKeys(static function (WorkflowMemo $memo): array {
190+
// Try typed table first (optimal for new runs)
191+
if ($this->relationLoaded('memos')) {
192+
$typed = $this->memos->mapWithKeys(static function (WorkflowMemo $memo) {
197193
return [
198194
$memo->key => $memo->getValue(),
199195
];
200-
})
201-
->toArray();
202-
}
196+
})->toArray();
203197

204-
/**
205-
* @return array<string, mixed>
206-
*/
207-
public function getSearchAttributesAttribute(mixed $value): array
208-
{
209-
return $this->getTypedSearchAttributes();
210-
}
198+
if (! empty($typed)) {
199+
return $typed;
200+
}
201+
}
211202

212-
/**
213-
* @return array<string, mixed>
214-
*/
215-
public function getMemoAttribute(mixed $value): array
216-
{
217-
return $this->getMemos();
203+
// Fallback to JSON blob (for old runs or if typed storage failed)
204+
return is_array($this->memo) ? $this->memo : [];
218205
}
219206

220207
/**
@@ -252,22 +239,4 @@ public function scopeWithSearchAttribute($query, string $key, mixed $value)
252239
}
253240
});
254241
}
255-
256-
/**
257-
* @return array<string, mixed>
258-
*/
259-
private function decodeVisibilityArrayAttribute(mixed $value): array
260-
{
261-
if (is_array($value)) {
262-
return $value;
263-
}
264-
265-
if (! is_string($value) || $value === '') {
266-
return [];
267-
}
268-
269-
$decoded = json_decode($value, true);
270-
271-
return is_array($decoded) ? $decoded : [];
272-
}
273242
}

src/V2/Support/DefaultWorkflowControlPlane.php

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,6 @@ public function start(string $workflowType, ?string $instanceId = null, array $o
201201
'last_history_sequence' => 0,
202202
]);
203203

204-
$this->seedTypedVisibilityMetadata(
205-
$run,
206-
is_array($memo) ? $memo : null,
207-
is_array($searchAttributes) ? $searchAttributes : null,
208-
);
209-
210204
$command = WorkflowCommand::record($instance, $run, $this->commandAttributes($commandContext, [
211205
'command_type' => CommandType::Start->value,
212206
'target_scope' => 'instance',
@@ -228,9 +222,6 @@ public function start(string $workflowType, ?string $instanceId = null, array $o
228222
'run_count' => $run->run_number,
229223
])->save();
230224

231-
$memoPayload = self::visibilityMetadataPayload($memo);
232-
$searchAttributesPayload = self::visibilityMetadataPayload($searchAttributes);
233-
234225
WorkflowHistoryEvent::record($run, HistoryEventType::StartAccepted, [
235226
'workflow_command_id' => $command->id,
236227
'workflow_instance_id' => $instance->id,
@@ -239,8 +230,8 @@ public function start(string $workflowType, ?string $instanceId = null, array $o
239230
'workflow_type' => $run->workflow_type,
240231
'business_key' => $run->business_key,
241232
'visibility_labels' => $run->visibility_labels,
242-
'memo' => $memoPayload,
243-
'search_attributes' => $searchAttributesPayload,
233+
'memo' => $run->memo,
234+
'search_attributes' => $run->search_attributes,
244235
'outcome' => $command->outcome?->value,
245236
], null, $command);
246237

@@ -252,8 +243,8 @@ public function start(string $workflowType, ?string $instanceId = null, array $o
252243
'workflow_command_id' => $command->id,
253244
'business_key' => $run->business_key,
254245
'visibility_labels' => $run->visibility_labels,
255-
'memo' => $memoPayload,
256-
'search_attributes' => $searchAttributesPayload,
246+
'memo' => $run->memo,
247+
'search_attributes' => $run->search_attributes,
257248
'execution_timeout_seconds' => $executionTimeoutSeconds,
258249
'run_timeout_seconds' => $runTimeoutSeconds,
259250
'execution_deadline_at' => $executionDeadlineAt?->toIso8601String(),
@@ -989,35 +980,4 @@ private function taskQuery(): \Illuminate\Database\Eloquent\Builder
989980
{
990981
return ConfiguredV2Models::query('task_model', WorkflowTask::class);
991982
}
992-
993-
/**
994-
* @param array<string, mixed>|null $memo
995-
* @param array<string, scalar|null>|null $searchAttributes
996-
*/
997-
private function seedTypedVisibilityMetadata(WorkflowRun $run, ?array $memo, ?array $searchAttributes): void
998-
{
999-
if (is_array($memo) && $memo !== []) {
1000-
app(MemoUpsertService::class)->upsert($run, new UpsertMemosCall($memo), 0);
1001-
$run->unsetRelation('memos');
1002-
}
1003-
1004-
if (is_array($searchAttributes) && $searchAttributes !== []) {
1005-
app(SearchAttributeUpsertService::class)->upsert(
1006-
$run,
1007-
new UpsertSearchAttributesCall($searchAttributes),
1008-
0,
1009-
);
1010-
$run->unsetRelation('searchAttributes');
1011-
}
1012-
}
1013-
1014-
/**
1015-
* @param array<string, mixed>|null $values
1016-
*
1017-
* @return array<string, mixed>|null
1018-
*/
1019-
private static function visibilityMetadataPayload(?array $values): ?array
1020-
{
1021-
return is_array($values) && $values !== [] ? $values : null;
1022-
}
1023983
}

src/V2/Support/DefaultWorkflowTaskBridge.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,8 +1608,6 @@ private function applyStartChildWorkflow(
16081608
'last_history_sequence' => 0,
16091609
]);
16101610

1611-
$this->inheritTypedVisibilityMetadata($run, $childRun);
1612-
16131611
$childInstance->forceFill([
16141612
'current_run_id' => $childRun->id,
16151613
])->save();
@@ -1846,8 +1844,6 @@ private function applyContinueAsNew(
18461844
'last_history_sequence' => 0,
18471845
]);
18481846

1849-
$this->inheritTypedVisibilityMetadata($run, $continuedRun);
1850-
18511847
$instance->forceFill([
18521848
'current_run_id' => $continuedRun->id,
18531849
'run_count' => $continuedRun->run_number,
@@ -2036,8 +2032,6 @@ private function startChildRetryIfAvailable(
20362032
'last_history_sequence' => 0,
20372033
]);
20382034

2039-
$this->inheritTypedVisibilityMetadata($failedChildRun, $retryRun);
2040-
20412035
$childInstance->forceFill([
20422036
'current_run_id' => $retryRun->id,
20432037
'run_count' => max((int) $childInstance->run_count, $nextRunNumber),
@@ -2976,13 +2970,4 @@ private static function nonEmptyString(mixed $value): ?string
29762970
? $value
29772971
: null;
29782972
}
2979-
2980-
private function inheritTypedVisibilityMetadata(WorkflowRun $sourceRun, WorkflowRun $targetRun): void
2981-
{
2982-
app(MemoUpsertService::class)->inheritFromParent($sourceRun, $targetRun, 1);
2983-
app(SearchAttributeUpsertService::class)->inheritFromParent($sourceRun, $targetRun, 1);
2984-
2985-
$targetRun->unsetRelation('memos');
2986-
$targetRun->unsetRelation('searchAttributes');
2987-
}
29882973
}

0 commit comments

Comments
 (0)