flyte icon indicating copy to clipboard operation
flyte copied to clipboard

bug: actions client ignores the run service's in-band status, skipping the terminal-status retry

Open pingsutw opened this issue 3 months ago • 4 comments

Why

InternalRunService.UpdateActionStatus reports failures in the response body, not as a transport error. The handler always returns a nil error and puts the failure in Status:

// runs/service/internal_run_service.go:204
func (s *RunService) UpdateActionStatus(...) (*connect.Response[workflow.UpdateActionStatusResponse], error) {
	resp := s.updateActionStatus(ctx, req.Msg)   // errors become resp.Status via statusFromError
	return connect.NewResponse(resp), nil        // <- always nil
}

Its only caller ignores that field and keys off the transport error alone:

// actions/k8s/client.go:840
if _, err := c.runClient.UpdateActionStatus(ctx, connect.NewRequest(statusReq)); err != nil {
	logger.Warnf(ctx, "Failed to update action status in run service for %s: %v", update.ActionID.Name, err)
} else if isTerminalPhase(update.Phase) && !update.IsDeleted {
	c.markTerminalStatusRecorded(ctx, taskAction)   // runs even when the run service rejected the update
}

So when the run service fails to record a terminal phase (a DB blip in UpdateActionPhase, or in mergeRunInfoOutput for a signalled condition), the executor treats it as success and patches flyte.org/terminal-status-recorded=true onto the TaskAction.

That label is what closes the door. shouldSkipTaskAction (actions/k8s/client.go:713) makes the informer skip every subsequent event for that CR — including the Delete event the garbage collector produces at TTL, which is the one retry the system actually has: buildActionUpdate preserves the terminal phase and SignalValue on deletes, so that event would otherwise re-issue the same UpdateActionStatus. The GC selects on LabelTerminationStatus/LabelCompletedTime (executor/pkg/controller/garbage_collector.go:109), not on terminal-status-recorded, so the CR is deleted regardless and the action is gone for good.

User-visible result: the action stays in its last non-terminal phase in the DB forever. The console shows it as running/paused long after the pod finished, and nothing anywhere errors — the executor logged success. Recovering requires editing the DB by hand.

Concrete example: works after the change, broken today

Same input: a terminal UpdateActionStatus where the run service hits a transient DB error.

today after the change
run service returns Status{Code: 13 (Internal)} in the response body same
executor sees err == nil → "success" non-zero Status.Code → logs a warning
CR label terminal-status-recorded=true patched not patched
GC delete event skipped by shouldSkipTaskAction delivered → status update retried
final DB phase stuck at RUNNING/PAUSED SUCCEEDED

What to change

  • actions/k8s/client.go:840 — treat a non-zero resp.Msg.GetStatus().GetCode() as a failure, so markTerminalStatusRecorded is skipped and the CR stays eligible for the GC delete-event retry:

    resp, err := c.runClient.UpdateActionStatus(ctx, connect.NewRequest(statusReq))
    switch {
    case err != nil:
    	logger.Warnf(ctx, "Failed to update action status for %s: %v", update.ActionID.Name, err)
    case resp.Msg.GetStatus().GetCode() != 0:
    	logger.Warnf(ctx, "Run service rejected status update for %s: %s",
    		update.ActionID.Name, resp.Msg.GetStatus().GetMessage())
    case isTerminalPhase(update.Phase) && !update.IsDeleted:
    	if err := c.markTerminalStatusRecorded(ctx, taskAction); err != nil {
    		logger.Warnf(ctx, "Failed to mark terminal status recorded for %s: %v", update.ActionID.Name, err)
    	}
    }
    
  • actions/k8s/client.go:806 — the parent-promotion call has the same unchecked pattern. No label is patched there, so it only costs a missing log line; worth fixing in the same pass for consistency.

  • actions/k8s/client_test.go — add a case where the mocked run client returns a response carrying a non-zero Status.Code, asserting the TaskAction is not labelled terminal-status-recorded. The existing tests around TestNotifyRunService_* (line 118 onward) show the mock setup.

Outcome

  • [ ] A terminal status update rejected by the run service does not label the TaskAction flyte.org/terminal-status-recorded
  • [ ] The GC delete event therefore still reaches notifyRunService, retrying the status update
  • [ ] The rejection is logged with the run service's status message, not silently swallowed
  • [ ] A test covers the non-zero-Status.Code path

Getting started

  • Reproduce (unit): in actions/k8s/client_test.go, have the mock return &connect.Response[workflow.UpdateActionStatusResponse]{Msg: &workflow.UpdateActionStatusResponse{ Status: &status.Status{Code: int32(connect.CodeInternal), Message: "boom"}}} with a nil error, then assert on the CR's labels. Today the label is patched; after the fix it isn't.
  • Relevant code: notifyRunService in actions/k8s/client.go (the two call sites at 806 and 840), shouldSkipTaskAction at 713, markTerminalStatusRecorded at 904. The producer side is UpdateActionStatus/statusFromError in runs/service/internal_run_service.go.
  • Note: connect.Response{} with a nil Msg is safe to call GetStatus() on — protobuf getters are nil-receiver safe — so existing tests that return an empty response keep passing unchanged.
  • Test: go test ./actions/k8s/...
  • Setup: CONTRIBUTING.md

pingsutw avatar Aug 20 '26 04:08 pingsutw

It seems likely that the current implementation of notifyRunService in actions/k8s/client.go only checks for transport errors when calling UpdateActionStatus, ignoring the in-band status code in the response body. As a result, even if the run service rejects a terminal status update (e.g., due to a DB error), the executor still marks the TaskAction as terminal-status-recorded, preventing any further retries—including the crucial retry on GC delete events. This can leave the action stuck in a non-terminal phase in the DB, with no visible error, as described in your example. The proposed fix is to check resp.Msg.GetStatus().GetCode() and only mark the TaskAction as terminal if the status code is zero, logging a warning otherwise. This ensures that failed updates are retried and not silently swallowed, and that the GC delete event can trigger another attempt.

My understanding is that the data sources confirm the relevant code paths and test patterns, but do not show the fix already implemented. The test guidance and code references you provided align with the structure in the sources, such as the use of notifyRunService, label patching, and the test setup in client_test.go (see here). Would you like a step-by-step breakdown of how to implement and test this fix?

Sources:


This is an AI-generated response and your feedback is appreciated! Please leave a 👍 if this is helpful and 👎 if it is not.

Mention @herald to ask follow-up questions. See runllm.com for more!

runllm avatar Aug 20 '26 04:08 runllm

I'd like to work on this, could you assign it to me?

Fayupable avatar Aug 20 '26 10:08 Fayupable

I'd like to work on this, could you assign it to me?

@Fayupable You can comment #take and the bot will automatically assign it to you.

davidlin20dev avatar Aug 20 '26 15:08 davidlin20dev

#take

Fayupable avatar Aug 20 '26 16:08 Fayupable